mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-23 11:18:25 +00:00
nbio_test.c - cleanup
This commit is contained in:
parent
3b539cd2f1
commit
ddf24f90d8
105
nbio/nbio_test.c
105
nbio/nbio_test.c
@ -2,48 +2,67 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
static void nbio_write_test(void)
|
||||
{
|
||||
struct nbio_t* write = nbio_open("test.bin", NBIO_WRITE);
|
||||
nbio_resize(write, 1024*1024);
|
||||
|
||||
size_t size;
|
||||
void* ptr = nbio_get_ptr(write, &size);
|
||||
if (size != 1024*1024) puts("ERROR: wrong size (1)");
|
||||
|
||||
memset(ptr, 0x42, 1024*1024);
|
||||
nbio_begin_write(write);
|
||||
|
||||
size_t prog;
|
||||
bool looped=false;
|
||||
while (!nbio_iterate(write, &prog, &size))
|
||||
{
|
||||
printf("%u/%u\n", (unsigned)prog, (unsigned)size);
|
||||
looped=true;
|
||||
}
|
||||
if (!looped) puts("Write finished immediately?");
|
||||
nbio_free(write);
|
||||
|
||||
|
||||
struct nbio_t* read = nbio_open("test.bin", NBIO_READ);
|
||||
|
||||
ptr = nbio_get_ptr(read, &size);
|
||||
if (size != 1024*1024) puts("ERROR: wrong size (2)");
|
||||
if (ptr) puts("Read pointer is available before iterating?");
|
||||
|
||||
nbio_begin_read(read);
|
||||
|
||||
looped=false;
|
||||
while (!nbio_iterate(read, &prog, &size))
|
||||
{
|
||||
printf("%u/%u\n", (unsigned)prog, (unsigned)size);
|
||||
looped=true;
|
||||
}
|
||||
if (!looped) puts("Read finished immediately?");
|
||||
|
||||
ptr = nbio_get_ptr(read, &size);
|
||||
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);
|
||||
size_t size, prog;
|
||||
bool looped=false;
|
||||
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, &prog, &size))
|
||||
{
|
||||
printf("%u/%u\n", (unsigned)prog, (unsigned)size);
|
||||
looped=true;
|
||||
}
|
||||
|
||||
if (!looped)
|
||||
puts("Write finished immediately?");
|
||||
|
||||
nbio_free(write);
|
||||
}
|
||||
|
||||
static void nbio_read_test(void)
|
||||
{
|
||||
size_t size, prog;
|
||||
bool looped=false;
|
||||
struct nbio_t* read = nbio_open("test.bin", NBIO_READ);
|
||||
void *ptr = nbio_get_ptr(read, &size);
|
||||
|
||||
if (size != 1024*1024)
|
||||
puts("ERROR: wrong size (2)");
|
||||
if (ptr)
|
||||
puts("Read pointer is available before iterating?");
|
||||
|
||||
nbio_begin_read(read);
|
||||
|
||||
looped=false;
|
||||
while (!nbio_iterate(read, &prog, &size))
|
||||
{
|
||||
printf("%u/%u\n", (unsigned)prog, (unsigned)size);
|
||||
looped=true;
|
||||
}
|
||||
if (!looped) puts("Read finished immediately?");
|
||||
|
||||
ptr = nbio_get_ptr(read, &size);
|
||||
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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user