64 lines
1.3 KiB
C
Raw Normal View History

#include <stdio.h>
#include <string.h>
#include <file/nbio.h>
2015-02-15 23:21:35 +01:00
static void nbio_write_test(void)
{
size_t size;
2015-02-15 23:23:46 +01:00
bool looped = false;
2015-02-15 23:21:35 +01:00
void* ptr = NULL;
struct nbio_t* write = nbio_open("test.bin", NBIO_WRITE);
nbio_resize(write, 1024*1024);
ptr = nbio_get_ptr(write, &size);
if (size != 1024*1024)
puts("ERROR: wrong size (1)");
memset(ptr, 0x42, 1024*1024);
nbio_begin_write(write);
while (!nbio_iterate(write)) looped=true;
2015-02-15 23:21:35 +01:00
if (!looped)
puts("Write finished immediately?");
nbio_free(write);
}
static void nbio_read_test(void)
{
size_t size;
2015-02-15 23:23:46 +01:00
bool looped = false;
2015-02-15 23:21:35 +01:00
struct nbio_t* read = nbio_open("test.bin", NBIO_READ);
2015-02-15 23:25:17 +01:00
void* ptr = nbio_get_ptr(read, &size);
2015-02-15 23:21:35 +01:00
if (size != 1024*1024)
puts("ERROR: wrong size (2)");
if (ptr)
puts("Read pointer is available before iterating?");
nbio_begin_read(read);
while (!nbio_iterate(read)) looped=true;
2015-02-15 23:24:16 +01:00
if (!looped)
puts("Read finished immediately?");
2015-02-15 23:21:35 +01:00
ptr = nbio_get_ptr(read, &size);
2015-02-15 23:24:16 +01:00
2015-02-15 23:21:35 +01:00
if (size != 1024*1024)
puts("ERROR: wrong size (3)");
if (*(char*)ptr != 0x42 || memcmp(ptr, (char*)ptr+1, 1024*1024-1))
puts("ERROR: wrong data");
nbio_free(read);
}
int main(void)
{
nbio_write_test();
nbio_read_test();
}