unittest/common/main.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 // TerraLib
21 #include <terralib/common.h>
22 
23 // Unit-Test TerraLib includes by platform
24 #include "../Config.h"
25 
26 // cppUnit
27 #include <cppunit/BriefTestProgressListener.h>
28 #include <cppunit/CompilerOutputter.h>
29 #include <cppunit/XmlOutputter.h>
30 #include <cppunit/extensions/HelperMacros.h>
31 #include <cppunit/extensions/TestFactoryRegistry.h>
32 #include <cppunit/TestResult.h>
33 #include <cppunit/TestResultCollector.h>
34 #include <cppunit/TestRunner.h>
35 
36 int main(int /*argc*/, char** /*argv*/)
37 {
38 
40 
41 // it creates the event manager and test controller
42  CPPUNIT_NS::TestResult controller;
43 
44 // it adds a listener that colllects test result
45  CPPUNIT_NS::TestResultCollector result;
46 
47  controller.addListener(&result);
48 
49 // it adds a listener that print dots as test run.
50  CPPUNIT_NS::BriefTestProgressListener progress;
51 
52  controller.addListener(&progress);
53 
54 // it adds the top suite to the test runner
55  CppUnit::Test* suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
56 
57  CPPUNIT_NS::TestRunner runner;
58 
59  runner.addTest(suite);
60 
61  runner.run(controller);
62 
63  CPPUNIT_NS::CompilerOutputter outputter( &result, CPPUNIT_NS::stdCOut() );
64 
65  outputter.write();
66 
67  // Testing different outputs
68  // The testResult_*.xml files will be saved at TERRALIB_REPORT_DIR directory.
69  // The styleSheet 'report.xsl' should be at this directory (found originally at <third-party-lib>\cppunit-1.12.1\contrib\xml-xsl).
70  // The "data.zip" (downloaded) containing the data used in unit tests should be at TERRALIB_DATA_DIR
71 
72 // Note on how to run the unittests:
73  // Debug - terralib_unittest_common_d.exe- Start up terralib_unittest_dataaccess
74  // Release - terralib_unittest_common.exe
75 
76  CPPUNIT_NS::OFileStream file2(TERRALIB_REPORT_DIR"/testResults_common_xml.xml");
77  CPPUNIT_NS::XmlOutputter xml(&result, file2);
78  xml.setStyleSheet("report.xsl");
79  xml.write();
80  file2.close();
81 
82  bool resultStatus = result.wasSuccessful();
83 
85 
86  return resultStatus ? EXIT_SUCCESS : EXIT_FAILURE;
87 }
void finalize()
It finalizes the TerraLib Platform.
static TerraLib & getInstance()
It returns a reference to the singleton instance.
void initialize()
It initializes the TerraLib Platform.
This file contains include headers for the TerraLib Common Runtime module.
int main(int, char **)