File: geos_unit.cpp

package info (click to toggle)
geos 3.14.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,212 kB
  • sloc: cpp: 199,103; xml: 56,065; ansic: 6,162; sh: 287; makefile: 26
file content (128 lines) | stat: -rw-r--r-- 4,010 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//
// Test Suite Runner
//
#ifdef _MSC_VER
#ifdef GEOS_DEBUG_MSVC_USE_VLD
#include <vld.h>
#endif
#endif

// tut
#include <tut/tut.hpp>
#include <tut/tut_reporter.hpp>
// std
#include <cstdlib>
#include <iomanip>
#include <iostream>

std::string RESOURCE_DIR;

namespace tut {
test_runner_singleton runner;
}

void
usage()
{
    using std::cout;
    using std::endl;

    const std::string module("geos_unit");

    //[list] | [ group] [test]
    cout << "Usage: " << module << " [OPTION] [TARGET]\n"
         << endl
         << "Targets:\n"
         << "  <none>                          run all tests in all groups\n"
         << "  <group name>                    run all tests in group\n"
         << "  <group name> <test num>         run single group test <num>\n"
         << endl
         << "Options:\n"
         << "  --list                          list all registered test groups\n"
//         << "  --verbose                       run unit tests verbosely; displays non-error information\n"
//         << "  --version                       print version information and exit\n"
         << "  --data                          specify a directory containing test data files\n"
         << "  --help                          print this message and exit\n"
         << endl
         << "Examples:\n"
//         << "  " << module << " -v\n"
         << "  " << module << " list\n"
         << "  " << module << " geos::geom::Envelope\n"
         << "  " << module << " geos::geom::Envelope 2\n"
         << endl
         << "GEOS homepage: http://geos.osgeo.org" << endl;
}

int
main(int argc, const char* argv[]) {
    tut::reporter visi;

    bool listOnly = false;
    std::string grpname;
    std::string testName;

    for (std::size_t i = 1; i < static_cast<std::size_t>(argc); i++) {
        std::string arg = argv[i];
        if (arg == "--help") {
            usage();
            return EXIT_SUCCESS;
        } else if (arg == "--list") {
            listOnly = true;
        } else if (arg == "--data" && (i + 1) < static_cast<std::size_t>(argc)) {
            RESOURCE_DIR = argv[++i];
        } else if (arg[0] == '-') {
            std::cerr << "Invalid option: " << argv << std::endl;
            return EXIT_FAILURE;
        } else if (grpname.empty()) {
            grpname = arg;
        } else if (testName.empty()) {
            testName = arg;
        } else {
            std::cerr << "Unexpected positional argument: " << arg << std::endl;
            return EXIT_FAILURE;
        }
    }

    std::cout << "===============================\n"
              << "  GEOS Unit Test Suite\n"
              << "===============================\n";

    tut::runner.get().set_callback(&visi);

    try {
        if (listOnly) {
            tut::groupnames gl = tut::runner.get().list_groups();
            tut::groupnames::const_iterator b = gl.begin();
            tut::groupnames::const_iterator e = gl.end();

            tut::groupnames::difference_type d = std::distance(b, e);

            std::cout << "Registered " << d << " test groups:\n" << std::endl;

            while(b != e) {
                std::cout << "  " << *b << std::endl;
                ++b;
            }
            return EXIT_SUCCESS;
        } else {
            if (!testName.empty()) {
                tut::test_result result;
                tut::runner.get().run_test(grpname, std::atoi(testName.c_str()), result);
            } else if (!grpname.empty()) {
                tut::runner.get().run_tests(grpname);
            } else {
                tut::runner.get().run_tests();
            }
        }
    }
    catch(const tut::no_such_group& ex) {
        std::cerr << "!!! GEOS Test Suite - unknown test group " << ex.what() << std::endl;
        return EXIT_FAILURE;
    }
    catch(const std::exception& ex) {
        std::cerr << "!!! GEOS Test Suite raised exception: " << ex.what() << std::endl;
        return EXIT_FAILURE;
    }

    return (visi.all_ok() ? EXIT_SUCCESS : EXIT_FAILURE);
}