summaryrefslogtreecommitdiffstats
path: root/libdimension/tests
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
parentf61c7c75c3c7ff4a329315700d3efa1d77bafa6d (diff)
downloaddimension-45e219eac23ea4a8181f68300fed693d9ac361a0.tar.xz
canvas: Use pool.
Diffstat (limited to 'libdimension/tests')
-rw-r--r--libdimension/tests/gl.c33
-rw-r--r--libdimension/tests/png.c47
-rw-r--r--libdimension/tests/render.c12
3 files changed, 48 insertions, 44 deletions
diff --git a/libdimension/tests/gl.c b/libdimension/tests/gl.c
index 52b3256..c46eada 100644
--- a/libdimension/tests/gl.c
+++ b/libdimension/tests/gl.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. *
* *
@@ -27,14 +27,8 @@ main(void)
dmnsn_die_on_warnings(true);
/* Allocate our canvas */
- dmnsn_canvas *canvas = dmnsn_new_canvas(768, 480);
-
- /* Optimize the canvas for GL drawing */
- if (dmnsn_gl_optimize_canvas(canvas) != 0) {
- dmnsn_delete_canvas(canvas);
- fprintf(stderr, "--- Couldn't optimize canvas for GL! ---\n");
- return EXIT_FAILURE;
- }
+ dmnsn_pool *pool = dmnsn_new_pool();
+ dmnsn_canvas *canvas = dmnsn_new_canvas(pool, 768, 480);
/* Paint the test pattern */
dmnsn_paint_test_canvas(canvas);
@@ -43,7 +37,7 @@ main(void)
dmnsn_display *display = dmnsn_new_display(canvas);
if (!display) {
fprintf(stderr, "--- WARNING: Couldn't initialize X or glX! ---\n");
- dmnsn_delete_canvas(canvas);
+ dmnsn_delete_pool(pool);
return EXIT_SUCCESS;
}
@@ -51,23 +45,28 @@ main(void)
printf("Drawing to OpenGL\n");
if (dmnsn_gl_write_canvas(canvas) != 0) {
dmnsn_delete_display(display);
- dmnsn_delete_canvas(canvas);
+ dmnsn_delete_pool(pool);
fprintf(stderr, "--- Drawing to OpenGL failed! ---\n");
return EXIT_FAILURE;
}
dmnsn_display_flush(display);
- dmnsn_delete_canvas(canvas);
/*
* Now test GL import/export
*/
+ /* Optimize the canvas for GL drawing */
+ if (dmnsn_gl_optimize_canvas(canvas) != 0) {
+ dmnsn_delete_pool(pool);
+ fprintf(stderr, "--- Couldn't optimize canvas for GL! ---\n");
+ return EXIT_FAILURE;
+ }
+
/* Read the image back from OpenGL */
printf("Reading from OpenGL\n");
- canvas = dmnsn_gl_read_canvas(0, 0, 768, 480);
- if (!canvas) {
+ if (dmnsn_gl_read_canvas(canvas, 0, 0) != 0) {
dmnsn_delete_display(display);
- dmnsn_delete_canvas(canvas);
+ dmnsn_delete_pool(pool);
fprintf(stderr, "--- Reading from OpenGL failed! ---\n");
return EXIT_FAILURE;
}
@@ -76,13 +75,13 @@ main(void)
printf("Drawing to OpenGL\n");
if (dmnsn_gl_write_canvas(canvas) != 0) {
dmnsn_delete_display(display);
- dmnsn_delete_canvas(canvas);
+ dmnsn_delete_pool(pool);
fprintf(stderr, "--- Drawing to OpenGL failed! ---\n");
return EXIT_FAILURE;
}
dmnsn_display_flush(display);
dmnsn_delete_display(display);
- dmnsn_delete_canvas(canvas);
+ dmnsn_delete_pool(pool);
return EXIT_SUCCESS;
}
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;
}
diff --git a/libdimension/tests/render.c b/libdimension/tests/render.c
index e68dcc4..f5ba685 100644
--- a/libdimension/tests/render.c
+++ b/libdimension/tests/render.c
@@ -36,9 +36,9 @@ dmnsn_test_scene_set_defaults(dmnsn_scene *scene)
}
static void
-dmnsn_test_scene_add_canvas(dmnsn_scene *scene)
+dmnsn_test_scene_add_canvas(dmnsn_pool *pool, dmnsn_scene *scene)
{
- scene->canvas = dmnsn_new_canvas(768, 480);
+ scene->canvas = dmnsn_new_canvas(pool, 768, 480);
}
static void
@@ -69,7 +69,7 @@ dmnsn_test_scene_add_camera(dmnsn_scene *scene)
}
static void
-dmnsn_test_scene_add_background(dmnsn_scene *scene)
+dmnsn_test_scene_add_background(dmnsn_pool *pool, dmnsn_scene *scene)
{
dmnsn_pattern *sky_gradient = dmnsn_new_gradient_pattern(dmnsn_y);
dmnsn_map *sky_gradient_pigment_map = dmnsn_new_pigment_map();
@@ -78,7 +78,7 @@ dmnsn_test_scene_add_background(dmnsn_scene *scene)
dmnsn_pigment *png_pigment;
FILE *png = fopen("png2.png", "rb");
if (png) {
- png_canvas = dmnsn_png_read_canvas(png);
+ png_canvas = dmnsn_png_read_canvas(pool, png);
fclose(png);
}
if (png_canvas) {
@@ -305,9 +305,9 @@ dmnsn_new_test_scene(dmnsn_pool *pool)
{
dmnsn_scene *scene = dmnsn_new_scene(pool);
dmnsn_test_scene_set_defaults(scene);
- dmnsn_test_scene_add_canvas(scene);
+ dmnsn_test_scene_add_canvas(pool, scene);
dmnsn_test_scene_add_camera(scene);
- dmnsn_test_scene_add_background(scene);
+ dmnsn_test_scene_add_background(pool, scene);
dmnsn_test_scene_add_lights(scene);
dmnsn_test_scene_add_objects(scene);
return scene;