Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
dloebl committed Jun 18, 2024
1 parent 43976ce commit 4e532e4
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tests = [
{ 'name' : 'min_size', 'seed_should_fail' : false},
{ 'name' : 'more_than_256_colors', 'seed_should_fail' : false},
{ 'name' : 'noise256', 'seed_should_fail' : false},
{ 'name' : 'noise256_large', 'seed_should_fail' : false},
{ 'name' : 'noise6', 'seed_should_fail' : false},
{ 'name' : 'noise6_interlaced', 'seed_should_fail' : false},
{ 'name' : 'noloop', 'seed_should_fail' : false},
Expand Down
66 changes: 66 additions & 0 deletions tests/noise256_large.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>

#include "cgif.h"

#define WIDTH 3000
#define HEIGHT 3000

static uint64_t seed;

// unsigned integer overflow expected
__attribute__((no_sanitize("integer")))
int psdrand(void) {
// simple pseudo random function from musl libc
seed = 6364136223846793005ULL * seed + 1;
return seed >> 33;
}

int main(void) {
CGIF* pGIF;
CGIF_Config gConfig;
CGIF_FrameConfig fConfig;
uint8_t* pImageData;
cgif_result r;
uint8_t aPalette[256 * 3];

seed = 22;
for(int i = 0; i < 256; ++i) {
aPalette[i * 3] = psdrand() % 256;
aPalette[i * 3 + 1] = psdrand() % 256;
aPalette[i * 3 + 2] = psdrand() % 256;
}
memset(&gConfig, 0, sizeof(CGIF_Config));
memset(&fConfig, 0, sizeof(CGIF_FrameConfig));
gConfig.width = WIDTH;
gConfig.height = HEIGHT;
gConfig.pGlobalPalette = aPalette;
gConfig.numGlobalPaletteEntries = 256;
gConfig.path = "noise256_large.gif";
//
// create new GIF
pGIF = cgif_newgif(&gConfig);
if(pGIF == NULL) {
fputs("failed to create new GIF via cgif_newgif()\n", stderr);
return 1;
}
//
// add frames to GIF
pImageData = malloc(WIDTH * HEIGHT);
for(int i = 0; i < WIDTH * HEIGHT; ++i) pImageData[i] = psdrand() % 256;
fConfig.pImageData = pImageData;
r = cgif_addframe(pGIF, &fConfig);
free(pImageData);
//
// write GIF to file
r = cgif_close(pGIF); // free allocated space at the end of the session

// check for errors
if(r != CGIF_OK) {
fprintf(stderr, "failed to create GIF. error code: %d\n", r);
return 2;
}
return 0;
}
1 change: 1 addition & 0 deletions tests/tests.sha256
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ eeb9acd181da401748c9f39c59dbb5ecd71fd6f8f1685002f767de2ec0329bf4 min_color_tabl
b263ce6bde416426b6676c320846f73870d40b2125bfc9630087c3c54df21ac8 min_size.gif
5244e4ca77ea3923d27e790b9dddb6032a686e0272ba3d78ff5fa4af0523647b more_than_256_colors.gif
11c8de343ccd528e319afbe3ec0d0c657c1e6292faf6cb318713bcaf2979ab0d noise256.gif
75a2a7b04a21b785977fb2506e6468478418703835876755e78453223820b924 noise256_large.gif
ff1da19b0448af07d8561f0ee62b184f99ac7dcb75f1a2215474190ec6648901 noise6.gif
14cd8b2486e725d4136e1af656aa2398a882694fd1774ebfb23c57dae5ae00da noise6_interlaced.gif
98ec5ef9223f2c51bc2f4f94da4468f3b1e3c537a64d8050649787aaf433d13d noloop.gif
Expand Down

0 comments on commit 4e532e4

Please sign in to comment.