Version: 8.3.0
BasicMainTest.hxx File Reference
#include <cppunit/CompilerOutputter.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TextTestProgressListener.h>
#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/TestRunner.h>
#include <stdexcept>
#include <iostream>
#include <fstream>
#include <fpu_control.h>
Include dependency graph for BasicMainTest.hxx:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Main program source for Unit Tests with cppunit package does not depend on actual tests, so we use the same for all partial unit tests.

Definition at line 46 of file BasicMainTest.hxx.

47 {
48 #if !defined WIN32 && !defined __APPLE__
49  fpu_control_t cw = _FPU_DEFAULT & ~(_FPU_MASK_IM | _FPU_MASK_ZM | _FPU_MASK_OM);
50  _FPU_SETCW(cw);
51 #endif
52  // --- Create the event manager and test controller
53  CPPUNIT_NS::TestResult controller;
54 
55  // --- Add a listener that collects test result
56  CPPUNIT_NS::TestResultCollector result;
57  controller.addListener( &result );
58 
59  // --- Add a listener that print dots as test run.
60 #if defined WIN32 || defined __APPLE__
61  CPPUNIT_NS::TextTestProgressListener progress;
62 #else
63  CPPUNIT_NS::BriefTestProgressListener progress;
64 #endif
65  controller.addListener( &progress );
66 
67  // --- Get the top level suite from the registry
68 
69  CPPUNIT_NS::Test *suite =
70  CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
71 
72  // --- Adds the test to the list of test to run
73 
74  CPPUNIT_NS::TestRunner runner;
75  runner.addTest( suite );
76  runner.run( controller);
77 
78  // --- Print test in a compiler compatible format.
79 
80  std::ofstream testFile;
81  testFile.open("UnitTestsResult", std::ios::out | std::ios::trunc);
82  //CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr );
83  CPPUNIT_NS::CompilerOutputter outputter( &result, testFile );
84  outputter.write();
85 
86  // --- Run the tests.
87 
88  bool wasSucessful = result.wasSuccessful();
89  testFile.close();
90 
91  // --- Return error code 1 if the one of test failed.
92 
93  return wasSucessful ? 0 : 1;
94 }