Exemple #1
0
  inline bool run(Environment& environment, Suite& tests, Setup const&... setup)
  {
    // retrieve compact status
    auto is_compact = args("compact",false);
    auto is_fail_only = args("fail-only",false);
    environment.compact(is_compact);
    environment.fail_only(is_fail_only);

    // randomize test on non-null random seed option
    if(auto seed = args("random",0u))
    {
      ::stf::detail::shuffle( tests.begin(), tests.end(), std::mt19937{seed} );
    }

    for(auto& t : tests )
    {
      scenario_header(environment,t);
      auto count = environment.tests();

      t(environment);

      process_invalid(environment, count);

      environment.stream() << std::endl;
    }

    return ::stf::report(environment,setup...);
  }
Exemple #2
0
void AddTest(Suite& ts)
{
    ts.add(std::auto_ptr<Suite>(new CTestDataBox));
    ts.add(std::auto_ptr<Suite>(new CTestThreadSync));
    ts.add(std::auto_ptr<Suite>(new CTestSerialize));
    ts.add(std::auto_ptr<Suite>(new CTestPeutils));
}
Exemple #3
0
        int Suite::run( vector<string> suites ){
            for ( unsigned int i = 0; i < suites.size(); i++ ) {
                if ( _suites->find( suites[i] ) == _suites->end() ) {
                    cout << "invalid test [" << suites[i] << "], use --list to see valid names" << endl;
                    return -1;
                }
            }

            list<string> torun(suites.begin(), suites.end());

            if ( torun.size() == 0 )
                for ( map<string,Suite*>::iterator i=_suites->begin() ; i!=_suites->end(); i++ )
                    torun.push_back( i->first );

            list<Result*> results;

            for ( list<string>::iterator i=torun.begin(); i!=torun.end(); i++ ){
                string name = *i;
                Suite * s = (*_suites)[name];
                assert( s );

                log() << "going to run suite: " << name << endl;
                results.push_back( s->run() );
            }

            Logstream::get().flush();

            cout << "**************************************************" << endl;
            cout << "**************************************************" << endl;
            cout << "**************************************************" << endl;

            int rc = 0;

            int tests = 0;
            int fails = 0;
            int asserts = 0;

            for ( list<Result*>::iterator i=results.begin(); i!=results.end(); i++ ){
                Result * r = *i;
                cout << r->toString();
                if ( abs( r->rc() ) > abs( rc ) )
                    rc = r->rc();
                
                tests += r->_tests;
                fails += r->_fails;
                asserts += r->_asserts;
            }

            Result totals ("TOTALS");
            totals._tests = tests;
            totals._fails = fails;
            totals._asserts = asserts;
            
            cout << totals.toString(); // includes endl

            return rc;
        }
Exemple #4
0
void UniTest()
{
    Suite ts;
    AddTest(ts);
    std::auto_ptr<Output> output(new XmlOutput);
    ts.run(*output, true);
    Test::XmlOutput* const xml_output = dynamic_cast<XmlOutput*>(output.get());
    if (xml_output)
    {
        std::ofstream fout("./test_pellets.xml");
        xml_output->generate(fout, true, "zpublic");
    }
}
Exemple #5
0
//skriver ut data om suitene.
void Hotell::displaySuite(){

	Suite *tempSuite;

	for (int x = 1; x <= rom[2]->no_of_elements(); x++){

		tempSuite = (Suite*)rom[2]->remove_no(x);
		rom[2]->add(tempSuite);
		tempSuite->display();
	}

	_getch();
}
Exemple #6
0
//skriver data til fil.
void Hotell::tilfil(){

	//filnavnet er egen variabel.
	ofstream fil (filnavn+".DTA");

	//Statisk data
	fil << navn << endl;
	fil << postnummer << " " << addresse << endl;
	fil << telefon << " " << fax << " " << mail << endl;
	fil << frokost << " " << seng << " " << antFascilliteter << endl;

	//beskrivelse av fascillitetene.
	for(int x = 1; x <= antFascilliteter; x++){
		fil << fascilliteter[x] << endl;
	}


	for(int y = 0; y < 3; y++){

		//data om alle rom skriver seg selv.		
		Singel *tempSingel;
		Dobbel *tempDobbel;
		Suite  *tempSuite;
		
		fil << rom[y]->no_of_elements() << endl;
		for (int x = 1; x <= rom[y]->no_of_elements(); x++){

			if(y == 0){
				tempSingel = (Singel*)rom[y]->remove_no(x);
				rom[y]->add(tempSingel);
				tempSingel->toFile(fil);
			}

			else if (y == 1){
				tempDobbel = (Dobbel*)rom[y]->remove_no(x);
				rom[y]->add(tempDobbel);
				tempDobbel->toFile(fil);
			}

			else if (y == 2){
				tempSuite = (Suite*)rom[y]->remove_no(x);
				rom[y]->add(tempSuite);
				tempSuite->toFile(fil);
			}

			fil << endl;
		}

	}

}
Exemple #7
0
bool GetKeysRegistry::GetNextKey(DescriptorTypeID &type)
{
	if(m_iNextKey == m_iNumKeys)
		return false;

	OSErr err = m_DescriptorProcs->GetKey(*m_Descriptor, m_iNextKey, &m_CurKey);
	if(err)
		throw ExceptionSPErr(StringUtil::ssprintf("GetKeysRegistry::GetKey(%i)", m_iNextKey), err);
	err = m_DescriptorProcs->GetType(*m_Descriptor, m_CurKey, &type);
	if(err)
		throw ExceptionSPErr(StringUtil::ssprintf("GetKeysRegistry::GetType(%08x)", m_CurKey), err);

	++m_iNextKey;
	return true;
}
Exemple #8
0
bool GetKeysRegistry::GetBoolean()
{
	Boolean bValue;
	OSErr iErr = m_DescriptorProcs->GetBoolean(*m_Descriptor, m_CurKey, &bValue);
	if(iErr)
		throw ExceptionSPErr(StringUtil::ssprintf("GetKeysRegistry::GetBoolean(%08x)", m_CurKey), iErr);
	return !!bValue;
}
Exemple #9
0
float GetKeysRegistry::GetFloat()
{
	double fValue;
	OSErr iErr = m_DescriptorProcs->GetFloat(*m_Descriptor, m_CurKey, &fValue);
	if(iErr)
		throw ExceptionSPErr(StringUtil::ssprintf("GetKeysRegistry::GetFloat(%08x)", m_CurKey), iErr);
	return (float) fValue;
}
Exemple #10
0
int GetKeysRegistry::GetInteger()
{
	int32 iValue;
	OSErr iErr = m_DescriptorProcs->GetInteger(*m_Descriptor, m_CurKey, &iValue);
	if(iErr)
		throw ExceptionSPErr(StringUtil::ssprintf("GetKeysRegistry::GetInteger(%08x)", m_CurKey), iErr);
	return iValue;
}
Exemple #11
0
DescriptorEnumID GetKeysRegistry::GetEnum()
{
	DescriptorEnumID iValue;
	DescriptorEnumTypeID type;
	OSErr iErr = m_DescriptorProcs->GetEnumerated(*m_Descriptor, m_CurKey, &type, &iValue);
	if(iErr)
		throw ExceptionSPErr(StringUtil::ssprintf("GetKeysRegistry::GetEnumerated(%08x)", m_CurKey), iErr);
	return iValue;
}
void Runner::Run()
{
    Print("Starting Test Runner: %s\n", iDesc);
    SetAssertThrows(true);
    gPass = 0;
    gFail = 0;

    Suite* suite = iFirst;
    TUint i=1;
    for(; suite != 0; i++) {
        Print("Suite %d: %s\n", i,suite->Description());
        try {
            suite->Test();
        } catch(OpenHome::Exception& e) {
            Print("\nFAILURE: Suite: %d caused an unhandled exception: %s.  Exception thrown at:  File: %s.  Line: %d\n",i,e.Message(),e.File(),e.Line());
            Print("Last successful test: %s:%d\n", gLastSuccessfulFile, gLastSuccessfulLine);
            gFail++;
        } catch(...) {
            Print("\nFAILURE: Suite: %d caused an unhandled, unknown exception\n", i);
            Print("Last successful test: %s:%d\n", gLastSuccessfulFile, gLastSuccessfulLine);
            gFail++;
        }
        Print("\n");

        Suite* finishedSuite = suite;
        suite = suite->iNext;
        delete finishedSuite;
    }
    Print("Finished Test Runner: %s\n", iDesc);
    Print("%d of %d tests passed.\n",gPass, gPass+gFail);
    Print("%d of %d tests failed.\n",gFail, gPass+gFail);
    if (gFail != 0) {
        const char* a = getenv("ABORT_ON_FAILURE");
        if ( a == NULL || atoi(a) == 1 ) {
            // If env var is unset, or is set to "1", then exit.
            exit(1);
        }
    }
}
Exemple #13
0
void AddTest(Suite& ts)
{
//     ts.add(std::auto_ptr<Suite>(new CTestDataBox));
//     ts.add(std::auto_ptr<Suite>(new CTestThreadSync));
//     ts.add(std::auto_ptr<Suite>(new CTestSerialize));
//     ts.add(std::auto_ptr<Suite>(new CTestPeutils));
//     ts.add(std::auto_ptr<Suite>(new CTestThreadPool));
//     ts.add(std::auto_ptr<Suite>(new CTestDesignPattern));
//     ts.add(std::auto_ptr<Suite>(new CTestEvent));
//     ts.add(std::auto_ptr<Suite>(new CTestTimer));
//     ts.add(std::auto_ptr<Suite>(new CTestLuaBind));
    ts.add(std::auto_ptr<Suite>(new CTestWinUtils));
}
Exemple #14
0
void PutKeysRegistry::PutPercent(DescriptorKeyID key, float f)
{
	SPErr iErr = m_DescriptorProcs->PutFloat(*m_Descriptor, key, f);
	if(iErr)
		throw ExceptionSPErr(StringUtil::ssprintf("PutKeysRegistry::PutPercent(%08x)", key), iErr);
}
Exemple #15
0
void PutKeysRegistry::PutInteger(DescriptorKeyID key, int i)
{
	SPErr iErr = m_DescriptorProcs->PutInteger(*m_Descriptor, key, i);
	if(iErr)
		throw ExceptionSPErr(StringUtil::ssprintf("PutKeysRegistry::PutInteger(%08x)", key), iErr);
}
Exemple #16
0
void PutKeysRegistry::Finish()
{
	SPErr iErr = m_RegistryProcs->Register(plugInUniqueID, *m_Descriptor, true);
	if(iErr)
		throw ExceptionSPErr("m_RegistryProcs->Register", iErr);
}
Exemple #17
0
        int Suite::run( int argc , char ** argv ){
            list<string> torun;

            for ( int i=1; i<argc; i++ ){
            
                string s = argv[i];
                
                if ( s == "-list" ){
                    for ( map<string,Suite*>::iterator i=_suites->begin() ; i!=_suites->end(); i++ )
                        cout << i->first << endl;
                    return 0;
                }

                if ( s == "-debug" ){
                    logLevel = 1;
                    continue;
                }
                
                torun.push_back( s );
                if ( _suites->find( s ) == _suites->end() ){
                    cout << "invalid test [" << s << "]  use -list to see valid names" << endl;
                    return -1;
                }
            }
            
            if ( torun.size() == 0 )
                for ( map<string,Suite*>::iterator i=_suites->begin() ; i!=_suites->end(); i++ )
                    torun.push_back( i->first );
            
            list<Result*> results;
            
            for ( list<string>::iterator i=torun.begin(); i!=torun.end(); i++ ){
                string name = *i;
                Suite * s = (*_suites)[name];
                assert( s );
                
                log() << "going to run suite: " << name << endl;
                results.push_back( s->run() );
            }
            
            cout << "**************************************************" << endl;
            cout << "**************************************************" << endl;
            cout << "**************************************************" << endl;
            
            int rc = 0;
            
            int tests = 0;
            int fails = 0;
            int asserts = 0;

            for ( list<Result*>::iterator i=results.begin(); i!=results.end(); i++ ){
                Result * r = *i;
                cout << r->toString();
                if ( abs( r->rc() ) > abs( rc ) )
                    rc = r->rc();

                tests += r->_tests;
                fails += r->_fails;
                asserts += r->_asserts;
            }
            
            cout << "TOTALS  tests:" << tests << " fails: " << fails << " asserts calls: " << asserts << endl;

            return rc;
        }
Exemple #18
0
        int Suite::run( const std::vector<std::string>& suites , const std::string& filter , int runsPerTest ) {

            if (_allSuites().empty()) {
                log() << "error: no suites registered.";
                return EXIT_FAILURE;
            }

            for ( unsigned int i = 0; i < suites.size(); i++ ) {
                if ( _allSuites().count( suites[i] ) == 0 ) {
                    log() << "invalid test suite [" << suites[i] << "], use --list to see valid names" << std::endl;
                    return EXIT_FAILURE;
                }
            }

            std::vector<std::string> torun(suites);

            if ( torun.empty() ) {
                for ( SuiteMap::const_iterator i = _allSuites().begin();
                      i !=_allSuites().end(); ++i ) {

                    torun.push_back( i->first );
                }
            }

            std::vector<Result*> results;

            for ( std::vector<std::string>::iterator i=torun.begin(); i!=torun.end(); i++ ) {
                std::string name = *i;
                Suite* s = _allSuites()[name];
                fassert( 16145,  s );

                log() << "going to run suite: " << name << std::endl;
                results.push_back( s->run( filter, runsPerTest ) );
            }

            log() << "**************************************************" << std::endl;

            int rc = 0;

            int tests = 0;
            int fails = 0;
            int asserts = 0;

            for ( std::vector<Result*>::iterator i=results.begin(); i!=results.end(); i++ ) {
                Result* r = *i;
                log() << r->toString();
                if ( abs( r->rc() ) > abs( rc ) )
                    rc = r->rc();

                tests += r->_tests;
                fails += r->_fails;
                asserts += r->_asserts;
            }

            Result totals ("TOTALS");
            totals._tests = tests;
            totals._fails = fails;
            totals._asserts = asserts;

            log() << totals.toString(); // includes endl

            return rc;
        }
Exemple #19
0
int suite_run()
{
    int      i, stage;
    char     *extra;
    void    (*func)();

    passed = failed = 0;

    printf("Starting suite %s (%d tests)\n",suite.name, suite.num_tests);

    for ( i = 0; i < suite.num_tests; i++ ) {
        if ( setjmp(jmpbuf) == 0 ) {
#ifndef NO_LOG_RUNNING
            printf("Running test %s..",suite.testnames[i]);
#endif
            failed_message = NULL;
            stage = 0;
            if ( suite.setup ) {
                suite.setup();
            }
            func = suite.tests[i];
            stage++;
            func();
            stage++;
            if ( suite.teardown ) {
                suite.teardown();
            }
#ifndef NO_LOG_PASSED
#ifdef NO_LOG_RUNNING
            printf("Running test %s..",suite.testnames[i]);
#endif
            printf("...passed\n");
#endif
            passed++;
        } else {
            extra = "";
            switch ( stage ) {
            case 0:
                extra = "(in setup)";
                /* Fall through */
            case 1:
                /* Protect ourselves against teardown failing */
                if ( setjmp(jmpbuf) == 0 ) {
                    if ( suite.teardown() ) {
                        suite.teardown();
                    }
                } else {
                    stage = 3;
                }
                break;
            case 2:
                extra = "(in teardown) ";
                break;
            }
#ifdef NO_LOG_RUNNING
            printf("Running test %s..",suite.testnames[i]);
#endif
            printf("...failed %s%s:%d (%s)%s\n",extra,failed_file, failed_line, failed_message,stage == 3 ? " (and in teardown)" : "");
            failed++;
        }
    }

    printf("%d run, %d passed, %d failed\n", suite.num_tests, passed, failed);

    return failed != 0;
}
Exemple #20
0
void PutKeysRegistry::PutBoolean(DescriptorKeyID key, bool b)
{
	SPErr iErr = m_DescriptorProcs->PutBoolean(*m_Descriptor, key, b);
	if(iErr)
		throw ExceptionSPErr(StringUtil::ssprintf("PutKeysRegistry::PutBoolean(%08x)", key), iErr);
}
Exemple #21
0
        int Suite::run( const std::vector<std::string>& suites , const std::string& filter , int runsPerTest ) {

            if (_allSuites().empty()) {
                log() << "error: no suites registered.";
                return EXIT_FAILURE;
            }

            for ( unsigned int i = 0; i < suites.size(); i++ ) {
                if ( _allSuites().count( suites[i] ) == 0 ) {
                    log() << "invalid test suite [" << suites[i] << "], use --list to see valid names" << std::endl;
                    return EXIT_FAILURE;
                }
            }

            std::vector<std::string> torun(suites);

            if ( torun.empty() ) {
                for ( SuiteMap::const_iterator i = _allSuites().begin();
                      i !=_allSuites().end(); ++i ) {

                    torun.push_back( i->first );
                }
            }

            std::vector<Result*> results;

            for ( std::vector<std::string>::iterator i=torun.begin(); i!=torun.end(); i++ ) {
                std::string name = *i;
                Suite* s = _allSuites()[name];
                fassert( 16145,  s );

                log() << "going to run suite: " << name << std::endl;
                results.push_back( s->run( filter, runsPerTest ) );
            }

            log() << "**************************************************" << std::endl;

            int rc = 0;

            int tests = 0;
            int asserts = 0;
            int millis = 0;

            Result totals ("TOTALS");
            std::vector<std::string> failedSuites;

            for ( std::vector<Result*>::iterator i=results.begin(); i!=results.end(); i++ ) {
                Result* r = *i;
                log() << r->toString();
                if ( abs( r->rc() ) > abs( rc ) )
                    rc = r->rc();

                tests += r->_tests;
                if ( !r->_fails.empty() ) {
                    failedSuites.push_back(r->toString());
                    for ( std::vector<std::string>::const_iterator j=r->_fails.begin();
                          j!=r->_fails.end(); j++ ) {
                        const std::string& s = (*j);
                        totals._fails.push_back(r->_name + "/" + s);
                    }
                }
                asserts += r->_asserts;
                millis += r->_millis;
            }

            totals._tests = tests;
            totals._asserts = asserts;
            totals._millis = millis;

            log() << totals.toString(); // includes endl

            // summary
            if ( !totals._fails.empty() ) {
                log() << "Failing tests:" << std::endl;
                for ( std::vector<std::string>::const_iterator i=totals._fails.begin();
                      i!=totals._fails.end(); i++ ) {
                    const std::string& s = (*i);
                    log() << "\t " << s << " Failed";
                }
                log() << "FAILURE - " << totals._fails.size() << " tests in "
                      << failedSuites.size() << " suites failed";
            }
            else {
                log() << "SUCCESS - All tests in all suites passed";
            }

            return rc;
        }
Exemple #22
0
void PutKeysRegistry::PutEnum(DescriptorKeyID key, DescriptorEnumID e, DescriptorEnumTypeID type)
{
	SPErr iErr = m_DescriptorProcs->PutEnumerated(*m_Descriptor, key, type, e);
	if(iErr)
		throw ExceptionSPErr(StringUtil::ssprintf("PutKeysRegistry::PutEnum(%08x)", key), iErr);
}