当前位置: 首页>>代码示例>>C++>>正文


C++ TestResult::addListener方法代码示例

本文整理汇总了C++中cppunit::TestResult::addListener方法的典型用法代码示例。如果您正苦于以下问题:C++ TestResult::addListener方法的具体用法?C++ TestResult::addListener怎么用?C++ TestResult::addListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cppunit::TestResult的用法示例。


在下文中一共展示了TestResult::addListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

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;
}
开发者ID:LCLS,项目名称:OpenMMFBM,代码行数:25,代码来源:main.cpp

示例2: main

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;
}
开发者ID:Brainiarc7,项目名称:TS,代码行数:46,代码来源:testRunner.cpp

示例3: main

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::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();

    char *xml = ::getenv("CPPUNIT_XML");
    if(xml && !::strcmp(xml, "1")) {
      std::ofstream xmlfileout("cpptestresults.xml");
      CppUnit::XmlOutputter xmlout(&result, xmlfileout);
      xmlout.write();
    }
  }
  catch(std::invalid_argument &e){
    std::cerr << std::endl
              << "ERROR: " << e.what()
              << std::endl;
    return 0;
  }

  return result.wasSuccessful() ? 0 : 1;
}
开发者ID:5in4,项目名称:taglib,代码行数:45,代码来源:main.cpp

示例4: main

// 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;
}
开发者ID:gogowishfly,项目名称:CppUnitDemo,代码行数:44,代码来源:main.cpp

示例5: main

int main(int argc, char *argv[])
{
  po::options_description opt(std::string("Usage: ") + argv[0] + " [Options] [Test Path] ...\nOptions");
  opt.add_options()
    ("help,h", "Print this help")
    ("verbose,v", "Verbose mode")
    ("test-path,t", po::value<std::vector<std::string> >(), "Specify the test path");
  po::positional_options_description p;
  p.add("test-path", -1);
  po::variables_map vars;
  try {
    po::store(po::command_line_parser(argc, argv).options(opt).positional(p).run(), vars);
    po::notify(vars);
    if (vars.count("help") != 0) {
      std::cerr << opt << std::endl;
      return 1;
    }
    if (vars.count("verbose") == 0) {
      Logger::get_instance().set_level(Logger::LEVEL_FATAL);
    }
  } catch (std::exception &e) {
    std::cerr << "Error: " << e.what() << std::endl;
    std::cerr << opt << std::endl;
    return 1;
  }
  CppUnit::TextTestRunner runner;
  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
  if (vars.count("test-path") > 0) {
    CppUnit::TestResult controller;
    CppUnit::TestResultCollector result;
    controller.addListener(&result);
    CppUnit::TextTestProgressListener progress;
    controller.addListener(&progress);
    const std::vector<std::string> &v = vars["test-path"].as<std::vector<std::string> >();
    BOOST_FOREACH(std::string i, v) {
      std::cout << i << " ";
      try {
	runner.run(controller, i);
      } catch (std::invalid_argument &e) {
	std::cerr << "ERROR: " << e.what() << std::endl;
	return 1;
      }
    }
开发者ID:iwadon,项目名称:junk,代码行数:43,代码来源:test_main.cpp

示例6: main

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;
}
开发者ID:SeanNguyen,项目名称:cs3202-team-4-repo,代码行数:41,代码来源:UnitTest.cpp

示例7: runTest

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();
}
开发者ID:wgsyd,项目名称:wgtf,代码行数:41,代码来源:unit_test.cpp

示例8: main

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;
}
开发者ID:cadencii,项目名称:cadencii-nt,代码行数:41,代码来源:main.cpp

示例9: main

int main(int argc, char* argv[]) {
    
    TestLogListener listener;
    CppUnit::TestResult testresult;
    testresult.addListener (&listener);
    CppUnit::TextUi::TestRunner runner;
    runner.addTest( TestTupleOperatorsSuite::suite() );
    runner.addTest( TestTupleEqualsTest::suite() );
    runner.run(testresult);
    
	return EXIT_SUCCESS;
}
开发者ID:xtwxy,项目名称:boost-reciple,代码行数:12,代码来源:main.cpp

示例10: main

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;
}
开发者ID:nickmat,项目名称:HistoryCal,代码行数:40,代码来源:testmain.cpp

示例11: outputter

/*! 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();
}
开发者ID:LTears,项目名称:rktotal,代码行数:48,代码来源:DllPlugInTester.cpp

示例12: main

/**
 * @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;
}
开发者ID:bashwork,项目名称:common,代码行数:43,代码来源:UnitTester.cpp

示例13: main

int main(int argc, char* argv[])
{
	CppUnit::TestResult r;
	CppUnit::TestResultCollector rc;
	r.addListener(&rc); // 准备好结果收集器 

	SimpleTest t;
	t.run(&r); // 运行测试用例

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

	return 0;
}
开发者ID:lording,项目名称:common-utils,代码行数:14,代码来源:main.cpp

示例14: main

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;
}
开发者ID:RTCSD15,项目名称:Team1,代码行数:17,代码来源:testmain.cpp

示例15: main

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;
}
开发者ID:bellgrim,项目名称:SoftHSMv2,代码行数:19,代码来源:objstoretest.cpp


注:本文中的cppunit::TestResult::addListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。