Ejemplo n.º 1
0
/////////////////////////////////////////////////////////////////////////////////
// main function
int main(int argc, char* argv[])
{
    // argument 2 contains the working dir
    if (argc > 2)
        cTestDataDir.assign(argv[2]);

    // see http://stackoverflow.com/questions/3546054/how-do-i-run-a-single-test-with-unittest
    if( argc > 1 )
    {
        //walk list of all tests, add those with a name that
        //matches one of the arguments  to a new TestList
        const UnitTest::TestList& allTests( UnitTest::Test::GetTestList() );
        UnitTest::TestList selectedTests;
        UnitTest::Test* p = allTests.GetHead();
        while( p )
        {
            if( strcmp( p->m_details.suiteName, argv[ 1 ] ) == 0 )
                    selectedTests.Add( p );
            p = p->m_nextTest;
        }

        //run selected test(s) only
        UnitTest::TestReporterStdout reporter;
        UnitTest::TestRunner runner( reporter );
        return runner.RunTestsIf( selectedTests, 0, UnitTest::True(), 0 );
    }
    else
    {
        return UnitTest::RunAllTests();
    }
}
Ejemplo n.º 2
0
/////////////////////////////////////////////////////////////////////////////////
// main function
int main(int argc, char* argv[])
{

    // detect memory leaks in win32
#if (defined(WITH_MEMORYCHECK) && !defined(NDEBUG) && defined (GTCMT_WIN32))
    // set memory checking flags
    int iDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
    iDbgFlag |= _CRTDBG_CHECK_ALWAYS_DF;
    iDbgFlag |= _CRTDBG_LEAK_CHECK_DF;
    _CrtSetDbgFlag( iDbgFlag );

    //_CrtSetBreakAlloc(245);
#endif

    // enable floating point exceptions in win32
#if (defined(WITH_FLOATEXCEPTIONS) && !defined(NDEBUG) && defined (GTCMT_WIN32))
    // enable check for exceptions (don't forget to enable stop in MSVC!)
    _controlfp(~(_EM_INVALID | _EM_ZERODIVIDE | _EM_OVERFLOW | _EM_UNDERFLOW | _EM_DENORMAL), _MCW_EM) ;
#endif // #ifndef WITHOUT_EXCEPTIONS


    // argument 2 contains the working dir
    if (argc > 2)
        cTestDataDir.assign(argv[2]);
    
    // see http://stackoverflow.com/questions/3546054/how-do-i-run-a-single-test-with-unittest
    if( argc > 1 )
    {
        //walk list of all tests, add those with a name that
        //matches one of the arguments  to a new TestList
        const UnitTest::TestList& allTests( UnitTest::Test::GetTestList() );
        UnitTest::TestList selectedTests;
        UnitTest::Test* p = allTests.GetHead();
        while( p )
        {
            if( strcmp( p->m_details.suiteName, argv[ 1 ] ) == 0 )
            {
                selectedTests.Add( p );
            }
            p = p->m_nextTest;
        }
        selectedTests.Add(0);

        //run selected test(s) only
        UnitTest::TestReporterStdout reporter;
        UnitTest::TestRunner runner( reporter );
        return runner.RunTestsIf( selectedTests, 0, UnitTest::True(), 0 );
    }
    else
    {
        return UnitTest::RunAllTests();
    }
}
Ejemplo n.º 3
0
/**
 * \brief Runs only one test suite (all the tests in the suite) specified by
 *        the name. It runs nothing if the suite does not exists.
 *
 * Behaviours:
 *   it runs one suite in isolation
 * Intended use:
 *   int return_code = RunOneSuite("name_of_my_suite");
 *
 * \param rSuiteName the name of the suite you wish to run
 *
 * \return the return code of UnitTest::RunTestsIf()
 */
inline int RunOneSuite(const std::string& rSuiteName)
{
  const UnitTest::TestList& allTests(UnitTest::Test::GetTestList());
  UnitTest::TestList selectedTests;
  UnitTest::Test* p = allTests.GetHead();

  while (p) {
    if (p->m_details.suiteName == rSuiteName) selectedTests.Add(p);
    UnitTest::Test* q = p;
    p = p->m_nextTest;
    q->m_nextTest = nullptr;
  }

  UnitTest::TestReporterStdout reporter;
  UnitTest::TestRunner runner(reporter);

  return runner.RunTestsIf(selectedTests, nullptr, UnitTest::True(), 0);
}
Ejemplo n.º 4
0
/**
 * \brief Runs only multiple test suites (all the tests in the suites)
 *        specified by the names. It runs nothing if none of the suites
 *        exists.
 *
 * Behaviours:
 *   it runs multiple suites
 * Intended use:
 *   int return_code = RunMultipleSuites(names_of_my_suites);
 *
 * \param rSuiteNames The names of the suites you wish to run
 *
 * \return the return code of UnitTest::RunTestsIf()
 */
inline int RunMultipleSuites(const std::vector<std::string>& rSuiteNames)
{
  const UnitTest::TestList& allTests(UnitTest::Test::GetTestList());
  UnitTest::TestList selectedTests;
  UnitTest::Test* p = allTests.GetHead();

  while (p) {
    auto is_desired_suite = std::find(begin(rSuiteNames), end(rSuiteNames),
        p->m_details.suiteName) != end(rSuiteNames);
    if (is_desired_suite) selectedTests.Add(p);
    UnitTest::Test* q = p;
    p = p->m_nextTest;
    q->m_nextTest = nullptr;
  }

  UnitTest::TestReporterStdout reporter;
  UnitTest::TestRunner runner(reporter);

  return runner.RunTestsIf(selectedTests, nullptr, UnitTest::True(), 0);
}