1 // Copyright 2008, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 //     * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 //     * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 //     * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Author: wan@google.com (Zhanyong Wan)
31 
32 // A helper program for testing that Google Test parses the environment
33 // variables correctly.
34 
35 #include "gtest/gtest.h"
36 
37 #include <iostream>
38 
39 #define GTEST_IMPLEMENTATION_ 1
40 #include "src/gtest-internal-inl.h"
41 #undef GTEST_IMPLEMENTATION_
42 
43 using ::std::cout;
44 
45 namespace testing {
46 
47 // The purpose of this is to make the test more realistic by ensuring
48 // that the UnitTest singleton is created before main() is entered.
49 // We don't actual run the TEST itself.
TEST(GTestEnvVarTest,Dummy)50 TEST(GTestEnvVarTest, Dummy) {
51 }
52 
PrintFlag(const char * flag)53 void PrintFlag(const char* flag) {
54   if (strcmp(flag, "break_on_failure") == 0) {
55     cout << GTEST_FLAG(break_on_failure);
56     return;
57   }
58 
59   if (strcmp(flag, "catch_exceptions") == 0) {
60     cout << GTEST_FLAG(catch_exceptions);
61     return;
62   }
63 
64   if (strcmp(flag, "color") == 0) {
65     cout << GTEST_FLAG(color);
66     return;
67   }
68 
69   if (strcmp(flag, "death_test_style") == 0) {
70     cout << GTEST_FLAG(death_test_style);
71     return;
72   }
73 
74   if (strcmp(flag, "death_test_use_fork") == 0) {
75     cout << GTEST_FLAG(death_test_use_fork);
76     return;
77   }
78 
79   if (strcmp(flag, "filter") == 0) {
80     cout << GTEST_FLAG(filter);
81     return;
82   }
83 
84   if (strcmp(flag, "output") == 0) {
85     cout << GTEST_FLAG(output);
86     return;
87   }
88 
89   if (strcmp(flag, "print_time") == 0) {
90     cout << GTEST_FLAG(print_time);
91     return;
92   }
93 
94   if (strcmp(flag, "repeat") == 0) {
95     cout << GTEST_FLAG(repeat);
96     return;
97   }
98 
99   if (strcmp(flag, "stack_trace_depth") == 0) {
100     cout << GTEST_FLAG(stack_trace_depth);
101     return;
102   }
103 
104   if (strcmp(flag, "throw_on_failure") == 0) {
105     cout << GTEST_FLAG(throw_on_failure);
106     return;
107   }
108 
109   cout << "Invalid flag name " << flag
110        << ".  Valid names are break_on_failure, color, filter, etc.\n";
111   exit(1);
112 }
113 
114 }  // namespace testing
115 
main(int argc,char ** argv)116 int main(int argc, char** argv) {
117   testing::InitGoogleTest(&argc, argv);
118 
119   if (argc != 2) {
120     cout << "Usage: gtest_env_var_test_ NAME_OF_FLAG\n";
121     return 1;
122   }
123 
124   testing::PrintFlag(argv[1]);
125   return 0;
126 }
127