FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
run_tests.cc
1 /*
2  * Copyright (C) 2014-2015, Siemens AG
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * version 2 as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16  */
17 
18 #include <cppunit/BriefTestProgressListener.h>
19 #include <cppunit/CompilerOutputter.h>
20 #include <cppunit/TestResult.h>
21 #include <cppunit/TestResultCollector.h>
22 #include <cppunit/TestRunner.h>
23 #include <cppunit/XmlOutputter.h>
24 #include <cppunit/extensions/TestFactoryRegistry.h>
25 #include <fstream>
26 #include <stdexcept>
27 
28 using namespace std;
29 
30 int main(int argc, char* argv[])
31 {
32  // Retrieve test path from command line first argument.
33  // Default to "" which resolves to the top level suite.
34  string testPath = (argc > 1) ? string(argv[1]) : string("");
35 
36  // Create the event manager and test controller.
37  CPPUNIT_NS::TestResult controller;
38 
39  // Add a listener that colllects test results.
40  CPPUNIT_NS::TestResultCollector result;
41  controller.addListener(&result);
42 
43  // Add a listener that prints dots as tests run.
44  CPPUNIT_NS::BriefTestProgressListener progress;
45  controller.addListener(&progress);
46 
47  // Add the top suite to the test runner.
48  CPPUNIT_NS::TestRunner runner;
49  runner.addTest(CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest());
50 
51  try
52  {
53  CPPUNIT_NS::stdCOut() << "Running " << (testPath.empty() ? "all tests" : testPath) << endl;
54  runner.run(controller, testPath);
55  CPPUNIT_NS::stdCOut() << endl;
56 
57  // Print test in a compiler compatible format.
58  CPPUNIT_NS::CompilerOutputter outputter(&result, CPPUNIT_NS::stdCOut());
59  outputter.write();
60 
61  // Generate XML output.
62  ofstream file("ninka-Tests-Results.xml");
63  CPPUNIT_NS::XmlOutputter xml(&result, file);
64  xml.write();
65  file.close();
66  } catch (invalid_argument& e)
67  { // Test path not resolved.
68  CPPUNIT_NS::stdCOut() << endl << "ERROR: " << e.what() << endl;
69  return 1;
70  }
71 
72  return result.wasSuccessful() ? 0 : 1;
73 }
int main(int argc, char *argv[])
Definition: run_tests.cc:40