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