1
0
mirror of https://github.com/nothings/stb synced 2025-03-12 16:11:11 -04:00

introduce unit tests

This commit is contained in:
Michael Mestnik 2018-10-12 12:47:16 -05:00
parent e6afb9cbae
commit 8137345fa4
18 changed files with 245 additions and 0 deletions

6
tests/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
/a.out
/test_c_compilation.o
/test_cpp_compilation.o
image_pnm_ascii
image_pnm
image_pnm_8bit

View File

@ -5,3 +5,7 @@ CPPFLAGS = -Wno-write-strings -DSTB_DIVIDE_TEST
all:
$(CC) $(INCLUDES) $(CFLAGS) ../stb_vorbis.c test_c_compilation.c -lm
$(CC) $(INCLUDES) $(CPPFLAGS) test_cpp_compilation.cpp -lm -lstdc++
$(MAKE) -C tx all || true
prove -v -f tx || true
$(MAKE) -C t all
prove -f

11
tests/images/feep.pgm Normal file
View File

@ -0,0 +1,11 @@
P2
# feep.pgm
24 7
15
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0
0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0
0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15 0
0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 0 0
0 3 0 0 0 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

8
tests/images/feep.ppm Normal file
View File

@ -0,0 +1,8 @@
P3
# feep.ppm
4 4
15
0 0 0 0 0 0 0 0 0 15 0 15
0 0 0 0 15 7 0 0 0 0 0 0
0 0 0 0 0 0 0 15 7 0 0 0
15 0 15 0 0 0 0 0 0 0 0 0

BIN
tests/images/feepP5.pgm Normal file

Binary file not shown.

17
tests/images/feepP58bit.h Normal file
View File

@ -0,0 +1,17 @@
unsigned char feepP58bit[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x00, 0x00, 0x77, 0x77, 0x77, 0x77,
0x00, 0x00, 0xbb, 0xbb, 0xbb, 0xbb, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00,
0x00, 0x00, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
0x00, 0x00, 0x33, 0x33, 0x33, 0x00, 0x00, 0x00, 0x77, 0x77, 0x77, 0x00,
0x00, 0x00, 0xbb, 0xbb, 0xbb, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00,
0x00, 0x00, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x77, 0x77, 0x77,
0x00, 0x00, 0xbb, 0xbb, 0xbb, 0xbb, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00
};

BIN
tests/images/feepP58bit.pgm Normal file

Binary file not shown.

BIN
tests/images/feepP6.ppm Normal file

Binary file not shown.

View File

@ -0,0 +1,6 @@
unsigned char feepP68bit[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
0x00, 0x00, 0x00, 0x00, 0xff, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x77, 0x00, 0x00, 0x00,
0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

BIN
tests/images/feepP68bit.ppm Normal file

Binary file not shown.

11
tests/t/Makefile Normal file
View File

@ -0,0 +1,11 @@
INCLUDES = -I../..
CFLAGS = $(INCLUDES) -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -DSTB_DIVIDE_TEST
CPPFLAGS = $(INCLUDES) -Wno-write-strings -DSTB_DIVIDE_TEST
LDLIBS = -lm
all: clean image_pnm_8bit
clean:
rm -f image_pnm_8bit
.PHONY: all clean

55
tests/t/image_pnm_8bit.c Normal file
View File

@ -0,0 +1,55 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <limits.h>
#include <assert.h>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#include "../images/feepP58bit.h"
#include "../images/feepP68bit.h"
int main() {
printf("1..4\n");
{
int width, height, channels;
unsigned char *image = stbi_load("images/feepP58bit.pgm",
&width,
&height,
&channels,
0);
if(width != 24 || height != 7 || channels != 1)
printf("not ");
printf("ok 1 - read grayscale image header\n");
if(!(image && 0 == memcmp(image, feepP58bit, sizeof(feepP58bit))))
printf("not ");
printf("ok 2 - read grayscale image data\n");
stbi_image_free(image);
}
{
int width, height, channels;
unsigned char *image = stbi_load("images/feepP68bit.ppm",
&width,
&height,
&channels,
0);
if(width != 4 || height != 4 || channels != 3)
printf("not ");
printf("ok 3 - read RGB image header\n");
if(!(image && 0 == memcmp(image, feepP68bit, sizeof(feepP68bit))))
printf("not ");
printf("ok 4 - read RGB image data\n");
stbi_image_free(image);
}
}

2
tests/t/image_pnm_8bit.t Normal file
View File

@ -0,0 +1,2 @@
__FILE__ =~ /([\w.\/-]+)\.t/;
exec($1) or die("exec $1");

11
tests/tx/Makefile Normal file
View File

@ -0,0 +1,11 @@
INCLUDES = -I../..
CFLAGS = $(INCLUDES) -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -DSTB_DIVIDE_TEST
CPPFLAGS = $(INCLUDES) -Wno-write-strings -DSTB_DIVIDE_TEST
LDLIBS = -lm
all: clean image_pnm image_pnm_ascii
clean:
rm -f image_pnm image_pnm_ascii
.PHONY: all clean

55
tests/tx/image_pnm.c Normal file
View File

@ -0,0 +1,55 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <limits.h>
#include <assert.h>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#include "../images/feepP58bit.h"
#include "../images/feepP68bit.h"
int main() {
printf("1..4\n");
{
int width, height, channels;
unsigned char *image = stbi_load("images/feepP5.pgm",
&width,
&height,
&channels,
0);
if(width != 24 || height != 7 || channels != 1)
printf("not ");
printf("ok 1 - read grayscale image header\n");
if(!(image && 0 == memcmp(image, feepP58bit, sizeof(feepP58bit))))
printf("not ");
printf("ok 2 - read grayscale image data\n");
stbi_image_free(image);
}
{
int width, height, channels;
unsigned char *image = stbi_load("images/feepP6.ppm",
&width,
&height,
&channels,
0);
if(width != 4 || height != 4 || channels != 3)
printf("not ");
printf("ok 3 - read RGB image header\n");
if(!(image && 0 == memcmp(image, feepP68bit, sizeof(feepP68bit))))
printf("not ");
printf("ok 4 - read RGB image data\n");
stbi_image_free(image);
}
}

2
tests/tx/image_pnm.t Normal file
View File

@ -0,0 +1,2 @@
__FILE__ =~ /([\w.\/-]+)\.t/;
exec($1) or die("exec $1");

View File

@ -0,0 +1,55 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <limits.h>
#include <assert.h>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#include "../images/feepP58bit.h"
#include "../images/feepP68bit.h"
int main() {
printf("1..4\n");
{
int width, height, channels;
unsigned char *image = stbi_load("images/feep.pgm",
&width,
&height,
&channels,
0);
if(width != 24 || height != 7 || channels != 1)
printf("not ");
printf("ok 1 - read grayscale image header\n");
if(!(image && 0 == memcmp(image, feepP58bit, sizeof(feepP58bit))))
printf("not ");
printf("ok 2 - read grayscale image data\n");
stbi_image_free(image);
}
{
int width, height, channels;
unsigned char *image = stbi_load("images/feep.ppm",
&width,
&height,
&channels,
0);
if(width != 4 || height != 4 || channels != 3)
printf("not ");
printf("ok 3 - read RGB image header\n");
if(!(image && 0 == memcmp(image, feepP68bit, sizeof(feepP68bit))))
printf("not ");
printf("ok 4 - read RGB image data\n");
stbi_image_free(image);
}
}

View File

@ -0,0 +1,2 @@
__FILE__ =~ /([\w.\/-]+)\.t/;
exec($1) or die("exec $1");