Пример #1
0
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;
}
Пример #2
0
int main(int argc, char* argv[])
{
    std::ofstream xmlout("DasherTest.xml");
    CPPUNIT_NS::TextTestRunner runner;
    CPPUNIT_NS::XmlOutputter *outputter = new CPPUNIT_NS::XmlOutputter(&runner.result(), xmlout);

    runner.addTest( CppUnit::TestFactoryRegistry::getRegistry().makeTest() );
    runner.run( "", false );
    outputter->write();

    utils::printMood(runner.result().wasSuccessful());

    return runner.result().wasSuccessful() ? 0 : 1;
}
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;

}