add support for -D foobar when running tests
[ardour.git] / libs / ardour / test / testrunner.cc
1 #include <getopt.h>
2
3 #include <cppunit/CompilerOutputter.h>
4 #include <cppunit/extensions/TestFactoryRegistry.h>
5 #include <cppunit/TestResult.h>
6 #include <cppunit/TestResultCollector.h>
7 #include <cppunit/TestRunner.h>
8 #include <cppunit/BriefTestProgressListener.h>
9
10 #include "pbd/debug.h"
11 #include "ardour/ardour.h"
12
13 int
14 main(int argc, char* argv[])
15 {
16         if (!Glib::thread_supported()) {
17                 Glib::thread_init();
18         }
19
20         const struct option longopts[] = {
21                 { "debug", 1, 0, 'D' },
22                 { 0, 0, 0, 0 }
23         };
24         const char *optstring = "D:";
25         int option_index = 0;
26         int c = 0;
27
28         while (1) {
29                 c = getopt_long (argc, argv, optstring, longopts, &option_index);
30
31                 if (c == -1) {
32                         break;
33                 }
34
35                 switch (c) {
36                 case 0:
37                         break;
38
39                 case 'D':
40                         if (PBD::parse_debug_options (optarg)) {
41                                 exit (0);
42                         }
43                         break;
44                 }
45         }
46
47         ARDOUR::init (false, false);
48         
49         CppUnit::TestResult testresult;
50         
51         CppUnit::TestResultCollector collectedresults;
52         testresult.addListener (&collectedresults);
53         
54         CppUnit::BriefTestProgressListener progress;
55         testresult.addListener (&progress);
56         
57         CppUnit::TestRunner testrunner;
58         testrunner.addTest (CppUnit::TestFactoryRegistry::getRegistry ().makeTest ());
59         testrunner.run (testresult);
60         
61         CppUnit::CompilerOutputter compileroutputter (&collectedresults, std::cerr);
62         compileroutputter.write ();
63         
64         return collectedresults.wasSuccessful () ? 0 : 1;
65 }