コード例 #1
0
ファイル: utest_main.cpp プロジェクト: Elgu/rpgml
int main( int argc, char **argv)
{
  // Create the event manager and test controller
  CppUnit::TestResult controller;

  // Add a listener that colllects test result
  CppUnit::TestResultCollector result;
  controller.addListener( &result );

  // Add a listener that print dots as test run.
  CppUnit::BriefTestProgressListener progress;
  controller.addListener( &progress );

  CppUnit::TextUi::TestRunner runner;
  CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
  runner.addTest( registry.makeTest() );
  runner.run( controller, "" );

  // Resultate im Compiler-Format ausgeben
  CppUnit::CompilerOutputter compileroutputter( &result, std::cerr );
  compileroutputter.write();

  // Rueckmeldung, ob Tests erfolgreich waren
  return ( result.wasSuccessful() ? 0 : -1 );
}
コード例 #2
0
ファイル: UtilTestMain.cpp プロジェクト: ofaismail/Util
int main(int argc, char ** argv) {
	Util::init();

	const std::string testPath = (argc > 1) ? std::string(argv[1]) : "";

	CppUnit::TestResult controller;

	CppUnit::TestResultCollector result;
	controller.addListener(&result);

	CppUnit::BriefTestProgressListener progress;
	controller.addListener(&progress);

	CppUnit::TestRunner runner;
	runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());

	runner.run(controller, testPath);

	std::ofstream fileStream("cppunit_results.xml");
	CppUnit::XmlOutputter xmlOutput(&result, fileStream, "UTF-8");
	xmlOutput.write();

	CppUnit::TextOutputter textOutput(&result, std::cout);
	textOutput.write();

	return result.wasSuccessful() ? 0 : 1;
}
コード例 #3
0
ファイル: main.cpp プロジェクト: LCLS/OpenMMFBM
int main( int argc, char *argv[] ) {
	// informs test-listener about testresults
	CppUnit::TestResult testresult;

	// register listener for collecting the test-results
	CppUnit::TestResultCollector collectedresults;
	testresult.addListener( &collectedresults );

	// insert test-suite at test-runner by registry
	CppUnit::TestRunner testrunner;
	testrunner.addTest( CppUnit::TestFactoryRegistry :: getRegistry().makeTest() );
	testrunner.run( testresult );

	// output results in compiler-format
	CppUnit::CompilerOutputter compileroutputter( &collectedresults, std::cerr );
	compileroutputter.write();

	// writing result on a XML file
	std::ofstream xmlFileOut( "testresults.xml" );
	CppUnit::XmlOutputter xmlOut(&collectedresults, xmlFileOut);
	xmlOut.write();

	// return 0 if tests were successful
	return collectedresults.wasSuccessful() ? 0 : 1;
}
コード例 #4
0
ファイル: test_runner.cpp プロジェクト: gfordyce/stan
int main (int argc, char* argv[])
{
    // informs test-listener about testresults
    CppUnit::TestResult testresult;

    // register listener for collecting the test-results
    CppUnit::TestResultCollector collectedresults;
    testresult.addListener (&collectedresults);

    // register listener for per-test progress output
    CppUnit::BriefTestProgressListener progress;
    testresult.addListener (&progress);

    // insert test-suite at test-runner by registry
    CppUnit::TestRunner testrunner;
    testrunner.addTest (CppUnit::TestFactoryRegistry::getRegistry ().makeTest ());
    testrunner.run (testresult);

    // output results in compiler-format
    CppUnit::CompilerOutputter compileroutputter (&collectedresults, std::cerr);
    compileroutputter.write ();

    // return 0 if tests were successful
    return collectedresults.wasSuccessful () ? 0 : 1;
}
コード例 #5
0
int main() {
  // Create the event manager and test controller
  CppUnit::TestResult controller;

  // Add a listener that collects test result
  CppUnit::TestResultCollector result;
  controller.addListener( &result );

  // Add a listener that print dots as test run.
  CppUnit::BriefTestProgressListener progress;
  controller.addListener( &progress );

  // Add the top suite to the test runner
  CppUnit::TestRunner runner;
  runner.addTest( CppUnit::TestFactoryRegistry::getRegistry().makeTest() );
  runner.run( controller );

  CppUnit::TextOutputter output(&result, std::cout);
  std::cout << std::endl
      << "==================================================" << std::endl
      << "Papyrus Library Unit Tests: " << std::endl;
  output.printHeader();
  output.printStatistics();
  output.printFailures();

  return result.wasSuccessful() ? 0 : 1;
}
コード例 #6
0
ファイル: main.cpp プロジェクト: DiodeZ/taglib
int main(int argc, char* argv[])
{
  std::string testPath = (argc > 1) ? std::string(argv[1]) : "";

  // Create the event manager and test controller
  CppUnit::TestResult controller;

  // Add a listener that collects test result
  CppUnit::TestResultCollector result;
  controller.addListener(&result);

  // Add a listener that print dots as test run.
  CppUnit::BriefTestProgressListener progress;
  controller.addListener(&progress);

  // Add the top suite to the test runner
  CppUnit::TestRunner runner;
  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());

  try {
    std::cout << "Running "  << testPath;
    runner.run(controller, testPath);

    std::cerr << std::endl;

    // Print test in a compiler compatible format.
    CppUnit::CompilerOutputter outputter(&result, std::cerr);
    outputter.write();

#if defined(_MSC_VER) && _MSC_VER > 1500
    char *xml = NULL;
    ::_dupenv_s(&xml, NULL, "CPPUNIT_XML");
#else
    char *xml = ::getenv("CPPUNIT_XML");
#endif
    if(xml && !::strcmp(xml, "1")) {
      std::ofstream xmlfileout("cpptestresults.xml");
      CppUnit::XmlOutputter xmlout(&result, xmlfileout);
      xmlout.write();
    }
#if defined(_MSC_VER) && _MSC_VER > 1500
    ::free(xml);
#endif
  }
  catch(std::invalid_argument &e){
    std::cerr << std::endl
              << "ERROR: " << e.what()
              << std::endl;
    return 0;
  }

  return result.wasSuccessful() ? 0 : 1;
}
コード例 #7
0
ファイル: CutiMain.cpp プロジェクト: k-brac/CUTI
bool runPlugin(const CommandLineParser &arguments) {
	CppUnit::PlugInManager pluginManager;
	pluginManager.load(arguments.plugName);

	// Create the event manager and test controller
	CppUnit::TestResult controller;

	// Add a listener that collects test result
	CppUnit::TestResultCollector result;
	controller.addListener(&result);

	// Add a listener
	CppUnit::BriefTestProgressListener progress;
	controller.addListener(&progress);

	pluginManager.addListener(&controller);

	// Add the top suite to the test runner
	CppUnit::TestRunner runner;
	runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
	try
	{
		if (arguments.testPaths.empty()) {
			std::cout << "Running " << std::endl;
			runner.run(controller);
		}
		else {
			for (const auto & p : arguments.testPaths) {
				std::cout << "Running " << p << std::endl;
				runner.run(controller, p);
			}
		}
		std::cerr << std::endl;

		// Print test in a compiler compatible format.
		CppUnit::CompilerOutputter outputter(&result, std::cerr);
		outputter.write();

        if (!arguments.xmlOutputFile.empty()) {
            std::ofstream file(arguments.xmlOutputFile);
            CppUnit::XmlOutputter xOutputter(&result, file);
            xOutputter.write();
        }
	}
	catch (std::invalid_argument &e)  // Test path not resolved
	{
		std::cerr << std::endl
			<< "ERROR: " << e.what()
			<< std::endl;
		return false;
	}
	return result.wasSuccessful();
}
コード例 #8
0
ファイル: testRunner.cpp プロジェクト: EugeneVolkorez/vmime
int main(int argc, char* argv[])
{
	// VMime initialization
	vmime::platform::setHandler<vmime::platforms::posix::posixHandler>();

	// Parse arguments
	bool xmlOutput = false;

	for (int c = 1 ; c < argc ; ++c)
	{
		const std::string arg = argv[c];

		if (arg == "--xml")
			xmlOutput = true;
	}

	// Run the tests
	if (xmlOutput)
	{
		// Get the test suites from the registry and add them to the list of tests to run
		CppUnit::TestRunner runner;

		for (unsigned int i = 0 ; i < getTestModules().size() ; ++i)
		{
			runner.addTest(CppUnit::TestFactoryRegistry::
				getRegistry(getTestModules()[i]).makeTest());
		}

		std::auto_ptr <XmlTestListener> xmlListener(new XmlTestListener);

		CppUnit::TestResult controller;
		controller.addListener(xmlListener.get());

		CppUnit::TestResultCollector result;
		controller.addListener(&result);

		runner.run(controller);

		xmlListener->output(std::cout);

		// Return error code 1 if a test failed
		return result.wasSuccessful() ? 0 : 1;
	}
	else
	{
		// Get the top level suite from the registry
		CppUnit::TextUi::TestRunner runner;
		runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());

		return runner.run() ? 0 : 1;
	}
}
コード例 #9
0
ファイル: test_runner.cpp プロジェクト: dziadu/FitterFactory
int main (int argc, char* argv[])
{
	std::string testPath = (argc > 1) ? std::string(argv[1]) : "";

	// Create the event manager and test controller
	CppUnit::TestResult controller;

	// Add a listener that colllects test result
	CppUnit::TestResultCollector result;
	controller.addListener( &result );        

	// Add a listener that print dots as test run.
	CppUnit::TextTestProgressListener progress;
	controller.addListener( &progress );      

	TestRunner runner;
	TestFactoryRegistry & registry = TestFactoryRegistry::getRegistry();

	// run all tests if none specified on command line 
	Test * test_to_run = registry.makeTest();
	if (argc > 1)
		test_to_run = test_to_run->findTest(argv[1]);

	runner.addTest( test_to_run );
// 	runner.run(controller);

	try
	{
		std::cout << "Running tests"  /*<<  testPath*/ << endl;;
// 		runner.run( controller, testPath );
		runner.run(controller);

// 		std::cerr << std::endl;

		// Print test in a compiler compatible format.
		CppUnit::CompilerOutputter outputter( &result, std::cerr );
		outputter.write();                      
	}
	catch ( std::invalid_argument &e )  // Test path not resolved
	{
		std::cerr  <<  std::endl  
								<<  "ERROR: "  <<  e.what()
								<< std::endl;
		return 0;
	}

// 	result.runTest();
// 	results.printResults();
// 	runner.prin();

	return result.wasSuccessful() ? 0 : 1;
}
コード例 #10
0
ファイル: testRunner.cpp プロジェクト: Brainiarc7/TS
int main (int argc, char *argv[])
{
    // set up logger
    //log4cxx::BasicConfigurator::configure();

    CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
    if (argc == 1)
        registry.addRegistry("All");
    else
    {
        // run just the specified tests
        for (int i=1; i<argc; i++)
            registry.addRegistry(argv[i]);
    }

    CppUnit::TextUi::TestRunner runner;
    runner.addTest(registry.makeTest());

    // Errors have line numbers
    runner.setOutputter(
     CppUnit::CompilerOutputter::defaultOutputter( 
     &runner.result(),
     std::cerr ) );

    CppUnit::TestResult controller;
    CppUnit::TestResultCollector result;
    controller.addListener(&result);

    // register listener for per-test progress output
    // verbose, per-test output: test : OK
    CppUnit::BriefTestProgressListener progress;
    controller.addListener (&progress);

    runner.run(controller);

    // output stderr summary report
    CppUnit::TextOutputter compilerOutputter(&result, std::cerr);
    compilerOutputter.write();

    // output xml report
    std::ofstream strm("result.xml");
    CppUnit::XmlOutputter xmlOutputter(&result, strm);
    xmlOutputter.write();

    return result.wasSuccessful() ? 0 : 1;
}
コード例 #11
0
ファイル: testmain.cpp プロジェクト: RTCSD15/Team1
int main()
{
	CppUnit::TestResult r;
	CppUnit::TestResultCollector rc;
	r.addListener(&rc); // 准备好结果收集器

	CppUnit::TestRunner runner; // 定义执行实体
	runner.addTest(CppUnit::TestFactoryRegistry::getRegistry("alltest").makeTest());
	runner.run(r); // 运行测试

	CppUnit::TextOutputter o(&rc, std::cout);
	o.write(); // 将结果输出

	//system("pause");

	return rc.wasSuccessful() ? 0 : -1;
}
コード例 #12
0
ファイル: objstoretest.cpp プロジェクト: bellgrim/SoftHSMv2
int main(int /*argc*/, char** /*argv*/)
{
	CppUnit::TestResult controller;
	CppUnit::TestResultCollector result;
	CppUnit::TextUi::TestRunner runner;
	controller.addListener(&result);
	CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();

	runner.addTest(registry.makeTest());
	runner.run(controller);

	std::ofstream xmlFileOut("test-results.xml");
	CppUnit::XmlOutputter xmlOut(&result, xmlFileOut);
	xmlOut.write();

	CryptoFactory::reset();

	return result.wasSuccessful() ? 0 : 1;
}
コード例 #13
0
ファイル: main.cpp プロジェクト: gogowishfly/CppUnitDemo
// If TestSuite is not changes, the following code don't need to change.
int main()
{
    CppUnit::TestResult r;
    CppUnit::TestResultCollector listener;
    CppUnit::TestResultCollector result;

    r.addListener(&listener);
    r.addListener(&result);

    CppUnit::TextUi::TestRunner runner;
    //Get test suit.
    CppUnit::Test *test = CppUnit::TestFactoryRegistry::getRegistry("alltest").makeTest();
    // Add this test suit to test runner.
    runner.addTest( test );

    //output log to run.log file.
    std::ofstream ofile;
    ofile.open("run.log");
    CppUnit::TextOutputter outputter(&listener, ofile);;
    //This would occur code dumped.reason unkonwn.
    //runner.setOutputter(&outputter);

    //output result to result.xml.
    std::ofstream file( "result.xml" );
    CppUnit::XmlOutputter xml( &result, file );

    //run the test runner.
    runner.run(r);

    //write to file.
    outputter.write();
    xml.write();

    //close ofstream.
    ofile.close();
    file.close();

    //output test results to console.
    CppUnit::TextOutputter o(&listener, std::cout);
    o.write();

    return listener.wasSuccessful() ? 0 : -1;
}
コード例 #14
0
int main (int argc , char** argv)
{
	std::ofstream xml("./cppUnit_output.xml",ios::app);
	
	CppUnit::TestResult controller;
	CppUnit::TestResultCollector result;
	controller.addListener( &result );
	
	TestRunner runner;
	runner.addTest(Manipulation_test::suite());
	runner.run(controller);
	
	CppUnit::XmlOutputter outputter( &result, xml );
	CppUnit::TextOutputter outputter2( &result, std::cerr );
	outputter.write();
	outputter2.write();
	
	return result.wasSuccessful() ? 0 : 1 ;
}
コード例 #15
0
ファイル: main.cpp プロジェクト: emdeesee/rct
int main(int argc, char* argv[])
{
    CppUnit::TestRunner runner;

    CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();

    runner.addTest( registry.makeTest() );

    CppUnit::TestResult controller;
    CppUnit::TestResultCollector result;
    controller.addListener(&result);

    runner.run(controller);

    CustomOutputter outputter(&result, std::cerr);

    outputter.write();

    return result.wasSuccessful() ? 0 : 1;
}
コード例 #16
0
ファイル: unit_test.cpp プロジェクト: wgsyd/wgtf
int runTest(const std::string& testName, int argc, char* argv[])
{
	DebugFilter::shouldWriteToConsole(false);

	for (int i = 1; i < argc; ++i)
	{
		if ((strcmp("-v", argv[i]) == 0) || (strcmp("--verbose", argv[i]) == 0))
		{
			DebugFilter::shouldWriteToConsole(true);
		}
	}

	// Create the event manager and test controller
	CppUnit::TestResult controller;

	// Add a listener that collects test result
	CppUnit::TestResultCollector result;
	controller.addListener(&result);

#if 0 // original CppUnit progress listener
	// Add a listener that print dots as test run.
	CppUnit::TextTestProgressListener progress;
#else
	BWTestProgressListener progress;
#endif

	controller.addListener(&progress);

	CppUnit::TestRunner runner;
	runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());

	BWUnitTest::unitTestInfo("Running %s:\n", testName.c_str());
	runner.run(controller);
	BWUnitTest::unitTestError("\n");

	// Print test in a compiler compatible format.
	CppUnit::CompilerOutputter outputter(&result, std::cout);
	outputter.write();

	return result.testFailures();
}
コード例 #17
0
ファイル: main.cpp プロジェクト: cadencii/cadencii-nt
int main( int argc, char* argv[] )
{
    string xmlPath = "";
    string currentParse = "";
    for( int i = 1; i < argc; i++ ){
        string s = argv[i];
        if( s.substr( 0, 1 ) == "-" ){
            currentParse = s;
        }else{
            if( currentParse == "-o" ){
                xmlPath = s;
            }else if( currentParse == "-f" ){
                TestUtil::setFixtureRootPath( s );
            }
            currentParse = "";
        }
    }
    CppUnit::TestResult controller;
    CppUnit::TestResultCollector results;
    controller.addListener( &results );

    CppUnit::BriefTestProgressListener progress;
    if( xmlPath.size() == 0 ){
        controller.addListener( &progress );
    }

    CppUnit::TestRunner runner;
    runner.addTest( CppUnit::TestFactoryRegistry::getRegistry().makeTest() );
    runner.run( controller );

    if( xmlPath.size() == 0 ){
        CppUnit::CompilerOutputter outputter( &results, CppUnit::stdCOut() );
        outputter.write();
    }else{
        std::ofstream ofs( xmlPath.c_str() );
        CppUnit::XmlOutputter outputter( &results, ofs, "UTF-8" );
        outputter.write();
    }

    return results.wasSuccessful() ? 0 : 1;
}
コード例 #18
0
int main(int argc, char* argv[])
{
	// Create the event manager and test controller
	CppUnit::TestResult controller;

	// Add a listener that colllects test result
	CppUnit::TestResultCollector result;
	controller.addListener( &result );

	// Add a listener that print dots as test run.
	CppUnit::TextTestProgressListener progress;
	controller.addListener( &progress );

	// Add the top suite to the test runner
	CppUnit::TestRunner runner;
	runner.addTest( CppUnit::TestFactoryRegistry::getRegistry().makeTest() );   

	try
	{
		std::cout << "Running ";
		CPPUNIT_NS::TestRunner runner;
		runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
		runner.run( controller );

		std::cerr << std::endl;

		// Print test in a compiler compatible format.
		CppUnit::CompilerOutputter outputter( &result, std::cerr );
		outputter.write();
		cin.get();
	}
	catch ( std::invalid_argument &e )  // Test path not resolved
	{
		std::cerr  <<  std::endl  
			<<  "ERROR: "  <<  e.what()
			<< std::endl;
		return 0;
	}

	return result.wasSuccessful() ? 0 : 1;
}
コード例 #19
0
ファイル: testmain.cpp プロジェクト: nickmat/HistoryCal
int main( int argc, char* argv[] )
{
    std::string testPath = (argc > 1) ? std::string( argv[1] ) : "";

    // Create the event manager and test controller
    CppUnit::TestResult controller;

    // Add a listener that colllects test result
    CppUnit::TestResultCollector result;
    controller.addListener( &result );

    // Add a listener that print dots as test run.
    CppUnit::TextTestProgressListener progress;
    controller.addListener( &progress );

    // Add the top suite to the test runner
    CppUnit::TestRunner runner;
    runner.addTest( CppUnit::TestFactoryRegistry::getRegistry().makeTest() );
    try {
        clock_t t = clock();
        
        std::cout << "Unit running " <<  testPath;
        runner.run( controller, testPath );

        std::cerr << std::endl;

        // Print test in a compiler compatible format.
        CppUnit::CompilerOutputter outputter( &result, std::cerr );
        outputter.write();

        double dt = ((double) clock() - t) / CLOCKS_PER_SEC;
        std::cout << "Timed: " << dt << "s" << std::endl;
    }
    catch( std::invalid_argument &e ) { // Test path not resolved
        std::cerr << std::endl << "ERROR: " << e.what() << std::endl;
        return 0;
    }

    return result.wasSuccessful() ? 0 : 1;
}
コード例 #20
0
ファイル: DllPlugInTester.cpp プロジェクト: LTears/rktotal
/*! Runs the specified tests located in the root suite.
 * \param root Root suite that contains all the test of the DLL.
 * \param testPaths Array of string that contains the test paths of all the test to run.
 * \param numberOfPath Number of test paths in \a testPaths. If 0 then \a root suite
 *                     is run.
 * \return \c true if the run succeed, \c false if a test failed or if a test
 *         path was not resolved.
 */
bool 
runDllTest( CppUnit::Test *root,
            TCHAR *testPaths[],
            int numberOfPath )
{
  CppUnit::TestResult controller;
  CppUnit::TestResultCollector result;
  controller.addListener( &result );        
  CppUnit::TextTestProgressListener progress;
  controller.addListener( &progress );      

  NotOwningTestRunner runner;
  if ( numberOfPath == 0 )
    runner.addTest( root );
  else
  {
    for ( int index =0; index < numberOfPath; ++index )
    {
      const TCHAR *testPath = testPaths[index];
      try
      {
        runner.addTest( root->resolveTestPath( testPath).getChildTest() );
      }
      catch ( std::invalid_argument & )
      {
        TCERR  <<  _T("Failed to resolve test path: ")  <<  testPath  <<  std::endl;
        return false;
      }
    }
  }

  runner.run( controller );

  std::cerr << std::endl;

  CppUnit::CompilerOutputter outputter( &result, std::cerr );
  outputter.write();

  return result.wasSuccessful();
}
コード例 #21
0
ファイル: main.cpp プロジェクト: HerrPeterPaul/anna
int main (int argc, char* argv[])
{
  // stores test results (listener)
  CppUnit::TestResult testresult;
  CppUnit::TestResultCollector collectedresults;
  testresult.addListener (&collectedresults);

  // get testsuit and add it to our TestRunner
  CppUnit::TestRunner tester;
  tester.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());

  // run unit tests
 tester.run(testresult);

  // format results in a nice compiler friendly format
  CppUnit::CompilerOutputter compileroutputter( &collectedresults, 
                                                std::cout);
  compileroutputter.write ();

  // returns 0 on success
  return collectedresults.wasSuccessful () ? 0 : 1;
}
コード例 #22
0
ファイル: UnitTester.cpp プロジェクト: bashwork/common
/**
 * @brief Main test runner for available fixtures
 * @return True if all the tests were successfull, false otherwise
 */
int main(int argc, char *argv[])
{
	std::string path = (argc > 1) ? std::string(argv[1]) : "";

	/* create event manager and test controller */
	CppUnit::TestResult controller;

	/* add a listener that collects the results */
	CppUnit::TestResultCollector result;
	controller.addListener(&result);

	/* add a listener that prints dots while the test runs */
	CppUnit::TextTestProgressListener progress;
	controller.addListener( &progress );    

	/* add a listener that prints each running test */
	//CppUnit::BriefTestProgressListener progress;
	//controller.addListener( &progress );    

	/* add the suites to the test runner */
	CppUnit::TestRunner runner;
	runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
	try {
		runner.run(controller, path);
		std::cerr << "\n";

		/* add compiler formatted output */
		CppUnit::CompilerOutputter outputter(&result, std::cerr);
		outputter.write();
	}
	/* invalid path */
	catch (std::invalid_argument &e) {
		std::cerr << "\n" << "ERROR: " << e.what() << "\n";
		return 0;
	}

	/* return result for autobuild tools */
	return result.wasSuccessful() ? 0 : 1;
}
コード例 #23
0
ファイル: type_test.cpp プロジェクト: CESNET/glite-jp
int main (int argc,const char *argv[])
{
	CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();

	assert(argc == 2);
	std::ofstream	xml(argv[1]);

	CppUnit::TestResult controller;
	CppUnit::TestResultCollector result;
	controller.addListener( &result );

	CppUnit::TestRunner runner;
	runner.addTest(suite);
	runner.run(controller);

	CppUnit::XmlOutputter xout( &result, xml );
	CppUnit::CompilerOutputter tout( &result, std::cout);
	xout.write();
	tout.write();

	return result.wasSuccessful() ? 0 : 1 ;
}
コード例 #24
0
int main()
{
	CppUnit::TextUi::TestRunner runner;
	CppUnit::TestFactoryRegistry& registry = CppUnit::TestFactoryRegistry::getRegistry();
	CppUnit::TestResult controller;
	CppUnit::TestResultCollector result;

	controller.addListener(&result);

	runner.addTest(registry.makeTest());

	std::ofstream xmlout("results.xml");
	CppUnit::XmlOutputter out(&result, xmlout);
	CppUnit::TextOutputter console(&result, std::cout);

	runner.run(controller, "");

	out.write();
	console.write();
	return result.wasSuccessful()? 0: 1;

}
コード例 #25
0
ファイル: kmymoneytest.cpp プロジェクト: sajidji94/kmymoney2
int main(int testargc, char** testargv)
{
  int rc = 0;

#ifdef HAVE_LIBCPPUNIT
  static const KCmdLineOptions options[] =
  {
     { "+[test_suite]", ("Optionally specify a test suite"), 0 },
     { "", ("Optional arguments are for ctest"), 0 },
     KCmdLineLastOption // End of options.
  };

  // we seem to need a KApplication object to use KGlobal::locale()
  KCmdLineArgs::init(testargc, testargv, testargv[0], "UNIT TESTS", "", "0.1");
  KCmdLineArgs::addCmdLineOptions( options );
  KApplication::disableAutoDcopRegistration();
  KApplication app(false, false);

#ifdef _CHECK_MEMORY
  _CheckMemory_Init(0);
#endif

  // mymoney tests
  //CPPUNIT_TEST_SUITE_REGISTRATION(KReportsViewTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(MyMoneyMapTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(ConverterTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(MyMoneyKeyValueContainerTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(MyMoneySplitTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(MyMoneyMoneyTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(MyMoneyAccountTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(MyMoneyScheduleTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(MyMoneyDatabaseMgrTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(MyMoneySeqAccessMgrTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(MyMoneyFileTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(MyMoneyObjectTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(MyMoneyInstitutionTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(MyMoneyFinancialCalculatorTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(MyMoneyTransactionTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(MyMoneySecurityTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(MyMoneyForecastTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(MyMoneyExceptionTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(MyMoneyObserverTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(MyMoneyPriceTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(MyMoneyPayeeTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(PivotGridTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(PivotTableTest);
  CPPUNIT_TEST_SUITE_REGISTRATION(QueryTableTest);

  // off we go
  CppUnit::TestFactoryRegistry &registry =
    CppUnit::TestFactoryRegistry::getRegistry();

  // run all tests if no test is specified on the command line
  // this way, CTest can perform each test individually
  CppUnit::Test *suite = registry.makeTest();
  if (testargc>1)
  {
    try
    {
      suite = suite->findTest(testargv[1]);
    }
    catch(const std::invalid_argument &ex)
    {
      // oh, cmake perfomed bad at guessing the correct test names.
      std::cout << ex.what() << std::endl;
      // we output that the test passed since the test is deactivated
      return 0;
    }
  }

  CppUnit::TextTestRunner* runner = new CppUnit::TextTestRunner();

  runner->addTest(suite);

  MyProgressListener progress;
  CppUnit::TestResultCollector result;

  runner->eventManager().addListener(&progress);
  runner->eventManager().addListener(&result);

  runner->run();
  std::cout << "Tests were run with CPPUNIT version " CPPUNIT_VERSION << std::endl;

  rc = result.wasSuccessful() ? 0 : 1;
  delete runner;

  // make sure to delete the singletons before we start memory checking
  // to avoid false error reports
  // delete MyMoneyFile::instance();

#ifdef _CHECK_MEMORY
  chkmem.CheckMemoryLeak( true );
  _CheckMemory_End();
#endif // _CHECK_MEMORY

#else
  std::cout << "libcppunit not installed. no automatic tests available."
     << std::endl;
#endif // HAVE_LIBCPPUNIT
  return rc;
}
コード例 #26
0
ファイル: checker.cpp プロジェクト: bessey/picnic-doc-server
int main(int argc, char* argv[]) {
	bool verbose = false;
	bool outputXML = false;

	// Parse parameters
	std::vector<std::string> testsToRun;
	for (int i = 1; i < argc; ++i) {
		std::string param(argv[i]);
		if (param == "--verbose") {
			verbose = true;
		}
		else if (param == "--xml") {
			outputXML = true;
		}
		else {
			testsToRun.push_back(param);
		}
	}
	if (testsToRun.empty()) {
		testsToRun.push_back("");
	}

	// Set up the listeners
	CppUnit::TestResult controller;

	CppUnit::TestResultCollector result;
	controller.addListener(&result);

	CppUnit::TextTestProgressListener progressListener;
	CppUnit::BriefTestProgressListener verboseListener;
	if (!outputXML) {
		if (verbose) {
			controller.addListener(&verboseListener);
		}
		else {
			controller.addListener(&progressListener);
		}
	}

	// Run the tests
	CppUnit::TestRunner runner;
	runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
	for (std::vector<std::string>::const_iterator i = testsToRun.begin(); i != testsToRun.end(); ++i) {
		try {
			runner.run(controller, *i);
		}
		catch (const std::exception& e) {
			std::cerr << "Error: " << e.what() << std::endl;
			return -1;
		}
	}

	// Output the results
	if (outputXML) {
		CppUnit::XmlOutputter outputter(&result, std::cout);
		outputter.write();
	}
	else {
		CppUnit::TextOutputter outputter(&result, std::cerr);
		outputter.write();
	}

	return result.wasSuccessful() ? 0 : 1;
}
コード例 #27
0
ファイル: test_main.cpp プロジェクト: fargies/jenkins-tray
/* Test program */
int main(int argc, char** argv)
{
  CppUnit::TestResult testresult;
  CppUnit::TestResultCollector collectedresults;
  CppUnit::TestRunner testrunner;
  std::ofstream fb;
  std::list< std::string > test_list;

#ifdef HAVE_GETOPT_LONG
  int c;
  struct option long_options[] = {
    {"help", 0, 0, 'h'},
    {"list", 0, 0, 'l'},
    {0, 0, 0, 0}
  };

  while ((c = getopt_long(argc, argv, "hl", long_options, NULL)) != -1) {
    switch (c) {
      case 'h':
        std::cout << "Usage: " << argv[0] << " [test name]\n";
        std::cout << "\nOptions:\n" <<
          "  -h, --help           Show this help message and exit\n" <<
          "  -l, --list           List available tests and exit" <<
          std::endl;
        exit(EXIT_SUCCESS);
      case 'l':
      {
        CppUnit::Test *t = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
        std::cout << "Available test suites:\n";
        printTest(std::cout, t);
        delete t;
        exit(EXIT_SUCCESS);
      }
    }
  }

  if (optind < argc) {
    while (optind < argc) {
      test_list.push_back(argv[optind++]);
    }
  }
#endif

  testresult.addListener(&collectedresults);
  testrunner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
  if (test_list.empty())
    testrunner.run(testresult);
  else {
    std::list<std::string>::const_iterator it;
    for (it = test_list.begin(); it != test_list.end(); ++it) {
      testrunner.run(testresult, *it);
    }
  }

  fb.open((std::string(argv[0]) + ".xml").c_str());
  CppUnit::XmlOutputter xml_outputter(&collectedresults, fb);
  xml_outputter.write();
  fb.close();

  fb.open((std::string(argv[0]) + ".cmp").c_str());
  CppUnit::CompilerOutputter comp_outputter(&collectedresults, fb);
  comp_outputter.write();
  fb.close();

  CppUnit::TextOutputter txt_outputter(&collectedresults, std::cout);
  txt_outputter.write();

  return collectedresults.wasSuccessful() ? 0 : 1;
}