Complete Note#1 in the http://wiki.osgeo.org/wiki/GEOS_Provenance_Review to get out...
[geos.git] / tests / unit / geos_unit.cpp
blobeaef7a2044cefa182269c4df30d65bc51e3e8bab
1 //
2 // Test Suite Runner
3 //
4 #ifdef _MSC_VER
5 #ifdef GEOS_DEBUG_MSVC_USE_VLD
6 #include <vld.h>
7 #endif
8 #endif
10 // tut
11 #include <tut.hpp>
12 #include <tut_reporter.hpp>
13 // geos
14 #include <geos/unload.h>
15 // std
16 #include <cstdlib>
17 #include <iomanip>
18 #include <iostream>
20 namespace tut
22 test_runner_singleton runner;
25 void usage()
27 using std::cout;
28 using std::endl;
30 const std::string module("geos_unit");
32 //[list] | [ group] [test]
33 cout << "Usage: " << module << " [OPTION] [TARGET]\n"
34 << endl
35 << "Targets:\n"
36 << " <none> run all tests in all groups\n"
37 << " <group name> run all tests from given group\n"
38 << " <group name> <test nr> run single test with given number from given group\n"
39 << endl
40 << "Options:\n"
41 << " --list list all registered test groups\n"
42 << " --verbose run unit tests verbosely; displays non-error information\n"
43 << " --version print version information and exit\n"
44 << " --help print this message and exit\n"
45 << endl
46 << "Examples:\n"
47 << " " << module << " -v\n"
48 << " " << module << " list\n"
49 << " " << module << " geos::geom::Envelope\n"
50 << " " << module << " geos::geom::Envelope 2\n"
51 << endl
52 << "GEOS homepage: http://geos.osgeo.org" << endl;
55 int main(int argc, const char* argv[])
57 tut::reporter visi;
59 if ( (argc == 2 && std::string(argv[1]) == "--help") || argc > 3 )
61 usage();
62 return 0;
65 std::cout << "===============================\n"
66 << " GEOS Test Suite Application\n"
67 << "===============================\n";
69 tut::runner.get().set_callback(&visi);
71 try
73 if ( argc == 1 )
75 tut::runner.get().run_tests();
77 else if ( argc == 2 && std::string(argv[1]) == "--list" )
79 tut::groupnames gl = tut::runner.get().list_groups();
80 tut::groupnames::const_iterator b = gl.begin();
81 tut::groupnames::const_iterator e = gl.end();
83 tut::groupnames::difference_type d = std::distance(b, e);
85 std::cout << "Registered " << d << " test groups:\n" << std::endl;
87 while ( b != e )
89 std::cout << " " << *b << std::endl;
90 ++b;
93 else if ( argc == 2 && std::string(argv[1]) != "--list" )
95 tut::runner.get().run_tests(argv[1]);
97 else if( argc == 3 )
99 // TODO - mloskot - check if test group with given name exists
100 // TODO - mloskot - check if test case with given number exists
101 std::string grpname(argv[1]);
102 if (grpname.empty())
103 throw std::runtime_error("missing test group name");
105 tut::test_result result;
106 tut::runner.get().run_test(grpname, std::atoi(argv[2]), result);
109 catch( const std::exception& ex )
111 std::cerr << "!!! GEOS Test Suite raised exception: " << ex.what() << std::endl;
114 // XXX - mloskot - this should be removed in future!
115 geos::io::Unload::Release();
117 return (visi.all_ok() ? EXIT_SUCCESS : EXIT_FAILURE);