2
* Licensed to the Apache Software Foundation (ASF) under one
3
* or more contributor license agreements. See the NOTICE file
4
* distributed with this work for additional information
5
* regarding copyright ownership. The ASF licenses this file
6
* to you under the Apache License, Version 2.0 (the
7
* "License"); you may not use this file except in compliance
8
* with the License. You may obtain a copy of the License at
10
* http://www.apache.org/licenses/LICENSE-2.0
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
20
#include <cppunit/TestRunner.h>
21
#include <cppunit/CompilerOutputter.h>
22
#include <cppunit/TestResult.h>
23
#include <cppunit/TestResultCollector.h>
24
#include <cppunit/TextTestProgressListener.h>
25
#include <cppunit/BriefTestProgressListener.h>
26
#include <cppunit/extensions/TestFactoryRegistry.h>
28
#include <cppunit/Exception.h>
29
#include <cppunit/TestFailure.h>
30
#include <cppunit/XmlOutputter.h>
39
class EclipseOutputter: public CompilerOutputter
42
EclipseOutputter(TestResultCollector *result,ostream &stream):
43
CompilerOutputter(result,stream,"%p:%l: "),stream_(stream)
46
virtual void printFailedTestName( TestFailure *failure ){}
47
virtual void printFailureMessage( TestFailure *failure )
50
Message msg = failure->thrownException()->message();
51
stream_<< msg.shortDescription();
54
for(int i=0; i<msg.detailCount();i++){
55
text+=msg.detailAt(i);
56
if(i+1!=msg.detailCount())
60
stream_ <<" ["<<text<<"]";
68
int main( int argc, char* argv[] ) {
69
// if command line contains "-ide" then this is the post build check
70
// => the output must be in the compiler error format.
71
//bool selfTest = (argc > 1) && (std::string("-ide") == argv[1]);
72
globalTestConfig.addConfigFromCmdLine(argc,argv);
74
// Create the event manager and test controller
75
CPPUNIT_NS::TestResult controller;
76
// Add a listener that colllects test result
77
CPPUNIT_NS::TestResultCollector result;
78
controller.addListener( &result );
80
// Add a listener that print dots as tests run.
81
// CPPUNIT_NS::TextTestProgressListener progress;
82
CPPUNIT_NS::BriefTestProgressListener progress;
83
controller.addListener( &progress );
85
CPPUNIT_NS::TestRunner runner;
86
runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
90
cout << "Running " << globalTestConfig.getTestName();
91
runner.run( controller, globalTestConfig.getTestName());
94
// Print test in a compiler compatible format.
95
CPPUNIT_NS::EclipseOutputter outputter( &result,cout);
98
// Uncomment this for XML output
99
#ifdef ENABLE_XML_OUTPUT
100
std::ofstream file( "tests.xml" );
101
CPPUNIT_NS::XmlOutputter xml( &result, file );
102
xml.setStyleSheet( "report.xsl" );
107
catch ( std::invalid_argument &e ) // Test path not resolved
109
cout<<"\nERROR: "<<e.what()<<endl;
113
return result.wasSuccessful() ? 0 : 1;