45 NO_FAILURE, NON_FATAL_FAILURE, FATAL_FAILURE
51 MyEnvironment() { Reset(); }
56 void SetUp()
override {
57 set_up_was_run_ =
true;
59 switch (failure_in_set_up_) {
60 case NON_FATAL_FAILURE:
61 ADD_FAILURE() <<
"Expected non-fatal failure in global set-up.";
64 FAIL() <<
"Expected fatal failure in global set-up.";
73 tear_down_was_run_ =
true;
74 ADD_FAILURE() <<
"Expected non-fatal failure in global tear-down.";
79 failure_in_set_up_ = NO_FAILURE;
80 set_up_was_run_ =
false;
81 tear_down_was_run_ =
false;
87 failure_in_set_up_ = type;
91 bool set_up_was_run()
const {
return set_up_was_run_; }
94 bool tear_down_was_run()
const {
return tear_down_was_run_; }
99 bool tear_down_was_run_;
112 void Check(
bool condition,
const char* msg) {
114 printf(
"FAILED: %s\n", msg);
125 env->set_failure_in_set_up(failure);
126 test_was_run =
false;
127 testing::internal::GetUnitTestImpl()->ClearAdHocTestResult();
133 int main(
int argc,
char **argv) {
138 MyEnvironment*
const env =
new MyEnvironment;
140 "AddGlobalTestEnvironment() should return its argument.");
145 "RUN_ALL_TESTS() should return non-zero, as the global tear-down "
146 "should generate a failure.");
148 "The tests should run, as the global set-up should generate no "
150 Check(env->tear_down_was_run(),
151 "The global tear-down should run, as the global set-up was run.");
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.");
159 "The tests should run, as the global set-up should generate no "
161 Check(env->tear_down_was_run(),
162 "The global tear-down should run, as the global set-up was run.");
167 "RUN_ALL_TESTS() should return non-zero, as the global set-up "
168 "should generate a fatal failure.");
170 "The tests should not run, as the global set-up should generate "
172 Check(env->tear_down_was_run(),
173 "The global tear-down should run, as the global set-up was run.");
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.");
Environment * AddGlobalTestEnvironment(Environment *env)
#define TEST(test_suite_name, test_name)
GTEST_DECLARE_string_(death_test_style)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
GTEST_API_ void InitGoogleTest(int *argc, char **argv)