tesseract v5.3.3.20231005
gtest_environment_test.cc File Reference
#include <stdlib.h>
#include <stdio.h>
#include "gtest/gtest.h"
#include "src/gtest-internal-inl.h"

Go to the source code of this file.

Namespaces

namespace  testing
 

Functions

 testing::GTEST_DECLARE_string_ (filter)
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 133 of file gtest_environment_test.cc.

133 {
134 testing::InitGoogleTest(&argc, argv);
135
136 // Registers a global test environment, and verifies that the
137 // registration function returns its argument.
138 MyEnvironment* const env = new MyEnvironment;
139 Check(testing::AddGlobalTestEnvironment(env) == env,
140 "AddGlobalTestEnvironment() should return its argument.");
141
142 // Verifies that RUN_ALL_TESTS() runs the tests when the global
143 // set-up is successful.
144 Check(RunAllTests(env, NO_FAILURE) != 0,
145 "RUN_ALL_TESTS() should return non-zero, as the global tear-down "
146 "should generate a failure.");
147 Check(test_was_run,
148 "The tests should run, as the global set-up should generate no "
149 "failure");
150 Check(env->tear_down_was_run(),
151 "The global tear-down should run, as the global set-up was run.");
152
153 // Verifies that RUN_ALL_TESTS() runs the tests when the global
154 // set-up generates no fatal failure.
155 Check(RunAllTests(env, NON_FATAL_FAILURE) != 0,
156 "RUN_ALL_TESTS() should return non-zero, as both the global set-up "
157 "and the global tear-down should generate a non-fatal failure.");
158 Check(test_was_run,
159 "The tests should run, as the global set-up should generate no "
160 "fatal failure.");
161 Check(env->tear_down_was_run(),
162 "The global tear-down should run, as the global set-up was run.");
163
164 // Verifies that RUN_ALL_TESTS() runs no test when the global set-up
165 // generates a fatal failure.
166 Check(RunAllTests(env, FATAL_FAILURE) != 0,
167 "RUN_ALL_TESTS() should return non-zero, as the global set-up "
168 "should generate a fatal failure.");
169 Check(!test_was_run,
170 "The tests should not run, as the global set-up should generate "
171 "a fatal failure.");
172 Check(env->tear_down_was_run(),
173 "The global tear-down should run, as the global set-up was run.");
174
175 // Verifies that RUN_ALL_TESTS() doesn't do global set-up or
176 // tear-down when there is no test to run.
177 testing::GTEST_FLAG(filter) = "-*";
178 Check(RunAllTests(env, NO_FAILURE) == 0,
179 "RUN_ALL_TESTS() should return zero, as there is no test to run.");
180 Check(!env->set_up_was_run(),
181 "The global set-up should not run, as there is no test to run.");
182 Check(!env->tear_down_was_run(),
183 "The global tear-down should not run, "
184 "as the global set-up was not run.");
185
186 printf("PASS\n");
187 return 0;
188}
#define GTEST_FLAG(name)
Definition: gtest-port.h:2205
int RunAllTests()
Environment * AddGlobalTestEnvironment(Environment *env)
Definition: gtest.h:1493
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: gtest.cc:6660