diff options
author | Hubert Figuiere <hub@figuiere.net> | 2007-12-16 14:10:06 -0500 |
---|---|---|
committer | Hubert Figuiere <hub@figuiere.net> | 2007-12-16 14:10:06 -0500 |
commit | dce14eb24d7e10342b772cfcb18f7160a80add38 (patch) | |
tree | 5ff36756a3f6a5cee03094e0708c801dfd7d797f | |
parent | c91af02a177b47c690f1a87d7b0434aa198c2735 (diff) |
* exempi/tests/*: refactor the test preparation.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | exempi/tests/Makefile.am | 11 | ||||
-rw-r--r-- | exempi/tests/test1.cpp | 22 | ||||
-rw-r--r-- | exempi/tests/test2.cpp | 15 | ||||
-rw-r--r-- | exempi/tests/test3.cpp | 16 | ||||
-rw-r--r-- | exempi/tests/testinit.cpp | 15 | ||||
-rw-r--r-- | exempi/tests/utils.cpp | 58 | ||||
-rw-r--r-- | exempi/tests/utils.h | 49 |
9 files changed, 130 insertions, 61 deletions
@@ -1,3 +1,7 @@ +2007-12-16 Hubert Figuiere <hub@figuiere.net> + + * exempi/tests/*: refactor the test preparation. + 2007-11-13 Hubert Figuiere <hub@figuiere.net> * exempi/tests/*.c: Add a bunch of include deemed necessary @@ -1,5 +1,6 @@ 1.99.6 +- Test: refactor a the tests preparation - Test: add a test for multiple initializations. - Bug: fix configure to allow building on MacOS X. Closes bug #13596 diff --git a/exempi/tests/Makefile.am b/exempi/tests/Makefile.am index 58ce913..49fa97a 100644 --- a/exempi/tests/Makefile.am +++ b/exempi/tests/Makefile.am @@ -47,19 +47,20 @@ EXTRA_DIST = $(check_DATA) $(check_SCRIPTS) CLEANFILES = test.jpg TESTS = testcore.sh testinit test1 test2 test3 +TESTS_ENVIRONMENT = TEST_DIR=$(srcdir) -testinit_SOURCES = testinit.cpp +testinit_SOURCES = testinit.cpp utils.cpp testinit_LDADD = ../libexempi.la @BOOST_UNIT_TEST_FRAMEWORK_LIB@ testinit_LDFLAGS = -static -test1_SOURCES = test1.cpp +test1_SOURCES = test1.cpp utils.cpp test1_LDADD = ../libexempi.la @BOOST_UNIT_TEST_FRAMEWORK_LIB@ test1_LDFLAGS = -static -test2_SOURCES = test2.cpp +test2_SOURCES = test2.cpp utils.cpp test2_LDADD = ../libexempi.la @BOOST_UNIT_TEST_FRAMEWORK_LIB@ test2_LDFLAGS = -static -test3_SOURCES = test3.cpp +test3_SOURCES = test3.cpp utils.cpp test3_LDADD = ../libexempi.la @BOOST_UNIT_TEST_FRAMEWORK_LIB@ -test3_LDFLAGS = -static
\ No newline at end of file +test3_LDFLAGS = -static diff --git a/exempi/tests/test1.cpp b/exempi/tests/test1.cpp index bddf2b3..82e61d7 100644 --- a/exempi/tests/test1.cpp +++ b/exempi/tests/test1.cpp @@ -43,12 +43,12 @@ #include <boost/static_assert.hpp> #include <boost/test/auto_unit_test.hpp> +#include "utils.h" #include "xmpconsts.h" #include "xmp.h" using boost::unit_test::test_suite; -std::string g_testfile; void test_write_new_property() { @@ -250,22 +250,12 @@ init_unit_test_suite( int argc, char * argv[] ) { test_suite* test = BOOST_TEST_SUITE("test exempi"); - if (argc == 1) { - // no argument, lets run like we are in "check" - const char * srcdir = getenv("srcdir"); - - BOOST_ASSERT(srcdir != NULL); - g_testfile = std::string(srcdir); - g_testfile += "/test1.xmp"; - } - else { - g_testfile = argv[1]; - } - - test->add(BOOST_TEST_CASE(&test_exempi)); - test->add(BOOST_TEST_CASE(&test_serialize)); - test->add(BOOST_TEST_CASE(&test_write_new_property)); + prepare_test(argc, argv, "test1.xmp"); + test->add(BOOST_TEST_CASE(&test_exempi)); + test->add(BOOST_TEST_CASE(&test_serialize)); + test->add(BOOST_TEST_CASE(&test_write_new_property)); + return test; } diff --git a/exempi/tests/test2.cpp b/exempi/tests/test2.cpp index 8b3efff..395bcbf 100644 --- a/exempi/tests/test2.cpp +++ b/exempi/tests/test2.cpp @@ -43,13 +43,12 @@ #include <boost/static_assert.hpp> #include <boost/test/auto_unit_test.hpp> +#include "utils.h" #include "xmp.h" #include "xmpconsts.h" using boost::unit_test::test_suite; -std::string g_testfile; - void test_xmpfiles_write() { @@ -148,17 +147,7 @@ init_unit_test_suite( int argc, char * argv[] ) { test_suite* test = BOOST_TEST_SUITE("test xmpfiles"); - if (argc == 1) { - // no argument, lets run like we are in "check" - const char * srcdir = getenv("srcdir"); - - BOOST_ASSERT(srcdir != NULL); - g_testfile = std::string(srcdir); - g_testfile += "/../../samples/BlueSquares/BlueSquare.jpg"; - } - else { - g_testfile = argv[1]; - } + prepare_test(argc, argv, "../../samples/BlueSquares/BlueSquare.jpg"); test->add(BOOST_TEST_CASE(&test_xmpfiles)); test->add(BOOST_TEST_CASE(&test_xmpfiles_write)); diff --git a/exempi/tests/test3.cpp b/exempi/tests/test3.cpp index 3ed8023..5529b8f 100644 --- a/exempi/tests/test3.cpp +++ b/exempi/tests/test3.cpp @@ -45,14 +45,12 @@ #include <boost/test/auto_unit_test.hpp> #include <boost/format.hpp> +#include "utils.h" #include "xmp.h" #include "xmpconsts.h" using boost::unit_test::test_suite; -std::string g_testfile; - - void test_exempi_iterate() { size_t len; @@ -120,17 +118,7 @@ init_unit_test_suite( int argc, char * argv[] ) { test_suite* test = BOOST_TEST_SUITE("test exempi"); - if (argc == 1) { - // no argument, lets run like we are in "check" - const char * srcdir = getenv("srcdir"); - - BOOST_ASSERT(srcdir != NULL); - g_testfile = std::string(srcdir); - g_testfile += "/test1.xmp"; - } - else { - g_testfile = argv[1]; - } + prepare_test(argc, argv, "test1.xmp"); test->add(BOOST_TEST_CASE(&test_exempi_iterate)); diff --git a/exempi/tests/testinit.cpp b/exempi/tests/testinit.cpp index ed5afe7..0e4dd1d 100644 --- a/exempi/tests/testinit.cpp +++ b/exempi/tests/testinit.cpp @@ -43,13 +43,12 @@ #include <boost/static_assert.hpp> #include <boost/test/auto_unit_test.hpp> +#include "utils.h" #include "xmpconsts.h" #include "xmp.h" using boost::unit_test::test_suite; -std::string g_testfile; - void test_exempi_init() { size_t len; @@ -98,17 +97,7 @@ init_unit_test_suite( int argc, char * argv[] ) { test_suite* test = BOOST_TEST_SUITE("test exempi"); - if (argc == 1) { - // no argument, lets run like we are in "check" - const char * srcdir = getenv("srcdir"); - - BOOST_ASSERT(srcdir != NULL); - g_testfile = std::string(srcdir); - g_testfile += "/test1.xmp"; - } - else { - g_testfile = argv[1]; - } + prepare_test(argc, argv, "test1.xmp"); test->add(BOOST_TEST_CASE(&test_exempi_init)); diff --git a/exempi/tests/utils.cpp b/exempi/tests/utils.cpp new file mode 100644 index 0000000..3edadf4 --- /dev/null +++ b/exempi/tests/utils.cpp @@ -0,0 +1,58 @@ +/* + * exempi - utils.cpp + * + * Copyright (C) 2007 Hubert Figuiere + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1 Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2 Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * 3 Neither the name of the Authors, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software wit hout specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include <boost/test/unit_test.hpp> + +#include "utils.h" + +std::string g_testfile; + +void prepare_test(int argc, char * argv[], const char *filename) +{ + if (argc == 1) { + // no argument, lets run like we are in "check" + const char * srcdir = getenv("TEST_DIR"); + + BOOST_ASSERT(srcdir != NULL); + g_testfile = std::string(srcdir); + g_testfile += "/"; + g_testfile += filename; + } + else { + g_testfile = argv[1]; + } +} diff --git a/exempi/tests/utils.h b/exempi/tests/utils.h new file mode 100644 index 0000000..64da7ea --- /dev/null +++ b/exempi/tests/utils.h @@ -0,0 +1,49 @@ +/* + * exempi - utils.h + * + * Copyright (C) 2007 Hubert Figuiere + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1 Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2 Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * 3 Neither the name of the Authors, nor the names of its + * contributors may be used to endorse or promote products derived + * from this software wit hout specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + + + +#ifndef __TEST_UTILS_H__ +#define __TEST_UTILS_H__ + +#include <string> + +extern std::string g_testfile; + +void prepare_test(int argc, char * argv[], const char * filename); + +#endif |