| 1 | #include "Test.h" |
|---|
| 2 | #include "TestReporterStdout.h" |
|---|
| 3 | #include "UnitTest++.h" |
|---|
| 4 | #include "bdmerror.h" |
|---|
| 5 | #include "itpp_ext.h" |
|---|
| 6 | #include <string.h> |
|---|
| 7 | |
|---|
| 8 | using std::cout; |
|---|
| 9 | using std::cerr; |
|---|
| 10 | using std::endl; |
|---|
| 11 | |
|---|
| 12 | using namespace itpp; |
|---|
| 13 | |
|---|
| 14 | Array<const char *> selected_tests; |
|---|
| 15 | |
|---|
| 16 | bool is_selected_test ( const UnitTest::Test *test ) { |
|---|
| 17 | bdm_assert_debug ( test, "NULL test" ); |
|---|
| 18 | |
|---|
| 19 | if ( !selected_tests.length() ) { |
|---|
| 20 | return true; |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | for ( int i = 0; i < selected_tests.length(); ++i ) { |
|---|
| 24 | const char *n = test->m_details.testName; |
|---|
| 25 | bdm_assert_debug ( n, "NULL test name" ); |
|---|
| 26 | const char *sname = selected_tests ( i ); |
|---|
| 27 | bdm_assert_debug ( sname, "NULL selected test name" ); |
|---|
| 28 | if ( !strcmp ( n, sname ) ) { |
|---|
| 29 | return true; |
|---|
| 30 | } |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | return false; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | int main ( int argc, char const *argv[] ) { |
|---|
| 37 | if ( argc > 1 ) { |
|---|
| 38 | if ( !strcmp ( argv[1], "print" ) ) { |
|---|
| 39 | UnitTest::Test* curTest = UnitTest::Test::GetTestList().GetHead(); |
|---|
| 40 | |
|---|
| 41 | while ( curTest != 0 ) { |
|---|
| 42 | const char *n = curTest->m_details.testName; |
|---|
| 43 | printf ( "%s\n", n ); |
|---|
| 44 | curTest = curTest->next; |
|---|
| 45 | } |
|---|
| 46 | return 0; |
|---|
| 47 | } else { |
|---|
| 48 | selected_tests.set_length ( argc - 1 ); |
|---|
| 49 | const char **param = argv + 1; |
|---|
| 50 | int i = 0; |
|---|
| 51 | while ( *param ) { |
|---|
| 52 | selected_tests ( i ) = *param; |
|---|
| 53 | ++i; |
|---|
| 54 | ++param; |
|---|
| 55 | } |
|---|
| 56 | } |
|---|
| 57 | } else { |
|---|
| 58 | cout << "usage: " << endl << |
|---|
| 59 | "\"" << argv[0] << "\" - to run all unit tests " << endl << |
|---|
| 60 | "\"" << argv[0] << " particular_test_1 particular_test_2\" - to run selected unit tests" << endl << |
|---|
| 61 | "\"" << argv[0] << " print\" - to print all the implemented unit tests" << endl; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | itpp::RNG_randomize(); |
|---|
| 65 | |
|---|
| 66 | UnitTest::TestReporterStdout reporter; |
|---|
| 67 | UnitTest::TestRunner runner ( reporter ); |
|---|
| 68 | return runner.RunTestsIf ( UnitTest::Test::GetTestList(), |
|---|
| 69 | 0, |
|---|
| 70 | is_selected_test, |
|---|
| 71 | 0 ); |
|---|
| 72 | } |
|---|