Line data Source code
1 : /*
2 : Zipios -- a small C++ library that provides easy access to .zip files.
3 :
4 : Copyright (C) 2000-2007 Thomas Sondergaard
5 : Copyright (C) 2015-2019 Made to Order Software Corporation
6 :
7 : This library is free software; you can redistribute it and/or
8 : modify it under the terms of the GNU Lesser General Public
9 : License as published by the Free Software Foundation; either
10 : version 2.1 of the License, or (at your option) any later version.
11 :
12 : This library is distributed in the hope that it will be useful,
13 : but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 : Lesser General Public License for more details.
16 :
17 : You should have received a copy of the GNU Lesser General Public
18 : License along with this library; if not, write to the Free Software
19 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 : */
21 :
22 : /** \file
23 : * \anchor catch_tests_anchor
24 : *
25 : * Zipios unit test suite using catch.hpp, see for details:
26 : *
27 : * https://github.com/philsquared/Catch/blob/master/docs/tutorial.md
28 : */
29 :
30 : // Prevent Catch from defining a default main() function in this file
31 : // but let it know this is the file that does contain the main() function
32 : #define CATCH_CONFIG_RUNNER
33 :
34 : #include "tests.hpp"
35 :
36 : #include <cstring>
37 :
38 : #include <stdlib.h>
39 :
40 :
41 : // static variables
42 : namespace
43 : {
44 :
45 : char *g_progname;
46 :
47 : }
48 :
49 :
50 1 : int main(int argc, char *argv[])
51 : {
52 : // define program name
53 1 : g_progname = argv[0];
54 1 : char *e(strrchr(g_progname, '/'));
55 1 : if(e)
56 : {
57 : g_progname = e + 1; // LCOV_EXCL_LINE
58 : }
59 1 : e = strrchr(g_progname, '\\');
60 1 : if(e)
61 : {
62 : g_progname = e + 1; // LCOV_EXCL_LINE
63 : }
64 :
65 1 : unsigned int seed(static_cast<unsigned int>(time(nullptr)));
66 1 : bool help(false);
67 3 : for(int i(1); i < argc; ++i)
68 : {
69 : if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) // LCOV_EXCL_LINE
70 : {
71 : help = true; // LCOV_EXCL_LINE
72 : }
73 : else if(strcmp(argv[i], "--seed") == 0) // LCOV_EXCL_LINE
74 : {
75 : if(i + 1 >= argc) // LCOV_EXCL_LINE
76 : {
77 : std::cerr << "error: --seed needs to be followed by the actual seed." << std::endl; // LCOV_EXCL_LINE
78 : exit(1); // LCOV_EXCL_LINE
79 : }
80 : seed = atoll(argv[i + 1]); // LCOV_EXCL_LINE
81 : // remove the --seed and <value>
82 : for(int j(i); j + 2 < argc; ++j) // LCOV_EXCL_LINE
83 : {
84 : argv[j] = argv[j + 2]; // LCOV_EXCL_LINE
85 : }
86 : argc -= 2; // LCOV_EXCL_LINE
87 : }
88 : }
89 1 : srand(seed);
90 1 : std::cout << g_progname << "[" << getpid() << "]" << ": version " << ZIPIOS_VERSION_STRING << ", seed is " << seed << std::endl;
91 :
92 1 : if(help)
93 : {
94 : std::cout << std::endl // LCOV_EXCL_LINE
95 : << "WARNING: at this point we hack the main() to add the following options:" << std::endl // LCOV_EXCL_LINE
96 : << " --seed <seed> to force the seed at the start of the process to a specific value (i.e. to reproduce the exact same test over and over again)" << std::endl // LCOV_EXCL_LINE
97 : << std::endl; // LCOV_EXCL_LINE
98 : }
99 :
100 1 : return Catch::Session().run(argc, argv);
101 3 : }
102 :
103 :
104 :
105 : // Local Variables:
106 : // mode: cpp
107 : // indent-tabs-mode: nil
108 : // c-basic-offset: 4
109 : // tab-width: 4
110 : // End:
111 :
112 : // vim: ts=4 sw=4 et
|