From a5a6b94c038e01ebf1e2de0a0774a69b02fb8e1e Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 15 May 2011 15:54:56 -0600 Subject: Group tests and benchmarks with the corresponding source code. --- .gitignore | 12 +- HACKING | 8 +- Makefile.am | 8 +- bench/Makefile.am | 26 --- bench/dimension/Makefile.am | 35 ---- bench/dimension/bench.pov | 118 ------------- bench/dimension/parse.sh | 59 ------- bench/dimension/render.sh | 25 --- bench/dimension/tokenize.sh | 24 --- bench/libdimension/Makefile.am | 41 ----- bench/libdimension/array.c | 118 ------------- bench/libdimension/geometry.c | 171 ------------------- bench/libdimension/polynomial.c | 72 -------- bench/libdimension/prtree.c | 119 ------------- configure.ac | 11 +- dimension/Makefile.am | 8 + dimension/bench/Makefile.am | 35 ++++ dimension/bench/bench.pov | 118 +++++++++++++ dimension/bench/parse.sh | 59 +++++++ dimension/bench/render.sh | 25 +++ dimension/bench/tokenize.sh | 24 +++ dimension/tests/Makefile.am | 55 ++++++ dimension/tests/arithexp.pov | 218 ++++++++++++++++++++++++ dimension/tests/arithexp.sh | 35 ++++ dimension/tests/csg.pov | 65 +++++++ dimension/tests/csg.sh | 94 +++++++++++ dimension/tests/demo.pov | 150 +++++++++++++++++ dimension/tests/demo.sh | 220 ++++++++++++++++++++++++ dimension/tests/directives.inc | 21 +++ dimension/tests/directives.pov | 92 ++++++++++ dimension/tests/directives.sh | 124 ++++++++++++++ dimension/tests/integer-overflow.pov | 25 +++ dimension/tests/integer-overflow.sh | 35 ++++ dimension/tests/invalid-macro.pov | 26 +++ dimension/tests/invalid-macro.sh | 23 +++ dimension/tests/labels.pov | 31 ++++ dimension/tests/labels.sh | 29 ++++ dimension/tests/numeric.pov | 30 ++++ dimension/tests/numeric.sh | 43 +++++ dimension/tests/punctuation.pov | 24 +++ dimension/tests/punctuation.sh | 29 ++++ dimension/tests/strings.pov | 21 +++ dimension/tests/strings.sh | 29 ++++ dimension/tests/tbuffer-overlap.pov | 22 +++ dimension/tests/tbuffer-overlap.sh | 23 +++ dimension/tests/transformations.pov | 39 +++++ dimension/tests/transformations.sh | 64 +++++++ doc/Makefile.am | 18 -- libdimension/Doxyfile.in | 2 +- libdimension/Makefile.am | 12 +- libdimension/bench/Makefile.am | 41 +++++ libdimension/bench/array.c | 118 +++++++++++++ libdimension/bench/geometry.c | 171 +++++++++++++++++++ libdimension/bench/polynomial.c | 72 ++++++++ libdimension/bench/prtree.c | 119 +++++++++++++ libdimension/tests/Makefile.am | 81 +++++++++ libdimension/tests/cxx.cpp | 36 ++++ libdimension/tests/display-stubs.c | 38 +++++ libdimension/tests/display.c | 151 +++++++++++++++++ libdimension/tests/error.c | 30 ++++ libdimension/tests/gl.c | 87 ++++++++++ libdimension/tests/png.c | 106 ++++++++++++ libdimension/tests/polynomial.c | 62 +++++++ libdimension/tests/prtree.c | 98 +++++++++++ libdimension/tests/render.c | 309 ++++++++++++++++++++++++++++++++++ libdimension/tests/tests.h | 46 +++++ libdimension/tests/warning-as-error.c | 31 ++++ libdimension/tests/warning.c | 30 ++++ tests/Makefile.am | 20 --- tests/dimension/Makefile.am | 55 ------ tests/dimension/arithexp.pov | 218 ------------------------ tests/dimension/arithexp.sh | 35 ---- tests/dimension/csg.pov | 65 ------- tests/dimension/csg.sh | 94 ----------- tests/dimension/demo.pov | 150 ----------------- tests/dimension/demo.sh | 220 ------------------------ tests/dimension/directives.inc | 21 --- tests/dimension/directives.pov | 92 ---------- tests/dimension/directives.sh | 124 -------------- tests/dimension/integer-overflow.pov | 25 --- tests/dimension/integer-overflow.sh | 35 ---- tests/dimension/invalid-macro.pov | 26 --- tests/dimension/invalid-macro.sh | 23 --- tests/dimension/labels.pov | 31 ---- tests/dimension/labels.sh | 29 ---- tests/dimension/numeric.pov | 30 ---- tests/dimension/numeric.sh | 43 ----- tests/dimension/punctuation.pov | 24 --- tests/dimension/punctuation.sh | 29 ---- tests/dimension/strings.pov | 21 --- tests/dimension/strings.sh | 29 ---- tests/dimension/tbuffer-overlap.pov | 22 --- tests/dimension/tbuffer-overlap.sh | 23 --- tests/dimension/transformations.pov | 39 ----- tests/dimension/transformations.sh | 64 ------- tests/libdimension/Makefile.am | 81 --------- tests/libdimension/cxx.cpp | 36 ---- tests/libdimension/display-stubs.c | 38 ----- tests/libdimension/display.c | 151 ----------------- tests/libdimension/error.c | 30 ---- tests/libdimension/gl.c | 87 ---------- tests/libdimension/png.c | 106 ------------ tests/libdimension/polynomial.c | 62 ------- tests/libdimension/prtree.c | 98 ----------- tests/libdimension/render.c | 309 ---------------------------------- tests/libdimension/tests.h | 46 ----- tests/libdimension/warning-as-error.c | 31 ---- tests/libdimension/warning.c | 30 ---- 108 files changed, 3490 insertions(+), 3543 deletions(-) delete mode 100644 bench/Makefile.am delete mode 100644 bench/dimension/Makefile.am delete mode 100644 bench/dimension/bench.pov delete mode 100755 bench/dimension/parse.sh delete mode 100755 bench/dimension/render.sh delete mode 100755 bench/dimension/tokenize.sh delete mode 100644 bench/libdimension/Makefile.am delete mode 100644 bench/libdimension/array.c delete mode 100644 bench/libdimension/geometry.c delete mode 100644 bench/libdimension/polynomial.c delete mode 100644 bench/libdimension/prtree.c create mode 100644 dimension/bench/Makefile.am create mode 100644 dimension/bench/bench.pov create mode 100755 dimension/bench/parse.sh create mode 100755 dimension/bench/render.sh create mode 100755 dimension/bench/tokenize.sh create mode 100644 dimension/tests/Makefile.am create mode 100644 dimension/tests/arithexp.pov create mode 100755 dimension/tests/arithexp.sh create mode 100644 dimension/tests/csg.pov create mode 100755 dimension/tests/csg.sh create mode 100644 dimension/tests/demo.pov create mode 100755 dimension/tests/demo.sh create mode 100644 dimension/tests/directives.inc create mode 100644 dimension/tests/directives.pov create mode 100755 dimension/tests/directives.sh create mode 100644 dimension/tests/integer-overflow.pov create mode 100755 dimension/tests/integer-overflow.sh create mode 100644 dimension/tests/invalid-macro.pov create mode 100755 dimension/tests/invalid-macro.sh create mode 100644 dimension/tests/labels.pov create mode 100755 dimension/tests/labels.sh create mode 100644 dimension/tests/numeric.pov create mode 100755 dimension/tests/numeric.sh create mode 100644 dimension/tests/punctuation.pov create mode 100755 dimension/tests/punctuation.sh create mode 100644 dimension/tests/strings.pov create mode 100755 dimension/tests/strings.sh create mode 100644 dimension/tests/tbuffer-overlap.pov create mode 100755 dimension/tests/tbuffer-overlap.sh create mode 100644 dimension/tests/transformations.pov create mode 100755 dimension/tests/transformations.sh delete mode 100644 doc/Makefile.am create mode 100644 libdimension/bench/Makefile.am create mode 100644 libdimension/bench/array.c create mode 100644 libdimension/bench/geometry.c create mode 100644 libdimension/bench/polynomial.c create mode 100644 libdimension/bench/prtree.c create mode 100644 libdimension/tests/Makefile.am create mode 100644 libdimension/tests/cxx.cpp create mode 100644 libdimension/tests/display-stubs.c create mode 100644 libdimension/tests/display.c create mode 100644 libdimension/tests/error.c create mode 100644 libdimension/tests/gl.c create mode 100644 libdimension/tests/png.c create mode 100644 libdimension/tests/polynomial.c create mode 100644 libdimension/tests/prtree.c create mode 100644 libdimension/tests/render.c create mode 100644 libdimension/tests/tests.h create mode 100644 libdimension/tests/warning-as-error.c create mode 100644 libdimension/tests/warning.c delete mode 100644 tests/Makefile.am delete mode 100644 tests/dimension/Makefile.am delete mode 100644 tests/dimension/arithexp.pov delete mode 100755 tests/dimension/arithexp.sh delete mode 100644 tests/dimension/csg.pov delete mode 100755 tests/dimension/csg.sh delete mode 100644 tests/dimension/demo.pov delete mode 100755 tests/dimension/demo.sh delete mode 100644 tests/dimension/directives.inc delete mode 100644 tests/dimension/directives.pov delete mode 100755 tests/dimension/directives.sh delete mode 100644 tests/dimension/integer-overflow.pov delete mode 100755 tests/dimension/integer-overflow.sh delete mode 100644 tests/dimension/invalid-macro.pov delete mode 100755 tests/dimension/invalid-macro.sh delete mode 100644 tests/dimension/labels.pov delete mode 100755 tests/dimension/labels.sh delete mode 100644 tests/dimension/numeric.pov delete mode 100755 tests/dimension/numeric.sh delete mode 100644 tests/dimension/punctuation.pov delete mode 100755 tests/dimension/punctuation.sh delete mode 100644 tests/dimension/strings.pov delete mode 100755 tests/dimension/strings.sh delete mode 100644 tests/dimension/tbuffer-overlap.pov delete mode 100755 tests/dimension/tbuffer-overlap.sh delete mode 100644 tests/dimension/transformations.pov delete mode 100755 tests/dimension/transformations.sh delete mode 100644 tests/libdimension/Makefile.am delete mode 100644 tests/libdimension/cxx.cpp delete mode 100644 tests/libdimension/display-stubs.c delete mode 100644 tests/libdimension/display.c delete mode 100644 tests/libdimension/error.c delete mode 100644 tests/libdimension/gl.c delete mode 100644 tests/libdimension/png.c delete mode 100644 tests/libdimension/polynomial.c delete mode 100644 tests/libdimension/prtree.c delete mode 100644 tests/libdimension/render.c delete mode 100644 tests/libdimension/tests.h delete mode 100644 tests/libdimension/warning-as-error.c delete mode 100644 tests/libdimension/warning.c diff --git a/.gitignore b/.gitignore index f202c53..62104f0 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,7 @@ Makefile Makefile.in # Documentation files created by make -/doc/libdimension +/*/doc Doxyfile # pkg-config files @@ -33,13 +33,13 @@ Doxyfile /dimension/lexer.c # Files created by `make check' -/tests/*/*-test -/tests/*/*.png -/tests/*/*.log +/*/tests/*-test +/*/tests/*.png +/*/tests/*.log # Files created by `make bench' -/bench/*/bench-* -/bench/*/*.png +/*/bench/bench-* +/*/bench/*.png # Files and folders created by libtool .libs/ diff --git a/HACKING b/HACKING index d57be49..3b613ab 100644 --- a/HACKING +++ b/HACKING @@ -8,8 +8,8 @@ Tokenizing: dimension/lexer.l Language directives: dimension/tokenize.c Parsing: dimension/common.rules Extra parsing stuff: dimension/{common,grammar,directives}.* -Tests: tests/dimension/*.{pov,sh} -Benchmarks: bench/dimension/*.{sh,pov} +Tests: dimension/tests/*.{pov,sh} +Benchmarks: dimension/bench/*.{sh,pov} Library (LGPLv3): ================= @@ -20,5 +20,5 @@ API: libdimension/dimension.h, libdimension/dimension/*.h Ray tracing algorithm: libdimension/raytrace.c Bounding hierarchy: libdimension/prtree.{c,h} Library internals: libdimension/dimension-impl.h and its #includes -Tests: tests/libdimension/*.{c,cpp} -Benchmarks: bench/libdimension/*.c +Tests: libdimension/tests/*.{c,cpp} +Benchmarks: libdimension/bench/*.c diff --git a/Makefile.am b/Makefile.am index 44cbc86..898a0c0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,15 +19,13 @@ ACLOCAL_AMFLAGS = -I m4 SUBDIRS = libdimension \ - dimension \ - tests \ - bench \ - doc + dimension EXTRA_DIST = autogen.sh bench: all-recursive - cd bench && $(MAKE) $(AM_MAKEFLAGS) bench + cd libdimension && $(MAKE) $(AM_MAKEFLAGS) bench + cd dimension && $(MAKE) $(AM_MAKEFLAGS) bench doc: cd libdimension && $(MAKE) $(AM_MAKEFLAGS) doc diff --git a/bench/Makefile.am b/bench/Makefile.am deleted file mode 100644 index 8404c22..0000000 --- a/bench/Makefile.am +++ /dev/null @@ -1,26 +0,0 @@ -########################################################################### -## Copyright (C) 2009-2010 Tavian Barnes ## -## ## -## This file is part of The Dimension Build Suite. ## -## ## -## The Dimension Build 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 Build 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 . ## -########################################################################### - -SUBDIRS = libdimension dimension - -bench: all-recursive - cd libdimension && $(MAKE) $(AM_MAKEFLAGS) bench - cd dimension && $(MAKE) $(AM_MAKEFLAGS) bench - -.PHONY: bench diff --git a/bench/dimension/Makefile.am b/bench/dimension/Makefile.am deleted file mode 100644 index e7fe03f..0000000 --- a/bench/dimension/Makefile.am +++ /dev/null @@ -1,35 +0,0 @@ -########################################################################### -## Copyright (C) 2009-2010 Tavian Barnes ## -## ## -## This file is part of The Dimension Build Suite. ## -## ## -## The Dimension Build 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 Build 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 . ## -########################################################################### - -ENVIRONMENT = top_builddir=$(top_builddir) - -bench: tokenize.sh parse.sh render.sh - $(ENVIRONMENT) ./tokenize.sh - $(ENVIRONMENT) ./parse.sh - $(ENVIRONMENT) ./render.sh - -.sh: - cp $(srcdir)/$@ . - -clean-local: - rm -f *.png - -EXTRA_DIST = bench.pov - -.PHONY: bench diff --git a/bench/dimension/bench.pov b/bench/dimension/bench.pov deleted file mode 100644 index a4f632f..0000000 --- a/bench/dimension/bench.pov +++ /dev/null @@ -1,118 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes * - * * - * This file is part of The Dimension Benchmark Suite. * - * * - * The Dimension Benchmark 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 Benchmark 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 . * - *************************************************************************/ - -camera { - location <3.0, 6.0, -11.0> - right x*image_width/image_height - look_at 0 -} - -background { - color rgb 1 -} - -// inside center sphere -light_source { - 0, - color rgb 1 -} - -light_source { - 2*y, - color rgb 1 -} - -/* plane { - y, - -1 - // *** hollow on - pigment { - rgb <0.73, 0.90, 0.97> - } - finish { - diffuse 0.35 - ambient .5 - } -} */ - -#macro sph(center) - sphere { - center, - 1 - texture { - // *** crackle - scale 0.5 - - /* *** texture_map { - [ 0.03 - pigment { - color rgb 1 - } - finish { - ambient 1 - } - normal { - facets size 0.1 - } - ] - [ 0.04 - pigment { - color rgbf <1, 1, 1, 0.9> - } - finish { - reflection { 0.2 } - specular 0.1 - roughness 0.02 - conserve_energy - } - normal { - facets size 0.1 - } - ] - } *** */ - } - interior { - ior 1.3 - } - } -#end - -union { - #declare Size = 4; - #declare I = -Size; - #while (I <= Size) - #declare J = -Size; - - #while (J <= Size) - #declare K = -Size; - - #while (K <= Size) - object { - sph(<2.5*I, 2.5*K, 2.5*J>) - } - - #declare K = K + 1; - #end - - #declare J = J + 1; - #end - - #declare I = I + 1; - #end -} diff --git a/bench/dimension/parse.sh b/bench/dimension/parse.sh deleted file mode 100755 index b7db055..0000000 --- a/bench/dimension/parse.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash - -######################################################################### -# Copyright (C) 2009-2010 Tavian Barnes # -# # -# This file is part of The Dimension Benchmark Suite. # -# # -# The Dimension Benchmark 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 Benchmark 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 . # -######################################################################### - -for i in {1..10000}; do - echo ' -difference { - box { - <-1, -1, -1>, <1, 1, 1> - - rotate 45*x - - texture { - pigment { - color rgbft <0, 0, 1, 0.25, 0.5> - } - finish { - reflection { 0.5 } - } - } - - interior { - ior 1.1 - } - } - - sphere { - <0, 0, 0>, 1.25 - - texture { - pigment { - color rgb <0, 1, 0> - } - finish { - phong 0.2 - phong_size 40.0 - } - } - } -} -' -done | (time ${top_builddir}/dimension/dimension --parse /dev/stdin >/dev/null) diff --git a/bench/dimension/render.sh b/bench/dimension/render.sh deleted file mode 100755 index b661e53..0000000 --- a/bench/dimension/render.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -######################################################################### -# Copyright (C) 2009-2011 Tavian Barnes # -# # -# This file is part of The Dimension Benchmark Suite. # -# # -# The Dimension Benchmark 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 Benchmark 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 . # -######################################################################### - -echo -e "Single-threaded" -time ${top_builddir}/dimension/dimension -w1920 -h1080 --quality=1 --threads=1 bench.pov -echo -e "\nMulti-threaded" -time ${top_builddir}/dimension/dimension -w1920 -h1080 --quality=1 bench.pov diff --git a/bench/dimension/tokenize.sh b/bench/dimension/tokenize.sh deleted file mode 100755 index 1d833d5..0000000 --- a/bench/dimension/tokenize.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -######################################################################### -# Copyright (C) 2009-2010 Tavian Barnes # -# # -# This file is part of The Dimension Benchmark Suite. # -# # -# The Dimension Benchmark 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 Benchmark 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 . # -######################################################################### - -for i in {1..10000}; do - echo '{}()[]+-*/,;?:&.|=<>!<= >= != "This is a string with escape sequences: \a\b\f\n\r\t\u2123\v\\\"" 1 123456789 01234567 0x123456789 -0x01 .1 0.1 1.0 0.123456789 -0.123456789 <1, 2.2, -3.03> Undefined' -done | (time ${top_builddir}/dimension/dimension --tokenize /dev/stdin >/dev/null) diff --git a/bench/libdimension/Makefile.am b/bench/libdimension/Makefile.am deleted file mode 100644 index 353acb3..0000000 --- a/bench/libdimension/Makefile.am +++ /dev/null @@ -1,41 +0,0 @@ -########################################################################### -## Copyright (C) 2009-2010 Tavian Barnes ## -## ## -## This file is part of The Dimension Build Suite. ## -## ## -## The Dimension Build 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 Build 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 . ## -########################################################################### - -INCLUDES = -I$(top_srcdir)/libdimension - -EXTRA_PROGRAMS = bench-array \ - bench-geometry \ - bench-polynomial \ - bench-prtree - -AM_CFLAGS = $(libsandglass_CFLAGS) -fno-inline -AM_LDFLAGS = $(libsandglass_LIBS) $(top_builddir)/libdimension/libdimension.la - -bench_array_SOURCES = array.c -bench_geometry_SOURCES = geometry.c -bench_polynomial_SOURCES = polynomial.c -bench_prtree_SOURCES = prtree.c - -bench: $(EXTRA_PROGRAMS) - ./bench-array - ./bench-geometry - ./bench-polynomial - ./bench-prtree - -.PHONY: bench diff --git a/bench/libdimension/array.c b/bench/libdimension/array.c deleted file mode 100644 index 3fe0c83..0000000 --- a/bench/libdimension/array.c +++ /dev/null @@ -1,118 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes * - * * - * This file is part of The Dimension Benchmark Suite. * - * * - * The Dimension Benchmark 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 Benchmark 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 . * - *************************************************************************/ - -#include "dimension.h" -#include -#include -#include - -int -main(void) -{ - const unsigned int count = 32; - uint32_t object = 1; - - sandglass_t sandglass; - if (sandglass_init_monotonic(&sandglass, SANDGLASS_CPUTIME) != 0) { - perror("sandglass_create()"); - return EXIT_FAILURE; - } - - /* Benchmark allocation and deallocation */ - dmnsn_array *array; - sandglass_bench_fine(&sandglass, { - array = dmnsn_new_array(sizeof(object)); - dmnsn_delete_array(array); - }); - printf("dmnsn_new_array() + dmnsn_delete_array(): %ld\n", sandglass.grains); - - /* Create our test array */ - array = dmnsn_new_array(sizeof(object)); - - /* dmnsn_array_push() */ - - printf("dmnsn_array_push():"); - - for (unsigned int i = 0; i < count; ++i) { - sandglass_bench_noprecache(&sandglass, dmnsn_array_push(array, &object)); - printf(" %ld", sandglass.grains); - } - printf("\n"); - - /* dmnsn_array_get() */ - sandglass_bench_fine(&sandglass, dmnsn_array_get(array, count/2, &object)); - printf("dmnsn_array_get(): %ld\n", sandglass.grains); - - /* dmnsn_array_set() */ - sandglass_bench_fine(&sandglass, dmnsn_array_set(array, count/2, &object)); - printf("dmnsn_array_set(): %ld\n", sandglass.grains); - - /* dmnsn_array_at() */ - void *ptr; - sandglass_bench_fine(&sandglass, ptr = dmnsn_array_at(array, count/2)); - printf("dmnsn_array_at() = %p: %ld\n", ptr, sandglass.grains); - - /* dmnsn_array_size() */ - size_t size; - sandglass_bench_fine(&sandglass, size = dmnsn_array_size(array)); - printf("dmnsn_array_size() = %zu: %ld\n", size, sandglass.grains); - - /* dmnsn_array_resize() */ - dmnsn_array_resize(array, count); - sandglass_bench_noprecache(&sandglass, dmnsn_array_resize(array, count * 2)); - printf("dmnsn_array_resize(): %ld", sandglass.grains); - - sandglass_bench_noprecache(&sandglass, dmnsn_array_resize(array, count)); - printf(" %ld\n", sandglass.grains); - - /* dmnsn_array_insert() */ - - printf("dmnsn_array_insert():"); - - for (size_t i = 0; i < count; ++i) { - sandglass_bench_noprecache(&sandglass, - dmnsn_array_insert(array, count/2, &object)); - printf(" %ld", sandglass.grains); - } - printf("\n"); - - /* dmnsn_array_remove() */ - - printf("dmnsn_array_remove():"); - - for (size_t i = 0; i < count; ++i) { - sandglass_bench_noprecache(&sandglass, - dmnsn_array_remove(array, count/2)); - printf(" %ld", sandglass.grains); - } - printf("\n"); - - /* dmnsn_array_pop() */ - - printf("dmnsn_array_pop():"); - - for (size_t i = 0; i < count; ++i) { - sandglass_bench_noprecache(&sandglass, dmnsn_array_pop(array, &object)); - printf(" %ld", sandglass.grains); - } - printf("\n"); - - dmnsn_delete_array(array); - return EXIT_SUCCESS; -} diff --git a/bench/libdimension/geometry.c b/bench/libdimension/geometry.c deleted file mode 100644 index 4b77c9b..0000000 --- a/bench/libdimension/geometry.c +++ /dev/null @@ -1,171 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes * - * * - * This file is part of The Dimension Benchmark Suite. * - * * - * The Dimension Benchmark 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 Benchmark 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 . * - *************************************************************************/ - -#include "dimension.h" -#include -#include - -int -main(void) -{ - dmnsn_vector vector, vector2; - dmnsn_matrix matrix, matrix2; - dmnsn_line line; - double result; - - sandglass_t sandglass; - if (sandglass_init_monotonic(&sandglass, SANDGLASS_CPUTIME) != 0) { - perror("sandglass_create()"); - return EXIT_FAILURE; - } - - /* dmnsn_new_vector() */ - sandglass_bench_fine(&sandglass, { - vector = dmnsn_new_vector(1.0, 2.0, 3.0); - }); - printf("dmnsn_new_vector(): %ld\n", sandglass.grains); - - /* dmnsn_matrix_construct() */ - sandglass_bench_fine(&sandglass, { - matrix = dmnsn_new_matrix(1.0, 1.0, 0.0, 0.0, - 1.0, 1.0, 1.0, 0.0, - 0.0, 1.0, 1.0, 0.0); - }); - printf("dmnsn_new_matrix(): %ld\n", sandglass.grains); - - /* dmnsn_identity_matrix() */ - sandglass_bench_fine(&sandglass, { - matrix = dmnsn_identity_matrix(); - }); - printf("dmnsn_identity_matrix(): %ld\n", sandglass.grains); - - /* dmnsn_scale_matrix() */ - sandglass_bench_fine(&sandglass, { - matrix = dmnsn_scale_matrix(vector); - }); - printf("dmnsn_scale_matrix(): %ld\n", sandglass.grains); - - /* dmnsn_identity_matrix() */ - sandglass_bench_fine(&sandglass, { - matrix = dmnsn_translation_matrix(vector); - }); - printf("dmnsn_translation_matrix(): %ld\n", sandglass.grains); - - /* dmnsn_rotation_matrix() */ - sandglass_bench_fine(&sandglass, { - matrix = dmnsn_rotation_matrix(vector); - }); - printf("dmnsn_rotation_matrix(): %ld\n", sandglass.grains); - - /* dmnsn_new_line() */ - vector2 = dmnsn_new_vector(3.0, 2.0, 1.0); - sandglass_bench_fine(&sandglass, { - line = dmnsn_new_line(vector, vector2); - }); - printf("dmnsn_new_line(): %ld\n", sandglass.grains); - - /* dmnsn_vector_add() */ - sandglass_bench_fine(&sandglass, { - vector = dmnsn_vector_add(vector, vector2); - }); - printf("dmnsn_vector_add(): %ld\n", sandglass.grains); - - /* dmnsn_vector_sub() */ - sandglass_bench_fine(&sandglass, { - vector = dmnsn_vector_sub(vector, vector2); - }); - printf("dmnsn_vector_sub(): %ld\n", sandglass.grains); - - /* dmnsn_vector_mul() */ - sandglass_bench_fine(&sandglass, { - vector = dmnsn_vector_mul(2.0, vector); - }); - printf("dmnsn_vector_mul(): %ld\n", sandglass.grains); - - /* dmnsn_vector_div() */ - sandglass_bench_fine(&sandglass, { - vector = dmnsn_vector_div(vector, 2.0); - }); - printf("dmnsn_vector_div(): %ld\n", sandglass.grains); - - /* dmnsn_vector_cross() */ - sandglass_bench_fine(&sandglass, { - vector = dmnsn_vector_cross(vector, vector2); - }); - printf("dmnsn_vector_cross(): %ld\n", sandglass.grains); - - /* dmnsn_vector_dot() */ - sandglass_bench_fine(&sandglass, { - result = dmnsn_vector_dot(vector, vector2); - }); - printf("dmnsn_vector_dot(): %ld\n", sandglass.grains); - - /* dmnsn_vector_norm() */ - sandglass_bench_fine(&sandglass, { - result = dmnsn_vector_norm(vector); - }); - printf("dmnsn_vector_norm(): %ld\n", sandglass.grains); - - /* dmnsn_vector_normalize() */ - sandglass_bench_fine(&sandglass, { - vector = dmnsn_vector_normalize(vector); - }); - printf("dmnsn_vector_normalize(): %ld\n", sandglass.grains); - - /* dmnsn_matrix_inverse() */ - sandglass_bench_fine(&sandglass, { - matrix = dmnsn_matrix_inverse(matrix); - }); - printf("dmnsn_matrix_inverse(): %ld\n", sandglass.grains); - - /* dmnsn_matrix_inverse(HARD) */ - matrix2 = dmnsn_new_matrix(1.0, 1.0, 0.0, 0.0, - 1.0, 1.0, 1.0, 0.0, - 0.0, 1.0, 1.0, 0.0); - sandglass_bench_fine(&sandglass, { - matrix = dmnsn_matrix_inverse(matrix2); - }); - printf("dmnsn_matrix_inverse(HARD): %ld\n", sandglass.grains); - - /* dmnsn_matrix_mul() */ - sandglass_bench_fine(&sandglass, { - matrix = dmnsn_matrix_mul(matrix, matrix2); - }); - printf("dmnsn_matrix_mul(): %ld\n", sandglass.grains); - - /* dmnsn_transform_vector() */ - sandglass_bench_fine(&sandglass, { - vector = dmnsn_transform_vector(matrix, vector); - }); - printf("dmnsn_transform_vector(): %ld\n", sandglass.grains); - - /* dmnsn_transform_line() */ - sandglass_bench_fine(&sandglass, { - line = dmnsn_transform_line(matrix, line); - }); - printf("dmnsn_transform_line(): %ld\n", sandglass.grains); - - /* dmnsn_line_point() */ - sandglass_bench_fine(&sandglass, { - vector = dmnsn_line_point(line, result); - }); - printf("dmnsn_line_point(): %ld\n", sandglass.grains); - - return EXIT_SUCCESS; -} diff --git a/bench/libdimension/polynomial.c b/bench/libdimension/polynomial.c deleted file mode 100644 index 0313060..0000000 --- a/bench/libdimension/polynomial.c +++ /dev/null @@ -1,72 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes * - * * - * This file is part of The Dimension Benchmark Suite. * - * * - * The Dimension Benchmark 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 Benchmark 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 . * - *************************************************************************/ - -#include "dimension.h" -#include -#include - -int -main(void) -{ -#define NPOLY 5 - double p[NPOLY][NPOLY + 1], x[NPOLY]; - - /* p[0][] = x - 0.5; */ - p[0][1] = 1.0; - p[0][0] = -0.5; - - /* p[1][] = (x + 0.5)*(x - 0.5) */ - p[1][2] = 1.0; - p[1][1] = 0.0; - p[1][0] = -0.25; - - /* p[2][] = (x + 1)*(x - 1.2345)*(x - 100) */ - p[2][3] = 1.0; - p[2][2] = -100.2345; - p[2][1] = 22.2155; - p[2][0] = 123.45; - - /* p[3][] = (x + 1)*(x - 1.2345)*(x - 5)*(x - 100) */ - p[3][4] = 1.0; - p[3][3] = -105.2345; - p[3][2] = 523.388; - p[3][1] = 12.3725; - p[3][0] = -617.25; - - /* p[4][] = (x + 1)*(x - 1.2345)*(x - 2.3456)*(x - 5)*(x - 100) */ - p[4][5] = 1.0; - p[4][4] = -107.5801; - p[4][3] = 770.2260432; - p[4][2] = -1215.2863928; - p[4][1] = -646.270936; - p[4][0] = 1447.8216; - - sandglass_t sandglass; - if (sandglass_init_monotonic(&sandglass, SANDGLASS_CPUTIME) != 0) { - perror("sandglass_create()"); - return EXIT_FAILURE; - } - - for (size_t i = 0; i < NPOLY; ++i) { - sandglass_bench_fine(&sandglass, dmnsn_solve_polynomial(p[i], i + 1, x)); - printf("dmnsn_solve_polynomial(x^%zu): %ld\n", i + 1, sandglass.grains); - } - - return EXIT_SUCCESS; -} diff --git a/bench/libdimension/prtree.c b/bench/libdimension/prtree.c deleted file mode 100644 index b6f778a..0000000 --- a/bench/libdimension/prtree.c +++ /dev/null @@ -1,119 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2011 Tavian Barnes * - * * - * This file is part of The Dimension Benchmark Suite. * - * * - * The Dimension Benchmark 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 Benchmark 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 . * - *************************************************************************/ - -#include "dimension-impl.h" -#include -#include - -static bool -dmnsn_fake_intersection_fn(const dmnsn_object *object, dmnsn_line line, - dmnsn_intersection *intersection) -{ - intersection->t = (object->bounding_box.min.z - line.x0.z)/line.n.z; - intersection->normal = dmnsn_x; - return true; -} - -static bool -dmnsn_fake_inside_fn(const dmnsn_object *object, dmnsn_vector point) -{ - return true; -} - -static void -dmnsn_randomize_bounding_box(dmnsn_object *object) -{ - dmnsn_vector a, b; - - a.x = 2.0*((double)rand())/RAND_MAX - 1.0; - a.y = 2.0*((double)rand())/RAND_MAX - 1.0; - a.z = 2.0*((double)rand())/RAND_MAX - 1.0; - - b.x = 2.0*((double)rand())/RAND_MAX - 1.0; - b.y = 2.0*((double)rand())/RAND_MAX - 1.0; - b.z = 2.0*((double)rand())/RAND_MAX - 1.0; - - object->bounding_box.min = dmnsn_vector_min(a, b); - object->bounding_box.max = dmnsn_vector_max(a, b); -} - -static dmnsn_object * -dmnsn_new_fake_object(void) -{ - dmnsn_object *object = dmnsn_new_object(); - /* Generate a bounding box in (-1, -1, -1), (1, 1, 1) */ - dmnsn_randomize_bounding_box(object); - object->intersection_fn = dmnsn_fake_intersection_fn; - object->inside_fn = dmnsn_fake_inside_fn; - return object; -} - -int -main(void) -{ - const size_t nobjects = 10000; - - sandglass_t sandglass; - if (sandglass_init_monotonic(&sandglass, SANDGLASS_CPUTIME) != 0) { - perror("sandglass_create()"); - return EXIT_FAILURE; - } - - dmnsn_array *objects = dmnsn_new_array(sizeof(dmnsn_object *)); - for (size_t i = 0; i < nobjects; ++i) { - dmnsn_object *object = dmnsn_new_fake_object(); - dmnsn_initialize_object(object); - dmnsn_array_push(objects, &object); - } - - dmnsn_prtree *tree; - sandglass_bench_noprecache(&sandglass, { - tree = dmnsn_new_prtree(objects); - }); - printf("dmnsn_new_prtree(): %ld\n", sandglass.grains); - - /* dmnsn_prtree_intersection() */ - dmnsn_line ray = dmnsn_new_line( - dmnsn_new_vector( 1.0, 1.0, -2.0), - dmnsn_new_vector(-0.5, -0.5, 1.0) - ); - dmnsn_intersection intersection; - - sandglass_bench_fine(&sandglass, { - dmnsn_prtree_intersection(tree, ray, &intersection, true); - }); - printf("dmnsn_prtree_intersection(): %ld\n", sandglass.grains); - - /* dmnsn_prtree_inside() */ - sandglass_bench_fine(&sandglass, { - dmnsn_prtree_inside(tree, dmnsn_zero); - }); - printf("dmnsn_prtree_inside(): %ld\n", sandglass.grains); - - /* Cleanup */ - dmnsn_delete_prtree(tree); - for (size_t i = 0; i < nobjects; ++i) { - dmnsn_object *object; - dmnsn_array_get(objects, i, &object); - dmnsn_delete_object(object); - } - - dmnsn_delete_array(objects); - return EXIT_SUCCESS; -} diff --git a/configure.ac b/configure.ac index 66833e3..e8e8b8c 100644 --- a/configure.ac +++ b/configure.ac @@ -170,13 +170,10 @@ AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_FILES([Makefile libdimension/Makefile libdimension/Doxyfile + libdimension/bench/Makefile libdimension/libdimension.pc + libdimension/tests/Makefile dimension/Makefile - tests/Makefile - tests/libdimension/Makefile - tests/dimension/Makefile - bench/Makefile - bench/libdimension/Makefile - bench/dimension/Makefile - doc/Makefile]) + dimension/bench/Makefile + dimension/tests/Makefile]) AC_OUTPUT diff --git a/dimension/Makefile.am b/dimension/Makefile.am index 4eaf64a..72aaad9 100644 --- a/dimension/Makefile.am +++ b/dimension/Makefile.am @@ -17,6 +17,9 @@ ## along with this program. If not, see . ## ########################################################################### +SUBDIRS = bench \ + tests + # Make dmnsn_error() backtraces useful AM_LDFLAGS = -rdynamic @@ -78,3 +81,8 @@ dimension_SOURCES = directives.y \ y.tab.h dimension_LDADD = $(top_builddir)/libdimension/libdimension.la dimension_LDFLAGS = $(AM_LDFLAGS) + +bench: all-recursive + cd bench && $(MAKE) $(AM_MAKEFLAGS) bench + +.PHONY: bench diff --git a/dimension/bench/Makefile.am b/dimension/bench/Makefile.am new file mode 100644 index 0000000..e7fe03f --- /dev/null +++ b/dimension/bench/Makefile.am @@ -0,0 +1,35 @@ +########################################################################### +## Copyright (C) 2009-2010 Tavian Barnes ## +## ## +## This file is part of The Dimension Build Suite. ## +## ## +## The Dimension Build 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 Build 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 . ## +########################################################################### + +ENVIRONMENT = top_builddir=$(top_builddir) + +bench: tokenize.sh parse.sh render.sh + $(ENVIRONMENT) ./tokenize.sh + $(ENVIRONMENT) ./parse.sh + $(ENVIRONMENT) ./render.sh + +.sh: + cp $(srcdir)/$@ . + +clean-local: + rm -f *.png + +EXTRA_DIST = bench.pov + +.PHONY: bench diff --git a/dimension/bench/bench.pov b/dimension/bench/bench.pov new file mode 100644 index 0000000..a4f632f --- /dev/null +++ b/dimension/bench/bench.pov @@ -0,0 +1,118 @@ +/************************************************************************* + * Copyright (C) 2009-2010 Tavian Barnes * + * * + * This file is part of The Dimension Benchmark Suite. * + * * + * The Dimension Benchmark 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 Benchmark 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 . * + *************************************************************************/ + +camera { + location <3.0, 6.0, -11.0> + right x*image_width/image_height + look_at 0 +} + +background { + color rgb 1 +} + +// inside center sphere +light_source { + 0, + color rgb 1 +} + +light_source { + 2*y, + color rgb 1 +} + +/* plane { + y, + -1 + // *** hollow on + pigment { + rgb <0.73, 0.90, 0.97> + } + finish { + diffuse 0.35 + ambient .5 + } +} */ + +#macro sph(center) + sphere { + center, + 1 + texture { + // *** crackle + scale 0.5 + + /* *** texture_map { + [ 0.03 + pigment { + color rgb 1 + } + finish { + ambient 1 + } + normal { + facets size 0.1 + } + ] + [ 0.04 + pigment { + color rgbf <1, 1, 1, 0.9> + } + finish { + reflection { 0.2 } + specular 0.1 + roughness 0.02 + conserve_energy + } + normal { + facets size 0.1 + } + ] + } *** */ + } + interior { + ior 1.3 + } + } +#end + +union { + #declare Size = 4; + #declare I = -Size; + #while (I <= Size) + #declare J = -Size; + + #while (J <= Size) + #declare K = -Size; + + #while (K <= Size) + object { + sph(<2.5*I, 2.5*K, 2.5*J>) + } + + #declare K = K + 1; + #end + + #declare J = J + 1; + #end + + #declare I = I + 1; + #end +} diff --git a/dimension/bench/parse.sh b/dimension/bench/parse.sh new file mode 100755 index 0000000..b7db055 --- /dev/null +++ b/dimension/bench/parse.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +######################################################################### +# Copyright (C) 2009-2010 Tavian Barnes # +# # +# This file is part of The Dimension Benchmark Suite. # +# # +# The Dimension Benchmark 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 Benchmark 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 . # +######################################################################### + +for i in {1..10000}; do + echo ' +difference { + box { + <-1, -1, -1>, <1, 1, 1> + + rotate 45*x + + texture { + pigment { + color rgbft <0, 0, 1, 0.25, 0.5> + } + finish { + reflection { 0.5 } + } + } + + interior { + ior 1.1 + } + } + + sphere { + <0, 0, 0>, 1.25 + + texture { + pigment { + color rgb <0, 1, 0> + } + finish { + phong 0.2 + phong_size 40.0 + } + } + } +} +' +done | (time ${top_builddir}/dimension/dimension --parse /dev/stdin >/dev/null) diff --git a/dimension/bench/render.sh b/dimension/bench/render.sh new file mode 100755 index 0000000..b661e53 --- /dev/null +++ b/dimension/bench/render.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +######################################################################### +# Copyright (C) 2009-2011 Tavian Barnes # +# # +# This file is part of The Dimension Benchmark Suite. # +# # +# The Dimension Benchmark 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 Benchmark 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 . # +######################################################################### + +echo -e "Single-threaded" +time ${top_builddir}/dimension/dimension -w1920 -h1080 --quality=1 --threads=1 bench.pov +echo -e "\nMulti-threaded" +time ${top_builddir}/dimension/dimension -w1920 -h1080 --quality=1 bench.pov diff --git a/dimension/bench/tokenize.sh b/dimension/bench/tokenize.sh new file mode 100755 index 0000000..1d833d5 --- /dev/null +++ b/dimension/bench/tokenize.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +######################################################################### +# Copyright (C) 2009-2010 Tavian Barnes # +# # +# This file is part of The Dimension Benchmark Suite. # +# # +# The Dimension Benchmark 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 Benchmark 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 . # +######################################################################### + +for i in {1..10000}; do + echo '{}()[]+-*/,;?:&.|=<>!<= >= != "This is a string with escape sequences: \a\b\f\n\r\t\u2123\v\\\"" 1 123456789 01234567 0x123456789 -0x01 .1 0.1 1.0 0.123456789 -0.123456789 <1, 2.2, -3.03> Undefined' +done | (time ${top_builddir}/dimension/dimension --tokenize /dev/stdin >/dev/null) diff --git a/dimension/tests/Makefile.am b/dimension/tests/Makefile.am new file mode 100644 index 0000000..c54bcd4 --- /dev/null +++ b/dimension/tests/Makefile.am @@ -0,0 +1,55 @@ +########################################################################### +## Copyright (C) 2009-2010 Tavian Barnes ## +## ## +## This file is part of The Dimension Build Suite. ## +## ## +## The Dimension Build 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 Build 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 . ## +########################################################################### + +INCLUDES = -I$(top_srcdir)/libdimension + +TESTS = punctuation.sh \ + numeric.sh \ + strings.sh \ + labels.sh \ + directives.sh \ + arithexp.sh \ + transformations.sh \ + invalid-macro.sh \ + tbuffer-overlap.sh \ + integer-overflow.sh \ + csg.sh \ + demo.sh +TESTS_ENVIRONMENT = top_builddir=$(top_builddir) dimension_flags=--strict + +.sh: + cp $(srcdir)/$@ . + +EXTRA_DIST = $(TESTS) \ + punctuation.pov \ + numeric.pov \ + strings.pov \ + labels.pov \ + directives.inc \ + directives.pov \ + arithexp.pov \ + transformations.pov \ + invalid-macro.pov \ + tbuffer-overlap.pov \ + integer-overflow.pov \ + csg.pov \ + demo.pov + +clean-local: + rm -f *.png diff --git a/dimension/tests/arithexp.pov b/dimension/tests/arithexp.pov new file mode 100644 index 0000000..d38b13a --- /dev/null +++ b/dimension/tests/arithexp.pov @@ -0,0 +1,218 @@ +/************************************************************************* + * Copyright (C) 2009-2010 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +// Test arithmetic expression handling + +sphere { + 2*<<2.0 - 1.0, 3.0, 4.0>.x, (1.0 + 2)*2 - 5, 1.0 + 2*2 - 4> - -<0, 0, 1>, + exp(1) - (0 >= 1 ? 0 : 1*2) +} + +/* Float functions */ + +#if (abs(-1) != 1) + #error "abs" +#end + +#if (acos(0) != 1.570796326794897) + #error "acos" +#end + +#if (acosh(2) != 1.316957896924817) + #error "acosh" +#end + +#if (asc("ABC") != 65) + #error "asc" +#end + +#if (asin(1) != 1.570796326794897) + #error "asin" +#end + +#if (asinh(2) != 1.44363547517881) + #error "asinh" +#end + +#if (atan(1) != 0.7853981633974483) + #error "atan" +#end + +#if (atan2(-1, -1) != -2.35619449019234) + #error "atan2" +#end + +#if (atanh(0.5) != 0.5493061443340548) + #error "atanh" +#end + +#if (ceil(-1.5) != -1) + #error "ceil" +#end + +#if (cos(1.570796326794897) != 0) + #error "cos" +#end + +#if (cosh(1.316957896924817) != 2) + #error "cosh" +#end + +#if (degrees(1.570796326794897) != 90) + #error "degrees" +#end + +#if (div(3,2) != 1) + #error "div" +#end + +#if (exp(1) != 2.718281828459045) + #error "exp" +#end + +#if (floor(-1.5) != -2) + #error "floor" +#end + +#if (int(-1.9) != -1) + #error "int" +#end + +#if (ln(2.718281828459045) != 1) + #error "ln" +#end + +#if (log(1000) != 3) + #error "log" +#end + +#if (max(-1.5, 0, 1) != 1) + #error "max" +#end + +#if (min(-1.5, 0, 1) != -1.5) + #error "min" +#end + +#if (mod(3.5, 2) != 1.5) + #error "mod" +#end + +#if (pow(2, 3) != 8) + #error "pow" +#end + +#if (radians(90) != 1.570796326794897) + #error "radians" +#end + +#if (sin(1.570796326794897) != 1) + #error "sin" +#end + +#if (sinh(1.44363547517881) != 2) + #error "sinh" +#end + +#if (strcmp("asdfjkl;", "jkl;asdf") >= 0) + #error "strcmp" +#end + +#if (strlen("asdfjkl;") != 8) + #error "strlen" +#end + +#if (sqrt(2) != 1.414213562373095) + #error "sqrt" +#end + +#if (tan(0.7853981633974483) != 1) + #error "tan" +#end + +#if (tanh(0.5493061443340548) != 0.5) + #error "tanh" +#end + +#if (val("123.45") != 123.45) + #error "val" +#end + +#if (vaxis_rotate(<1, 0, 0>, <1, 0, 1>, 180) != <0, 0, 1>) + #error "vaxis_rotate" +#end + +#if (vaxis_rotate(1, 1, 180) != <1, 1, 1>) + #error "vaxis_rotate" +#end + +#if (vcross(<1, 2, 3>, <3, 2, 1>) != <-4, 8, -4>) + #error "vcross" +#end + +#if (vcross(1, 2) != 0) + #error "vcross" +#end + +#if (vdot(<1, 2, 3>, 2) != 12) + #error "vdot" +#end + +#if (vdot(2, 2) != 12) + #error "vdot" +#end + +#if (vlength(<1, 1, 1>) != 1.732050807568877) + #error "vlength" +#end + +#if (vlength(1) != 1.732050807568877) + #error "vlength" +#end + +#if (vnormalize(<1, 1, 1>) + != <0.5773502691896258, 0.5773502691896258, 0.5773502691896258>) + #error "vnormalize" +#end + +#if (vnormalize(1) != 0.4472135954999579) // Vector promoted comparison + #error "vnormalize" +#end + +#if (vrotate(<1, 0, 0>, <0, -90, 0>) != <0, 0, 1>) + #error "vrotate" +#end + +#if (vrotate(1, 2) != <1, 1, 1>) + #error "vrotate" +#end + +/* Float built-in IDs */ + +#if (pi != 3.141592653589793) + #error "pi" +#end + +#if (!true | !yes | !on) + #error "true" +#end + +#if (false | no | off) + #error "false" +#end diff --git a/dimension/tests/arithexp.sh b/dimension/tests/arithexp.sh new file mode 100755 index 0000000..e46ab04 --- /dev/null +++ b/dimension/tests/arithexp.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +######################################################################### +# Copyright (C) 2009-2011 Tavian Barnes # +# # +# 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 . # +######################################################################### + +arithexp=$(${top_builddir}/dimension/dimension ${dimension_flags} --parse ${srcdir}/arithexp.pov) +arithexp_exp="$(echo -n \ +'((object + (sphere + (vector (float 2) (float 2) (float 3) (integer 0) (integer 0)) + (float 0.718282)) + object-modifiers))' \ +| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g')" + +if [ "$arithexp" != "$arithexp_exp" ]; then + echo "arithexp.pov parsed as \"$arithexp\"" >&2 + echo " -- expected \"$arithexp_exp\"" >&2 + exit 1 +fi diff --git a/dimension/tests/csg.pov b/dimension/tests/csg.pov new file mode 100644 index 0000000..357fd7b --- /dev/null +++ b/dimension/tests/csg.pov @@ -0,0 +1,65 @@ +/************************************************************************* + * Copyright (C) 2010 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +// Test constructive solid geometry + +camera { + perspective + location -4*z + right x*image_width/image_height + look_at 0 +} + +background { + color rgbf <0, 0.1, 0.2, 0.1> +} + +/* One-object unions */ + +union { + sphere { + -1.5*x, 1 + pigment { color red 1 } + } +} + +union { + light_source { + 20*y, color rgb 0.5 + } +} + +/* CSG with lights */ +difference { + light_source { + -15*x, color rgb 0.5 + } + sphere { + 1.5*x - 20*y, 1 + pigment { color green 1 } + } + light_source { + 15*x, color rgb 0.5 + } + box { + <0.7, -20.8, -0.8>, <2.3, -19.2, 0.8> + pigment { color blue 1 } + } + translate 20*y +} diff --git a/dimension/tests/csg.sh b/dimension/tests/csg.sh new file mode 100755 index 0000000..b57389d --- /dev/null +++ b/dimension/tests/csg.sh @@ -0,0 +1,94 @@ +#!/bin/sh + +######################################################################### +# Copyright (C) 2010-2011 Tavian Barnes # +# # +# 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 . # +######################################################################### + +csg=$(${top_builddir}/dimension/dimension ${dimension_flags} -w768 -h480 --parse ${srcdir}/csg.pov) +csg_exp="$(echo -n \ +'((camera + perspective + (location (vector (integer 0) (integer 0) (integer -4) + (integer 0) (integer 0))) + (right (vector (float 1.6) (integer 0) (integer 0) (integer 0) (integer 0))) + (look_at (vector (integer 0) (integer 0) (integer 0) + (integer 0) (integer 0)))) + (background + (vector (integer 0) (float 0.1) (float 0.2) (float 0.1) (integer 0))) + (object + (union + (object + (sphere + (vector (float -1.5) (float 0) (float 0) (float 0) (float 0)) + (integer 1)) + (object-modifiers + (pigment + (vector (integer 1) (integer 0) (integer 0) + (integer 0) (integer 0)) + pigment-modifiers)))) + object-modifiers) + (object + (union + (light_source + (vector (integer 0) (integer 20) (integer 0) (integer 0) (integer 0)) + (vector (float 0.5) (float 0.5) (float 0.5) (integer 0) (integer 0)) + object-modifiers)) + object-modifiers) + (object + (difference + (light_source + (vector (integer -15) (integer 0) (integer 0) (integer 0) (integer 0)) + (vector (float 0.5) (float 0.5) (float 0.5) (integer 0) (integer 0)) + object-modifiers) + (object + (sphere + (vector (float 1.5) (float -20) (float 0) (float 0) (float 0)) + (integer 1)) + (object-modifiers + (pigment + (vector (integer 0) (integer 1) (integer 0) + (integer 0) (integer 0)) + pigment-modifiers))) + (light_source + (vector (integer 15) (integer 0) (integer 0) (integer 0) (integer 0)) + (vector (float 0.5) (float 0.5) (float 0.5) (integer 0) (integer 0)) + object-modifiers) + (object + (box + (vector (float 0.7) (float -20.8) (float -0.8) + (integer 0) (integer 0)) + (vector (float 2.3) (float -19.2) (float 0.8) + (integer 0) (integer 0))) + (object-modifiers + (pigment + (vector (integer 0) (integer 0) (integer 1) + (integer 0) (integer 0)) + pigment-modifiers)))) + (object-modifiers + (transformation + (translation (vector (integer 0) (integer 20) (integer 0) + (integer 0) (integer 0)))))))' \ +| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g')" + +if [ "$csg" != "$csg_exp" ]; then + echo "csg.pov parsed as \"$csg\"" >&2 + echo " -- expected \"$csg_exp\"" >&2 + exit 1 +fi + +${top_builddir}/dimension/dimension ${dimension_flags} -w768 -h480 -o csg.png ${srcdir}/csg.pov diff --git a/dimension/tests/demo.pov b/dimension/tests/demo.pov new file mode 100644 index 0000000..91be9d2 --- /dev/null +++ b/dimension/tests/demo.pov @@ -0,0 +1,150 @@ +/************************************************************************* + * Copyright (C) 2009-2010 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +// Render demo scene + +global_settings { + max_trace_level 5 + adc_bailout 1/255 +} + +camera { + perspective + location <0, 0.25, -4> + right x*image_width/image_height + look_at <0, 0, 0> + + rotate 53*y +} + +background { + color transmit 1 +} + +sky_sphere { + pigment { + gradient y + color_map { + [0.0 color rgb <1, 0.5, 0>] + [0.35 color rgbf <0, 0.1, 0.2, 0.1>] + } + } +} + +light_source { + <-15, 20, 10>, color rgb <1, 1, 1> +} + +difference { + box { + <-1, -1, -1>, <1, 1, 1> + + rotate 45*x + + texture { + pigment { + color rgbft <0, 0, 1, 0.25, 0.5> + } + finish { + reflection { 0.5 } + } + } + + interior { + ior 1.1 + } + } + + sphere { + <0, 0, 0>, 1.25 + + texture { + pigment { + color rgb <0, 1, 0> + } + finish { + phong 0.2 + phong_size 40.0 + } + } + } +} + +union { + cylinder { + -1.25*y, 1.25*y, 0.1 + } + cone { + 1.25*y, 0.1, 1.5*y, 0 + open + } + + pigment { + gradient y + color_map { + [0 color rgb <1, 0, 0>] + [1/6 color rgb <1, 0.5, 0>] + [2/6 color rgb <1, 1, 0>] + [3/6 color rgb <0, 1, 0>] + [4/6 color rgb <0, 0, 1>] + [5/6 color rgb <1, 0, 1>] + [1 color rgb <1, 0, 0>] + } + scale <1, 2.75, 1> + translate -1.25*y + } + rotate -45*x +} + +union { + torus { + 0.15, 0.05 + translate -y + } + torus { + 0.15, 0.05 + } + torus { + 0.15, 0.05 + translate y + } + + pigment { + color rgb <0, 0, 1> + } + finish { + ambient 1 + } + rotate -45*x +} + +plane { + y, -2 + pigment { + checker + pigment { + color rgb 1 + } + pigment { + checker color rgb 0, color rgb 1 + scale 1/3 + } + quick_color rgb <1, 0.5, 0.75> + } +} diff --git a/dimension/tests/demo.sh b/dimension/tests/demo.sh new file mode 100755 index 0000000..233b880 --- /dev/null +++ b/dimension/tests/demo.sh @@ -0,0 +1,220 @@ +#!/bin/sh + +######################################################################### +# Copyright (C) 2009-2011 Tavian Barnes # +# # +# 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 . # +######################################################################### + +demo=$(${top_builddir}/dimension/dimension ${dimension_flags} -w768 -h480 --parse ${srcdir}/demo.pov) +demo_exp=$(echo -n \ +'((global_settings + (max_trace_level (integer 5)) + (adc_bailout (float 0.00392157))) + (camera + perspective + (location (vector (integer 0) (float 0.25) (integer -4) + (integer 0) (integer 0))) + (right (vector (float 1.6) (integer 0) (integer 0) (integer 0) (integer 0))) + (look_at (vector (integer 0) (integer 0) (integer 0) + (integer 0) (integer 0))) + (transformation + (rotation (vector (integer 0) (integer 53) (integer 0) + (integer 0) (integer 0))))) + (background + (vector (integer 0) (integer 0) (integer 0) (integer 0) (integer 1))) + (sky_sphere + (pigment + (pattern + (gradient (vector (integer 0) (integer 1) + (integer 0) (integer 0) (integer 0)))) + (pigment-modifiers + (color_map + (color_map-entry + (float 0) + (vector (integer 1) (float 0.5) (integer 0) + (integer 0) (integer 0))) + (color_map-entry + (float 0.35) + (vector (integer 0) (float 0.1) (float 0.2) + (float 0.1) (integer 0))))))) + (light_source + (vector (integer -15) (integer 20) (integer 10) (integer 0) (integer 0)) + (vector (integer 1) (integer 1) (integer 1) (integer 0) (integer 0)) + object-modifiers) + (object + (difference + (object + (box + (vector (integer -1) (integer -1) (integer -1) + (integer 0) (integer 0)) + (vector (integer 1) (integer 1) (integer 1) (integer 0) (integer 0))) + (object-modifiers + (transformation + (rotation (vector (integer 45) (integer 0) (integer 0) + (integer 0) (integer 0)))) + (texture + (pigment + (vector (integer 0) (integer 0) (integer 1) + (float 0.25) (float 0.5)) + pigment-modifiers) + (finish + (reflection + (vector (float 0.5) (float 0.5) (float 0.5) + (float 0.5) (float 0.5)) + (vector (float 0.5) (float 0.5) (float 0.5) + (float 0.5) (float 0.5)) + reflection-items))) + (interior + (ior (float 1.1))))) + (object + (sphere + (vector (integer 0) (integer 0) (integer 0) (integer 0) (integer 0)) + (float 1.25)) + (object-modifiers + (texture + (pigment + (vector (integer 0) (integer 1) (integer 0) + (integer 0) (integer 0)) + pigment-modifiers) + (finish + (phong (float 0.2)) + (phong_size (float 40))))))) + object-modifiers) + (object + (union + (object + (cylinder + (vector (float 0) (float -1.25) (float 0) (float 0) (float 0)) + (vector (float 0) (float 1.25) (float 0) (float 0) (float 0)) + (float 0.1) + (integer 0)) + object-modifiers) + (object + (cone + (vector (float 0) (float 1.25) (float 0) (float 0) (float 0)) + (float 0.1) + (vector (float 0) (float 1.5) (float 0) (float 0) (float 0)) + (integer 0) + (integer 1)) + object-modifiers)) + (object-modifiers + (pigment + (pattern (gradient (vector (integer 0) (integer 1) (integer 0) + (integer 0) (integer 0)))) + (pigment-modifiers + (color_map + (color_map-entry + (integer 0) + (vector (integer 1) (integer 0) (integer 0) + (integer 0) (integer 0))) + (color_map-entry + (float 0.166667) + (vector (integer 1) (float 0.5) (integer 0) + (integer 0) (integer 0))) + (color_map-entry + (float 0.333333) + (vector (integer 1) (integer 1) (integer 0) + (integer 0) (integer 0))) + (color_map-entry + (float 0.5) + (vector (integer 0) (integer 1) (integer 0) + (integer 0) (integer 0))) + (color_map-entry + (float 0.666667) + (vector (integer 0) (integer 0) (integer 1) + (integer 0) (integer 0))) + (color_map-entry + (float 0.833333) + (vector (integer 1) (integer 0) (integer 1) + (integer 0) (integer 0))) + (color_map-entry + (integer 1) + (vector (integer 1) (integer 0) (integer 0) + (integer 0) (integer 0)))) + (transformation + (scale (vector (integer 1) (float 2.75) (integer 1) + (integer 0) (integer 0)))) + (transformation + (translation (vector (float 0) (float -1.25) (float 0) + (float 0) (float 0)))))) + (transformation + (rotation (vector (integer -45) (integer 0) (integer 0) + (integer 0) (integer 0)))))) + (object + (union + (object + (torus (float 0.15) (float 0.05)) + (object-modifiers + (transformation + (translation (vector (integer 0) (integer -1) (integer 0) + (integer 0) (integer 0)))))) + (object + (torus (float 0.15) (float 0.05)) + object-modifiers) + (object + (torus (float 0.15) (float 0.05)) + (object-modifiers + (transformation + (translation (vector (integer 0) (integer 1) (integer 0) + (integer 0) (integer 0))))))) + (object-modifiers + (pigment + (vector (integer 0) (integer 0) (integer 1) (integer 0) (integer 0)) + pigment-modifiers) + (finish + (ambient + (vector (integer 1) (integer 1) (integer 1) (integer 1) (integer 1)))) + (transformation + (rotation (vector (integer -45) (integer 0) (integer 0) + (integer 0) (integer 0)))))) + (object + (plane + (vector (integer 0) (integer 1) (integer 0) (integer 0) (integer 0)) + (integer -2)) + (object-modifiers + (pigment + (pattern checker) + (pigment-modifiers + (quick_color + (vector (integer 1) (float 0.5) (float 0.75) + (integer 0) (integer 0))) + (pigment-list + (pigment + (vector (integer 1) (integer 1) (integer 1) + (integer 0) (integer 0)) + pigment-modifiers) + (pigment + (pattern checker) + (pigment-modifiers + (transformation + (scale (vector (float 0.333333) (float 0.333333) + (float 0.333333) (float 0.333333) + (float 0.333333)))) + (color-list + (vector (integer 0) (integer 0) (integer 0) + (integer 0) (integer 0)) + (vector (integer 1) (integer 1) (integer 1) + (integer 0) (integer 0)))))))))))' \ +| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g') + +if [ "$demo" != "$demo_exp" ]; then + echo "demo.pov parsed as \"$demo\"" >&2 + echo " -- expected \"$demo_exp\"" >&2 + exit 1 +fi + +${top_builddir}/dimension/dimension ${dimension_flags} -w768 -h480 -o demo.png ${srcdir}/demo.pov diff --git a/dimension/tests/directives.inc b/dimension/tests/directives.inc new file mode 100644 index 0000000..a3dadb3 --- /dev/null +++ b/dimension/tests/directives.inc @@ -0,0 +1,21 @@ +/************************************************************************* + * Copyright (C) 2010 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +#declare Center = 0; +#local Local = -1; diff --git a/dimension/tests/directives.pov b/dimension/tests/directives.pov new file mode 100644 index 0000000..5c3cfa3 --- /dev/null +++ b/dimension/tests/directives.pov @@ -0,0 +1,92 @@ +/************************************************************************* + * Copyright (C) 2009-2010 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +// Test the language directives + +#version 3.6; + +#debug "debug" +#warning "warning" + +#include "directives.inc" + +#declare R = 1; +#local Color = rgb <1, 0, 1>; + +#declare Unused = -1; +#undef Unused + +#ifdef (Local) + #error "Local escaped from include file" +#end + +#ifdef (Unused) + #error "#undef failed" +#end + +#macro Make_Sphere(n) + sphere { + Center + <0, n, 0>, R + pigment { + color Color green 1 + } + } +#end + +#macro Inc(n) + #declare n = n + 1; +#end + +#declare Counter = 0; +#while (Counter < 2) + #if (#if (1 = 1) 0 #end = 0 & !1) + #error "Nested #if parsing failed" + #else + Make_Sphere(Counter) + #end + + Inc(Counter) +#end + +// Test macro parameters with the same name as existing variables +#declare Test1 = 0; +#declare Test2 = 1; +#declare Test3 = 2; +#macro ScopeTest(Test1, Test2, Test3) + #declare Test1 = Test2 - Test3; +#end +ScopeTest(Test1, Test3, Test2) +sphere { + 0, Test1 +} + +#declare Box = + box { + <-1, -1, -1>, <1, 1, 1> + pigment { + color rgb <1, 1, 1> + } + } + +object { + Box + finish { + phong 0.2 + } +} diff --git a/dimension/tests/directives.sh b/dimension/tests/directives.sh new file mode 100755 index 0000000..9e3974a --- /dev/null +++ b/dimension/tests/directives.sh @@ -0,0 +1,124 @@ +#!/bin/sh + +######################################################################### +# Copyright (C) 2009-2011 Tavian Barnes # +# # +# 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 . # +######################################################################### + +directives=$(${top_builddir}/dimension/dimension ${dimension_flags} --tokenize --parse ${srcdir}/directives.pov) +directives_exp="$(echo -n \ +'(#version (float "3.6") ; + #debug (string "debug") + #warning (string "warning") + #include (string "directives.inc") + #declare (identifier "R") = (integer "1") ; + #local (identifier "Color") = rgb < (integer "1") , (integer "0") , (integer "1") > ; + #declare (identifier "Unused") = - (integer "1") ; + #undef (identifier "Unused") + #ifdef \( (identifier "Local") \) + #error (string "Local escaped from include file") + #end + #ifdef \( (identifier "Unused") \) + #error (string "#undef failed") + #end + #macro (identifier "Make_Sphere") \( (identifier "n") \) + sphere { + (identifier "Center") + < (integer "0") , (identifier "n") , (integer "0") > , (identifier "R") + pigment { + color (identifier "Color") green (integer "1") + } + } + #end + #macro (identifier "Inc") \( (identifier "n") \) + #declare (identifier "n") = (identifier "n") + (integer "1") ; + #end + #declare (identifier "Counter") = (integer "0") ; + #while \( (identifier "Counter") < (integer "2") \) + #if \( #if \( (integer "1") = (integer "1") \) (integer "0") #end = (integer "0") & ! (integer "1") \) + #error (string "Nested #if parsing failed") + #else + (identifier "Make_Sphere") \( (identifier "Counter") \) + #end + (identifier "Inc") \( (identifier "Counter") \) + #end + + #declare (identifier "Test1") = (integer "0") ; + #declare (identifier "Test2") = (integer "1") ; + #declare (identifier "Test3") = (integer "2") ; + #macro (identifier "ScopeTest") \( (identifier "Test1") , (identifier "Test2") , (identifier "Test3") \) + #declare (identifier "Test1") = (identifier "Test2") - (identifier "Test3") ; + #end + (identifier "ScopeTest") \( (identifier "Test1") , (identifier "Test3") , (identifier "Test2") \) + sphere { + (integer "0") , (identifier "Test1") + } + + #declare (identifier "Box") = + box { + < - (integer "1") , - (integer "1") , - (integer "1") > , + < (integer "1") , (integer "1") , (integer "1") > + pigment { + color rgb < (integer "1") , (integer "1") , (integer "1") > + } + } + + object { + (identifier "Box") + finish { + phong (float "0.2") + } + })' \ +| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g') +$(echo -n \ +'((object + (sphere + (vector (integer 0) (integer 0) (integer 0) (integer 0) (integer 0)) + (integer 1)) + (object-modifiers + (pigment + (vector (integer 1) (integer 1) (integer 1) (integer 0) (integer 0)) + pigment-modifiers))) + (object + (sphere + (vector (integer 0) (integer 1) (integer 0) (integer 0) (integer 0)) + (integer 1)) + (object-modifiers + (pigment + (vector (integer 1) (integer 1) (integer 1) (integer 0) (integer 0)) + pigment-modifiers))) + (object + (sphere + (vector (integer 0) (integer 0) (integer 0) (integer 0) (integer 0)) + (integer 1)) + object-modifiers) + (object + (box + (vector (integer -1) (integer -1) (integer -1) (integer 0) (integer 0)) + (vector (integer 1) (integer 1) (integer 1) (integer 0) (integer 0))) + (object-modifiers + (pigment + (vector (integer 1) (integer 1) (integer 1) (integer 0) (integer 0)) + pigment-modifiers) + (finish + (phong (float 0.2))))))' \ +| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g')" + +if [ "$directives" != "$directives_exp" ]; then + echo "directives.pov parsed as \"$directives\"" >&2 + echo " -- expected \"$directives_exp\"" >&2 + exit 1 +fi diff --git a/dimension/tests/integer-overflow.pov b/dimension/tests/integer-overflow.pov new file mode 100644 index 0000000..a063fab --- /dev/null +++ b/dimension/tests/integer-overflow.pov @@ -0,0 +1,25 @@ +/************************************************************************* + * Copyright (C) 2009-2010 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +// Test integer overflow handling -- overflows should convert to floats + +torus { + 10000000000000000000, + abs(-2147483647 - 1)*abs(-9223372036854775807 - 1)*((-2147483647 - 2)*(2147483647 + 1))*((-9223372036854775807.0 - 2)*(9223372036854775807.0 + 1))*(65536*65536)*(4294967296*4294967296.0) +} diff --git a/dimension/tests/integer-overflow.sh b/dimension/tests/integer-overflow.sh new file mode 100755 index 0000000..0e1f03e --- /dev/null +++ b/dimension/tests/integer-overflow.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +######################################################################### +# Copyright (C) 2009-2011 Tavian Barnes # +# # +# 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 . # +######################################################################### + +integer_overflow=$(${top_builddir}/dimension/dimension ${dimension_flags} --parse ${srcdir}/integer-overflow.pov) +integer_overflow_exp="$(echo -n \ +'((object + (torus + (float 1e+19) + (float 6.15656e+113)) + object-modifiers))' \ +| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g')" + +if [ "$integer_overflow" != "$integer_overflow_exp" ]; then + echo "integer-overflow.pov parsed as \"$integer_overflow\"" >&2 + echo " -- expected \"$integer_overflow_exp\"" >&2 + exit 1 +fi diff --git a/dimension/tests/invalid-macro.pov b/dimension/tests/invalid-macro.pov new file mode 100644 index 0000000..9906da4 --- /dev/null +++ b/dimension/tests/invalid-macro.pov @@ -0,0 +1,26 @@ +/************************************************************************* + * Copyright (C) 2009-2010 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +// Regression test for commit 11d364ec365c46c21271012b566966d342a90a8b + +#macro Macro() + { } +#end + +Macro() diff --git a/dimension/tests/invalid-macro.sh b/dimension/tests/invalid-macro.sh new file mode 100755 index 0000000..cf6f353 --- /dev/null +++ b/dimension/tests/invalid-macro.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +######################################################################### +# Copyright (C) 2009-2011 Tavian Barnes # +# # +# 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 . # +######################################################################### + +${top_builddir}/dimension/dimension ${dimension_flags} --parse ${srcdir}/invalid-macro.pov +[ $? -lt 128 -a $? -gt 0 ] diff --git a/dimension/tests/labels.pov b/dimension/tests/labels.pov new file mode 100644 index 0000000..369e1fd --- /dev/null +++ b/dimension/tests/labels.pov @@ -0,0 +1,31 @@ +/************************************************************************* + * Copyright (C) 2009-2010 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +// Test that we correctly tokenize identifiers and keywords + +camera { +} + +sphere { + color new_identifier +} + +box { + colour new_identifier +} diff --git a/dimension/tests/labels.sh b/dimension/tests/labels.sh new file mode 100755 index 0000000..47365bd --- /dev/null +++ b/dimension/tests/labels.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +######################################################################### +# Copyright (C) 2009-2011 Tavian Barnes # +# # +# 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 . # +######################################################################### + +labels=$(${top_builddir}/dimension/dimension ${dimension_flags} --tokenize ${srcdir}/labels.pov) +labels_exp='(camera { } sphere { color (identifier "new_identifier") } box { color (identifier "new_identifier") })'; + +if [ "$labels" != "$labels_exp" ]; then + echo "labels.pov tokenized as \"$labels\"" >&2 + echo " -- expected \"$labels_exp\"" >&2 + exit 1 +fi diff --git a/dimension/tests/numeric.pov b/dimension/tests/numeric.pov new file mode 100644 index 0000000..dbf3c19 --- /dev/null +++ b/dimension/tests/numeric.pov @@ -0,0 +1,30 @@ +/************************************************************************* + * Copyright (C) 2009-2010 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +// Test that we correctly tokenize numeric values. Note that the `-' in `-1', +// for example, is a separate token and not part of the number. + +// Integers: +1 123456789 01234567 0x123456789 -0x01 + +// Floats: +.1 0.1 1.0 0.123456789 -0.123456789 + +// A vector: +<1, 2.2, -3.03> diff --git a/dimension/tests/numeric.sh b/dimension/tests/numeric.sh new file mode 100755 index 0000000..c5e7c93 --- /dev/null +++ b/dimension/tests/numeric.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +######################################################################### +# Copyright (C) 2009-2011 Tavian Barnes # +# # +# 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 . # +######################################################################### + +numeric=$(${top_builddir}/dimension/dimension ${dimension_flags} --tokenize ${srcdir}/numeric.pov) +numeric_exp=$(echo -n \ +'((integer "1") + (integer "123456789") + (integer "01234567") + (integer "0x123456789") + - (integer "0x01") + + (float ".1") + (float "0.1") + (float "1.0") + (float "0.123456789") + - (float "0.123456789") + + < (integer "1") , (float "2.2") , - (float "3.03") >)' \ +| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g') + +if [ "$numeric" != "$numeric_exp" ]; then + echo "numeric.pov tokenized as \"$numeric\"" >&2 + echo " -- expected \"$numeric_exp\"" >&2 + exit 1 +fi diff --git a/dimension/tests/punctuation.pov b/dimension/tests/punctuation.pov new file mode 100644 index 0000000..d61db25 --- /dev/null +++ b/dimension/tests/punctuation.pov @@ -0,0 +1,24 @@ +/************************************************************************* + * Copyright (C) 2009-2010 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +/* Test that we correctly tokenize all simple punctuation marks + * // Also make sure we handle nested /* comments */ properly + */ + +{}()[]+-*/,;?:&.|=<>!<= >= != diff --git a/dimension/tests/punctuation.sh b/dimension/tests/punctuation.sh new file mode 100755 index 0000000..6990657 --- /dev/null +++ b/dimension/tests/punctuation.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +######################################################################### +# Copyright (C) 2009-2011 Tavian Barnes # +# # +# 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 . # +######################################################################### + +punctuation=$(${top_builddir}/dimension/dimension ${dimension_flags} --tokenize ${srcdir}/punctuation.pov) +punctuation_exp='({ } \( \) [ ] + - * / , ; ? : & . | = < > ! <= >= !=)' + +if [ "$punctuation" != "$punctuation_exp" ]; then + echo "punctuation.pov tokenized as \"$punctuation\"" >&2 + echo " -- expected \"$punctuation_exp\"" >&2 + exit 1 +fi diff --git a/dimension/tests/strings.pov b/dimension/tests/strings.pov new file mode 100644 index 0000000..eafe1ba --- /dev/null +++ b/dimension/tests/strings.pov @@ -0,0 +1,21 @@ +/************************************************************************* + * Copyright (C) 2009-2010 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +// Test string handling, including escape sequences +"This is a string with escape sequences: \a\b\f\n\r\t\u2123\v\\\'\"" diff --git a/dimension/tests/strings.sh b/dimension/tests/strings.sh new file mode 100755 index 0000000..1f5f4f9 --- /dev/null +++ b/dimension/tests/strings.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +######################################################################### +# Copyright (C) 2009-2011 Tavian Barnes # +# # +# 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 . # +######################################################################### + +strings=$(${top_builddir}/dimension/dimension ${dimension_flags} --tokenize ${srcdir}/strings.pov) +strings_exp=$(/bin/echo -e "((string \"This is a string with escape sequences: \a\b\f\n\r\t!#\v\\\'\"\"))") + +if [ "$strings" != "$strings_exp" ]; then + echo "strings.pov tokenized as \"$strings\"" >&2 + echo " -- expected \"$strings_exp\"" >&2 + exit 1 +fi diff --git a/dimension/tests/tbuffer-overlap.pov b/dimension/tests/tbuffer-overlap.pov new file mode 100644 index 0000000..872b124 --- /dev/null +++ b/dimension/tests/tbuffer-overlap.pov @@ -0,0 +1,22 @@ +/************************************************************************* + * Copyright (C) 2009-2010 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +// Regression test for commit 72be096ff528306b1af6b41d5cacd1157b096d72 + +#if (1=1) #declare foo = #end; diff --git a/dimension/tests/tbuffer-overlap.sh b/dimension/tests/tbuffer-overlap.sh new file mode 100755 index 0000000..bc3126d --- /dev/null +++ b/dimension/tests/tbuffer-overlap.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +######################################################################### +# Copyright (C) 2009-2011 Tavian Barnes # +# # +# 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 . # +######################################################################### + +${top_builddir}/dimension/dimension ${dimension_flags} --parse ${srcdir}/tbuffer-overlap.pov +[ $? -lt 128 -a $? -gt 0 ] diff --git a/dimension/tests/transformations.pov b/dimension/tests/transformations.pov new file mode 100644 index 0000000..312445d --- /dev/null +++ b/dimension/tests/transformations.pov @@ -0,0 +1,39 @@ +/************************************************************************* + * Copyright (C) 2009-2010 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +// Test transformations + +#declare Trans = transform { translate 1*z } + +sphere { + 0, 1 + translate -1*x + rotate 90*y + scale 2 + transform Trans + matrix <1, 1, 0, + 0, 1, 0, + 0, 0, 1, + 0, 0, 0> + transform { + Trans + rotate 45*z + inverse + } +} diff --git a/dimension/tests/transformations.sh b/dimension/tests/transformations.sh new file mode 100755 index 0000000..727bf3b --- /dev/null +++ b/dimension/tests/transformations.sh @@ -0,0 +1,64 @@ +#!/bin/sh + +######################################################################### +# Copyright (C) 2009-2011 Tavian Barnes # +# # +# 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 . # +######################################################################### + +transformations=$(${top_builddir}/dimension/dimension ${dimension_flags} --parse ${srcdir}/transformations.pov) +transformations_exp="$(echo -n \ +'((object + (sphere + (vector (integer 0) (integer 0) (integer 0) (integer 0) (integer 0)) + (integer 1)) + (object-modifiers + (transformation + (translation + (vector (integer -1) (integer 0) (integer 0) + (integer 0) (integer 0)))) + (transformation + (rotation + (vector (integer 0) (integer 90) (integer 0) + (integer 0) (integer 0)))) + (transformation + (scale + (vector (integer 2) (integer 2) (integer 2) (integer 2) (integer 2)))) + (transformation + (translation + (vector (integer 0) (integer 0) (integer 1) (integer 0) (integer 0)))) + (transformation + (matrix + (integer 1) (integer 1) (integer 0) + (integer 0) (integer 1) (integer 0) + (integer 0) (integer 0) (integer 1) + (integer 0) (integer 0) (integer 0))) + (transformation + (translation + (vector (integer 0) (integer 0) (integer 1) (integer 0) (integer 0))) + (rotation + (vector (integer 0) (integer 0) (integer 45) + (integer 0) (integer 0))) + inverse))))' \ +| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g')" + +if [ "$transformations" != "$transformations_exp" ]; then + echo "transformations.pov parsed as \"$transformations\"" >&2 + echo " -- expected \"$transformations_exp\"" >&2 + exit 1 +fi + +${top_builddir}/dimension/dimension ${dimension_flags} -w1 -h1 -o /dev/null ${srcdir}/transformations.pov diff --git a/doc/Makefile.am b/doc/Makefile.am deleted file mode 100644 index 928bb0f..0000000 --- a/doc/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ -########################################################################### -## Copyright (C) 2009-2010 Tavian Barnes ## -## ## -## This file is part of The Dimension Build Suite. ## -## ## -## The Dimension Build 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 Build 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 . ## -########################################################################### diff --git a/libdimension/Doxyfile.in b/libdimension/Doxyfile.in index 23d7bfb..145bd15 100644 --- a/libdimension/Doxyfile.in +++ b/libdimension/Doxyfile.in @@ -1,7 +1,7 @@ DOXYFILE_ENCODING = UTF-8 PROJECT_NAME = libdimension PROJECT_NUMBER = @VERSION@ -OUTPUT_DIRECTORY = @top_builddir@/doc/libdimension +OUTPUT_DIRECTORY = @top_builddir@/libdimension/doc OUTPUT_LANGUAGE = English FULL_PATH_NAMES = YES OPTIMIZE_OUTPUT_FOR_C = YES diff --git a/libdimension/Makefile.am b/libdimension/Makefile.am index 4d4f58e..0a134b1 100644 --- a/libdimension/Makefile.am +++ b/libdimension/Makefile.am @@ -17,6 +17,9 @@ ## along with this program. If not, see . ## ########################################################################### +SUBDIRS = bench \ + tests + # Make dmnsn_error() backtraces useful AM_LDFLAGS = -rdynamic @@ -130,6 +133,12 @@ if PROFILE libdimension_la_SOURCES += profile.c endif +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = libdimension.pc + +bench: all-recursive + cd bench && $(MAKE) $(AM_MAKEFLAGS) bench + clean-local: clean-docs doc: @@ -137,5 +146,4 @@ doc: clean-docs: rm -rf $(top_builddir)/doc/libdimension -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = libdimension.pc +.PHONY: bench doc diff --git a/libdimension/bench/Makefile.am b/libdimension/bench/Makefile.am new file mode 100644 index 0000000..353acb3 --- /dev/null +++ b/libdimension/bench/Makefile.am @@ -0,0 +1,41 @@ +########################################################################### +## Copyright (C) 2009-2010 Tavian Barnes ## +## ## +## This file is part of The Dimension Build Suite. ## +## ## +## The Dimension Build 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 Build 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 . ## +########################################################################### + +INCLUDES = -I$(top_srcdir)/libdimension + +EXTRA_PROGRAMS = bench-array \ + bench-geometry \ + bench-polynomial \ + bench-prtree + +AM_CFLAGS = $(libsandglass_CFLAGS) -fno-inline +AM_LDFLAGS = $(libsandglass_LIBS) $(top_builddir)/libdimension/libdimension.la + +bench_array_SOURCES = array.c +bench_geometry_SOURCES = geometry.c +bench_polynomial_SOURCES = polynomial.c +bench_prtree_SOURCES = prtree.c + +bench: $(EXTRA_PROGRAMS) + ./bench-array + ./bench-geometry + ./bench-polynomial + ./bench-prtree + +.PHONY: bench diff --git a/libdimension/bench/array.c b/libdimension/bench/array.c new file mode 100644 index 0000000..3fe0c83 --- /dev/null +++ b/libdimension/bench/array.c @@ -0,0 +1,118 @@ +/************************************************************************* + * Copyright (C) 2009-2010 Tavian Barnes * + * * + * This file is part of The Dimension Benchmark Suite. * + * * + * The Dimension Benchmark 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 Benchmark 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 . * + *************************************************************************/ + +#include "dimension.h" +#include +#include +#include + +int +main(void) +{ + const unsigned int count = 32; + uint32_t object = 1; + + sandglass_t sandglass; + if (sandglass_init_monotonic(&sandglass, SANDGLASS_CPUTIME) != 0) { + perror("sandglass_create()"); + return EXIT_FAILURE; + } + + /* Benchmark allocation and deallocation */ + dmnsn_array *array; + sandglass_bench_fine(&sandglass, { + array = dmnsn_new_array(sizeof(object)); + dmnsn_delete_array(array); + }); + printf("dmnsn_new_array() + dmnsn_delete_array(): %ld\n", sandglass.grains); + + /* Create our test array */ + array = dmnsn_new_array(sizeof(object)); + + /* dmnsn_array_push() */ + + printf("dmnsn_array_push():"); + + for (unsigned int i = 0; i < count; ++i) { + sandglass_bench_noprecache(&sandglass, dmnsn_array_push(array, &object)); + printf(" %ld", sandglass.grains); + } + printf("\n"); + + /* dmnsn_array_get() */ + sandglass_bench_fine(&sandglass, dmnsn_array_get(array, count/2, &object)); + printf("dmnsn_array_get(): %ld\n", sandglass.grains); + + /* dmnsn_array_set() */ + sandglass_bench_fine(&sandglass, dmnsn_array_set(array, count/2, &object)); + printf("dmnsn_array_set(): %ld\n", sandglass.grains); + + /* dmnsn_array_at() */ + void *ptr; + sandglass_bench_fine(&sandglass, ptr = dmnsn_array_at(array, count/2)); + printf("dmnsn_array_at() = %p: %ld\n", ptr, sandglass.grains); + + /* dmnsn_array_size() */ + size_t size; + sandglass_bench_fine(&sandglass, size = dmnsn_array_size(array)); + printf("dmnsn_array_size() = %zu: %ld\n", size, sandglass.grains); + + /* dmnsn_array_resize() */ + dmnsn_array_resize(array, count); + sandglass_bench_noprecache(&sandglass, dmnsn_array_resize(array, count * 2)); + printf("dmnsn_array_resize(): %ld", sandglass.grains); + + sandglass_bench_noprecache(&sandglass, dmnsn_array_resize(array, count)); + printf(" %ld\n", sandglass.grains); + + /* dmnsn_array_insert() */ + + printf("dmnsn_array_insert():"); + + for (size_t i = 0; i < count; ++i) { + sandglass_bench_noprecache(&sandglass, + dmnsn_array_insert(array, count/2, &object)); + printf(" %ld", sandglass.grains); + } + printf("\n"); + + /* dmnsn_array_remove() */ + + printf("dmnsn_array_remove():"); + + for (size_t i = 0; i < count; ++i) { + sandglass_bench_noprecache(&sandglass, + dmnsn_array_remove(array, count/2)); + printf(" %ld", sandglass.grains); + } + printf("\n"); + + /* dmnsn_array_pop() */ + + printf("dmnsn_array_pop():"); + + for (size_t i = 0; i < count; ++i) { + sandglass_bench_noprecache(&sandglass, dmnsn_array_pop(array, &object)); + printf(" %ld", sandglass.grains); + } + printf("\n"); + + dmnsn_delete_array(array); + return EXIT_SUCCESS; +} diff --git a/libdimension/bench/geometry.c b/libdimension/bench/geometry.c new file mode 100644 index 0000000..4b77c9b --- /dev/null +++ b/libdimension/bench/geometry.c @@ -0,0 +1,171 @@ +/************************************************************************* + * Copyright (C) 2009-2010 Tavian Barnes * + * * + * This file is part of The Dimension Benchmark Suite. * + * * + * The Dimension Benchmark 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 Benchmark 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 . * + *************************************************************************/ + +#include "dimension.h" +#include +#include + +int +main(void) +{ + dmnsn_vector vector, vector2; + dmnsn_matrix matrix, matrix2; + dmnsn_line line; + double result; + + sandglass_t sandglass; + if (sandglass_init_monotonic(&sandglass, SANDGLASS_CPUTIME) != 0) { + perror("sandglass_create()"); + return EXIT_FAILURE; + } + + /* dmnsn_new_vector() */ + sandglass_bench_fine(&sandglass, { + vector = dmnsn_new_vector(1.0, 2.0, 3.0); + }); + printf("dmnsn_new_vector(): %ld\n", sandglass.grains); + + /* dmnsn_matrix_construct() */ + sandglass_bench_fine(&sandglass, { + matrix = dmnsn_new_matrix(1.0, 1.0, 0.0, 0.0, + 1.0, 1.0, 1.0, 0.0, + 0.0, 1.0, 1.0, 0.0); + }); + printf("dmnsn_new_matrix(): %ld\n", sandglass.grains); + + /* dmnsn_identity_matrix() */ + sandglass_bench_fine(&sandglass, { + matrix = dmnsn_identity_matrix(); + }); + printf("dmnsn_identity_matrix(): %ld\n", sandglass.grains); + + /* dmnsn_scale_matrix() */ + sandglass_bench_fine(&sandglass, { + matrix = dmnsn_scale_matrix(vector); + }); + printf("dmnsn_scale_matrix(): %ld\n", sandglass.grains); + + /* dmnsn_identity_matrix() */ + sandglass_bench_fine(&sandglass, { + matrix = dmnsn_translation_matrix(vector); + }); + printf("dmnsn_translation_matrix(): %ld\n", sandglass.grains); + + /* dmnsn_rotation_matrix() */ + sandglass_bench_fine(&sandglass, { + matrix = dmnsn_rotation_matrix(vector); + }); + printf("dmnsn_rotation_matrix(): %ld\n", sandglass.grains); + + /* dmnsn_new_line() */ + vector2 = dmnsn_new_vector(3.0, 2.0, 1.0); + sandglass_bench_fine(&sandglass, { + line = dmnsn_new_line(vector, vector2); + }); + printf("dmnsn_new_line(): %ld\n", sandglass.grains); + + /* dmnsn_vector_add() */ + sandglass_bench_fine(&sandglass, { + vector = dmnsn_vector_add(vector, vector2); + }); + printf("dmnsn_vector_add(): %ld\n", sandglass.grains); + + /* dmnsn_vector_sub() */ + sandglass_bench_fine(&sandglass, { + vector = dmnsn_vector_sub(vector, vector2); + }); + printf("dmnsn_vector_sub(): %ld\n", sandglass.grains); + + /* dmnsn_vector_mul() */ + sandglass_bench_fine(&sandglass, { + vector = dmnsn_vector_mul(2.0, vector); + }); + printf("dmnsn_vector_mul(): %ld\n", sandglass.grains); + + /* dmnsn_vector_div() */ + sandglass_bench_fine(&sandglass, { + vector = dmnsn_vector_div(vector, 2.0); + }); + printf("dmnsn_vector_div(): %ld\n", sandglass.grains); + + /* dmnsn_vector_cross() */ + sandglass_bench_fine(&sandglass, { + vector = dmnsn_vector_cross(vector, vector2); + }); + printf("dmnsn_vector_cross(): %ld\n", sandglass.grains); + + /* dmnsn_vector_dot() */ + sandglass_bench_fine(&sandglass, { + result = dmnsn_vector_dot(vector, vector2); + }); + printf("dmnsn_vector_dot(): %ld\n", sandglass.grains); + + /* dmnsn_vector_norm() */ + sandglass_bench_fine(&sandglass, { + result = dmnsn_vector_norm(vector); + }); + printf("dmnsn_vector_norm(): %ld\n", sandglass.grains); + + /* dmnsn_vector_normalize() */ + sandglass_bench_fine(&sandglass, { + vector = dmnsn_vector_normalize(vector); + }); + printf("dmnsn_vector_normalize(): %ld\n", sandglass.grains); + + /* dmnsn_matrix_inverse() */ + sandglass_bench_fine(&sandglass, { + matrix = dmnsn_matrix_inverse(matrix); + }); + printf("dmnsn_matrix_inverse(): %ld\n", sandglass.grains); + + /* dmnsn_matrix_inverse(HARD) */ + matrix2 = dmnsn_new_matrix(1.0, 1.0, 0.0, 0.0, + 1.0, 1.0, 1.0, 0.0, + 0.0, 1.0, 1.0, 0.0); + sandglass_bench_fine(&sandglass, { + matrix = dmnsn_matrix_inverse(matrix2); + }); + printf("dmnsn_matrix_inverse(HARD): %ld\n", sandglass.grains); + + /* dmnsn_matrix_mul() */ + sandglass_bench_fine(&sandglass, { + matrix = dmnsn_matrix_mul(matrix, matrix2); + }); + printf("dmnsn_matrix_mul(): %ld\n", sandglass.grains); + + /* dmnsn_transform_vector() */ + sandglass_bench_fine(&sandglass, { + vector = dmnsn_transform_vector(matrix, vector); + }); + printf("dmnsn_transform_vector(): %ld\n", sandglass.grains); + + /* dmnsn_transform_line() */ + sandglass_bench_fine(&sandglass, { + line = dmnsn_transform_line(matrix, line); + }); + printf("dmnsn_transform_line(): %ld\n", sandglass.grains); + + /* dmnsn_line_point() */ + sandglass_bench_fine(&sandglass, { + vector = dmnsn_line_point(line, result); + }); + printf("dmnsn_line_point(): %ld\n", sandglass.grains); + + return EXIT_SUCCESS; +} diff --git a/libdimension/bench/polynomial.c b/libdimension/bench/polynomial.c new file mode 100644 index 0000000..0313060 --- /dev/null +++ b/libdimension/bench/polynomial.c @@ -0,0 +1,72 @@ +/************************************************************************* + * Copyright (C) 2009-2010 Tavian Barnes * + * * + * This file is part of The Dimension Benchmark Suite. * + * * + * The Dimension Benchmark 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 Benchmark 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 . * + *************************************************************************/ + +#include "dimension.h" +#include +#include + +int +main(void) +{ +#define NPOLY 5 + double p[NPOLY][NPOLY + 1], x[NPOLY]; + + /* p[0][] = x - 0.5; */ + p[0][1] = 1.0; + p[0][0] = -0.5; + + /* p[1][] = (x + 0.5)*(x - 0.5) */ + p[1][2] = 1.0; + p[1][1] = 0.0; + p[1][0] = -0.25; + + /* p[2][] = (x + 1)*(x - 1.2345)*(x - 100) */ + p[2][3] = 1.0; + p[2][2] = -100.2345; + p[2][1] = 22.2155; + p[2][0] = 123.45; + + /* p[3][] = (x + 1)*(x - 1.2345)*(x - 5)*(x - 100) */ + p[3][4] = 1.0; + p[3][3] = -105.2345; + p[3][2] = 523.388; + p[3][1] = 12.3725; + p[3][0] = -617.25; + + /* p[4][] = (x + 1)*(x - 1.2345)*(x - 2.3456)*(x - 5)*(x - 100) */ + p[4][5] = 1.0; + p[4][4] = -107.5801; + p[4][3] = 770.2260432; + p[4][2] = -1215.2863928; + p[4][1] = -646.270936; + p[4][0] = 1447.8216; + + sandglass_t sandglass; + if (sandglass_init_monotonic(&sandglass, SANDGLASS_CPUTIME) != 0) { + perror("sandglass_create()"); + return EXIT_FAILURE; + } + + for (size_t i = 0; i < NPOLY; ++i) { + sandglass_bench_fine(&sandglass, dmnsn_solve_polynomial(p[i], i + 1, x)); + printf("dmnsn_solve_polynomial(x^%zu): %ld\n", i + 1, sandglass.grains); + } + + return EXIT_SUCCESS; +} diff --git a/libdimension/bench/prtree.c b/libdimension/bench/prtree.c new file mode 100644 index 0000000..b6f778a --- /dev/null +++ b/libdimension/bench/prtree.c @@ -0,0 +1,119 @@ +/************************************************************************* + * Copyright (C) 2009-2011 Tavian Barnes * + * * + * This file is part of The Dimension Benchmark Suite. * + * * + * The Dimension Benchmark 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 Benchmark 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 . * + *************************************************************************/ + +#include "dimension-impl.h" +#include +#include + +static bool +dmnsn_fake_intersection_fn(const dmnsn_object *object, dmnsn_line line, + dmnsn_intersection *intersection) +{ + intersection->t = (object->bounding_box.min.z - line.x0.z)/line.n.z; + intersection->normal = dmnsn_x; + return true; +} + +static bool +dmnsn_fake_inside_fn(const dmnsn_object *object, dmnsn_vector point) +{ + return true; +} + +static void +dmnsn_randomize_bounding_box(dmnsn_object *object) +{ + dmnsn_vector a, b; + + a.x = 2.0*((double)rand())/RAND_MAX - 1.0; + a.y = 2.0*((double)rand())/RAND_MAX - 1.0; + a.z = 2.0*((double)rand())/RAND_MAX - 1.0; + + b.x = 2.0*((double)rand())/RAND_MAX - 1.0; + b.y = 2.0*((double)rand())/RAND_MAX - 1.0; + b.z = 2.0*((double)rand())/RAND_MAX - 1.0; + + object->bounding_box.min = dmnsn_vector_min(a, b); + object->bounding_box.max = dmnsn_vector_max(a, b); +} + +static dmnsn_object * +dmnsn_new_fake_object(void) +{ + dmnsn_object *object = dmnsn_new_object(); + /* Generate a bounding box in (-1, -1, -1), (1, 1, 1) */ + dmnsn_randomize_bounding_box(object); + object->intersection_fn = dmnsn_fake_intersection_fn; + object->inside_fn = dmnsn_fake_inside_fn; + return object; +} + +int +main(void) +{ + const size_t nobjects = 10000; + + sandglass_t sandglass; + if (sandglass_init_monotonic(&sandglass, SANDGLASS_CPUTIME) != 0) { + perror("sandglass_create()"); + return EXIT_FAILURE; + } + + dmnsn_array *objects = dmnsn_new_array(sizeof(dmnsn_object *)); + for (size_t i = 0; i < nobjects; ++i) { + dmnsn_object *object = dmnsn_new_fake_object(); + dmnsn_initialize_object(object); + dmnsn_array_push(objects, &object); + } + + dmnsn_prtree *tree; + sandglass_bench_noprecache(&sandglass, { + tree = dmnsn_new_prtree(objects); + }); + printf("dmnsn_new_prtree(): %ld\n", sandglass.grains); + + /* dmnsn_prtree_intersection() */ + dmnsn_line ray = dmnsn_new_line( + dmnsn_new_vector( 1.0, 1.0, -2.0), + dmnsn_new_vector(-0.5, -0.5, 1.0) + ); + dmnsn_intersection intersection; + + sandglass_bench_fine(&sandglass, { + dmnsn_prtree_intersection(tree, ray, &intersection, true); + }); + printf("dmnsn_prtree_intersection(): %ld\n", sandglass.grains); + + /* dmnsn_prtree_inside() */ + sandglass_bench_fine(&sandglass, { + dmnsn_prtree_inside(tree, dmnsn_zero); + }); + printf("dmnsn_prtree_inside(): %ld\n", sandglass.grains); + + /* Cleanup */ + dmnsn_delete_prtree(tree); + for (size_t i = 0; i < nobjects; ++i) { + dmnsn_object *object; + dmnsn_array_get(objects, i, &object); + dmnsn_delete_object(object); + } + + dmnsn_delete_array(objects); + return EXIT_SUCCESS; +} diff --git a/libdimension/tests/Makefile.am b/libdimension/tests/Makefile.am new file mode 100644 index 0000000..6b5f8ca --- /dev/null +++ b/libdimension/tests/Makefile.am @@ -0,0 +1,81 @@ +########################################################################### +## Copyright (C) 2009-2011 Tavian Barnes ## +## ## +## This file is part of The Dimension Build Suite. ## +## ## +## The Dimension Build 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 Build 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 . ## +########################################################################### + +INCLUDES = -I$(top_srcdir)/libdimension + +check_LTLIBRARIES = libdimension-tests.la +check_PROGRAMS = warning-test \ + warning-as-error-test \ + error-test \ + polynomial-test \ + prtree-test \ + png-test \ + gl-test \ + render-test \ + cxx-test +TESTS = $(check_PROGRAMS) +XFAIL_TESTS = warning-as-error-test error-test + +if !PNG +XFAIL_TESTS += png-test +endif + +if !GL +XFAIL_TESTS += gl-test +endif + +libdimension_tests_la_SOURCES = tests.h +libdimension_tests_la_LIBADD = $(top_builddir)/libdimension/libdimension.la + +if GLX +libdimension_tests_la_SOURCES += display.c +libdimension_tests_la_LIBADD += -lX11 -lGL +else +libdimension_tests_la_SOURCES += display-stubs.c +endif + +warning_test_SOURCES = warning.c +warning_test_LDADD = libdimension-tests.la + +warning_as_error_test_SOURCES = warning-as-error.c +warning_as_error_test_LDADD = libdimension-tests.la + +error_test_SOURCES = error.c +error_test_LDADD = libdimension-tests.la + +polynomial_test_SOURCES = polynomial.c +polynomial_test_LDADD = libdimension-tests.la + +prtree_test_SOURCES = prtree.c +prtree_test_LDADD = libdimension-tests.la + +png_test_SOURCES = png.c +png_test_LDADD = libdimension-tests.la + +gl_test_SOURCES = gl.c +gl_test_LDADD = libdimension-tests.la + +render_test_SOURCES = render.c +render_test_LDADD = libdimension-tests.la + +cxx_test_SOURCES = cxx.cpp +cxx_test_LDADD = libdimension-tests.la + +clean-local: + rm -f *.png diff --git a/libdimension/tests/cxx.cpp b/libdimension/tests/cxx.cpp new file mode 100644 index 0000000..7405502 --- /dev/null +++ b/libdimension/tests/cxx.cpp @@ -0,0 +1,36 @@ +/************************************************************************* + * Copyright (C) 2010-2011 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +#include "tests.h" +#include + +/* + * Ensure that dimension.h can be included in a C++ program and behave properly. + */ +int +main(void) +{ + /* Treat warnings as errors for tests */ + dmnsn_die_on_warnings(true); + + /* Make sure we can to bit-ops on this enum type */ + dmnsn_quality quality = DMNSN_RENDER_PIGMENT | DMNSN_RENDER_LIGHTS; + + return EXIT_SUCCESS; +} diff --git a/libdimension/tests/display-stubs.c b/libdimension/tests/display-stubs.c new file mode 100644 index 0000000..e3fb99e --- /dev/null +++ b/libdimension/tests/display-stubs.c @@ -0,0 +1,38 @@ +/************************************************************************* + * Copyright (C) 2009-2010 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +#include "tests.h" +#include + +dmnsn_display * +dmnsn_new_display(const dmnsn_canvas *canvas) +{ + errno = ENOSYS; + return NULL; +} + +void +dmnsn_delete_display(dmnsn_display *display) +{ +} + +void +dmnsn_display_flush(dmnsn_display *display) +{ +} diff --git a/libdimension/tests/display.c b/libdimension/tests/display.c new file mode 100644 index 0000000..d4e2a1c --- /dev/null +++ b/libdimension/tests/display.c @@ -0,0 +1,151 @@ +/************************************************************************* + * Copyright (C) 2009-2010 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +#include "tests.h" +#include +#include +#include + +struct dmnsn_display { + Display *dpy; + Window win; + Colormap cmap; + GLXContext cx; + XEvent event; + XVisualInfo *vi; +}; + +/* XIfEvent callback */ +static Bool +WaitForNotify(Display *d, XEvent *e, char *arg) +{ + return (e->type == MapNotify) && (e->xmap.window == (Window)arg); +} + +dmnsn_display * +dmnsn_new_display(const dmnsn_canvas *canvas) +{ + int attributeList[] = { + GLX_RGBA, + GLX_DOUBLEBUFFER, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + None + }; + XSetWindowAttributes swa; + dmnsn_display *display; + + display = dmnsn_malloc(sizeof(dmnsn_display)); + + display->dpy = NULL; + display->win = 0; + display->cmap = 0; + display->cx = NULL; + display->vi = NULL; + + /* Get an X connection */ + display->dpy = XOpenDisplay(0); + if (!display->dpy) { + dmnsn_delete_display(display); + return NULL; + } + + /* Get an appropriate visual */ + display->vi = glXChooseVisual(display->dpy, DefaultScreen(display->dpy), + attributeList); + if (!display->vi) { + dmnsn_delete_display(display); + return NULL; + } + + /* Create a GLX context */ + display->cx = glXCreateContext(display->dpy, display->vi, 0, GL_TRUE); + if (!display->cx) { + dmnsn_delete_display(display); + return NULL; + } + + /* Create a color map */ + display->cmap = XCreateColormap(display->dpy, + RootWindow(display->dpy, display->vi->screen), + display->vi->visual, AllocNone); + if (!display->cmap) { + dmnsn_delete_display(display); + return NULL; + } + + /* Create a window */ + swa.colormap = display->cmap; + swa.border_pixel = 0; + swa.event_mask = StructureNotifyMask; + display->win = XCreateWindow(display->dpy, + RootWindow(display->dpy, display->vi->screen), + 0, 0, canvas->width, canvas->height, + 0, display->vi->depth, InputOutput, + display->vi->visual, + CWBorderPixel|CWColormap|CWEventMask, &swa); + if (!display->win) { + dmnsn_delete_display(display); + return NULL; + } + + XStoreName(display->dpy, display->win, "glX"); + + XMapWindow(display->dpy, display->win); + XIfEvent(display->dpy, &display->event, WaitForNotify, (char*)display->win); + + /* Connect the context to the window */ + glXMakeCurrent(display->dpy, display->win, display->cx); + glClearColor(0.0, 0.0, 0.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + dmnsn_display_flush(display); + + return display; +} + +void +dmnsn_delete_display(dmnsn_display *display) +{ + if (display) { + if (display->win) + XDestroyWindow(display->dpy, display->win); + + if (display->cmap) + XFreeColormap(display->dpy, display->cmap); + + if (display->cx) + glXDestroyContext(display->dpy, display->cx); + + if (display->vi) + XFree(display->vi); + + if (display->dpy) + XCloseDisplay(display->dpy); + + dmnsn_free(display); + } +} + +void +dmnsn_display_flush(dmnsn_display *display) +{ + glXWaitX(); + glXSwapBuffers(display->dpy, display->win); +} diff --git a/libdimension/tests/error.c b/libdimension/tests/error.c new file mode 100644 index 0000000..5a4d7fd --- /dev/null +++ b/libdimension/tests/error.c @@ -0,0 +1,30 @@ +/************************************************************************* + * Copyright (C) 2009-2011 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +/* Make sure that errors terminate us - this test should fail */ + +#include "dimension.h" +#include + +int +main(void) +{ + dmnsn_error("This error is expected."); + return EXIT_SUCCESS; +} diff --git a/libdimension/tests/gl.c b/libdimension/tests/gl.c new file mode 100644 index 0000000..8d93cf5 --- /dev/null +++ b/libdimension/tests/gl.c @@ -0,0 +1,87 @@ +/************************************************************************* + * Copyright (C) 2009-2011 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +#include "tests.h" +#include + +int +main(void) +{ + /* Treat warnings as errors for tests */ + 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; + } + + /* Paint the canvas blue */ + dmnsn_clear_canvas(canvas, dmnsn_blue); + + /* Create a new glX display */ + dmnsn_display *display = dmnsn_new_display(canvas); + if (!display) { + fprintf(stderr, "--- WARNING: Couldn't initialize X or glX! ---\n"); + return EXIT_SUCCESS; + } + + /* Draw to OpenGL */ + printf("Drawing to OpenGL\n"); + if (dmnsn_gl_write_canvas(canvas) != 0) { + dmnsn_delete_display(display); + dmnsn_delete_canvas(canvas); + fprintf(stderr, "--- Drawing to OpenGL failed! ---\n"); + return EXIT_FAILURE; + } + dmnsn_display_flush(display); + dmnsn_delete_canvas(canvas); + + /* + * Now test GL import/export + */ + + /* Read the image back from OpenGL */ + printf("Reading from OpenGL\n"); + canvas = dmnsn_gl_read_canvas(0, 0, 768, 480); + if (!canvas) { + dmnsn_delete_display(display); + dmnsn_delete_canvas(canvas); + fprintf(stderr, "--- Reading from OpenGL failed! ---\n"); + return EXIT_FAILURE; + } + + /* And draw it back */ + printf("Drawing to OpenGL\n"); + if (dmnsn_gl_write_canvas(canvas) != 0) { + dmnsn_delete_display(display); + dmnsn_delete_canvas(canvas); + fprintf(stderr, "--- Drawing to OpenGL failed! ---\n"); + return EXIT_FAILURE; + } + + dmnsn_display_flush(display); + dmnsn_delete_display(display); + dmnsn_delete_canvas(canvas); + return EXIT_SUCCESS; +} diff --git a/libdimension/tests/png.c b/libdimension/tests/png.c new file mode 100644 index 0000000..328ee36 --- /dev/null +++ b/libdimension/tests/png.c @@ -0,0 +1,106 @@ +/************************************************************************* + * Copyright (C) 2009-2011 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +#include "tests.h" +#include +#include + +int +main(void) +{ + /* Treat warnings as errors for tests */ + dmnsn_die_on_warnings(true); + + /* Allocate our canvas */ + dmnsn_canvas *canvas = dmnsn_new_canvas(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; + } + + /* Paint the canvas blue */ + dmnsn_clear_canvas(canvas, dmnsn_blue); + + /* Write the image to PNG */ + + 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; + } + + 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); + dmnsn_delete_canvas(canvas); + + /* + * Now test PNG import/export + */ + + /* Read the image back from PNG */ + + printf("Reading scene from PNG\n"); + FILE *ifile = fopen("png1.png", "rb"); + if (!ifile) { + fprintf(stderr, "--- Couldn't open 'png1.png' for reading! ---\n"); + return EXIT_FAILURE; + } + + canvas = dmnsn_png_read_canvas(ifile); + if (!canvas) { + fclose(ifile); + fprintf(stderr, "--- Reading canvas from PNG failed! ---\n"); + return EXIT_FAILURE; + } + + fclose(ifile); + + /* And write it back */ + + printf("Writing scene to PNG\n"); + ofile = fopen("png2.png", "wb"); + if (!ofile) { + fprintf(stderr, "--- Couldn't open 'png2.png' for writing! ---\n"); + dmnsn_delete_canvas(canvas); + return EXIT_FAILURE; + } + + 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); + dmnsn_delete_canvas(canvas); + + return EXIT_SUCCESS; +} diff --git a/libdimension/tests/polynomial.c b/libdimension/tests/polynomial.c new file mode 100644 index 0000000..5632b49 --- /dev/null +++ b/libdimension/tests/polynomial.c @@ -0,0 +1,62 @@ +/************************************************************************* + * Copyright (C) 2010-2011 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +/* + * Basic test of numerical polynomial root-finder + */ + +#include "dimension.h" +#include +#include + +int +main(void) +{ + /* Treat warnings as errors for tests */ + dmnsn_die_on_warnings(true); + + double poly[6], x[5]; + /* poly[] = (x + 1)*(x - 1.2345)*(x - 2.3456)*(x - 5)*(x - 100) */ + poly[5] = 1.0; + poly[4] = -107.5801; + poly[3] = 770.2260432; + poly[2] = -1215.2863928; + poly[1] = -646.270936; + poly[0] = 1447.8216; + + size_t n = dmnsn_solve_polynomial(poly, 5, x); + if (n != 4) { + fprintf(stderr, + "--- Wrong number of roots found (%zu, should be %u) ---\n", + n, 4); + return EXIT_FAILURE; + } + + for (size_t i = 0; i < n; ++i) { + double evmin = dmnsn_evaluate_polynomial(poly, 5, x[i] - dmnsn_epsilon); + double ev = dmnsn_evaluate_polynomial(poly, 5, x[i]); + double evmax = dmnsn_evaluate_polynomial(poly, 5, x[i] + dmnsn_epsilon); + if (fabs(evmin) < ev || fabs(evmax) < ev) { + fprintf(stderr, "--- Root %.15g is inaccurate! ---\n", x[i]); + return EXIT_FAILURE; + } + } + + return EXIT_SUCCESS; +} diff --git a/libdimension/tests/prtree.c b/libdimension/tests/prtree.c new file mode 100644 index 0000000..cb36153 --- /dev/null +++ b/libdimension/tests/prtree.c @@ -0,0 +1,98 @@ +/************************************************************************* + * Copyright (C) 2010-2011 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +/* + * Basic tests of PR-trees + */ + +#include "dimension-impl.h" +#include "../../libdimension/prtree.c" /* For DMNSN_PRTREE_B */ +#include +#include + +unsigned int calls = 0; + +static bool +dmnsn_fake_intersection_fn(const dmnsn_object *object, dmnsn_line line, + dmnsn_intersection *intersection) +{ + intersection->t = (object->bounding_box.min.z - line.x0.z)/line.n.z; + intersection->normal = dmnsn_x; + ++calls; + return true; +} + +static void +dmnsn_randomize_bounding_box(dmnsn_object *object) +{ + dmnsn_vector a, b; + + a.x = 2.0*((double)rand())/RAND_MAX - 1.0; + a.y = 2.0*((double)rand())/RAND_MAX - 1.0; + a.z = 2.0*((double)rand())/RAND_MAX - 1.0; + + b.x = 2.0*((double)rand())/RAND_MAX - 1.0; + b.y = 2.0*((double)rand())/RAND_MAX - 1.0; + b.z = 2.0*((double)rand())/RAND_MAX - 1.0; + + object->bounding_box.min = dmnsn_vector_min(a, b); + object->bounding_box.max = dmnsn_vector_max(a, b); +} + +int +main(void) +{ + /* Treat warnings as errors for tests */ + dmnsn_die_on_warnings(true); + + const size_t nobjects = 128; + dmnsn_scene *scene = dmnsn_new_scene(); + + for (size_t i = 0; i < nobjects; ++i) { + dmnsn_object *object = dmnsn_new_object(); + dmnsn_randomize_bounding_box(object); + object->intersection_fn = dmnsn_fake_intersection_fn; + dmnsn_initialize_object(object); + dmnsn_array_push(scene->objects, &object); + } + + dmnsn_prtree *prtree = dmnsn_new_prtree(scene->objects); + + dmnsn_intersection intersection; + dmnsn_line ray = dmnsn_new_line( + dmnsn_new_vector(0.0, 0.0, -2.0), + dmnsn_new_vector(0.0, 0.0, 1.0) + ); + + if (!dmnsn_prtree_intersection(prtree, ray, &intersection, true)) { + fprintf(stderr, "--- Didn't find intersection! ---\n"); + return EXIT_FAILURE; + } + + if (calls > DMNSN_PRTREE_B) { + fprintf(stderr, + "--- Too many intersection function calls: %u! ---\n", + calls); + return EXIT_FAILURE; + } + + dmnsn_delete_prtree(prtree); + dmnsn_delete_scene(scene); + return EXIT_SUCCESS; +} diff --git a/libdimension/tests/render.c b/libdimension/tests/render.c new file mode 100644 index 0000000..5b03423 --- /dev/null +++ b/libdimension/tests/render.c @@ -0,0 +1,309 @@ +/************************************************************************* + * Copyright (C) 2010-2011 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +#include "tests.h" +#include +#include +#include + +/* + * Test scene -- code version of tests/dimension/demo.pov + */ +static dmnsn_scene * +dmnsn_new_test_scene(void) +{ + /* Allocate a new scene */ + dmnsn_scene *scene = dmnsn_new_scene(); + + /* Default finish */ + scene->default_texture->finish = dmnsn_new_finish_combination( + dmnsn_new_ambient_finish( + dmnsn_color_mul(0.1, dmnsn_white) + ), + dmnsn_new_diffuse_finish(0.6) + ); + + /* Allocate a canvas */ + scene->canvas = dmnsn_new_canvas(768, 480); + + /* Set up the transformation matrix for the perspective camera */ + dmnsn_matrix trans = dmnsn_scale_matrix( + dmnsn_new_vector( + ((double)scene->canvas->width)/scene->canvas->height, 1.0, 1.0 + ) + ); + trans = dmnsn_matrix_mul( + dmnsn_rotation_matrix(dmnsn_new_vector(0.0624188099959577, 0.0, 0.0)), + trans + ); + trans = dmnsn_matrix_mul( + dmnsn_translation_matrix(dmnsn_new_vector(0.0, 0.25, -4.0)), + trans + ); + trans = dmnsn_matrix_mul( + dmnsn_rotation_matrix(dmnsn_new_vector(0.0, dmnsn_radians(53.0), 0.0)), + trans + ); + + /* Create a perspective camera */ + scene->camera = dmnsn_new_perspective_camera(); + scene->camera->trans = trans; + + /* Background color */ + scene->background = dmnsn_clear; + + /* Sky sphere */ + scene->sky_sphere = dmnsn_new_sky_sphere(); + dmnsn_pattern *sky_gradient = dmnsn_new_gradient_pattern(dmnsn_y); + dmnsn_map *sky_gradient_color_map = dmnsn_new_color_map(); + dmnsn_add_map_entry(sky_gradient_color_map, 0.0, &dmnsn_orange); + dmnsn_color background = dmnsn_new_color5(0.0, 0.1, 0.2, 0.1, 0.0); + dmnsn_add_map_entry(sky_gradient_color_map, 0.35, &background); + dmnsn_pigment *sky_pigment + = dmnsn_new_color_map_pigment(sky_gradient, sky_gradient_color_map); + dmnsn_array_push(scene->sky_sphere->pigments, &sky_pigment); + + /* Light source */ + dmnsn_light *light = dmnsn_new_point_light( + dmnsn_new_vector(-15.0, 20.0, 10.0), + dmnsn_white + ); + dmnsn_array_push(scene->lights, &light); + + /* Now make our objects */ + + dmnsn_object *cube = dmnsn_new_cube(); + cube->trans = dmnsn_rotation_matrix( + dmnsn_new_vector(dmnsn_radians(45.0), 0.0, 0.0) + ); + cube->texture = dmnsn_new_texture(); + + dmnsn_color cube_color = dmnsn_blue; + cube_color.filter = 0.25; + cube_color.trans = 0.5; + cube->texture->pigment = dmnsn_new_solid_pigment(cube_color); + + dmnsn_color reflect = dmnsn_color_mul(0.5, dmnsn_white); + cube->texture->finish = dmnsn_new_reflective_finish(reflect, reflect, 1.0); + + cube->interior = dmnsn_new_interior(); + cube->interior->ior = 1.1; + + dmnsn_object *sphere = dmnsn_new_sphere(); + sphere->texture = dmnsn_new_texture(); + sphere->texture->pigment = dmnsn_new_solid_pigment(dmnsn_green); + sphere->texture->finish = dmnsn_new_phong_finish(0.2, 40.0); + sphere->trans = dmnsn_scale_matrix(dmnsn_new_vector(1.25, 1.25, 1.25)); + + dmnsn_object *csg = dmnsn_new_csg_difference(cube, sphere); + dmnsn_array_push(scene->objects, &csg); + + dmnsn_array *arrow_array = dmnsn_new_array(sizeof(dmnsn_object *)); + + dmnsn_object *cylinder = dmnsn_new_cone(0.1, 0.1, false); + cylinder->trans = dmnsn_scale_matrix(dmnsn_new_vector(1.0, 1.25, 1.0)); + dmnsn_array_push(arrow_array, &cylinder); + + dmnsn_object *cone = dmnsn_new_cone(0.1, 0.0, true); + cone->trans = + dmnsn_matrix_mul( + dmnsn_translation_matrix(dmnsn_new_vector(0.0, 1.375, 0.0)), + dmnsn_scale_matrix(dmnsn_new_vector(1.0, 0.125, 1.0)) + ); + dmnsn_array_push(arrow_array, &cone); + + dmnsn_object *arrow = dmnsn_new_csg_union(arrow_array); + arrow->trans = dmnsn_rotation_matrix( + dmnsn_new_vector(dmnsn_radians(-45.0), 0.0, 0.0) + ); + dmnsn_pattern *gradient = dmnsn_new_gradient_pattern(dmnsn_y); + dmnsn_map *gradient_color_map = dmnsn_new_color_map(); + dmnsn_add_map_entry(gradient_color_map, 0.0, &dmnsn_red); + dmnsn_add_map_entry(gradient_color_map, 1.0/6.0, &dmnsn_orange); + dmnsn_add_map_entry(gradient_color_map, 2.0/6.0, &dmnsn_yellow); + dmnsn_add_map_entry(gradient_color_map, 3.0/6.0, &dmnsn_green); + dmnsn_add_map_entry(gradient_color_map, 4.0/6.0, &dmnsn_blue); + dmnsn_add_map_entry(gradient_color_map, 5.0/6.0, &dmnsn_magenta); + dmnsn_add_map_entry(gradient_color_map, 1.0, &dmnsn_red); + arrow->texture = dmnsn_new_texture(); + arrow->texture->pigment + = dmnsn_new_color_map_pigment(gradient, gradient_color_map); + arrow->texture->trans = + dmnsn_matrix_mul( + dmnsn_translation_matrix(dmnsn_new_vector(0.0, -1.25, 0.0)), + dmnsn_scale_matrix(dmnsn_new_vector(1.0, 2.75, 1.0)) + ); + dmnsn_array_push(scene->objects, &arrow); + dmnsn_delete_array(arrow_array); + + dmnsn_array *torus_array = dmnsn_new_array(sizeof(dmnsn_object *)); + + dmnsn_object *torus1 = dmnsn_new_torus(0.15, 0.05); + torus1->trans = dmnsn_translation_matrix(dmnsn_new_vector(0.0, -1.0, 0.0)); + dmnsn_array_push(torus_array, &torus1); + + dmnsn_object *torus2 = dmnsn_new_torus(0.15, 0.05); + dmnsn_array_push(torus_array, &torus2); + + dmnsn_object *torus3 = dmnsn_new_torus(0.15, 0.05); + torus3->trans = dmnsn_translation_matrix(dmnsn_new_vector(0.0, 1.0, 0.0)); + dmnsn_array_push(torus_array, &torus3); + + dmnsn_object *torii = dmnsn_new_csg_union(torus_array); + torii->trans = dmnsn_rotation_matrix( + dmnsn_new_vector(dmnsn_radians(-45.0), 0.0, 0.0) + ); + torii->texture = dmnsn_new_texture(); + torii->texture->pigment = dmnsn_new_solid_pigment(dmnsn_blue); + torii->texture->finish = dmnsn_new_ambient_finish(dmnsn_white); + dmnsn_array_push(scene->objects, &torii); + dmnsn_delete_array(torus_array); + + dmnsn_object *plane = dmnsn_new_plane(dmnsn_new_vector(0.0, 1.0, 0.0)); + plane->trans = dmnsn_translation_matrix(dmnsn_new_vector(0.0, -2.0, 0.0)); + plane->texture = dmnsn_new_texture(); + dmnsn_pattern *checker1 = dmnsn_new_checker_pattern(); + dmnsn_pattern *checker2 = dmnsn_new_checker_pattern(); + dmnsn_map *checker_color_map = dmnsn_new_color_map(); + dmnsn_add_map_entry(checker_color_map, 0.0, &dmnsn_black); + dmnsn_add_map_entry(checker_color_map, 1.0, &dmnsn_white); + dmnsn_pigment *pigment1 = dmnsn_new_solid_pigment(dmnsn_white); + dmnsn_pigment *pigment2 + = dmnsn_new_color_map_pigment(checker1, checker_color_map); + pigment2->trans + = dmnsn_scale_matrix(dmnsn_new_vector(1.0/3.0, 1.0/3.0, 1.0/3.0)); + dmnsn_map *checker_pigment_map = dmnsn_new_pigment_map(); + dmnsn_add_map_entry(checker_pigment_map, 0.0, &pigment1); + dmnsn_add_map_entry(checker_pigment_map, 1.0, &pigment2); + plane->texture->pigment + = dmnsn_new_pigment_map_pigment(checker2, checker_pigment_map); + plane->texture->pigment->quick_color = dmnsn_new_color(1.0, 0.5, 0.75); + dmnsn_array_push(scene->objects, &plane); + + return scene; +} + +int +main(void) +{ + /* Treat warnings as errors for tests */ + dmnsn_die_on_warnings(true); + + /* Create the test scene */ + dmnsn_scene *scene = dmnsn_new_test_scene(); + + /* Optimize the canvas for PNG export */ + bool have_png = true; + errno = 0; + if (dmnsn_png_optimize_canvas(scene->canvas) != 0) { + if (errno == ENOSYS) { + have_png = false; + } else { + dmnsn_delete_scene(scene); + fprintf(stderr, "--- Couldn't optimize canvas for PNG! ---\n"); + return EXIT_FAILURE; + } + } + + /* Optimize the canvas for GL drawing */ + bool have_gl = true; + errno = 0; + if (dmnsn_gl_optimize_canvas(scene->canvas) != 0) { + if (errno == ENOSYS) { + have_gl = false; + } else { + dmnsn_delete_scene(scene); + fprintf(stderr, "--- Couldn't optimize canvas for GL! ---\n"); + return EXIT_FAILURE; + } + } + + dmnsn_clear_canvas(scene->canvas, dmnsn_black); + + /* Create a new glX display */ + dmnsn_display *display = NULL; + if (have_gl) { + display = dmnsn_new_display(scene->canvas); + if (!display) { + fprintf(stderr, "--- WARNING: Couldn't initialize X or glX! ---\n"); + } + } + + /* Render the scene */ + + printf("Rendering scene\n"); + dmnsn_progress *progress = dmnsn_raytrace_scene_async(scene); + + /* Display the scene as it's rendered */ + if (display) { + while (dmnsn_get_progress(progress) < 1.0) { + if (dmnsn_gl_write_canvas(scene->canvas) != 0) { + dmnsn_delete_display(display); + dmnsn_delete_scene(scene); + fprintf(stderr, "--- Drawing to OpenGL failed! ---\n"); + return EXIT_FAILURE; + } + dmnsn_display_flush(display); + } + } + + if (dmnsn_finish_progress(progress) != 0) { + dmnsn_delete_display(display); + dmnsn_delete_scene(scene); + fprintf(stderr, "--- Raytracing failed! ---\n"); + return EXIT_FAILURE; + } + + /* Make sure we show the completed rendering */ + if (display) { + printf("Drawing to OpenGL\n"); + if (dmnsn_gl_write_canvas(scene->canvas) != 0) { + dmnsn_delete_display(display); + dmnsn_delete_scene(scene); + fprintf(stderr, "--- Drawing to OpenGL failed! ---\n"); + return EXIT_FAILURE; + } + dmnsn_display_flush(display); + } + + if (have_png) { + printf("Writing scene to PNG\n"); + FILE *ofile = fopen("render.png", "wb"); + if (!ofile) { + dmnsn_delete_display(display); + dmnsn_delete_scene(scene); + fprintf(stderr, "--- Couldn't open 'render.png' for writing! ---\n"); + return EXIT_FAILURE; + } + + if (dmnsn_png_write_canvas(scene->canvas, ofile) != 0) { + fclose(ofile); + dmnsn_delete_display(display); + dmnsn_delete_scene(scene); + fprintf(stderr, "--- Writing canvas to PNG failed! ---\n"); + return EXIT_FAILURE; + } + + fclose(ofile); + } + + dmnsn_delete_display(display); + dmnsn_delete_scene(scene); + return EXIT_SUCCESS; +} diff --git a/libdimension/tests/tests.h b/libdimension/tests/tests.h new file mode 100644 index 0000000..d61e442 --- /dev/null +++ b/libdimension/tests/tests.h @@ -0,0 +1,46 @@ +/************************************************************************* + * Copyright (C) 2009-2010 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +#ifndef TESTS_H +#define TESTS_H + +#include "dimension.h" + +#ifdef __cplusplus +/* We've been included from a C++ file; mark everything here as extern "C" */ +extern "C" { +#endif + +/* + * Windowing + */ + +typedef struct dmnsn_display dmnsn_display; + +dmnsn_display *dmnsn_new_display(const dmnsn_canvas *canvas); +void dmnsn_delete_display(dmnsn_display *display); + +/* Flush the GL buffers */ +void dmnsn_display_flush(dmnsn_display *display); + +#ifdef __cplusplus +} +#endif + +#endif /* TESTS_H */ diff --git a/libdimension/tests/warning-as-error.c b/libdimension/tests/warning-as-error.c new file mode 100644 index 0000000..ce274d3 --- /dev/null +++ b/libdimension/tests/warning-as-error.c @@ -0,0 +1,31 @@ +/************************************************************************* + * Copyright (C) 2009-2011 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +/* Make sure warnings kill us in strict mode - this test should fail */ + +#include "dimension.h" +#include + +int +main(void) +{ + dmnsn_die_on_warnings(true); + dmnsn_warning("This warning is expected."); + return EXIT_SUCCESS; +} diff --git a/libdimension/tests/warning.c b/libdimension/tests/warning.c new file mode 100644 index 0000000..aecedd5 --- /dev/null +++ b/libdimension/tests/warning.c @@ -0,0 +1,30 @@ +/************************************************************************* + * Copyright (C) 2009-2011 Tavian Barnes * + * * + * 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 . * + *************************************************************************/ + +/* Make sure warnings don't kill us - this test should pass */ + +#include "dimension.h" +#include + +int +main(void) +{ + dmnsn_warning("This warning is expected."); + return EXIT_SUCCESS; +} diff --git a/tests/Makefile.am b/tests/Makefile.am deleted file mode 100644 index 9bcd2fd..0000000 --- a/tests/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -########################################################################### -## Copyright (C) 2009-2010 Tavian Barnes ## -## ## -## This file is part of The Dimension Build Suite. ## -## ## -## The Dimension Build 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 Build 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 . ## -########################################################################### - -SUBDIRS = libdimension dimension diff --git a/tests/dimension/Makefile.am b/tests/dimension/Makefile.am deleted file mode 100644 index c54bcd4..0000000 --- a/tests/dimension/Makefile.am +++ /dev/null @@ -1,55 +0,0 @@ -########################################################################### -## Copyright (C) 2009-2010 Tavian Barnes ## -## ## -## This file is part of The Dimension Build Suite. ## -## ## -## The Dimension Build 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 Build 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 . ## -########################################################################### - -INCLUDES = -I$(top_srcdir)/libdimension - -TESTS = punctuation.sh \ - numeric.sh \ - strings.sh \ - labels.sh \ - directives.sh \ - arithexp.sh \ - transformations.sh \ - invalid-macro.sh \ - tbuffer-overlap.sh \ - integer-overflow.sh \ - csg.sh \ - demo.sh -TESTS_ENVIRONMENT = top_builddir=$(top_builddir) dimension_flags=--strict - -.sh: - cp $(srcdir)/$@ . - -EXTRA_DIST = $(TESTS) \ - punctuation.pov \ - numeric.pov \ - strings.pov \ - labels.pov \ - directives.inc \ - directives.pov \ - arithexp.pov \ - transformations.pov \ - invalid-macro.pov \ - tbuffer-overlap.pov \ - integer-overflow.pov \ - csg.pov \ - demo.pov - -clean-local: - rm -f *.png diff --git a/tests/dimension/arithexp.pov b/tests/dimension/arithexp.pov deleted file mode 100644 index d38b13a..0000000 --- a/tests/dimension/arithexp.pov +++ /dev/null @@ -1,218 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -// Test arithmetic expression handling - -sphere { - 2*<<2.0 - 1.0, 3.0, 4.0>.x, (1.0 + 2)*2 - 5, 1.0 + 2*2 - 4> - -<0, 0, 1>, - exp(1) - (0 >= 1 ? 0 : 1*2) -} - -/* Float functions */ - -#if (abs(-1) != 1) - #error "abs" -#end - -#if (acos(0) != 1.570796326794897) - #error "acos" -#end - -#if (acosh(2) != 1.316957896924817) - #error "acosh" -#end - -#if (asc("ABC") != 65) - #error "asc" -#end - -#if (asin(1) != 1.570796326794897) - #error "asin" -#end - -#if (asinh(2) != 1.44363547517881) - #error "asinh" -#end - -#if (atan(1) != 0.7853981633974483) - #error "atan" -#end - -#if (atan2(-1, -1) != -2.35619449019234) - #error "atan2" -#end - -#if (atanh(0.5) != 0.5493061443340548) - #error "atanh" -#end - -#if (ceil(-1.5) != -1) - #error "ceil" -#end - -#if (cos(1.570796326794897) != 0) - #error "cos" -#end - -#if (cosh(1.316957896924817) != 2) - #error "cosh" -#end - -#if (degrees(1.570796326794897) != 90) - #error "degrees" -#end - -#if (div(3,2) != 1) - #error "div" -#end - -#if (exp(1) != 2.718281828459045) - #error "exp" -#end - -#if (floor(-1.5) != -2) - #error "floor" -#end - -#if (int(-1.9) != -1) - #error "int" -#end - -#if (ln(2.718281828459045) != 1) - #error "ln" -#end - -#if (log(1000) != 3) - #error "log" -#end - -#if (max(-1.5, 0, 1) != 1) - #error "max" -#end - -#if (min(-1.5, 0, 1) != -1.5) - #error "min" -#end - -#if (mod(3.5, 2) != 1.5) - #error "mod" -#end - -#if (pow(2, 3) != 8) - #error "pow" -#end - -#if (radians(90) != 1.570796326794897) - #error "radians" -#end - -#if (sin(1.570796326794897) != 1) - #error "sin" -#end - -#if (sinh(1.44363547517881) != 2) - #error "sinh" -#end - -#if (strcmp("asdfjkl;", "jkl;asdf") >= 0) - #error "strcmp" -#end - -#if (strlen("asdfjkl;") != 8) - #error "strlen" -#end - -#if (sqrt(2) != 1.414213562373095) - #error "sqrt" -#end - -#if (tan(0.7853981633974483) != 1) - #error "tan" -#end - -#if (tanh(0.5493061443340548) != 0.5) - #error "tanh" -#end - -#if (val("123.45") != 123.45) - #error "val" -#end - -#if (vaxis_rotate(<1, 0, 0>, <1, 0, 1>, 180) != <0, 0, 1>) - #error "vaxis_rotate" -#end - -#if (vaxis_rotate(1, 1, 180) != <1, 1, 1>) - #error "vaxis_rotate" -#end - -#if (vcross(<1, 2, 3>, <3, 2, 1>) != <-4, 8, -4>) - #error "vcross" -#end - -#if (vcross(1, 2) != 0) - #error "vcross" -#end - -#if (vdot(<1, 2, 3>, 2) != 12) - #error "vdot" -#end - -#if (vdot(2, 2) != 12) - #error "vdot" -#end - -#if (vlength(<1, 1, 1>) != 1.732050807568877) - #error "vlength" -#end - -#if (vlength(1) != 1.732050807568877) - #error "vlength" -#end - -#if (vnormalize(<1, 1, 1>) - != <0.5773502691896258, 0.5773502691896258, 0.5773502691896258>) - #error "vnormalize" -#end - -#if (vnormalize(1) != 0.4472135954999579) // Vector promoted comparison - #error "vnormalize" -#end - -#if (vrotate(<1, 0, 0>, <0, -90, 0>) != <0, 0, 1>) - #error "vrotate" -#end - -#if (vrotate(1, 2) != <1, 1, 1>) - #error "vrotate" -#end - -/* Float built-in IDs */ - -#if (pi != 3.141592653589793) - #error "pi" -#end - -#if (!true | !yes | !on) - #error "true" -#end - -#if (false | no | off) - #error "false" -#end diff --git a/tests/dimension/arithexp.sh b/tests/dimension/arithexp.sh deleted file mode 100755 index e46ab04..0000000 --- a/tests/dimension/arithexp.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh - -######################################################################### -# Copyright (C) 2009-2011 Tavian Barnes # -# # -# 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 . # -######################################################################### - -arithexp=$(${top_builddir}/dimension/dimension ${dimension_flags} --parse ${srcdir}/arithexp.pov) -arithexp_exp="$(echo -n \ -'((object - (sphere - (vector (float 2) (float 2) (float 3) (integer 0) (integer 0)) - (float 0.718282)) - object-modifiers))' \ -| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g')" - -if [ "$arithexp" != "$arithexp_exp" ]; then - echo "arithexp.pov parsed as \"$arithexp\"" >&2 - echo " -- expected \"$arithexp_exp\"" >&2 - exit 1 -fi diff --git a/tests/dimension/csg.pov b/tests/dimension/csg.pov deleted file mode 100644 index 357fd7b..0000000 --- a/tests/dimension/csg.pov +++ /dev/null @@ -1,65 +0,0 @@ -/************************************************************************* - * Copyright (C) 2010 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -// Test constructive solid geometry - -camera { - perspective - location -4*z - right x*image_width/image_height - look_at 0 -} - -background { - color rgbf <0, 0.1, 0.2, 0.1> -} - -/* One-object unions */ - -union { - sphere { - -1.5*x, 1 - pigment { color red 1 } - } -} - -union { - light_source { - 20*y, color rgb 0.5 - } -} - -/* CSG with lights */ -difference { - light_source { - -15*x, color rgb 0.5 - } - sphere { - 1.5*x - 20*y, 1 - pigment { color green 1 } - } - light_source { - 15*x, color rgb 0.5 - } - box { - <0.7, -20.8, -0.8>, <2.3, -19.2, 0.8> - pigment { color blue 1 } - } - translate 20*y -} diff --git a/tests/dimension/csg.sh b/tests/dimension/csg.sh deleted file mode 100755 index b57389d..0000000 --- a/tests/dimension/csg.sh +++ /dev/null @@ -1,94 +0,0 @@ -#!/bin/sh - -######################################################################### -# Copyright (C) 2010-2011 Tavian Barnes # -# # -# 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 . # -######################################################################### - -csg=$(${top_builddir}/dimension/dimension ${dimension_flags} -w768 -h480 --parse ${srcdir}/csg.pov) -csg_exp="$(echo -n \ -'((camera - perspective - (location (vector (integer 0) (integer 0) (integer -4) - (integer 0) (integer 0))) - (right (vector (float 1.6) (integer 0) (integer 0) (integer 0) (integer 0))) - (look_at (vector (integer 0) (integer 0) (integer 0) - (integer 0) (integer 0)))) - (background - (vector (integer 0) (float 0.1) (float 0.2) (float 0.1) (integer 0))) - (object - (union - (object - (sphere - (vector (float -1.5) (float 0) (float 0) (float 0) (float 0)) - (integer 1)) - (object-modifiers - (pigment - (vector (integer 1) (integer 0) (integer 0) - (integer 0) (integer 0)) - pigment-modifiers)))) - object-modifiers) - (object - (union - (light_source - (vector (integer 0) (integer 20) (integer 0) (integer 0) (integer 0)) - (vector (float 0.5) (float 0.5) (float 0.5) (integer 0) (integer 0)) - object-modifiers)) - object-modifiers) - (object - (difference - (light_source - (vector (integer -15) (integer 0) (integer 0) (integer 0) (integer 0)) - (vector (float 0.5) (float 0.5) (float 0.5) (integer 0) (integer 0)) - object-modifiers) - (object - (sphere - (vector (float 1.5) (float -20) (float 0) (float 0) (float 0)) - (integer 1)) - (object-modifiers - (pigment - (vector (integer 0) (integer 1) (integer 0) - (integer 0) (integer 0)) - pigment-modifiers))) - (light_source - (vector (integer 15) (integer 0) (integer 0) (integer 0) (integer 0)) - (vector (float 0.5) (float 0.5) (float 0.5) (integer 0) (integer 0)) - object-modifiers) - (object - (box - (vector (float 0.7) (float -20.8) (float -0.8) - (integer 0) (integer 0)) - (vector (float 2.3) (float -19.2) (float 0.8) - (integer 0) (integer 0))) - (object-modifiers - (pigment - (vector (integer 0) (integer 0) (integer 1) - (integer 0) (integer 0)) - pigment-modifiers)))) - (object-modifiers - (transformation - (translation (vector (integer 0) (integer 20) (integer 0) - (integer 0) (integer 0)))))))' \ -| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g')" - -if [ "$csg" != "$csg_exp" ]; then - echo "csg.pov parsed as \"$csg\"" >&2 - echo " -- expected \"$csg_exp\"" >&2 - exit 1 -fi - -${top_builddir}/dimension/dimension ${dimension_flags} -w768 -h480 -o csg.png ${srcdir}/csg.pov diff --git a/tests/dimension/demo.pov b/tests/dimension/demo.pov deleted file mode 100644 index 91be9d2..0000000 --- a/tests/dimension/demo.pov +++ /dev/null @@ -1,150 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -// Render demo scene - -global_settings { - max_trace_level 5 - adc_bailout 1/255 -} - -camera { - perspective - location <0, 0.25, -4> - right x*image_width/image_height - look_at <0, 0, 0> - - rotate 53*y -} - -background { - color transmit 1 -} - -sky_sphere { - pigment { - gradient y - color_map { - [0.0 color rgb <1, 0.5, 0>] - [0.35 color rgbf <0, 0.1, 0.2, 0.1>] - } - } -} - -light_source { - <-15, 20, 10>, color rgb <1, 1, 1> -} - -difference { - box { - <-1, -1, -1>, <1, 1, 1> - - rotate 45*x - - texture { - pigment { - color rgbft <0, 0, 1, 0.25, 0.5> - } - finish { - reflection { 0.5 } - } - } - - interior { - ior 1.1 - } - } - - sphere { - <0, 0, 0>, 1.25 - - texture { - pigment { - color rgb <0, 1, 0> - } - finish { - phong 0.2 - phong_size 40.0 - } - } - } -} - -union { - cylinder { - -1.25*y, 1.25*y, 0.1 - } - cone { - 1.25*y, 0.1, 1.5*y, 0 - open - } - - pigment { - gradient y - color_map { - [0 color rgb <1, 0, 0>] - [1/6 color rgb <1, 0.5, 0>] - [2/6 color rgb <1, 1, 0>] - [3/6 color rgb <0, 1, 0>] - [4/6 color rgb <0, 0, 1>] - [5/6 color rgb <1, 0, 1>] - [1 color rgb <1, 0, 0>] - } - scale <1, 2.75, 1> - translate -1.25*y - } - rotate -45*x -} - -union { - torus { - 0.15, 0.05 - translate -y - } - torus { - 0.15, 0.05 - } - torus { - 0.15, 0.05 - translate y - } - - pigment { - color rgb <0, 0, 1> - } - finish { - ambient 1 - } - rotate -45*x -} - -plane { - y, -2 - pigment { - checker - pigment { - color rgb 1 - } - pigment { - checker color rgb 0, color rgb 1 - scale 1/3 - } - quick_color rgb <1, 0.5, 0.75> - } -} diff --git a/tests/dimension/demo.sh b/tests/dimension/demo.sh deleted file mode 100755 index 233b880..0000000 --- a/tests/dimension/demo.sh +++ /dev/null @@ -1,220 +0,0 @@ -#!/bin/sh - -######################################################################### -# Copyright (C) 2009-2011 Tavian Barnes # -# # -# 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 . # -######################################################################### - -demo=$(${top_builddir}/dimension/dimension ${dimension_flags} -w768 -h480 --parse ${srcdir}/demo.pov) -demo_exp=$(echo -n \ -'((global_settings - (max_trace_level (integer 5)) - (adc_bailout (float 0.00392157))) - (camera - perspective - (location (vector (integer 0) (float 0.25) (integer -4) - (integer 0) (integer 0))) - (right (vector (float 1.6) (integer 0) (integer 0) (integer 0) (integer 0))) - (look_at (vector (integer 0) (integer 0) (integer 0) - (integer 0) (integer 0))) - (transformation - (rotation (vector (integer 0) (integer 53) (integer 0) - (integer 0) (integer 0))))) - (background - (vector (integer 0) (integer 0) (integer 0) (integer 0) (integer 1))) - (sky_sphere - (pigment - (pattern - (gradient (vector (integer 0) (integer 1) - (integer 0) (integer 0) (integer 0)))) - (pigment-modifiers - (color_map - (color_map-entry - (float 0) - (vector (integer 1) (float 0.5) (integer 0) - (integer 0) (integer 0))) - (color_map-entry - (float 0.35) - (vector (integer 0) (float 0.1) (float 0.2) - (float 0.1) (integer 0))))))) - (light_source - (vector (integer -15) (integer 20) (integer 10) (integer 0) (integer 0)) - (vector (integer 1) (integer 1) (integer 1) (integer 0) (integer 0)) - object-modifiers) - (object - (difference - (object - (box - (vector (integer -1) (integer -1) (integer -1) - (integer 0) (integer 0)) - (vector (integer 1) (integer 1) (integer 1) (integer 0) (integer 0))) - (object-modifiers - (transformation - (rotation (vector (integer 45) (integer 0) (integer 0) - (integer 0) (integer 0)))) - (texture - (pigment - (vector (integer 0) (integer 0) (integer 1) - (float 0.25) (float 0.5)) - pigment-modifiers) - (finish - (reflection - (vector (float 0.5) (float 0.5) (float 0.5) - (float 0.5) (float 0.5)) - (vector (float 0.5) (float 0.5) (float 0.5) - (float 0.5) (float 0.5)) - reflection-items))) - (interior - (ior (float 1.1))))) - (object - (sphere - (vector (integer 0) (integer 0) (integer 0) (integer 0) (integer 0)) - (float 1.25)) - (object-modifiers - (texture - (pigment - (vector (integer 0) (integer 1) (integer 0) - (integer 0) (integer 0)) - pigment-modifiers) - (finish - (phong (float 0.2)) - (phong_size (float 40))))))) - object-modifiers) - (object - (union - (object - (cylinder - (vector (float 0) (float -1.25) (float 0) (float 0) (float 0)) - (vector (float 0) (float 1.25) (float 0) (float 0) (float 0)) - (float 0.1) - (integer 0)) - object-modifiers) - (object - (cone - (vector (float 0) (float 1.25) (float 0) (float 0) (float 0)) - (float 0.1) - (vector (float 0) (float 1.5) (float 0) (float 0) (float 0)) - (integer 0) - (integer 1)) - object-modifiers)) - (object-modifiers - (pigment - (pattern (gradient (vector (integer 0) (integer 1) (integer 0) - (integer 0) (integer 0)))) - (pigment-modifiers - (color_map - (color_map-entry - (integer 0) - (vector (integer 1) (integer 0) (integer 0) - (integer 0) (integer 0))) - (color_map-entry - (float 0.166667) - (vector (integer 1) (float 0.5) (integer 0) - (integer 0) (integer 0))) - (color_map-entry - (float 0.333333) - (vector (integer 1) (integer 1) (integer 0) - (integer 0) (integer 0))) - (color_map-entry - (float 0.5) - (vector (integer 0) (integer 1) (integer 0) - (integer 0) (integer 0))) - (color_map-entry - (float 0.666667) - (vector (integer 0) (integer 0) (integer 1) - (integer 0) (integer 0))) - (color_map-entry - (float 0.833333) - (vector (integer 1) (integer 0) (integer 1) - (integer 0) (integer 0))) - (color_map-entry - (integer 1) - (vector (integer 1) (integer 0) (integer 0) - (integer 0) (integer 0)))) - (transformation - (scale (vector (integer 1) (float 2.75) (integer 1) - (integer 0) (integer 0)))) - (transformation - (translation (vector (float 0) (float -1.25) (float 0) - (float 0) (float 0)))))) - (transformation - (rotation (vector (integer -45) (integer 0) (integer 0) - (integer 0) (integer 0)))))) - (object - (union - (object - (torus (float 0.15) (float 0.05)) - (object-modifiers - (transformation - (translation (vector (integer 0) (integer -1) (integer 0) - (integer 0) (integer 0)))))) - (object - (torus (float 0.15) (float 0.05)) - object-modifiers) - (object - (torus (float 0.15) (float 0.05)) - (object-modifiers - (transformation - (translation (vector (integer 0) (integer 1) (integer 0) - (integer 0) (integer 0))))))) - (object-modifiers - (pigment - (vector (integer 0) (integer 0) (integer 1) (integer 0) (integer 0)) - pigment-modifiers) - (finish - (ambient - (vector (integer 1) (integer 1) (integer 1) (integer 1) (integer 1)))) - (transformation - (rotation (vector (integer -45) (integer 0) (integer 0) - (integer 0) (integer 0)))))) - (object - (plane - (vector (integer 0) (integer 1) (integer 0) (integer 0) (integer 0)) - (integer -2)) - (object-modifiers - (pigment - (pattern checker) - (pigment-modifiers - (quick_color - (vector (integer 1) (float 0.5) (float 0.75) - (integer 0) (integer 0))) - (pigment-list - (pigment - (vector (integer 1) (integer 1) (integer 1) - (integer 0) (integer 0)) - pigment-modifiers) - (pigment - (pattern checker) - (pigment-modifiers - (transformation - (scale (vector (float 0.333333) (float 0.333333) - (float 0.333333) (float 0.333333) - (float 0.333333)))) - (color-list - (vector (integer 0) (integer 0) (integer 0) - (integer 0) (integer 0)) - (vector (integer 1) (integer 1) (integer 1) - (integer 0) (integer 0)))))))))))' \ -| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g') - -if [ "$demo" != "$demo_exp" ]; then - echo "demo.pov parsed as \"$demo\"" >&2 - echo " -- expected \"$demo_exp\"" >&2 - exit 1 -fi - -${top_builddir}/dimension/dimension ${dimension_flags} -w768 -h480 -o demo.png ${srcdir}/demo.pov diff --git a/tests/dimension/directives.inc b/tests/dimension/directives.inc deleted file mode 100644 index a3dadb3..0000000 --- a/tests/dimension/directives.inc +++ /dev/null @@ -1,21 +0,0 @@ -/************************************************************************* - * Copyright (C) 2010 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -#declare Center = 0; -#local Local = -1; diff --git a/tests/dimension/directives.pov b/tests/dimension/directives.pov deleted file mode 100644 index 5c3cfa3..0000000 --- a/tests/dimension/directives.pov +++ /dev/null @@ -1,92 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -// Test the language directives - -#version 3.6; - -#debug "debug" -#warning "warning" - -#include "directives.inc" - -#declare R = 1; -#local Color = rgb <1, 0, 1>; - -#declare Unused = -1; -#undef Unused - -#ifdef (Local) - #error "Local escaped from include file" -#end - -#ifdef (Unused) - #error "#undef failed" -#end - -#macro Make_Sphere(n) - sphere { - Center + <0, n, 0>, R - pigment { - color Color green 1 - } - } -#end - -#macro Inc(n) - #declare n = n + 1; -#end - -#declare Counter = 0; -#while (Counter < 2) - #if (#if (1 = 1) 0 #end = 0 & !1) - #error "Nested #if parsing failed" - #else - Make_Sphere(Counter) - #end - - Inc(Counter) -#end - -// Test macro parameters with the same name as existing variables -#declare Test1 = 0; -#declare Test2 = 1; -#declare Test3 = 2; -#macro ScopeTest(Test1, Test2, Test3) - #declare Test1 = Test2 - Test3; -#end -ScopeTest(Test1, Test3, Test2) -sphere { - 0, Test1 -} - -#declare Box = - box { - <-1, -1, -1>, <1, 1, 1> - pigment { - color rgb <1, 1, 1> - } - } - -object { - Box - finish { - phong 0.2 - } -} diff --git a/tests/dimension/directives.sh b/tests/dimension/directives.sh deleted file mode 100755 index 9e3974a..0000000 --- a/tests/dimension/directives.sh +++ /dev/null @@ -1,124 +0,0 @@ -#!/bin/sh - -######################################################################### -# Copyright (C) 2009-2011 Tavian Barnes # -# # -# 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 . # -######################################################################### - -directives=$(${top_builddir}/dimension/dimension ${dimension_flags} --tokenize --parse ${srcdir}/directives.pov) -directives_exp="$(echo -n \ -'(#version (float "3.6") ; - #debug (string "debug") - #warning (string "warning") - #include (string "directives.inc") - #declare (identifier "R") = (integer "1") ; - #local (identifier "Color") = rgb < (integer "1") , (integer "0") , (integer "1") > ; - #declare (identifier "Unused") = - (integer "1") ; - #undef (identifier "Unused") - #ifdef \( (identifier "Local") \) - #error (string "Local escaped from include file") - #end - #ifdef \( (identifier "Unused") \) - #error (string "#undef failed") - #end - #macro (identifier "Make_Sphere") \( (identifier "n") \) - sphere { - (identifier "Center") + < (integer "0") , (identifier "n") , (integer "0") > , (identifier "R") - pigment { - color (identifier "Color") green (integer "1") - } - } - #end - #macro (identifier "Inc") \( (identifier "n") \) - #declare (identifier "n") = (identifier "n") + (integer "1") ; - #end - #declare (identifier "Counter") = (integer "0") ; - #while \( (identifier "Counter") < (integer "2") \) - #if \( #if \( (integer "1") = (integer "1") \) (integer "0") #end = (integer "0") & ! (integer "1") \) - #error (string "Nested #if parsing failed") - #else - (identifier "Make_Sphere") \( (identifier "Counter") \) - #end - (identifier "Inc") \( (identifier "Counter") \) - #end - - #declare (identifier "Test1") = (integer "0") ; - #declare (identifier "Test2") = (integer "1") ; - #declare (identifier "Test3") = (integer "2") ; - #macro (identifier "ScopeTest") \( (identifier "Test1") , (identifier "Test2") , (identifier "Test3") \) - #declare (identifier "Test1") = (identifier "Test2") - (identifier "Test3") ; - #end - (identifier "ScopeTest") \( (identifier "Test1") , (identifier "Test3") , (identifier "Test2") \) - sphere { - (integer "0") , (identifier "Test1") - } - - #declare (identifier "Box") = - box { - < - (integer "1") , - (integer "1") , - (integer "1") > , - < (integer "1") , (integer "1") , (integer "1") > - pigment { - color rgb < (integer "1") , (integer "1") , (integer "1") > - } - } - - object { - (identifier "Box") - finish { - phong (float "0.2") - } - })' \ -| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g') -$(echo -n \ -'((object - (sphere - (vector (integer 0) (integer 0) (integer 0) (integer 0) (integer 0)) - (integer 1)) - (object-modifiers - (pigment - (vector (integer 1) (integer 1) (integer 1) (integer 0) (integer 0)) - pigment-modifiers))) - (object - (sphere - (vector (integer 0) (integer 1) (integer 0) (integer 0) (integer 0)) - (integer 1)) - (object-modifiers - (pigment - (vector (integer 1) (integer 1) (integer 1) (integer 0) (integer 0)) - pigment-modifiers))) - (object - (sphere - (vector (integer 0) (integer 0) (integer 0) (integer 0) (integer 0)) - (integer 1)) - object-modifiers) - (object - (box - (vector (integer -1) (integer -1) (integer -1) (integer 0) (integer 0)) - (vector (integer 1) (integer 1) (integer 1) (integer 0) (integer 0))) - (object-modifiers - (pigment - (vector (integer 1) (integer 1) (integer 1) (integer 0) (integer 0)) - pigment-modifiers) - (finish - (phong (float 0.2))))))' \ -| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g')" - -if [ "$directives" != "$directives_exp" ]; then - echo "directives.pov parsed as \"$directives\"" >&2 - echo " -- expected \"$directives_exp\"" >&2 - exit 1 -fi diff --git a/tests/dimension/integer-overflow.pov b/tests/dimension/integer-overflow.pov deleted file mode 100644 index a063fab..0000000 --- a/tests/dimension/integer-overflow.pov +++ /dev/null @@ -1,25 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -// Test integer overflow handling -- overflows should convert to floats - -torus { - 10000000000000000000, - abs(-2147483647 - 1)*abs(-9223372036854775807 - 1)*((-2147483647 - 2)*(2147483647 + 1))*((-9223372036854775807.0 - 2)*(9223372036854775807.0 + 1))*(65536*65536)*(4294967296*4294967296.0) -} diff --git a/tests/dimension/integer-overflow.sh b/tests/dimension/integer-overflow.sh deleted file mode 100755 index 0e1f03e..0000000 --- a/tests/dimension/integer-overflow.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh - -######################################################################### -# Copyright (C) 2009-2011 Tavian Barnes # -# # -# 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 . # -######################################################################### - -integer_overflow=$(${top_builddir}/dimension/dimension ${dimension_flags} --parse ${srcdir}/integer-overflow.pov) -integer_overflow_exp="$(echo -n \ -'((object - (torus - (float 1e+19) - (float 6.15656e+113)) - object-modifiers))' \ -| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g')" - -if [ "$integer_overflow" != "$integer_overflow_exp" ]; then - echo "integer-overflow.pov parsed as \"$integer_overflow\"" >&2 - echo " -- expected \"$integer_overflow_exp\"" >&2 - exit 1 -fi diff --git a/tests/dimension/invalid-macro.pov b/tests/dimension/invalid-macro.pov deleted file mode 100644 index 9906da4..0000000 --- a/tests/dimension/invalid-macro.pov +++ /dev/null @@ -1,26 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -// Regression test for commit 11d364ec365c46c21271012b566966d342a90a8b - -#macro Macro() - { } -#end - -Macro() diff --git a/tests/dimension/invalid-macro.sh b/tests/dimension/invalid-macro.sh deleted file mode 100755 index cf6f353..0000000 --- a/tests/dimension/invalid-macro.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh - -######################################################################### -# Copyright (C) 2009-2011 Tavian Barnes # -# # -# 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 . # -######################################################################### - -${top_builddir}/dimension/dimension ${dimension_flags} --parse ${srcdir}/invalid-macro.pov -[ $? -lt 128 -a $? -gt 0 ] diff --git a/tests/dimension/labels.pov b/tests/dimension/labels.pov deleted file mode 100644 index 369e1fd..0000000 --- a/tests/dimension/labels.pov +++ /dev/null @@ -1,31 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -// Test that we correctly tokenize identifiers and keywords - -camera { -} - -sphere { - color new_identifier -} - -box { - colour new_identifier -} diff --git a/tests/dimension/labels.sh b/tests/dimension/labels.sh deleted file mode 100755 index 47365bd..0000000 --- a/tests/dimension/labels.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - -######################################################################### -# Copyright (C) 2009-2011 Tavian Barnes # -# # -# 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 . # -######################################################################### - -labels=$(${top_builddir}/dimension/dimension ${dimension_flags} --tokenize ${srcdir}/labels.pov) -labels_exp='(camera { } sphere { color (identifier "new_identifier") } box { color (identifier "new_identifier") })'; - -if [ "$labels" != "$labels_exp" ]; then - echo "labels.pov tokenized as \"$labels\"" >&2 - echo " -- expected \"$labels_exp\"" >&2 - exit 1 -fi diff --git a/tests/dimension/numeric.pov b/tests/dimension/numeric.pov deleted file mode 100644 index dbf3c19..0000000 --- a/tests/dimension/numeric.pov +++ /dev/null @@ -1,30 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -// Test that we correctly tokenize numeric values. Note that the `-' in `-1', -// for example, is a separate token and not part of the number. - -// Integers: -1 123456789 01234567 0x123456789 -0x01 - -// Floats: -.1 0.1 1.0 0.123456789 -0.123456789 - -// A vector: -<1, 2.2, -3.03> diff --git a/tests/dimension/numeric.sh b/tests/dimension/numeric.sh deleted file mode 100755 index c5e7c93..0000000 --- a/tests/dimension/numeric.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh - -######################################################################### -# Copyright (C) 2009-2011 Tavian Barnes # -# # -# 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 . # -######################################################################### - -numeric=$(${top_builddir}/dimension/dimension ${dimension_flags} --tokenize ${srcdir}/numeric.pov) -numeric_exp=$(echo -n \ -'((integer "1") - (integer "123456789") - (integer "01234567") - (integer "0x123456789") - - (integer "0x01") - - (float ".1") - (float "0.1") - (float "1.0") - (float "0.123456789") - - (float "0.123456789") - - < (integer "1") , (float "2.2") , - (float "3.03") >)' \ -| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g') - -if [ "$numeric" != "$numeric_exp" ]; then - echo "numeric.pov tokenized as \"$numeric\"" >&2 - echo " -- expected \"$numeric_exp\"" >&2 - exit 1 -fi diff --git a/tests/dimension/punctuation.pov b/tests/dimension/punctuation.pov deleted file mode 100644 index d61db25..0000000 --- a/tests/dimension/punctuation.pov +++ /dev/null @@ -1,24 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -/* Test that we correctly tokenize all simple punctuation marks - * // Also make sure we handle nested /* comments */ properly - */ - -{}()[]+-*/,;?:&.|=<>!<= >= != diff --git a/tests/dimension/punctuation.sh b/tests/dimension/punctuation.sh deleted file mode 100755 index 6990657..0000000 --- a/tests/dimension/punctuation.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - -######################################################################### -# Copyright (C) 2009-2011 Tavian Barnes # -# # -# 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 . # -######################################################################### - -punctuation=$(${top_builddir}/dimension/dimension ${dimension_flags} --tokenize ${srcdir}/punctuation.pov) -punctuation_exp='({ } \( \) [ ] + - * / , ; ? : & . | = < > ! <= >= !=)' - -if [ "$punctuation" != "$punctuation_exp" ]; then - echo "punctuation.pov tokenized as \"$punctuation\"" >&2 - echo " -- expected \"$punctuation_exp\"" >&2 - exit 1 -fi diff --git a/tests/dimension/strings.pov b/tests/dimension/strings.pov deleted file mode 100644 index eafe1ba..0000000 --- a/tests/dimension/strings.pov +++ /dev/null @@ -1,21 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -// Test string handling, including escape sequences -"This is a string with escape sequences: \a\b\f\n\r\t\u2123\v\\\'\"" diff --git a/tests/dimension/strings.sh b/tests/dimension/strings.sh deleted file mode 100755 index 1f5f4f9..0000000 --- a/tests/dimension/strings.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - -######################################################################### -# Copyright (C) 2009-2011 Tavian Barnes # -# # -# 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 . # -######################################################################### - -strings=$(${top_builddir}/dimension/dimension ${dimension_flags} --tokenize ${srcdir}/strings.pov) -strings_exp=$(/bin/echo -e "((string \"This is a string with escape sequences: \a\b\f\n\r\t!#\v\\\'\"\"))") - -if [ "$strings" != "$strings_exp" ]; then - echo "strings.pov tokenized as \"$strings\"" >&2 - echo " -- expected \"$strings_exp\"" >&2 - exit 1 -fi diff --git a/tests/dimension/tbuffer-overlap.pov b/tests/dimension/tbuffer-overlap.pov deleted file mode 100644 index 872b124..0000000 --- a/tests/dimension/tbuffer-overlap.pov +++ /dev/null @@ -1,22 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -// Regression test for commit 72be096ff528306b1af6b41d5cacd1157b096d72 - -#if (1=1) #declare foo = #end; diff --git a/tests/dimension/tbuffer-overlap.sh b/tests/dimension/tbuffer-overlap.sh deleted file mode 100755 index bc3126d..0000000 --- a/tests/dimension/tbuffer-overlap.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh - -######################################################################### -# Copyright (C) 2009-2011 Tavian Barnes # -# # -# 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 . # -######################################################################### - -${top_builddir}/dimension/dimension ${dimension_flags} --parse ${srcdir}/tbuffer-overlap.pov -[ $? -lt 128 -a $? -gt 0 ] diff --git a/tests/dimension/transformations.pov b/tests/dimension/transformations.pov deleted file mode 100644 index 312445d..0000000 --- a/tests/dimension/transformations.pov +++ /dev/null @@ -1,39 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -// Test transformations - -#declare Trans = transform { translate 1*z } - -sphere { - 0, 1 - translate -1*x - rotate 90*y - scale 2 - transform Trans - matrix <1, 1, 0, - 0, 1, 0, - 0, 0, 1, - 0, 0, 0> - transform { - Trans - rotate 45*z - inverse - } -} diff --git a/tests/dimension/transformations.sh b/tests/dimension/transformations.sh deleted file mode 100755 index 727bf3b..0000000 --- a/tests/dimension/transformations.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/sh - -######################################################################### -# Copyright (C) 2009-2011 Tavian Barnes # -# # -# 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 . # -######################################################################### - -transformations=$(${top_builddir}/dimension/dimension ${dimension_flags} --parse ${srcdir}/transformations.pov) -transformations_exp="$(echo -n \ -'((object - (sphere - (vector (integer 0) (integer 0) (integer 0) (integer 0) (integer 0)) - (integer 1)) - (object-modifiers - (transformation - (translation - (vector (integer -1) (integer 0) (integer 0) - (integer 0) (integer 0)))) - (transformation - (rotation - (vector (integer 0) (integer 90) (integer 0) - (integer 0) (integer 0)))) - (transformation - (scale - (vector (integer 2) (integer 2) (integer 2) (integer 2) (integer 2)))) - (transformation - (translation - (vector (integer 0) (integer 0) (integer 1) (integer 0) (integer 0)))) - (transformation - (matrix - (integer 1) (integer 1) (integer 0) - (integer 0) (integer 1) (integer 0) - (integer 0) (integer 0) (integer 1) - (integer 0) (integer 0) (integer 0))) - (transformation - (translation - (vector (integer 0) (integer 0) (integer 1) (integer 0) (integer 0))) - (rotation - (vector (integer 0) (integer 0) (integer 45) - (integer 0) (integer 0))) - inverse))))' \ -| tr '\n' ' ' | sed -r 's/[[:space:]]+/ /g')" - -if [ "$transformations" != "$transformations_exp" ]; then - echo "transformations.pov parsed as \"$transformations\"" >&2 - echo " -- expected \"$transformations_exp\"" >&2 - exit 1 -fi - -${top_builddir}/dimension/dimension ${dimension_flags} -w1 -h1 -o /dev/null ${srcdir}/transformations.pov diff --git a/tests/libdimension/Makefile.am b/tests/libdimension/Makefile.am deleted file mode 100644 index 6b5f8ca..0000000 --- a/tests/libdimension/Makefile.am +++ /dev/null @@ -1,81 +0,0 @@ -########################################################################### -## Copyright (C) 2009-2011 Tavian Barnes ## -## ## -## This file is part of The Dimension Build Suite. ## -## ## -## The Dimension Build 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 Build 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 . ## -########################################################################### - -INCLUDES = -I$(top_srcdir)/libdimension - -check_LTLIBRARIES = libdimension-tests.la -check_PROGRAMS = warning-test \ - warning-as-error-test \ - error-test \ - polynomial-test \ - prtree-test \ - png-test \ - gl-test \ - render-test \ - cxx-test -TESTS = $(check_PROGRAMS) -XFAIL_TESTS = warning-as-error-test error-test - -if !PNG -XFAIL_TESTS += png-test -endif - -if !GL -XFAIL_TESTS += gl-test -endif - -libdimension_tests_la_SOURCES = tests.h -libdimension_tests_la_LIBADD = $(top_builddir)/libdimension/libdimension.la - -if GLX -libdimension_tests_la_SOURCES += display.c -libdimension_tests_la_LIBADD += -lX11 -lGL -else -libdimension_tests_la_SOURCES += display-stubs.c -endif - -warning_test_SOURCES = warning.c -warning_test_LDADD = libdimension-tests.la - -warning_as_error_test_SOURCES = warning-as-error.c -warning_as_error_test_LDADD = libdimension-tests.la - -error_test_SOURCES = error.c -error_test_LDADD = libdimension-tests.la - -polynomial_test_SOURCES = polynomial.c -polynomial_test_LDADD = libdimension-tests.la - -prtree_test_SOURCES = prtree.c -prtree_test_LDADD = libdimension-tests.la - -png_test_SOURCES = png.c -png_test_LDADD = libdimension-tests.la - -gl_test_SOURCES = gl.c -gl_test_LDADD = libdimension-tests.la - -render_test_SOURCES = render.c -render_test_LDADD = libdimension-tests.la - -cxx_test_SOURCES = cxx.cpp -cxx_test_LDADD = libdimension-tests.la - -clean-local: - rm -f *.png diff --git a/tests/libdimension/cxx.cpp b/tests/libdimension/cxx.cpp deleted file mode 100644 index 7405502..0000000 --- a/tests/libdimension/cxx.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/************************************************************************* - * Copyright (C) 2010-2011 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -#include "tests.h" -#include - -/* - * Ensure that dimension.h can be included in a C++ program and behave properly. - */ -int -main(void) -{ - /* Treat warnings as errors for tests */ - dmnsn_die_on_warnings(true); - - /* Make sure we can to bit-ops on this enum type */ - dmnsn_quality quality = DMNSN_RENDER_PIGMENT | DMNSN_RENDER_LIGHTS; - - return EXIT_SUCCESS; -} diff --git a/tests/libdimension/display-stubs.c b/tests/libdimension/display-stubs.c deleted file mode 100644 index e3fb99e..0000000 --- a/tests/libdimension/display-stubs.c +++ /dev/null @@ -1,38 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -#include "tests.h" -#include - -dmnsn_display * -dmnsn_new_display(const dmnsn_canvas *canvas) -{ - errno = ENOSYS; - return NULL; -} - -void -dmnsn_delete_display(dmnsn_display *display) -{ -} - -void -dmnsn_display_flush(dmnsn_display *display) -{ -} diff --git a/tests/libdimension/display.c b/tests/libdimension/display.c deleted file mode 100644 index d4e2a1c..0000000 --- a/tests/libdimension/display.c +++ /dev/null @@ -1,151 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -#include "tests.h" -#include -#include -#include - -struct dmnsn_display { - Display *dpy; - Window win; - Colormap cmap; - GLXContext cx; - XEvent event; - XVisualInfo *vi; -}; - -/* XIfEvent callback */ -static Bool -WaitForNotify(Display *d, XEvent *e, char *arg) -{ - return (e->type == MapNotify) && (e->xmap.window == (Window)arg); -} - -dmnsn_display * -dmnsn_new_display(const dmnsn_canvas *canvas) -{ - int attributeList[] = { - GLX_RGBA, - GLX_DOUBLEBUFFER, - GLX_RED_SIZE, 1, - GLX_GREEN_SIZE, 1, - GLX_BLUE_SIZE, 1, - None - }; - XSetWindowAttributes swa; - dmnsn_display *display; - - display = dmnsn_malloc(sizeof(dmnsn_display)); - - display->dpy = NULL; - display->win = 0; - display->cmap = 0; - display->cx = NULL; - display->vi = NULL; - - /* Get an X connection */ - display->dpy = XOpenDisplay(0); - if (!display->dpy) { - dmnsn_delete_display(display); - return NULL; - } - - /* Get an appropriate visual */ - display->vi = glXChooseVisual(display->dpy, DefaultScreen(display->dpy), - attributeList); - if (!display->vi) { - dmnsn_delete_display(display); - return NULL; - } - - /* Create a GLX context */ - display->cx = glXCreateContext(display->dpy, display->vi, 0, GL_TRUE); - if (!display->cx) { - dmnsn_delete_display(display); - return NULL; - } - - /* Create a color map */ - display->cmap = XCreateColormap(display->dpy, - RootWindow(display->dpy, display->vi->screen), - display->vi->visual, AllocNone); - if (!display->cmap) { - dmnsn_delete_display(display); - return NULL; - } - - /* Create a window */ - swa.colormap = display->cmap; - swa.border_pixel = 0; - swa.event_mask = StructureNotifyMask; - display->win = XCreateWindow(display->dpy, - RootWindow(display->dpy, display->vi->screen), - 0, 0, canvas->width, canvas->height, - 0, display->vi->depth, InputOutput, - display->vi->visual, - CWBorderPixel|CWColormap|CWEventMask, &swa); - if (!display->win) { - dmnsn_delete_display(display); - return NULL; - } - - XStoreName(display->dpy, display->win, "glX"); - - XMapWindow(display->dpy, display->win); - XIfEvent(display->dpy, &display->event, WaitForNotify, (char*)display->win); - - /* Connect the context to the window */ - glXMakeCurrent(display->dpy, display->win, display->cx); - glClearColor(0.0, 0.0, 0.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - dmnsn_display_flush(display); - - return display; -} - -void -dmnsn_delete_display(dmnsn_display *display) -{ - if (display) { - if (display->win) - XDestroyWindow(display->dpy, display->win); - - if (display->cmap) - XFreeColormap(display->dpy, display->cmap); - - if (display->cx) - glXDestroyContext(display->dpy, display->cx); - - if (display->vi) - XFree(display->vi); - - if (display->dpy) - XCloseDisplay(display->dpy); - - dmnsn_free(display); - } -} - -void -dmnsn_display_flush(dmnsn_display *display) -{ - glXWaitX(); - glXSwapBuffers(display->dpy, display->win); -} diff --git a/tests/libdimension/error.c b/tests/libdimension/error.c deleted file mode 100644 index 5a4d7fd..0000000 --- a/tests/libdimension/error.c +++ /dev/null @@ -1,30 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2011 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -/* Make sure that errors terminate us - this test should fail */ - -#include "dimension.h" -#include - -int -main(void) -{ - dmnsn_error("This error is expected."); - return EXIT_SUCCESS; -} diff --git a/tests/libdimension/gl.c b/tests/libdimension/gl.c deleted file mode 100644 index 8d93cf5..0000000 --- a/tests/libdimension/gl.c +++ /dev/null @@ -1,87 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2011 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -#include "tests.h" -#include - -int -main(void) -{ - /* Treat warnings as errors for tests */ - 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; - } - - /* Paint the canvas blue */ - dmnsn_clear_canvas(canvas, dmnsn_blue); - - /* Create a new glX display */ - dmnsn_display *display = dmnsn_new_display(canvas); - if (!display) { - fprintf(stderr, "--- WARNING: Couldn't initialize X or glX! ---\n"); - return EXIT_SUCCESS; - } - - /* Draw to OpenGL */ - printf("Drawing to OpenGL\n"); - if (dmnsn_gl_write_canvas(canvas) != 0) { - dmnsn_delete_display(display); - dmnsn_delete_canvas(canvas); - fprintf(stderr, "--- Drawing to OpenGL failed! ---\n"); - return EXIT_FAILURE; - } - dmnsn_display_flush(display); - dmnsn_delete_canvas(canvas); - - /* - * Now test GL import/export - */ - - /* Read the image back from OpenGL */ - printf("Reading from OpenGL\n"); - canvas = dmnsn_gl_read_canvas(0, 0, 768, 480); - if (!canvas) { - dmnsn_delete_display(display); - dmnsn_delete_canvas(canvas); - fprintf(stderr, "--- Reading from OpenGL failed! ---\n"); - return EXIT_FAILURE; - } - - /* And draw it back */ - printf("Drawing to OpenGL\n"); - if (dmnsn_gl_write_canvas(canvas) != 0) { - dmnsn_delete_display(display); - dmnsn_delete_canvas(canvas); - fprintf(stderr, "--- Drawing to OpenGL failed! ---\n"); - return EXIT_FAILURE; - } - - dmnsn_display_flush(display); - dmnsn_delete_display(display); - dmnsn_delete_canvas(canvas); - return EXIT_SUCCESS; -} diff --git a/tests/libdimension/png.c b/tests/libdimension/png.c deleted file mode 100644 index 328ee36..0000000 --- a/tests/libdimension/png.c +++ /dev/null @@ -1,106 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2011 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -#include "tests.h" -#include -#include - -int -main(void) -{ - /* Treat warnings as errors for tests */ - dmnsn_die_on_warnings(true); - - /* Allocate our canvas */ - dmnsn_canvas *canvas = dmnsn_new_canvas(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; - } - - /* Paint the canvas blue */ - dmnsn_clear_canvas(canvas, dmnsn_blue); - - /* Write the image to PNG */ - - 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; - } - - 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); - dmnsn_delete_canvas(canvas); - - /* - * Now test PNG import/export - */ - - /* Read the image back from PNG */ - - printf("Reading scene from PNG\n"); - FILE *ifile = fopen("png1.png", "rb"); - if (!ifile) { - fprintf(stderr, "--- Couldn't open 'png1.png' for reading! ---\n"); - return EXIT_FAILURE; - } - - canvas = dmnsn_png_read_canvas(ifile); - if (!canvas) { - fclose(ifile); - fprintf(stderr, "--- Reading canvas from PNG failed! ---\n"); - return EXIT_FAILURE; - } - - fclose(ifile); - - /* And write it back */ - - printf("Writing scene to PNG\n"); - ofile = fopen("png2.png", "wb"); - if (!ofile) { - fprintf(stderr, "--- Couldn't open 'png2.png' for writing! ---\n"); - dmnsn_delete_canvas(canvas); - return EXIT_FAILURE; - } - - 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); - dmnsn_delete_canvas(canvas); - - return EXIT_SUCCESS; -} diff --git a/tests/libdimension/polynomial.c b/tests/libdimension/polynomial.c deleted file mode 100644 index 5632b49..0000000 --- a/tests/libdimension/polynomial.c +++ /dev/null @@ -1,62 +0,0 @@ -/************************************************************************* - * Copyright (C) 2010-2011 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -/* - * Basic test of numerical polynomial root-finder - */ - -#include "dimension.h" -#include -#include - -int -main(void) -{ - /* Treat warnings as errors for tests */ - dmnsn_die_on_warnings(true); - - double poly[6], x[5]; - /* poly[] = (x + 1)*(x - 1.2345)*(x - 2.3456)*(x - 5)*(x - 100) */ - poly[5] = 1.0; - poly[4] = -107.5801; - poly[3] = 770.2260432; - poly[2] = -1215.2863928; - poly[1] = -646.270936; - poly[0] = 1447.8216; - - size_t n = dmnsn_solve_polynomial(poly, 5, x); - if (n != 4) { - fprintf(stderr, - "--- Wrong number of roots found (%zu, should be %u) ---\n", - n, 4); - return EXIT_FAILURE; - } - - for (size_t i = 0; i < n; ++i) { - double evmin = dmnsn_evaluate_polynomial(poly, 5, x[i] - dmnsn_epsilon); - double ev = dmnsn_evaluate_polynomial(poly, 5, x[i]); - double evmax = dmnsn_evaluate_polynomial(poly, 5, x[i] + dmnsn_epsilon); - if (fabs(evmin) < ev || fabs(evmax) < ev) { - fprintf(stderr, "--- Root %.15g is inaccurate! ---\n", x[i]); - return EXIT_FAILURE; - } - } - - return EXIT_SUCCESS; -} diff --git a/tests/libdimension/prtree.c b/tests/libdimension/prtree.c deleted file mode 100644 index cb36153..0000000 --- a/tests/libdimension/prtree.c +++ /dev/null @@ -1,98 +0,0 @@ -/************************************************************************* - * Copyright (C) 2010-2011 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -/* - * Basic tests of PR-trees - */ - -#include "dimension-impl.h" -#include "../../libdimension/prtree.c" /* For DMNSN_PRTREE_B */ -#include -#include - -unsigned int calls = 0; - -static bool -dmnsn_fake_intersection_fn(const dmnsn_object *object, dmnsn_line line, - dmnsn_intersection *intersection) -{ - intersection->t = (object->bounding_box.min.z - line.x0.z)/line.n.z; - intersection->normal = dmnsn_x; - ++calls; - return true; -} - -static void -dmnsn_randomize_bounding_box(dmnsn_object *object) -{ - dmnsn_vector a, b; - - a.x = 2.0*((double)rand())/RAND_MAX - 1.0; - a.y = 2.0*((double)rand())/RAND_MAX - 1.0; - a.z = 2.0*((double)rand())/RAND_MAX - 1.0; - - b.x = 2.0*((double)rand())/RAND_MAX - 1.0; - b.y = 2.0*((double)rand())/RAND_MAX - 1.0; - b.z = 2.0*((double)rand())/RAND_MAX - 1.0; - - object->bounding_box.min = dmnsn_vector_min(a, b); - object->bounding_box.max = dmnsn_vector_max(a, b); -} - -int -main(void) -{ - /* Treat warnings as errors for tests */ - dmnsn_die_on_warnings(true); - - const size_t nobjects = 128; - dmnsn_scene *scene = dmnsn_new_scene(); - - for (size_t i = 0; i < nobjects; ++i) { - dmnsn_object *object = dmnsn_new_object(); - dmnsn_randomize_bounding_box(object); - object->intersection_fn = dmnsn_fake_intersection_fn; - dmnsn_initialize_object(object); - dmnsn_array_push(scene->objects, &object); - } - - dmnsn_prtree *prtree = dmnsn_new_prtree(scene->objects); - - dmnsn_intersection intersection; - dmnsn_line ray = dmnsn_new_line( - dmnsn_new_vector(0.0, 0.0, -2.0), - dmnsn_new_vector(0.0, 0.0, 1.0) - ); - - if (!dmnsn_prtree_intersection(prtree, ray, &intersection, true)) { - fprintf(stderr, "--- Didn't find intersection! ---\n"); - return EXIT_FAILURE; - } - - if (calls > DMNSN_PRTREE_B) { - fprintf(stderr, - "--- Too many intersection function calls: %u! ---\n", - calls); - return EXIT_FAILURE; - } - - dmnsn_delete_prtree(prtree); - dmnsn_delete_scene(scene); - return EXIT_SUCCESS; -} diff --git a/tests/libdimension/render.c b/tests/libdimension/render.c deleted file mode 100644 index 5b03423..0000000 --- a/tests/libdimension/render.c +++ /dev/null @@ -1,309 +0,0 @@ -/************************************************************************* - * Copyright (C) 2010-2011 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -#include "tests.h" -#include -#include -#include - -/* - * Test scene -- code version of tests/dimension/demo.pov - */ -static dmnsn_scene * -dmnsn_new_test_scene(void) -{ - /* Allocate a new scene */ - dmnsn_scene *scene = dmnsn_new_scene(); - - /* Default finish */ - scene->default_texture->finish = dmnsn_new_finish_combination( - dmnsn_new_ambient_finish( - dmnsn_color_mul(0.1, dmnsn_white) - ), - dmnsn_new_diffuse_finish(0.6) - ); - - /* Allocate a canvas */ - scene->canvas = dmnsn_new_canvas(768, 480); - - /* Set up the transformation matrix for the perspective camera */ - dmnsn_matrix trans = dmnsn_scale_matrix( - dmnsn_new_vector( - ((double)scene->canvas->width)/scene->canvas->height, 1.0, 1.0 - ) - ); - trans = dmnsn_matrix_mul( - dmnsn_rotation_matrix(dmnsn_new_vector(0.0624188099959577, 0.0, 0.0)), - trans - ); - trans = dmnsn_matrix_mul( - dmnsn_translation_matrix(dmnsn_new_vector(0.0, 0.25, -4.0)), - trans - ); - trans = dmnsn_matrix_mul( - dmnsn_rotation_matrix(dmnsn_new_vector(0.0, dmnsn_radians(53.0), 0.0)), - trans - ); - - /* Create a perspective camera */ - scene->camera = dmnsn_new_perspective_camera(); - scene->camera->trans = trans; - - /* Background color */ - scene->background = dmnsn_clear; - - /* Sky sphere */ - scene->sky_sphere = dmnsn_new_sky_sphere(); - dmnsn_pattern *sky_gradient = dmnsn_new_gradient_pattern(dmnsn_y); - dmnsn_map *sky_gradient_color_map = dmnsn_new_color_map(); - dmnsn_add_map_entry(sky_gradient_color_map, 0.0, &dmnsn_orange); - dmnsn_color background = dmnsn_new_color5(0.0, 0.1, 0.2, 0.1, 0.0); - dmnsn_add_map_entry(sky_gradient_color_map, 0.35, &background); - dmnsn_pigment *sky_pigment - = dmnsn_new_color_map_pigment(sky_gradient, sky_gradient_color_map); - dmnsn_array_push(scene->sky_sphere->pigments, &sky_pigment); - - /* Light source */ - dmnsn_light *light = dmnsn_new_point_light( - dmnsn_new_vector(-15.0, 20.0, 10.0), - dmnsn_white - ); - dmnsn_array_push(scene->lights, &light); - - /* Now make our objects */ - - dmnsn_object *cube = dmnsn_new_cube(); - cube->trans = dmnsn_rotation_matrix( - dmnsn_new_vector(dmnsn_radians(45.0), 0.0, 0.0) - ); - cube->texture = dmnsn_new_texture(); - - dmnsn_color cube_color = dmnsn_blue; - cube_color.filter = 0.25; - cube_color.trans = 0.5; - cube->texture->pigment = dmnsn_new_solid_pigment(cube_color); - - dmnsn_color reflect = dmnsn_color_mul(0.5, dmnsn_white); - cube->texture->finish = dmnsn_new_reflective_finish(reflect, reflect, 1.0); - - cube->interior = dmnsn_new_interior(); - cube->interior->ior = 1.1; - - dmnsn_object *sphere = dmnsn_new_sphere(); - sphere->texture = dmnsn_new_texture(); - sphere->texture->pigment = dmnsn_new_solid_pigment(dmnsn_green); - sphere->texture->finish = dmnsn_new_phong_finish(0.2, 40.0); - sphere->trans = dmnsn_scale_matrix(dmnsn_new_vector(1.25, 1.25, 1.25)); - - dmnsn_object *csg = dmnsn_new_csg_difference(cube, sphere); - dmnsn_array_push(scene->objects, &csg); - - dmnsn_array *arrow_array = dmnsn_new_array(sizeof(dmnsn_object *)); - - dmnsn_object *cylinder = dmnsn_new_cone(0.1, 0.1, false); - cylinder->trans = dmnsn_scale_matrix(dmnsn_new_vector(1.0, 1.25, 1.0)); - dmnsn_array_push(arrow_array, &cylinder); - - dmnsn_object *cone = dmnsn_new_cone(0.1, 0.0, true); - cone->trans = - dmnsn_matrix_mul( - dmnsn_translation_matrix(dmnsn_new_vector(0.0, 1.375, 0.0)), - dmnsn_scale_matrix(dmnsn_new_vector(1.0, 0.125, 1.0)) - ); - dmnsn_array_push(arrow_array, &cone); - - dmnsn_object *arrow = dmnsn_new_csg_union(arrow_array); - arrow->trans = dmnsn_rotation_matrix( - dmnsn_new_vector(dmnsn_radians(-45.0), 0.0, 0.0) - ); - dmnsn_pattern *gradient = dmnsn_new_gradient_pattern(dmnsn_y); - dmnsn_map *gradient_color_map = dmnsn_new_color_map(); - dmnsn_add_map_entry(gradient_color_map, 0.0, &dmnsn_red); - dmnsn_add_map_entry(gradient_color_map, 1.0/6.0, &dmnsn_orange); - dmnsn_add_map_entry(gradient_color_map, 2.0/6.0, &dmnsn_yellow); - dmnsn_add_map_entry(gradient_color_map, 3.0/6.0, &dmnsn_green); - dmnsn_add_map_entry(gradient_color_map, 4.0/6.0, &dmnsn_blue); - dmnsn_add_map_entry(gradient_color_map, 5.0/6.0, &dmnsn_magenta); - dmnsn_add_map_entry(gradient_color_map, 1.0, &dmnsn_red); - arrow->texture = dmnsn_new_texture(); - arrow->texture->pigment - = dmnsn_new_color_map_pigment(gradient, gradient_color_map); - arrow->texture->trans = - dmnsn_matrix_mul( - dmnsn_translation_matrix(dmnsn_new_vector(0.0, -1.25, 0.0)), - dmnsn_scale_matrix(dmnsn_new_vector(1.0, 2.75, 1.0)) - ); - dmnsn_array_push(scene->objects, &arrow); - dmnsn_delete_array(arrow_array); - - dmnsn_array *torus_array = dmnsn_new_array(sizeof(dmnsn_object *)); - - dmnsn_object *torus1 = dmnsn_new_torus(0.15, 0.05); - torus1->trans = dmnsn_translation_matrix(dmnsn_new_vector(0.0, -1.0, 0.0)); - dmnsn_array_push(torus_array, &torus1); - - dmnsn_object *torus2 = dmnsn_new_torus(0.15, 0.05); - dmnsn_array_push(torus_array, &torus2); - - dmnsn_object *torus3 = dmnsn_new_torus(0.15, 0.05); - torus3->trans = dmnsn_translation_matrix(dmnsn_new_vector(0.0, 1.0, 0.0)); - dmnsn_array_push(torus_array, &torus3); - - dmnsn_object *torii = dmnsn_new_csg_union(torus_array); - torii->trans = dmnsn_rotation_matrix( - dmnsn_new_vector(dmnsn_radians(-45.0), 0.0, 0.0) - ); - torii->texture = dmnsn_new_texture(); - torii->texture->pigment = dmnsn_new_solid_pigment(dmnsn_blue); - torii->texture->finish = dmnsn_new_ambient_finish(dmnsn_white); - dmnsn_array_push(scene->objects, &torii); - dmnsn_delete_array(torus_array); - - dmnsn_object *plane = dmnsn_new_plane(dmnsn_new_vector(0.0, 1.0, 0.0)); - plane->trans = dmnsn_translation_matrix(dmnsn_new_vector(0.0, -2.0, 0.0)); - plane->texture = dmnsn_new_texture(); - dmnsn_pattern *checker1 = dmnsn_new_checker_pattern(); - dmnsn_pattern *checker2 = dmnsn_new_checker_pattern(); - dmnsn_map *checker_color_map = dmnsn_new_color_map(); - dmnsn_add_map_entry(checker_color_map, 0.0, &dmnsn_black); - dmnsn_add_map_entry(checker_color_map, 1.0, &dmnsn_white); - dmnsn_pigment *pigment1 = dmnsn_new_solid_pigment(dmnsn_white); - dmnsn_pigment *pigment2 - = dmnsn_new_color_map_pigment(checker1, checker_color_map); - pigment2->trans - = dmnsn_scale_matrix(dmnsn_new_vector(1.0/3.0, 1.0/3.0, 1.0/3.0)); - dmnsn_map *checker_pigment_map = dmnsn_new_pigment_map(); - dmnsn_add_map_entry(checker_pigment_map, 0.0, &pigment1); - dmnsn_add_map_entry(checker_pigment_map, 1.0, &pigment2); - plane->texture->pigment - = dmnsn_new_pigment_map_pigment(checker2, checker_pigment_map); - plane->texture->pigment->quick_color = dmnsn_new_color(1.0, 0.5, 0.75); - dmnsn_array_push(scene->objects, &plane); - - return scene; -} - -int -main(void) -{ - /* Treat warnings as errors for tests */ - dmnsn_die_on_warnings(true); - - /* Create the test scene */ - dmnsn_scene *scene = dmnsn_new_test_scene(); - - /* Optimize the canvas for PNG export */ - bool have_png = true; - errno = 0; - if (dmnsn_png_optimize_canvas(scene->canvas) != 0) { - if (errno == ENOSYS) { - have_png = false; - } else { - dmnsn_delete_scene(scene); - fprintf(stderr, "--- Couldn't optimize canvas for PNG! ---\n"); - return EXIT_FAILURE; - } - } - - /* Optimize the canvas for GL drawing */ - bool have_gl = true; - errno = 0; - if (dmnsn_gl_optimize_canvas(scene->canvas) != 0) { - if (errno == ENOSYS) { - have_gl = false; - } else { - dmnsn_delete_scene(scene); - fprintf(stderr, "--- Couldn't optimize canvas for GL! ---\n"); - return EXIT_FAILURE; - } - } - - dmnsn_clear_canvas(scene->canvas, dmnsn_black); - - /* Create a new glX display */ - dmnsn_display *display = NULL; - if (have_gl) { - display = dmnsn_new_display(scene->canvas); - if (!display) { - fprintf(stderr, "--- WARNING: Couldn't initialize X or glX! ---\n"); - } - } - - /* Render the scene */ - - printf("Rendering scene\n"); - dmnsn_progress *progress = dmnsn_raytrace_scene_async(scene); - - /* Display the scene as it's rendered */ - if (display) { - while (dmnsn_get_progress(progress) < 1.0) { - if (dmnsn_gl_write_canvas(scene->canvas) != 0) { - dmnsn_delete_display(display); - dmnsn_delete_scene(scene); - fprintf(stderr, "--- Drawing to OpenGL failed! ---\n"); - return EXIT_FAILURE; - } - dmnsn_display_flush(display); - } - } - - if (dmnsn_finish_progress(progress) != 0) { - dmnsn_delete_display(display); - dmnsn_delete_scene(scene); - fprintf(stderr, "--- Raytracing failed! ---\n"); - return EXIT_FAILURE; - } - - /* Make sure we show the completed rendering */ - if (display) { - printf("Drawing to OpenGL\n"); - if (dmnsn_gl_write_canvas(scene->canvas) != 0) { - dmnsn_delete_display(display); - dmnsn_delete_scene(scene); - fprintf(stderr, "--- Drawing to OpenGL failed! ---\n"); - return EXIT_FAILURE; - } - dmnsn_display_flush(display); - } - - if (have_png) { - printf("Writing scene to PNG\n"); - FILE *ofile = fopen("render.png", "wb"); - if (!ofile) { - dmnsn_delete_display(display); - dmnsn_delete_scene(scene); - fprintf(stderr, "--- Couldn't open 'render.png' for writing! ---\n"); - return EXIT_FAILURE; - } - - if (dmnsn_png_write_canvas(scene->canvas, ofile) != 0) { - fclose(ofile); - dmnsn_delete_display(display); - dmnsn_delete_scene(scene); - fprintf(stderr, "--- Writing canvas to PNG failed! ---\n"); - return EXIT_FAILURE; - } - - fclose(ofile); - } - - dmnsn_delete_display(display); - dmnsn_delete_scene(scene); - return EXIT_SUCCESS; -} diff --git a/tests/libdimension/tests.h b/tests/libdimension/tests.h deleted file mode 100644 index d61e442..0000000 --- a/tests/libdimension/tests.h +++ /dev/null @@ -1,46 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2010 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -#ifndef TESTS_H -#define TESTS_H - -#include "dimension.h" - -#ifdef __cplusplus -/* We've been included from a C++ file; mark everything here as extern "C" */ -extern "C" { -#endif - -/* - * Windowing - */ - -typedef struct dmnsn_display dmnsn_display; - -dmnsn_display *dmnsn_new_display(const dmnsn_canvas *canvas); -void dmnsn_delete_display(dmnsn_display *display); - -/* Flush the GL buffers */ -void dmnsn_display_flush(dmnsn_display *display); - -#ifdef __cplusplus -} -#endif - -#endif /* TESTS_H */ diff --git a/tests/libdimension/warning-as-error.c b/tests/libdimension/warning-as-error.c deleted file mode 100644 index ce274d3..0000000 --- a/tests/libdimension/warning-as-error.c +++ /dev/null @@ -1,31 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2011 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -/* Make sure warnings kill us in strict mode - this test should fail */ - -#include "dimension.h" -#include - -int -main(void) -{ - dmnsn_die_on_warnings(true); - dmnsn_warning("This warning is expected."); - return EXIT_SUCCESS; -} diff --git a/tests/libdimension/warning.c b/tests/libdimension/warning.c deleted file mode 100644 index aecedd5..0000000 --- a/tests/libdimension/warning.c +++ /dev/null @@ -1,30 +0,0 @@ -/************************************************************************* - * Copyright (C) 2009-2011 Tavian Barnes * - * * - * 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 . * - *************************************************************************/ - -/* Make sure warnings don't kill us - this test should pass */ - -#include "dimension.h" -#include - -int -main(void) -{ - dmnsn_warning("This warning is expected."); - return EXIT_SUCCESS; -} -- cgit v1.2.3