summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/Makefile.am8
-rw-r--r--tests/png.c234
-rw-r--r--tests/pngxx.cpp113
-rw-r--r--tests/raytrace.c93
-rw-r--r--tests/raytracexx.cpp49
5 files changed, 125 insertions, 372 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 073e9b8..f4c4107 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -23,8 +23,6 @@ check_PROGRAMS = warning-test \
error-test \
png-test \
pngxx-test \
- raytrace-test \
- raytracexx-test \
gl-test \
glxx-test
TESTS = $(check_PROGRAMS)
@@ -53,12 +51,6 @@ png_test_LDADD = ./libdimension-tests.la
pngxx_test_SOURCES = pngxx.cpp
pngxx_test_LDADD = ./libdimensionxx-tests.la
-raytrace_test_SOURCES = raytrace.c
-raytrace_test_LDADD = ./libdimension-tests.la
-
-raytracexx_test_SOURCES = raytracexx.cpp
-raytracexx_test_LDADD = ./libdimensionxx-tests.la
-
gl_test_SOURCES = gl.c
gl_test_LDADD = ./libdimension-tests.la
diff --git a/tests/png.c b/tests/png.c
index a2f647a..e5641f5 100644
--- a/tests/png.c
+++ b/tests/png.c
@@ -17,181 +17,139 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
-/* Test PNG file I/O */
-
#include "tests.h"
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
int
main() {
- dmnsn_canvas *canvas;
dmnsn_progress *progress;
- dmnsn_color color;
- dmnsn_CIE_xyY xyY;
- dmnsn_CIE_Lab Lab;
- dmnsn_CIE_Luv Luv;
- dmnsn_sRGB sRGB;
- FILE *ofile, *ifile;
- unsigned int i, j;
- const unsigned int x = 333, y = 300;
+ FILE *ifile, *ofile;
+ dmnsn_scene *scene;
+ dmnsn_canvas *canvas;
/* Set the resilience low for tests */
dmnsn_set_resilience(DMNSN_SEVERITY_LOW);
- /* Allocate a canvas */
- canvas = dmnsn_new_canvas(3*x, y);
- if (!canvas) {
- fprintf(stderr, "--- Allocation of canvas failed! ---\n");
- return EXIT_FAILURE;
- }
+ /* Render the scene */
+ {
+ /* Allocate our default scene */
+ scene = dmnsn_new_default_scene();
+ if (!scene) {
+ fprintf(stderr, "--- Allocation of default scene failed! ---\n");
+ return EXIT_FAILURE;
+ }
- /* 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;
- }
+ /* Optimize the canvas for PNG export */
+ if (dmnsn_png_optimize_canvas(scene->canvas) != 0) {
+ dmnsn_delete_default_scene(scene);
+ fprintf(stderr, "--- Couldn't optimize canvas for PNG! ---\n");
+ return EXIT_FAILURE;
+ }
- for (i = 0; i < x; ++i) {
- for (j = 0; j < y; ++j) {
- /*
- * CIE xyY colorspace
- */
- xyY.Y = 0.5;
- xyY.x = ((double)i)/(x - 1);
- xyY.y = ((double)j)/(y - 1);
-
- color = dmnsn_color_from_xyY(xyY);
- sRGB = dmnsn_sRGB_from_color(color);
-
- if (sRGB.R > 1.0 || sRGB.G > 1.0 || sRGB.B > 1.0
- || sRGB.R < 0.0 || sRGB.G < 0.0 || sRGB.B < 0.0) {
- /* Out of sRGB gamut */
- color.trans = 0.5;
- }
-
- dmnsn_set_pixel(canvas, i, j, color);
-
- /*
- * CIE Lab colorspace
- */
- Lab.L = 75.0;
- Lab.a = 200.0*(((double)i)/(x - 1) - 0.5);
- Lab.b = 200.0*(((double)j)/(y - 1) - 0.5);
-
- color = dmnsn_color_from_Lab(Lab, dmnsn_whitepoint);
- sRGB = dmnsn_sRGB_from_color(color);
-
- if (sRGB.R > 1.0 || sRGB.G > 1.0 || sRGB.B > 1.0
- || sRGB.R < 0.0 || sRGB.G < 0.0 || sRGB.B < 0.0) {
- /* Out of sRGB gamut */
- color.trans = 0.5;
- }
-
- dmnsn_set_pixel(canvas, i + x, j, color);
-
- /*
- * CIE Luv colorspace
- */
- Luv.L = 75.0;
- Luv.u = 200.0*(((double)i)/(x - 1) - 0.5);
- Luv.v = 200.0*(((double)j)/(y - 1) - 0.5);
-
- color = dmnsn_color_from_Luv(Luv, dmnsn_whitepoint);
- sRGB = dmnsn_sRGB_from_color(color);
-
- if (sRGB.R > 1.0 || sRGB.G > 1.0 || sRGB.B > 1.0
- || sRGB.R < 0.0 || sRGB.G < 0.0 || sRGB.B < 0.0) {
- /* Out of sRGB gamut */
- color.trans = 0.5;
- }
-
- dmnsn_set_pixel(canvas, i + 2*x, j, color);
+ /* Render scene */
+
+ progress = dmnsn_raytrace_scene_async(scene);
+ if (!progress) {
+ dmnsn_delete_default_scene(scene);
+ fprintf(stderr, "--- Couldn't start raytracing worker thread! ---\n");
+ return EXIT_FAILURE;
}
- }
- /* Write the image to PNG */
+ progressbar("Raytracing scene: ", progress);
- ofile = fopen("dimension1.png", "wb");
- if (!ofile) {
- fprintf(stderr, "--- Opening 'dimension1.png' for writing failed! ---\n");
- dmnsn_delete_canvas(canvas);
- return EXIT_FAILURE;
- }
+ if (dmnsn_finish_progress(progress) != 0) {
+ dmnsn_delete_default_scene(scene);
+ fprintf(stderr, "--- Raytracing failed! ---\n");
+ return EXIT_FAILURE;
+ }
- progress = dmnsn_png_write_canvas_async(canvas, ofile);
- if (!progress) {
- fprintf(stderr, "--- Creating PNG writing worker thread failed! ---\n");
- fclose(ofile);
- dmnsn_delete_canvas(canvas);
- return EXIT_FAILURE;
- }
+ /* Write the image to PNG */
+
+ ofile = fopen("png1.png", "wb");
+ if (!ofile) {
+ dmnsn_delete_default_scene(scene);
+ fprintf(stderr, "--- Couldn't open 'png1.png' for writing! ---\n");
+ return EXIT_FAILURE;
+ }
- progressbar("Writing PNG file: ", progress);
+ progress = dmnsn_png_write_canvas_async(scene->canvas, ofile);
+ if (!progress) {
+ fclose(ofile);
+ dmnsn_delete_default_scene(scene);
+ fprintf(stderr, "--- Couldn't start PNG writing worker thread! ---\n");
+ return EXIT_FAILURE;
+ }
+
+ progressbar("Writing PNG file: ", progress);
+
+ if (dmnsn_finish_progress(progress) != 0) {
+ fclose(ofile);
+ dmnsn_delete_default_scene(scene);
+ fprintf(stderr, "--- Writing canvas to PNG failed! ---\n");
+ return EXIT_FAILURE;
+ }
- if (dmnsn_finish_progress(progress) != 0) {
- fprintf(stderr, "--- Writing canvas to PNG failed! ---\n");
fclose(ofile);
- dmnsn_delete_canvas(canvas);
- return EXIT_FAILURE;
+ dmnsn_delete_default_scene(scene);
}
- fclose(ofile);
- dmnsn_delete_canvas(canvas);
+ /* Now test PNG import/export */
+ {
+ /* Read the image back from PNG */
- /* Read the image back from the PNG file */
+ ifile = fopen("png1.png", "rb");
+ if (!ifile) {
+ fprintf(stderr, "--- Couldn't open 'png1.png' for reading! ---\n");
+ return EXIT_FAILURE;
+ }
- ifile = fopen("dimension1.png", "rb");
- if (!ifile) {
- fprintf(stderr, "--- Opening 'dimension1.png' for reading failed! ---\n");
- return EXIT_FAILURE;
- }
+ progress = dmnsn_png_read_canvas_async(&canvas, ifile);
+ if (!progress) {
+ fclose(ifile);
+ fprintf(stderr, "--- Couldn't start PNG reading worker thread! ---\n");
+ return EXIT_FAILURE;
+ }
- progress = dmnsn_png_read_canvas_async(&canvas, ifile);
- if (!progress) {
- fprintf(stderr, "--- Creating PNG reading worker thread failed! ---\n");
- fclose(ifile);
- return EXIT_FAILURE;
- }
+ progressbar("Reading PNG file: ", progress);
- progressbar("Reading PNG file: ", progress);
+ if (dmnsn_finish_progress(progress) != 0) {
+ fclose(ifile);
+ fprintf(stderr, "--- Reading canvas from PNG failed! ---\n");
+ return EXIT_FAILURE;
+ }
- if (dmnsn_finish_progress(progress) != 0) {
- fprintf(stderr, "--- Reading canvas from PNG failed! ---\n");
fclose(ifile);
- return EXIT_FAILURE;
- }
- fclose(ifile);
+ /* And write it back */
- /* ... and write it back again */
+ ofile = fopen("png2.png", "wb");
+ if (!ofile) {
+ fprintf(stderr, "--- Couldn't open 'png2.png' for writing! ---\n");
+ dmnsn_delete_canvas(canvas);
+ return EXIT_FAILURE;
+ }
- ofile = fopen("dimension2.png", "wb");
- if (!ofile) {
- fprintf(stderr, "--- Opening 'dimension2.png' for writing failed! ---\n");
- return EXIT_FAILURE;
- }
+ progress = dmnsn_png_write_canvas_async(canvas, ofile);
+ if (!progress) {
+ fclose(ofile);
+ dmnsn_delete_canvas(canvas);
+ fprintf(stderr, "--- Couldn't start PNG writing worker thread! ---\n");
+ return EXIT_FAILURE;
+ }
- progress = dmnsn_png_write_canvas_async(canvas, ofile);
- if (!progress) {
- fprintf(stderr, "--- Creating PNG writing worker thread failed! ---\n");
- fclose(ofile);
- dmnsn_delete_canvas(canvas);
- return EXIT_FAILURE;
- }
+ progressbar("Writing PNG file: ", progress);
- progressbar("Writing PNG file: ", progress);
+ if (dmnsn_finish_progress(progress) != 0) {
+ fclose(ofile);
+ dmnsn_delete_canvas(canvas);
+ fprintf(stderr, "--- Writing canvas to PNG failed! ---\n");
+ return EXIT_FAILURE;
+ }
- if (dmnsn_finish_progress(progress) != 0) {
- fprintf(stderr, "--- Writing canvas to PNG failed! ---\n");
fclose(ofile);
dmnsn_delete_canvas(canvas);
- return EXIT_FAILURE;
}
- fclose(ofile);
- dmnsn_delete_canvas(canvas);
return EXIT_SUCCESS;
}
diff --git a/tests/pngxx.cpp b/tests/pngxx.cpp
index 987c05b..327ccd0 100644
--- a/tests/pngxx.cpp
+++ b/tests/pngxx.cpp
@@ -17,104 +17,49 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
-// Test C++ PNG file I/O
-
#include "testsxx.hpp"
#include <fstream>
+#include <iostream>
int
-main()
-{
+main() {
using namespace Dimension;
// Set the resilience low for tests
resilience(SEVERITY_LOW);
- const unsigned int width = 333, height = 300;
-
+ // Perform the rendering
{
- std::ofstream ofstr("dimensionxx1.png", std::ios::binary);
- Canvas canvas(3*width, height);
- PNG_Writer writer(canvas, ofstr);
-
- CIE_xyY xyY;
- CIE_Lab Lab;
- CIE_Luv Luv;
- sRGB RGB;
- Color color;
-
- for (unsigned int x = 0; x < width; ++x) {
- for (unsigned int y = 0; y < height; ++y) {
- /* CIE xyY colorspace */
- xyY = CIE_xyY(static_cast<double>(x)/(width - 1),
- static_cast<double>(y)/(height - 1),
- 0.5);
- color = xyY;
- RGB = color;
-
- if (RGB.R() > 1.0 || RGB.G() > 1.0 || RGB.B() > 1.0
- || RGB.R() < 0.0 || RGB.G() < 0.0 || RGB.B() < 0.0) {
- /* Out of sRGB gamut */
- color.trans(0.5);
- }
-
- canvas.pixel(x, y, color);
-
- /* CIE Lab colorspace */
-
- Lab = CIE_Lab(75.0,
- 200.0*(static_cast<double>(x)/(width - 1) - 0.5),
- 200.0*(static_cast<double>(y)/(height - 1) - 0.5));
- color = Lab;
- RGB = color;
-
- if (RGB.R() > 1.0 || RGB.G() > 1.0 || RGB.B() > 1.0
- || RGB.R() < 0.0 || RGB.G() < 0.0 || RGB.B() < 0.0) {
- /* Out of sRGB gamut */
- color.trans(0.5);
- }
-
- canvas.pixel(x + width, y, color);
+ // Get the default test scene
+ Scene scene = Tests::default_scene();
- /* CIE Luv colorspace */
+ std::ofstream ofile("pngxx1.png");
+ PNG_Writer writer(scene.canvas(), ofile);
- Luv = CIE_Luv(75.0,
- 200.0*(static_cast<double>(x)/(width - 1) - 0.5),
- 200.0*(static_cast<double>(y)/(height - 1) - 0.5));
- color = Luv;
- RGB = color;
+ // Render the scene
+ Raytracer raytracer(scene);
+ Progress rprogress = raytracer.render_async();
+ std::cout << "Raytracing scene: " << rprogress << std::endl;
+ rprogress.finish();
- if (RGB.R() > 1.0 || RGB.G() > 1.0 || RGB.B() > 1.0
- || RGB.R() < 0.0 || RGB.G() < 0.0 || RGB.B() < 0.0) {
- /* Out of sRGB gamut */
- color.trans(0.5);
- }
-
- canvas.pixel(x + 2*width, y, color);
- }
- }
-
- // Write the image to PNG
- Progress progress = writer.write_async();
- std::cout << "Writing PNG file: " << progress << std::endl;
+ // Write the canvas
+ Progress oprogress = writer.write_async();
+ std::cout << "Writing PNG file: " << oprogress << std::endl;
}
- // Read the image back from PNG
-
- std::ifstream ifstr("dimensionxx1.png", std::ios::binary);
- PNG_Reader reader(ifstr);
-
- Progress iprogress = reader.read_async();
- std::cout << "Reading PNG file: " << iprogress << std::endl;
- Canvas canvas = PNG_Reader::finish(iprogress);
-
- // And write it again
-
- std::ofstream ofstr("dimensionxx2.png", std::ios::binary);
- PNG_Writer writer(canvas, ofstr);
-
- Progress oprogress = writer.write_async();
- std::cout << "Writing PNG file: " << oprogress << std::endl;
+ // Now test PNG import/export
+ {
+ std::ifstream ifile("pngxx1.png");
+ PNG_Reader reader(ifile);
+ Progress iprogress = reader.read_async();
+ std::cout << "Reading PNG file: " << iprogress << std::endl;
+
+ Canvas canvas = PNG_Reader::finish(iprogress);
+ std::ofstream ofile("pngxx2.png");
+ PNG_Writer writer(canvas, ofile);
+ Progress oprogress = writer.write_async();
+ std::cout << "Writing PNG file: " << oprogress << std::endl;
+ }
- return 0;
+ return EXIT_SUCCESS;
}
diff --git a/tests/raytrace.c b/tests/raytrace.c
deleted file mode 100644
index fe98bfc..0000000
--- a/tests/raytrace.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/*************************************************************************
- * Copyright (C) 2009 Tavian Barnes <tavianator@gmail.com> *
- * *
- * This file is part of The Dimension Test Suite. *
- * *
- * The Dimension Test Suite is free software; you can redistribute it *
- * and/or modify it under the terms of the GNU General Public License as *
- * published by the Free Software Foundation; either version 3 of the *
- * License, or (at your option) any later version. *
- * *
- * The Dimension Test Suite is distributed in the hope that it will be *
- * useful, but WITHOUT ANY WARRANTY; without even the implied warranty *
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program. If not, see <http://www.gnu.org/licenses/>. *
- *************************************************************************/
-
-#include "tests.h"
-#include <stdlib.h>
-#include <stdio.h>
-
-int
-main() {
- dmnsn_progress *progress;
- FILE *file;
- dmnsn_scene *scene;
-
- /* Set the resilience low for tests */
- dmnsn_set_resilience(DMNSN_SEVERITY_LOW);
-
- /* Allocate our default scene */
- scene = dmnsn_new_default_scene();
- if (!scene) {
- fprintf(stderr, "--- Allocation of default scene failed! ---\n");
- return EXIT_FAILURE;
- }
-
- /* Optimize the canvas for PNG export */
- if (dmnsn_png_optimize_canvas(scene->canvas) != 0) {
- dmnsn_delete_default_scene(scene);
- fprintf(stderr, "--- Couldn't optimize canvas for PNG! ---\n");
- return EXIT_FAILURE;
- }
-
- /* Render scene */
-
- progress = dmnsn_raytrace_scene_async(scene);
- if (!progress) {
- dmnsn_delete_default_scene(scene);
- fprintf(stderr, "--- Couldn't start raytracing worker thread! ---\n");
- return EXIT_FAILURE;
- }
-
- progressbar("Raytracing scene: ", progress);
-
- if (dmnsn_finish_progress(progress) != 0) {
- dmnsn_delete_default_scene(scene);
- fprintf(stderr, "--- Raytracing failed! ---\n");
- return EXIT_FAILURE;
- }
-
- /* Write the image to PNG */
-
- file = fopen("raytrace.png", "wb");
- if (!file) {
- dmnsn_delete_default_scene(scene);
- fprintf(stderr, "--- Couldn't open 'raytrace.png' for writing! ---\n");
- return EXIT_FAILURE;
- }
-
- progress = dmnsn_png_write_canvas_async(scene->canvas, file);
- if (!progress) {
- fclose(file);
- dmnsn_delete_default_scene(scene);
- fprintf(stderr, "--- Couldn't start PNG writing worker thread! ---\n");
- return EXIT_FAILURE;
- }
-
- progressbar("Writing PNG file: ", progress);
-
- if (dmnsn_finish_progress(progress) != 0) {
- fclose(file);
- dmnsn_delete_default_scene(scene);
- fprintf(stderr, "--- Writing canvas to PNG failed! ---\n");
- return EXIT_FAILURE;
- }
-
- fclose(file);
- dmnsn_delete_default_scene(scene);
- return EXIT_SUCCESS;
-}
diff --git a/tests/raytracexx.cpp b/tests/raytracexx.cpp
deleted file mode 100644
index d681f58..0000000
--- a/tests/raytracexx.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-/*************************************************************************
- * Copyright (C) 2009 Tavian Barnes <tavianator@gmail.com> *
- * *
- * This file is part of The Dimension Test Suite. *
- * *
- * The Dimension Test Suite is free software; you can redistribute it *
- * and/or modify it under the terms of the GNU General Public License as *
- * published by the Free Software Foundation; either version 3 of the *
- * License, or (at your option) any later version. *
- * *
- * The Dimension Test Suite is distributed in the hope that it will be *
- * useful, but WITHOUT ANY WARRANTY; without even the implied warranty *
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program. If not, see <http://www.gnu.org/licenses/>. *
- *************************************************************************/
-
-#include "testsxx.hpp"
-#include <fstream>
-#include <iostream>
-
-int
-main() {
- using namespace Dimension;
-
- // Set the resilience low for tests
- resilience(SEVERITY_LOW);
-
- // Get the default test scene
- Scene scene = Tests::default_scene();
-
- std::ofstream file("raytracexx.png");
- PNG_Writer writer(scene.canvas(), file);
-
- // Render the scene
- {
- Raytracer raytracer(scene);
- Progress rprogress = raytracer.render_async();
- std::cout << "Raytracing scene: " << rprogress << std::endl;
- }
-
- // Write the canvas
- Progress progress = writer.write_async();
- std::cout << "Writing PNG file: " << progress << std::endl;
-
- return EXIT_SUCCESS;
-}