Split up rpng_nbio.c test code to separate file

This commit is contained in:
twinaphex 2015-02-20 16:36:00 +01:00
parent 7f10904809
commit a3c5142040
3 changed files with 1215 additions and 31 deletions

View File

@ -1,6 +1,6 @@
TARGET := rpng
SOURCES := $(wildcard *.c)
SOURCES := rpng.c rpng_test.c
OBJS := $(SOURCES:.c=.o)
CFLAGS += -Wall -pedantic -std=gnu99 -O0 -g -DHAVE_ZLIB -DHAVE_ZLIB_DEFLATE -DRPNG_TEST -I../../include

View File

@ -45,8 +45,6 @@
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#endif
//#define NONBLOCKING_TEST
static const uint8_t png_magic[8] = {
0x89, 'P', 'N', 'G', 0x0d, 0x0a, 0x1a, 0x0a,
};
@ -794,10 +792,6 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
unsigned *width, unsigned *height)
{
long pos, file_len;
#ifdef NONBLOCKING_TEST
uint8_t *buff_data = NULL;
struct nbio_t* nbread = NULL;
#endif
uint8_t *inflate_buf = NULL;
struct idat_buffer idat_buf = {0};
struct png_ihdr ihdr = {0};
@ -808,22 +802,6 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
bool has_plte = false;
bool ret = true;
FILE *file;
#ifdef NONBLOCKING_TEST
{
size_t size = 0;
bool looped = false;
nbread = nbio_open(path, NBIO_READ);
void* ptr = nbio_get_ptr(nbread, &size);
nbio_begin_read(nbread);
while (!nbio_iterate(nbread)) looped=true;
ptr = nbio_get_ptr(nbread, &size);
(void)ptr;
(void)looped;
buff_data = (uint8_t*)ptr;
}
#endif
file = fopen(path, "rb");
if (!file)
@ -839,13 +817,8 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
unsigned i;
char header[8];
#ifdef NONBLOCKING_TEST
for (i = 0; i < 8; i++)
header[i] = buff_data[i];
#else
if (fread(header, 1, sizeof(header), file) != sizeof(header))
return false;
#endif
if (memcmp(header, png_magic, sizeof(png_magic)) != 0)
return false;
@ -883,9 +856,6 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
width, height);
end:
#ifdef NONBLOCKING_TEST
nbio_free(nbread);
#endif
if (file)
fclose(file);
if (!ret)

File diff suppressed because it is too large Load Diff