~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to lib/cppunit-1.10.0/examples/cppunittest/CppUnitTestMain.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2006-11-11 10:32:06 UTC
  • Revision ID: james.westby@ubuntu.com-20061111103206-f3p0r9g0vq44rp3r
Tags: upstream-3.0.PRE5
ImportĀ upstreamĀ versionĀ 3.0.PRE5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <cppunit/CompilerOutputter.h>
 
2
#include <cppunit/TestResult.h>
 
3
#include <cppunit/TestResultCollector.h>
 
4
#include <cppunit/TestRunner.h>
 
5
#include <cppunit/TextTestProgressListener.h>
 
6
#include <cppunit/BriefTestProgressListener.h>
 
7
#include <cppunit/XmlOutputter.h>
 
8
#include <cppunit/extensions/TestFactoryRegistry.h>
 
9
#include <stdexcept>
 
10
#include <fstream>
 
11
 
 
12
 
 
13
int 
 
14
main( int argc, char* argv[] )
 
15
{
 
16
  // Retreive test path from command line first argument. Default to "" which resolve
 
17
  // to the top level suite.
 
18
  std::string testPath = (argc > 1) ? std::string(argv[1]) : std::string("");
 
19
 
 
20
  // Create the event manager and test controller
 
21
  CPPUNIT_NS::TestResult controller;
 
22
 
 
23
  // Add a listener that colllects test result
 
24
  CPPUNIT_NS::TestResultCollector result;
 
25
  controller.addListener( &result );        
 
26
 
 
27
  // Add a listener that print dots as test run.
 
28
#ifdef WIN32
 
29
  CPPUNIT_NS::TextTestProgressListener progress;
 
30
#else
 
31
  CPPUNIT_NS::BriefTestProgressListener progress;
 
32
#endif
 
33
  controller.addListener( &progress );      
 
34
 
 
35
  // Add the top suite to the test runner
 
36
  CPPUNIT_NS::TestRunner runner;
 
37
  runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );   
 
38
  try
 
39
  {
 
40
    std::cout << "Running "  <<  testPath;
 
41
    runner.run( controller, testPath );
 
42
 
 
43
    std::cerr << std::endl;
 
44
 
 
45
    // Print test in a compiler compatible format.
 
46
    CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr );
 
47
    outputter.write(); 
 
48
 
 
49
// Uncomment this for XML output
 
50
//    std::ofstream file( "tests.xml" );
 
51
//    CPPUNIT_NS::XmlOutputter xml( &result, file );
 
52
//    xml.setStyleSheet( "report.xsl" );
 
53
//    xml.write();
 
54
//    file.close();
 
55
  }
 
56
  catch ( std::invalid_argument &e )  // Test path not resolved
 
57
  {
 
58
    std::cerr  <<  std::endl  
 
59
               <<  "ERROR: "  <<  e.what()
 
60
               << std::endl;
 
61
    return 0;
 
62
  }
 
63
 
 
64
  return result.wasSuccessful() ? 0 : 1;
 
65
}
 
66