~juju/pyjuju/zookeeper-vendor

« back to all changes in this revision

Viewing changes to recipes/lock/src/c/tests/TestDriver.cc

  • Committer: Gustavo Niemeyer
  • Date: 2011-05-24 20:53:37 UTC
  • Revision ID: gustavo@niemeyer.net-20110524205337-i11yow5biap5xapo
Importing stock Zookeeper 3.3.3 without jars.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
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
 
9
 *
 
10
 *     http://www.apache.org/licenses/LICENSE-2.0
 
11
 *
 
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.
 
17
 */
 
18
 
 
19
#include <string>
 
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>
 
27
#include <stdexcept>
 
28
#include <cppunit/Exception.h>
 
29
#include <cppunit/TestFailure.h>
 
30
#include <cppunit/XmlOutputter.h>
 
31
#include <fstream>
 
32
 
 
33
#include "Util.h"
 
34
 
 
35
using namespace std;
 
36
 
 
37
CPPUNIT_NS_BEGIN
 
38
 
 
39
class EclipseOutputter: public CompilerOutputter
 
40
{
 
41
public:
 
42
  EclipseOutputter(TestResultCollector *result,ostream &stream):
 
43
        CompilerOutputter(result,stream,"%p:%l: "),stream_(stream)
 
44
    {
 
45
    }
 
46
    virtual void printFailedTestName( TestFailure *failure ){}
 
47
    virtual void printFailureMessage( TestFailure *failure )
 
48
    {
 
49
      stream_<<": ";
 
50
      Message msg = failure->thrownException()->message();
 
51
      stream_<< msg.shortDescription();
 
52
 
 
53
      string text;
 
54
      for(int i=0; i<msg.detailCount();i++){
 
55
          text+=msg.detailAt(i);
 
56
          if(i+1!=msg.detailCount())
 
57
              text+=", ";
 
58
      }
 
59
      if(text.length()!=0)
 
60
          stream_ <<" ["<<text<<"]";
 
61
      stream_<<"\n";
 
62
    }
 
63
    ostream& stream_;
 
64
};
 
65
 
 
66
CPPUNIT_NS_END
 
67
 
 
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);
 
73
 
 
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 );
 
79
   
 
80
   // Add a listener that print dots as tests run.
 
81
   // CPPUNIT_NS::TextTestProgressListener progress;
 
82
   CPPUNIT_NS::BriefTestProgressListener progress;
 
83
   controller.addListener( &progress );
 
84
 
 
85
   CPPUNIT_NS::TestRunner runner;
 
86
   runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
 
87
 
 
88
   try
 
89
   {
 
90
     cout << "Running "  <<  globalTestConfig.getTestName();
 
91
     runner.run( controller, globalTestConfig.getTestName());
 
92
     cout<<endl;
 
93
 
 
94
     // Print test in a compiler compatible format.
 
95
     CPPUNIT_NS::EclipseOutputter outputter( &result,cout);
 
96
     outputter.write(); 
 
97
 
 
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" );
 
103
     xml.write();
 
104
     file.close();
 
105
#endif
 
106
   }
 
107
   catch ( std::invalid_argument &e )  // Test path not resolved
 
108
   {
 
109
     cout<<"\nERROR: "<<e.what()<<endl;
 
110
     return 0;
 
111
   }
 
112
 
 
113
   return result.wasSuccessful() ? 0 : 1;
 
114
 }