1 //--------------------------------------------------------------------------
2 // Copyright (C) 2014-2021 Cisco and/or its affiliates. All rights reserved.
3 //
4 // This program is free software; you can redistribute it and/or modify it
5 // under the terms of the GNU General Public License Version 2 as published
6 // by the Free Software Foundation.  You may not use, modify or distribute
7 // this program under any other version of the GNU General Public License.
8 //
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License along
15 // with this program; if not, write to the Free Software Foundation, Inc.,
16 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 //--------------------------------------------------------------------------
18 // unit_test.h author Russ Combs <rucombs@cisco.com>
19 
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include "unit_test.h"
25 
26 #define CATCH_CONFIG_RUNNER
27 #include "snort_catch.h"
28 
29 using namespace snort;
30 
31 static bool s_catch = false;
32 static std::vector<std::string> test_tags;
33 
catch_set_filter(const char * s)34 void catch_set_filter(const char* s)
35 {
36     if ( s && strcmp(s, "all") )
37         test_tags.push_back( s );
38 
39     s_catch = true;
40 }
41 
catch_enabled()42 bool catch_enabled()
43 {
44     return s_catch;
45 }
46 
run_catch()47 static bool run_catch()
48 {
49     Catch::Session session;
50 
51     if ( !test_tags.empty() )
52         session.configData().testsOrTags = test_tags;
53 
54     return session.run() == 0;
55 }
56 
catch_test()57 int catch_test()
58 {
59     if ( !run_catch() )
60         return -1;
61 
62     return 0;
63 }
64 
65 // This isn't in snort_catch.cc because the linker may exclude the file if no static components
66 // reference TestCaseInstaller
TestCaseInstaller(void (* fun)(),const char * name)67 SO_PUBLIC TestCaseInstaller::TestCaseInstaller(void(*fun)(), const char* name)
68 { REGISTER_TEST_CASE(fun, name) }
69 
TestCaseInstaller(void (* fun)(),const char * name,const char * group)70 SO_PUBLIC TestCaseInstaller::TestCaseInstaller(void(*fun)(), const char* name, const char* group)
71 { REGISTER_TEST_CASE(fun, name, group) }
72