E-MailRelay

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gtest.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2018 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 //
18 // gtest.cpp
19 //
20
21 #include "gdef.h"
22 #include "gtest.h"
23 #include "gdebug.h"
24 #include "genvironment.h"
25 #include <string>
26 #include <set>
27
28 #if defined(_DEBUG) || defined(G_TEST_ENABLED)
29 namespace
30 {
31 bool done = false ;
32 std::string spec ;
33 }
34 void G::Test::set( const std::string & s )
35 {
36 done = true ;
37 spec = s ;
38 }
39 bool G::Test::enabled( const char * name )
40 {
41 if( !done )
42 {
43 spec = G::Environment::get("G_TEST",std::string()) ;
44 if( !spec.empty() )
45 spec = "," + spec + "," ;
46 }
47 done = true ;
48
49 bool result = spec.empty() ? false : ( spec.find(","+std::string(name)+",") != std::string::npos ) ;
50 if( result )
51 {
52 static std::set<std::string> warned ;
53 if( warned.find(name) == warned.end() )
54 {
55 warned.insert( name ) ;
56 G_WARNING( "G::Test::enabled: test case enabled: [" << name << "]" ) ;
57 }
58 }
59 return result ;
60 }
61 bool G::Test::enabled()
62 {
63 return true ;
64 }
65 #else
66 void G::Test::set( const std::string & )
67 {
68 }
69 bool G::Test::enabled()
70 {
71 return false ;
72 }
73 #endif
74 /// \file gtest.cpp
G::Environment::get
static std::string get(const std::string &name, const std::string &default_)
Returns the environment variable value or the given default.
Definition: genvironment_unix.cpp:25
G::Test::set
static void set(const std::string &)
Sets the test specification string.
Definition: gtest.cpp:66
gtest.h
G::Test::enabled
static bool enabled()
Returns true if test features are enabled.
Definition: gtest.cpp:69
genvironment.h
gdebug.h