summaryrefslogtreecommitdiffstats
path: root/libdimension/tests/png.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2014-05-30 15:48:29 -0400
committerTavian Barnes <tavianator@tavianator.com>2014-05-30 15:48:29 -0400
commit45e219eac23ea4a8181f68300fed693d9ac361a0 (patch)
tree06b72b3ca9a97b1352537836a2a42af7033ae6b1 /libdimension/tests/png.c
parentf61c7c75c3c7ff4a329315700d3efa1d77bafa6d (diff)
downloaddimension-45e219eac23ea4a8181f68300fed693d9ac361a0.tar.xz
canvas: Use pool.
Diffstat (limited to 'libdimension/tests/png.c')
-rw-r--r--libdimension/tests/png.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/libdimension/tests/png.c b/libdimension/tests/png.c
index 1bd418f..ed64b39 100644
--- a/libdimension/tests/png.c
+++ b/libdimension/tests/png.c
@@ -1,5 +1,5 @@
/*************************************************************************
- * Copyright (C) 2009-2011 Tavian Barnes <tavianator@tavianator.com> *
+ * Copyright (C) 2009-2014 Tavian Barnes <tavianator@tavianator.com> *
* *
* This file is part of The Dimension Test Suite. *
* *
@@ -24,17 +24,20 @@
int
main(void)
{
+ int ret = EXIT_SUCCESS;
+
/* Treat warnings as errors for tests */
dmnsn_die_on_warnings(true);
/* Allocate our canvas */
- dmnsn_canvas *canvas = dmnsn_new_canvas(768, 480);
+ dmnsn_pool *pool = dmnsn_new_pool();
+ dmnsn_canvas *canvas = dmnsn_new_canvas(pool, 768, 480);
/* Optimize the canvas for PNG export */
if (dmnsn_png_optimize_canvas(canvas) != 0) {
- dmnsn_delete_canvas(canvas);
fprintf(stderr, "--- Couldn't optimize canvas for PNG! ---\n");
- return EXIT_FAILURE;
+ ret = EXIT_FAILURE;
+ goto exit;
}
/* Paint the test pattern */
@@ -45,20 +48,19 @@ main(void)
printf("Writing scene to PNG\n");
FILE *ofile = fopen("png1.png", "wb");
if (!ofile) {
- dmnsn_delete_canvas(canvas);
fprintf(stderr, "--- Couldn't open 'png1.png' for writing! ---\n");
- return EXIT_FAILURE;
+ ret = EXIT_FAILURE;
+ goto exit;
}
if (dmnsn_png_write_canvas(canvas, ofile) != 0) {
- fclose(ofile);
- dmnsn_delete_canvas(canvas);
fprintf(stderr, "--- Writing canvas to PNG failed! ---\n");
- return EXIT_FAILURE;
+ fclose(ofile);
+ ret = EXIT_FAILURE;
+ goto exit;
}
fclose(ofile);
- dmnsn_delete_canvas(canvas);
/*
* Now test PNG import/export
@@ -70,14 +72,16 @@ main(void)
FILE *ifile = fopen("png1.png", "rb");
if (!ifile) {
fprintf(stderr, "--- Couldn't open 'png1.png' for reading! ---\n");
- return EXIT_FAILURE;
+ ret = EXIT_FAILURE;
+ goto exit;
}
- canvas = dmnsn_png_read_canvas(ifile);
+ canvas = dmnsn_png_read_canvas(pool, ifile);
if (!canvas) {
- fclose(ifile);
fprintf(stderr, "--- Reading canvas from PNG failed! ---\n");
- return EXIT_FAILURE;
+ fclose(ifile);
+ ret = EXIT_FAILURE;
+ goto exit;
}
fclose(ifile);
@@ -88,19 +92,20 @@ main(void)
ofile = fopen("png2.png", "wb");
if (!ofile) {
fprintf(stderr, "--- Couldn't open 'png2.png' for writing! ---\n");
- dmnsn_delete_canvas(canvas);
- return EXIT_FAILURE;
+ ret = EXIT_FAILURE;
+ goto exit;
}
if (dmnsn_png_write_canvas(canvas, ofile) != 0) {
- fclose(ofile);
- dmnsn_delete_canvas(canvas);
fprintf(stderr, "--- Writing canvas to PNG failed! ---\n");
- return EXIT_FAILURE;
+ fclose(ofile);
+ ret = EXIT_FAILURE;
+ goto exit;
}
fclose(ofile);
- dmnsn_delete_canvas(canvas);
- return EXIT_SUCCESS;
+ exit:
+ dmnsn_delete_pool(pool);
+ return ret;
}