From a91667e54e042889de5480dd56b950923837335d Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 24 Jun 2009 21:29:09 +0000 Subject: New convienence libraries for tests. --- tests/Makefile.am | 31 +++++++++++++++++++------------ tests/error.c | 2 +- tests/png.c | 30 ++++-------------------------- tests/pngxx.cpp | 28 ++++------------------------ tests/raytrace.c | 2 +- tests/tests.c | 39 +++++++++++++++++++++++++++++++++++++++ tests/tests.h | 24 ++++++++++++++++++++++++ tests/testsxx.cpp | 34 ++++++++++++++++++++++++++++++++++ tests/testsxx.hpp | 25 +++++++++++++++++++++++++ tests/warning.c | 2 +- 10 files changed, 152 insertions(+), 65 deletions(-) create mode 100644 tests/tests.c create mode 100644 tests/tests.h create mode 100644 tests/testsxx.cpp create mode 100644 tests/testsxx.hpp (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am index 513e57a..5d09994 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -17,23 +17,30 @@ ## along with this program. If not, see . ## ########################################################################### -check_PROGRAMS = warning error png pngxx raytrace -TESTS = $(check_PROGRAMS) -XFAIL_TESTS = error +check_LTLIBRARIES = libdimension-tests.la libdimensionxx-tests.la +check_PROGRAMS = warning error png pngxx raytrace +TESTS = $(check_PROGRAMS) +XFAIL_TESTS = error INCLUDES = -I../libdimension -I../libdimensionxx -warning_SOURCES = warning.c -warning_LDADD = ../libdimension/libdimension.la +libdimension_tests_la_SOURCES = tests.h tests.c +libdimension_tests_la_LIBADD = ../libdimension/libdimension.la -error_SOURCES = error.c -error_LDADD = ../libdimension/libdimension.la +libdimensionxx_tests_la_SOURCES = testsxx.hpp testsxx.cpp +libdimensionxx_tests_la_LIBADD = ../libdimensionxx/libdimensionxx.la -png_SOURCES = png.c -png_LDADD = ../libdimension/libdimension.la +warning_SOURCES = warning.c +warning_LDADD = ./libdimension-tests.la -pngxx_SOURCES = pngxx.cpp -pngxx_LDADD = ../libdimensionxx/libdimensionxx.la +error_SOURCES = error.c +error_LDADD = ./libdimension-tests.la + +png_SOURCES = png.c +png_LDADD = ./libdimension-tests.la + +pngxx_SOURCES = pngxx.cpp +pngxx_LDADD = ./libdimensionxx-tests.la raytrace_SOURCES = raytrace.c -raytrace_LDADD = ../libdimension/libdimension.la +raytrace_LDADD = ./libdimension-tests.la diff --git a/tests/error.c b/tests/error.c index f1ef6ee..7bd8ef6 100644 --- a/tests/error.c +++ b/tests/error.c @@ -18,7 +18,7 @@ * . * *************************************************************************/ -#include "../libdimension/dimension.h" +#include "tests.h" #include int diff --git a/tests/png.c b/tests/png.c index 213e176..b80af04 100644 --- a/tests/png.c +++ b/tests/png.c @@ -18,7 +18,7 @@ * . * *************************************************************************/ -#include "../libdimension/dimension.h" +#include "tests.h" #include #include #include @@ -27,7 +27,6 @@ int main() { dmnsn_canvas *canvas; dmnsn_progress *progress; - double prog; dmnsn_color color; dmnsn_CIE_xyY xyY; dmnsn_CIE_Lab Lab; @@ -118,14 +117,7 @@ main() { return EXIT_FAILURE; } - /* Give an ellipsis progress indication */ - prog = 0.0; - while ((prog += 1.0/10.0) < 1.0) { - dmnsn_wait_progress(progress, prog); - printf("."); - fflush(stdout); - } - printf("\n"); + progressbar("Writing PNG file: ", progress); if (dmnsn_finish_progress(progress) != 0) { fprintf(stderr, "--- Writing canvas to PNG failed! ---\n"); @@ -150,14 +142,7 @@ main() { return EXIT_FAILURE; } - /* Give an ellipsis progress indication */ - prog = 0.0; - while ((prog += 1.0/10.0) < 1.0) { - dmnsn_wait_progress(progress, prog); - printf("."); - fflush(stdout); - } - printf("\n"); + progressbar("Reading PNG file: ", progress); if (dmnsn_finish_progress(progress) != 0) { fprintf(stderr, "--- Reading canvas from PNG failed! ---\n"); @@ -181,14 +166,7 @@ main() { return EXIT_FAILURE; } - /* Give an ellipsis progress indication */ - prog = 0.0; - while ((prog += 1.0/10.0) < 1.0) { - dmnsn_wait_progress(progress, prog); - printf("."); - fflush(stdout); - } - printf("\n"); + progressbar("Writing PNG file: ", progress); if (dmnsn_finish_progress(progress) != 0) { fprintf(stderr, "--- Writing canvas to PNG failed! ---\n"); diff --git a/tests/pngxx.cpp b/tests/pngxx.cpp index 2bb9fdb..4a99370 100644 --- a/tests/pngxx.cpp +++ b/tests/pngxx.cpp @@ -18,9 +18,8 @@ * . * *************************************************************************/ -#include "../libdimensionxx/dimensionxx.hpp" +#include "testsxx.hpp" #include -#include int main() @@ -95,14 +94,7 @@ main() } Dimension::Progress progress = ocanvas.write_async(); - - // Display ellipsis progress bar - double prog = 0.0; - while ((prog += 1.0/10.0) <= 1.0) { - progress.wait(prog); - std::cout << "." << std::flush; - } - std::cout << std::endl; + std::cout << "Writing PNG file: " << progress << std::endl; } std::ifstream ifstr("dimensionxx1.png", std::ios::binary); @@ -110,24 +102,12 @@ main() Dimension::Progress iprogress = Dimension::PNG_Canvas::read_async(ifstr); - - double iprog = 0.0; - while ((iprog += 1.0/10.0) <= 1.0) { - iprogress.wait(iprog); - std::cout << "." << std::flush; - } - std::cout << std::endl; + std::cout << "Reading PNG file: " << iprogress << std::endl; Dimension::PNG_Canvas iocanvas(iprogress, ofstr); Dimension::Progress oprogress = iocanvas.write_async(); - - double oprog = 0.0; - while ((oprog += 1.0/10.0) <= 1.0) { - oprogress.wait(oprog); - std::cout << "." << std::flush; - } - std::cout << std::endl; + std::cout << "Writing PNG file: " << oprogress << std::endl; return 0; } diff --git a/tests/raytrace.c b/tests/raytrace.c index abd4093..bb26f58 100644 --- a/tests/raytrace.c +++ b/tests/raytrace.c @@ -18,7 +18,7 @@ * . * *************************************************************************/ -#include "../libdimension/dimension.h" +#include "tests.h" #include #include diff --git a/tests/tests.c b/tests/tests.c new file mode 100644 index 0000000..67e5ee1 --- /dev/null +++ b/tests/tests.c @@ -0,0 +1,39 @@ +/************************************************************************* + * Copyright (C) 2008 Tavian Barnes * + * * + * This file is part of The Dimension Test Suite. * + * * + * Dimension is free software; you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as published * + * by the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * Dimension 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this program. If not, see * + * . * + *************************************************************************/ + +#include "tests.h" + +void +progressbar(const char *str, const dmnsn_progress *progress) +{ + const unsigned int increments = 32; + unsigned int i; + + printf("%s|", str); + fflush(stdout); + for (i = 0; i < increments; ++i) { + dmnsn_wait_progress(progress, ((double)(i + 1))/increments); + + printf("="); + fflush(stdout); + } + printf("|\n"); + fflush(stdout); +} diff --git a/tests/tests.h b/tests/tests.h new file mode 100644 index 0000000..c6b0de6 --- /dev/null +++ b/tests/tests.h @@ -0,0 +1,24 @@ +/************************************************************************* + * Copyright (C) 2008 Tavian Barnes * + * * + * This file is part of The Dimension Test Suite. * + * * + * Dimension is free software; you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as published * + * by the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * Dimension 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this program. If not, see * + * . * + *************************************************************************/ + +#include "../libdimension/dimension.h" +#include + +void progressbar(const char *str, const dmnsn_progress *progress); diff --git a/tests/testsxx.cpp b/tests/testsxx.cpp new file mode 100644 index 0000000..a4a7d7b --- /dev/null +++ b/tests/testsxx.cpp @@ -0,0 +1,34 @@ +/************************************************************************* + * Copyright (C) 2008 Tavian Barnes * + * * + * This file is part of The Dimension Test Suite. * + * * + * Dimension is free software; you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as published * + * by the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * Dimension 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this program. If not, see * + * . * + *************************************************************************/ + +#include "testsxx.hpp" + +std::ostream& +operator<<(std::ostream& ostr, const Dimension::Progress& progress) +{ + const unsigned int increments = 32; + + ostr << "|" << std::flush; + for (unsigned int i = 0; i < increments; ++i) { + progress.wait(static_cast(i + 1)/increments); + ostr << "=" << std::flush; + } + return ostr << "|" << std::flush; +} diff --git a/tests/testsxx.hpp b/tests/testsxx.hpp new file mode 100644 index 0000000..43c7593 --- /dev/null +++ b/tests/testsxx.hpp @@ -0,0 +1,25 @@ +/************************************************************************* + * Copyright (C) 2008 Tavian Barnes * + * * + * This file is part of The Dimension Test Suite. * + * * + * Dimension is free software; you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as published * + * by the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * Dimension 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this program. If not, see * + * . * + *************************************************************************/ + +#include "../libdimensionxx/dimensionxx.hpp" +#include + +std::ostream& operator<<(std::ostream& ostr, + const Dimension::Progress& progress); diff --git a/tests/warning.c b/tests/warning.c index 7816cc8..80199c9 100644 --- a/tests/warning.c +++ b/tests/warning.c @@ -18,7 +18,7 @@ * . * *************************************************************************/ -#include "../libdimension/dimension.h" +#include "tests.h" #include int -- cgit v1.2.3