[Liblas-commits] hg-main-tree: second try at the global data path

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Mar 17 12:38:25 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/fcf3cc21be42
changeset: 331:fcf3cc21be42
user:      Kirk McKelvey <kirkoman at gmail.com>
date:      Thu Mar 17 11:38:16 2011 -0500
description:
second try at the global data path

diffstat:

 test/unit/ChipperTest.cpp      |   4 +--
 test/unit/LiblasReaderTest.cpp |   5 +--
 test/unit/LiblasWriterTest.cpp |  10 +++-----
 test/unit/main.cpp             |  47 +++--------------------------------------
 test/unit/support.cpp          |  13 +++++++++++
 test/unit/support.hpp          |   5 ++++
 6 files changed, 29 insertions(+), 55 deletions(-)

diffs (189 lines):

diff -r 84c592526b99 -r fcf3cc21be42 test/unit/ChipperTest.cpp
--- a/test/unit/ChipperTest.cpp	Thu Mar 17 10:16:35 2011 -0500
+++ b/test/unit/ChipperTest.cpp	Thu Mar 17 11:38:16 2011 -0500
@@ -44,14 +44,12 @@
 using namespace libpc;
 using namespace libpc::drivers::liblas;
 
-extern std::string g_data_path;
-
 BOOST_AUTO_TEST_SUITE(ChipperTest)
 
 BOOST_AUTO_TEST_CASE(test_construction)
 {
 
-    std::istream* ifs = Utils::openFile(g_data_path + "1.2-with-color.las");
+    std::istream* ifs = Utils::openFile(TestConfig::g_data_path + "1.2-with-color.las");
     LiblasReader reader(*ifs);
     
 
diff -r 84c592526b99 -r fcf3cc21be42 test/unit/LiblasReaderTest.cpp
--- a/test/unit/LiblasReaderTest.cpp	Thu Mar 17 10:16:35 2011 -0500
+++ b/test/unit/LiblasReaderTest.cpp	Thu Mar 17 11:38:16 2011 -0500
@@ -36,13 +36,12 @@
 #include <boost/cstdint.hpp>
 
 #include <libpc/drivers/liblas/reader.hpp>
+#include "support.hpp"
 
 using namespace libpc;
 using namespace libpc::drivers::liblas;
 
 
-extern std::string g_data_path;
-
 BOOST_AUTO_TEST_SUITE(LiblasReaderTest)
 
 
@@ -71,7 +70,7 @@
 
 BOOST_AUTO_TEST_CASE(test_1)
 {
-    std::istream* ifs = Utils::openFile(g_data_path + "1.2-with-color.las");
+    std::istream* ifs = Utils::openFile(TestConfig::g_data_path + "1.2-with-color.las");
     
     LiblasReader reader(*ifs);
     BOOST_CHECK(reader.getName() == "Liblas Reader");
diff -r 84c592526b99 -r fcf3cc21be42 test/unit/LiblasWriterTest.cpp
--- a/test/unit/LiblasWriterTest.cpp	Thu Mar 17 10:16:35 2011 -0500
+++ b/test/unit/LiblasWriterTest.cpp	Thu Mar 17 11:38:16 2011 -0500
@@ -45,8 +45,6 @@
 using namespace libpc::drivers::liblas;
 
 
-extern std::string g_data_path;
-
 BOOST_AUTO_TEST_SUITE(LiblasWriterTest)
 
 BOOST_AUTO_TEST_CASE(test_simple_las)
@@ -54,7 +52,7 @@
     // remove file from earlier run, if needed
     Utils::deleteFile("temp.las");
 
-    std::istream* ifs = Utils::openFile(g_data_path + "1.2-with-color.las");
+    std::istream* ifs = Utils::openFile(TestConfig::g_data_path + "1.2-with-color.las");
     LiblasReader reader(*ifs);
     
     std::ostream* ofs = Utils::createFile("temp.las");
@@ -80,7 +78,7 @@
     Utils::closeFile(ofs);
     Utils::closeFile(ifs);
 
-    bool filesSame = compare_files("temp.las", g_data_path + "simple.las");
+    bool filesSame = compare_files("temp.las", TestConfig::g_data_path + "simple.las");
     BOOST_CHECK(filesSame);
 
     if (filesSame)
@@ -96,7 +94,7 @@
     // remove file from earlier run, if needed
     Utils::deleteFile("temp.las");
 
-    std::istream* ifs = Utils::openFile(g_data_path + "1.2-with-color.las");
+    std::istream* ifs = Utils::openFile(TestConfig::g_data_path + "1.2-with-color.las");
     LiblasReader reader(*ifs);
     
     std::ostream* ofs = Utils::createFile("temp.laz");
@@ -121,7 +119,7 @@
     Utils::closeFile(ofs);
     Utils::closeFile(ifs);
 
-    bool filesSame = compare_files("temp.laz", g_data_path + "simple.laz");
+    bool filesSame = compare_files("temp.laz", TestConfig::g_data_path + "simple.laz");
     BOOST_CHECK(filesSame);
 
     if (filesSame)
diff -r 84c592526b99 -r fcf3cc21be42 test/unit/main.cpp
--- a/test/unit/main.cpp	Thu Mar 17 10:16:35 2011 -0500
+++ b/test/unit/main.cpp	Thu Mar 17 11:38:16 2011 -0500
@@ -32,16 +32,11 @@
 * OF SUCH DAMAGE.
 ****************************************************************************/
 
-#include <string>
+#define BOOST_TEST_MODULE Main
+#include <boost/test/unit_test.hpp>
+#include "support.hpp"
 
-#ifndef BOOST_TEST_DYN_LINK
-#define BOOST_TEST_MODULE Main
-#endif
-
-#include <boost/test/unit_test.hpp>
-#include <boost/test/utils/assign_op.hpp>
-
-std::string g_data_path;
+BOOST_GLOBAL_FIXTURE(TestConfig)
 
 // Testing macros:
 //   BOOST_TEST_MESSAGE("...")
@@ -62,37 +57,3 @@
 //
 //     <path>                  # path to data (default=../test/data)
 
-#ifdef BOOST_TEST_ALTERNATIVE_INIT_API
-bool
-libpc_init_unit_test()
-#else
-::boost::unit_test::test_suite*
-libpc_init_unit_test_suite( int, char* [] )
-#endif
-{
-    ::boost::unit_test::assign_op( ::boost::unit_test::framework::master_test_suite().p_name.value, "Main", 0 );
-    int argc = ::boost::unit_test::framework::master_test_suite().argc;
-    char **argv = ::boost::unit_test::framework::master_test_suite().argv;
-    if (argc > 1)
-        g_data_path = argv[1];
-    else
-        g_data_path = "../test/data";
-    if (g_data_path[g_data_path.size()-1] != '/')
-        g_data_path += "/";
-    
-#ifdef BOOST_TEST_ALTERNATIVE_INIT_API
-    return true;
-#else
-    return 0;
-#endif
-}
-
-#if defined(BOOST_TEST_DYN_LINK) 
-
-int
-main( int argc, char* argv[] )
-{
-    return ::boost::unit_test::unit_test_main( &libpc_init_unit_test, argc, argv );
-}
-
-#endif // BOOST_TEST_DYN_LINK
diff -r 84c592526b99 -r fcf3cc21be42 test/unit/support.cpp
--- a/test/unit/support.cpp	Thu Mar 17 10:16:35 2011 -0500
+++ b/test/unit/support.cpp	Thu Mar 17 11:38:16 2011 -0500
@@ -87,3 +87,16 @@
 
     return true;
 }
+
+std::string TestConfig::g_data_path = "../test/data";
+
+TestConfig::TestConfig()
+{
+    int argc = ::boost::unit_test::framework::master_test_suite().argc;
+    char **argv = ::boost::unit_test::framework::master_test_suite().argv;
+    if (argc > 1)
+        g_data_path = argv[1];
+    if (g_data_path[g_data_path.size() - 1] != '/')
+        g_data_path += "/";
+}
+
diff -r 84c592526b99 -r fcf3cc21be42 test/unit/support.hpp
--- a/test/unit/support.hpp	Thu Mar 17 10:16:35 2011 -0500
+++ b/test/unit/support.hpp	Thu Mar 17 11:38:16 2011 -0500
@@ -43,4 +43,9 @@
 // verify if two files are the same
 extern bool compare_files(const std::string& file1, const std::string& file2);
 
+struct TestConfig {
+    TestConfig();
+    static std::string g_data_path;
+};
+
 #endif


More information about the Liblas-commits mailing list