openETCS
case study for the European Train Control System developed for the authors dissertation
UT/Main.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010-2011
3  Johannes Feuser <johannes.feuser@googlemail.com>
4  This file is part of the openETCS library.
5 
6  The openETCS library is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  any later version.
10 
11  The openETCS library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with the openETCS library. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 /*!
21  * \file
22  * \author Johannes Feuser <jfeuser@uni-bremen.de>
23  * \brief source file for the unit testing main function
24  */
25 
26 #include <TextTestRunner.h>
27 #include <TextTestProgressListener.h>
28 #include <BriefTestProgressListener.h>
29 #include <TestSuccessListener.h>
30 #include <TextTestResult.h>
31 #include <TestResult.h>
32 #include <TextOutputter.h>
33 #include <TestResultCollector.h>
34 
35 #include "UnitTesting.h"
36 
37 
38 int main(int argc, char** argv)
39 {
40  int iReturn(2);
41 
42 
43  try
44  {
45  CppUnit::TestResultCollector* pResultCollector(new CppUnit::TestResultCollector);
46  CppUnit::TextOutputter* pOutputter(new CppUnit::TextOutputter(pResultCollector, ::std::cout));
47  CppUnit::TextTestRunner Runner(pOutputter);
48  CppUnit::Test* pSuite(0);
49  CppUnit::BriefTestProgressListener BriefListener;
50  CppUnit::TextTestProgressListener ProgressListener;
51  CppUnit::TestSuccessListener SuccessListener;
52  CppUnit::TestResult Result;
53 
54 
55  // always initialise random generator with same constant
56  srand(0);
57 
58  // get the top level suite from the registry
59  pSuite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
60 
61  // add suite to runner
62  Runner.addTest(pSuite);
63 
64  // add listeners to result
65  Result.addListener(&BriefListener);
66  Result.addListener(&SuccessListener);
67  Result.addListener(pResultCollector);
68 
69  // run tests with own runner
70  Runner.run(Result);
71 
72  // print further infos about the run
73  pOutputter->printStatistics();
74  pOutputter->printFailures();
75 
76  // set return value;
77  iReturn = SuccessListener.wasSuccessful() ? 0 : 1;
78 
79  } // try
80  catch (const ::std::bad_alloc& Exception)
81  {
82  // print exception message
83  ::std::cerr << Exception.what() << ::std::endl;
84 
85  } // catch (const ::std::bad_alloc& Exception)
86 
87  // return execution code
88  return iReturn;
89 
90 } // int main(int argc, char** argv)

Copyright (C) 2010-2012 Johannes Feuser (feuser@uni-bremen.de)
The openETCS library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.
The openETCS library 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 General Public License for more details.
You should have received a copy of the GNU General Public License along with the openETCS library. If not, see "http://www.gnu.org/licenses/.