本文整理汇总了C++中TestCase::run方法的典型用法代码示例。如果您正苦于以下问题:C++ TestCase::run方法的具体用法?C++ TestCase::run怎么用?C++ TestCase::run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestCase
的用法示例。
在下文中一共展示了TestCase::run方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runAllTests
int test::runAllTests() {
const std::vector<TestCase*> &testCases = TestCase::getCases();
int passed = 0;
const char *prevFixture = "";
for (int i = 0; i < testCases.size(); i++) {
TestCase *tc = testCases[i];
if (strcmp(tc->fixture, prevFixture) != 0) {
if (strlen(prevFixture) != 0) {
cout << endl;
}
cout << tc->fixture << ":" << endl;
prevFixture = tc->fixture;
}
cout << "- " << tc->name << ": " << flush;
try {
tc->run();
cout << "[OK]" << endl;
passed++;
} catch (TestFailedException &e) {
cout << "[FAILED]" << endl;
cout << " " << e.message << endl;
cout << " (" << e.file << ":" << e.line << ")" << endl;
}
}
cout << endl << passed << " / " << testCases.size() << " tests passed." << endl;
return (passed == testCases.size() ? 0 : 1);
}
示例2: setupTests
Result * Suite::run(){
setupTests();
Result * r = new Result( _name );
Result::cur = r;
for ( list<TestCase*>::iterator i=_tests.begin(); i!=_tests.end(); i++ ){
TestCase * tc = *i;
r->_tests++;
bool passes = false;
log(1) << "\t" << tc->getName() << endl;
try {
tc->run();
passes = true;
}
catch ( ... ){
log() << "unknown exception in test: " << tc->getName() << endl;
}
if ( ! passes )
r->_fails++;
}
return r;
}
示例3: printf
void
Runner::runTestAt( unsigned int index, TestResult &result ) const
{
TestCase *test = tests_[index]();
result.setTestName( test->testName() );
printf( "Testing %s: ", test->testName() );
fflush( stdout );
#if JSON_USE_EXCEPTION
try
{
#endif // if JSON_USE_EXCEPTION
test->run( result );
#if JSON_USE_EXCEPTION
}
catch ( const std::exception &e )
{
result.addFailure( __FILE__, __LINE__,
"Unexpected exception caugth:" ) << e.what();
}
#endif // if JSON_USE_EXCEPTION
delete test;
const char *status = result.failed() ? "FAILED"
: "OK";
printf( "%s\n", status );
fflush( stdout );
}
示例4: log
Result * Suite::run(){
tlogLevel = -1;
log(1) << "\t about to setupTests" << endl;
setupTests();
log(1) << "\t done setupTests" << endl;
Result * r = new Result( _name );
Result::cur = r;
/* see note in SavedContext */
//writelock lk("");
for ( list<TestCase*>::iterator i=_tests.begin(); i!=_tests.end(); i++ ){
TestCase * tc = *i;
r->_tests++;
bool passes = false;
log(1) << "\t going to run test: " << tc->getName() << endl;
stringstream err;
err << tc->getName() << "\t";
try {
tc->run();
passes = true;
}
catch ( MyAssertionException * ae ){
err << ae->ss.str();
delete( ae );
}
catch ( std::exception& e ){
err << " exception: " << e.what();
}
catch ( int x ){
err << " caught int : " << x << endl;
}
catch ( ... ){
cerr << "unknown exception in test: " << tc->getName() << endl;
}
if ( ! passes ){
string s = err.str();
log() << "FAIL: " << s << endl;
r->_fails++;
r->_messages.push_back( s );
}
}
if ( r->_fails )
r->_rc = 17;
log(1) << "\t DONE running tests" << endl;
return r;
}
示例5: run
int TextTestRunner::run(TestCase& testCase)
{
testCase.testResult.attach(this);
Stopwatch sw;
testCase.run();
std::cout << sw.stop() << " mus" << std::endl;
testCase.testResult.detach(this);
return testCase.testResult.total - testCase.testResult.successful;
}
示例6: run
void TestSuite::run() {
unsigned i;
this->mAll = 0;
this->mPassed = 0;
for (i = 0; i < this->mTests->count(); ++i) {
TestCase * ts = (TestCase*)this->mTests->objectAtIndex(i);
this->mPassed += ts->run();
this->mAll += ts->getNumTest();
}
}
示例7:
void
run_h_tc_child(void* v)
{
run_h_tc_data* data = static_cast< run_h_tc_data* >(v);
TestCase tc;
tc.init(data->m_config);
tc.run("result");
std::exit(EXIT_SUCCESS);
}
示例8: main
int main()
{
std::sort(TestCase::allTests().begin(), TestCase::allTests().end(), TestComparator());
DebuggingTestImpl::get()->printf("Starting tests\n");
bool anyFailed = false;
for(int i = 0; i < (int)TestCase::allTests().size(); ++i)
{
if(i > 0)
DebuggingTestImpl::get()->printf("");
TestCase *test = TestCase::allTests()[i];
string name = test->name();
DebuggingTestImpl::get()->printf("running %s", name.c_str());
bool failed = true;
try
{
DebuggingTestImpl::get()->startTiming(name);
DebuggingTestImpl::get()->indent();
test->run();
failed = false;
DebuggingTestImpl::get()->unindent();
}
catch(Assertion)
{
DebuggingTestImpl::get()->unindent();
}
catch(...)
{
DebuggingTestImpl::get()->unindent();
DebuggingTestImpl::get()->printf("Exception thrown");
}
DebuggingTestImpl::get()->elapsedTime(name);
if(failed)
DebuggingTestImpl::get()->printf("FAILED! %s", name.c_str());
else
DebuggingTestImpl::get()->printf("passed %s", name.c_str());
anyFailed = anyFailed || failed;
}
return anyFailed ? 1 : 0;
}
示例9: setupTests
Result * Suite::run(){
setupTests();
Result * r = new Result( _name );
Result::cur = r;
for ( list<TestCase*>::iterator i=_tests.begin(); i!=_tests.end(); i++ ){
TestCase * tc = *i;
r->_tests++;
bool passes = false;
log(1) << "\t" << tc->getName() << endl;
stringstream err;
err << tc->getName() << "\t";
try {
tc->run();
passes = true;
}
catch ( MyAssertionException * ae ){
err << ae->ss.str();
delete( ae );
}
catch ( std::exception& e ){
err << " exception " << " : " << e.what();
}
catch ( int x ){
err << " caught int : " << x << endl;
}
catch ( ... ){
cerr << "unknown exception in test: " << tc->getName() << endl;
}
if ( ! passes ){
r->_fails++;
r->_messages.push_back( err.str() );
}
}
return r;
}
示例10: runTestCase
/*
* run the test case
* return 0 for pass. -1 for fail.
*/
inline int runTestCase( TestCase & test, TestContext & context, std::ostream & log)
{
int rst = 0;
try {
test.run(context);
log << test.name() << " Passed " << std::endl;
rst = 0;
}
catch (XTestFailure& e) {
log << outputLine(e.m_file, e.m_line) << e.what() << '\n' << "FAILED: ";
rst = -1;
}
catch (std::exception& e) {
log << outputLine(__FILE__, __LINE__)
<< "caught standard exception - " << e.what() << '\n'
<< "FAILED: ";
rst = -1;
}
return rst;
}
示例11: while
void
TestSuite::run(TestResult *result, TestOption *opt)
{
list<TestCase *>::iterator iter;
iter = this->tests.begin();
while (iter != this->tests.end()) {
TestCase *tc = *iter;
if (opt->verbose)
cout << "Starting test " << tc->name << "\n";
tc->result = result;
try {
tc->setup();
result->n_run++;
tc->statusSet = false;
tc->run();
if (tc->statusSet == false) {
result->n_fail++;
result->tests_f.push_back( tc->name );
}
}
catch (TestFailure e) {
TestFailure::setUnwindDone();
if (opt->verbose)
cout << " caught test fail exception\n";
result->tests_e.push_back( tc->name + e.what() );
result->n_exceptions++;
}
if (opt->verbose)
cout << " done\n";
iter++;
}
return;
}
示例12:
int
ACE_TMAIN(int argc, ACE_TCHAR* argv[])
{
TestCase test;
return test.run(argc, argv);
}
示例13: mtsutil
//.........这里部分代码省略.........
scheduler->registerWorker(new LocalWorker(formatString("wrk%i", i)));
std::vector<std::string> hosts = tokenize(networkHosts, ";");
/* Establish network connections to nested servers */
for (size_t i=0; i<hosts.size(); ++i) {
const std::string &hostName = hosts[i];
ref<Stream> stream;
if (hostName.find("@") == std::string::npos) {
int port = MTS_DEFAULT_PORT;
std::vector<std::string> tokens = tokenize(hostName, ":");
if (tokens.size() == 0 || tokens.size() > 2) {
SLog(EError, "Invalid host specification '%s'!", hostName.c_str());
} else if (tokens.size() == 2) {
port = strtol(tokens[1].c_str(), &end_ptr, 10);
if (*end_ptr != '\0')
SLog(EError, "Invalid host specification '%s'!", hostName.c_str());
}
stream = new SocketStream(tokens[0], port);
} else {
std::string path = "~/mitsuba"; // default path if not specified
std::vector<std::string> tokens = tokenize(hostName, "@:");
if (tokens.size() < 2 || tokens.size() > 3) {
SLog(EError, "Invalid host specification '%s'!", hostName.c_str());
} else if (tokens.size() == 3) {
path = tokens[2];
}
std::vector<std::string> cmdLine;
cmdLine.push_back(formatString("bash -c 'cd %s; . setpath.sh; mtssrv -ls'", path.c_str()));
stream = new SSHStream(tokens[0], tokens[1], cmdLine);
}
try {
scheduler->registerWorker(new RemoteWorker(formatString("net%i", i), stream));
} catch (std::runtime_error &e) {
if (hostName.find("@") != std::string::npos) {
#if defined(WIN32)
SLog(EWarn, "Please ensure that passwordless authentication "
"using plink.exe and pageant.exe is enabled (see the documentation for more information)");
#else
SLog(EWarn, "Please ensure that passwordless authentication "
"is enabled (e.g. using ssh-agent - see the documentation for more information)");
#endif
}
throw e;
}
}
scheduler->start();
if (testCaseMode) {
std::vector<fs::path> dirPaths = fileResolver->resolveAll("plugins");
std::set<std::string> seen;
int executed = 0, succeeded = 0;
for (size_t i=0; i<dirPaths.size(); ++i) {
fs::path dirPath = fs::complete(dirPaths[i]);
if (!fs::exists(dirPath) || !fs::is_directory(dirPath))
break;
fs::directory_iterator end, it(dirPath);
for (; it != end; ++it) {
if (!fs::is_regular_file(it->status()))
continue;
std::string extension(boost::to_lower_copy(it->path().extension()));
示例14: lk
Result * Suite::run( const string& filter ) {
// set tlogLevel to -1 to suppress tlog() output in a test program
tlogLevel = -1;
log(1) << "\t about to setupTests" << endl;
setupTests();
log(1) << "\t done setupTests" << endl;
Result * r = new Result( _name );
Result::cur = r;
/* see note in SavedContext */
//writelock lk("");
for ( list<TestCase*>::iterator i=_tests.begin(); i!=_tests.end(); i++ ) {
TestCase * tc = *i;
if ( filter.size() && tc->getName().find( filter ) == string::npos ) {
log(1) << "\t skipping test: " << tc->getName() << " because doesn't match filter" << endl;
continue;
}
r->_tests++;
bool passes = false;
log(1) << "\t going to run test: " << tc->getName() << endl;
stringstream err;
err << tc->getName() << "\t";
{
scoped_lock lk(minutesRunningMutex);
minutesRunning = 0;
currentTestName = tc->getName();
}
try {
tc->run();
passes = true;
}
catch ( MyAssertionException * ae ) {
err << ae->ss.str();
delete( ae );
}
catch ( std::exception& e ) {
err << " exception: " << e.what();
}
catch ( int x ) {
err << " caught int : " << x << endl;
}
catch ( ... ) {
cerr << "unknown exception in test: " << tc->getName() << endl;
}
if ( ! passes ) {
string s = err.str();
log() << "FAIL: " << s << endl;
r->_fails++;
r->_messages.push_back( s );
}
}
if ( r->_fails )
r->_rc = 17;
log(1) << "\t DONE running tests" << endl;
return r;
}