attic/unittest/dataaccess/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 #include <terralib/dataaccess.h>
23 #include <terralib/plugin.h>
24 
25 // STL
26 #include <cstdlib>
27 
28 // Boost
29 #include <boost/property_tree/json_parser.hpp>
30 #include <boost/foreach.hpp>
31 
32 // cppUnit
33 #include <cppunit/extensions/HelperMacros.h>
34 #include <cppunit/extensions/TestFactoryRegistry.h>
35 #include <cppunit/BriefTestProgressListener.h>
36 #include <cppunit/CompilerOutputter.h>
37 #include <cppunit/TestResult.h>
38 #include <cppunit/TestResultCollector.h>
39 #include <cppunit/TestRunner.h>
40 #include <cppunit/TextOutputter.h>
41 #include <cppunit/XmlOutputter.h>
42 
43 // Unit-Test TerraLib includes by platform
44 #include "LoadModules.h"
45 #include "Config.h"
46 
47 #include "TsManagerDataSource.h"
48 
49 int main(int /*argc*/, char** /*argv*/)
50 {
52  LoadModules();
53 
54  std::string report_dir = TERRALIB_REPORT_DIR;
55  bool resultStatus = false;
56 
57  boost::property_tree::ptree drivers;
58 
59  boost::property_tree::read_json("../data/json_files/drivers.json", drivers);
60 
61  BOOST_FOREACH(const boost::property_tree::ptree::value_type& v, drivers.get_child("drivers").get_child(""))
62  {
63  try
64  {
65  const std::string& driver_name = v.second.data();
66 
68 
69  boost::property_tree::ptree driver;
70 
71  boost::property_tree::read_json(driver_name, driver);
72 
73  std::string m_dsType = driver.get_child("ds.ds_type").data();
74 
75 // it creates the event manager and test controller
76  CPPUNIT_NS::TestResult controller;
77 
78 // it adds a listener that collects test result
79  CPPUNIT_NS::TestResultCollector result;
80 
81  controller.addListener(&result);
82 
83 // it adds a listener that print dots as test run.
84  CPPUNIT_NS::BriefTestProgressListener progress;
85 
86  controller.addListener(&progress);
87 
88 // it adds the top suite to the test runner
89  CppUnit::Test* suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
90 
91  CPPUNIT_NS::TestRunner runner;
92 
93  runner.addTest(suite);
94 
95  runner.run(controller);
96 
97  CPPUNIT_NS::CompilerOutputter outputter( &result, CPPUNIT_NS::stdCOut() );
98  outputter.write();
99 
100 // Testing different outputs
101  // The testResult_*.xml files will be saved at TERRALIB_REPORT_DIR directory.
102  // The styleSheet 'report.xsl' should be at this directory (found originally at <third-party-lib>\cppunit-1.12.1\contrib\xml-xsl).
103  // The "data.zip" (downloaded) containing the data used in unit tests should be at TERRALIB_DATA_DIR
104 
105 // Note on how to run the unittests:
106  // Debug - terralib_unittest_dataaccess_d.exe- Start up terralib_unittest_dataaccess
107  // Release - terralib_unittest_dataaccess.exe
108 
109 // Print only fail results in a txt file (the same containt you see in DOS window)
110  std::string testResultDriver = TERRALIB_REPORT_DIR"/testResult_" + m_dsType ;
111  std::ofstream file1( (testResultDriver + "_dos.txt" ).c_str() );
112 
113  CPPUNIT_NS::CompilerOutputter outputter1( &result, file1);
114  outputter1.write();
115  file1.close();
116 
117 // Printing testResults in XML file
118  CPPUNIT_NS::OFileStream file2( (testResultDriver + ".xml").c_str() );
119  CPPUNIT_NS::XmlOutputter xml( &result, file2 );
120  xml.setStyleSheet( "report.xsl" );
121 
122  xml.write();
123  file2.close();
124 
125 // Print formated testResult in a txt
126  CPPUNIT_NS::OFileStream file3( (testResultDriver + ".txt" ).c_str() );
127  CPPUNIT_NS::TextOutputter outputter3( &result, file3 );
128  outputter3.write();
129  file3.close();
130 
131  resultStatus = result.wasSuccessful();
132  }
133  catch (te::common::Exception e)
134  {
135  throw e;
136  }
137 
139  }
140 
141 // finalize TerraLib Plataform
142 
144 
145  return resultStatus ? EXIT_SUCCESS : EXIT_FAILURE;
146 }
void finalize()
It finalizes the TerraLib Platform.
static TerraLib & getInstance()
It returns a reference to the singleton instance.
static void initialize(const std::string driver_name)
It will initialize the resources used by Test Suit: TsDataSource, TsDataSet, TsDataSetTypePersistence...
static void finalize()
It will finalize the resources used in Teste Suit: TsDataSource, TsDataSet, TsDataSetTypePersistence...
A static class for managing the resources used by DataSource test suit.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
void initialize()
It initializes the TerraLib Platform.
int main(int, char **)
This file contains include headers for the TerraLib Common Runtime module.
This file contains include headers for the Data Access module of TerraLib.
void LoadModules()
Load terralib modules.