35 #include "gtest/gtest.h"
36 #include "src/gtest-internal-inl.h"
47 MyEnvironment() {
Reset(); }
52 void SetUp()
override {
53 set_up_was_run_ =
true;
55 switch (failure_in_set_up_) {
56 case NON_FATAL_FAILURE:
57 ADD_FAILURE() <<
"Expected non-fatal failure in global set-up.";
60 FAIL() <<
"Expected fatal failure in global set-up.";
69 tear_down_was_run_ =
true;
70 ADD_FAILURE() <<
"Expected non-fatal failure in global tear-down.";
75 failure_in_set_up_ = NO_FAILURE;
76 set_up_was_run_ =
false;
77 tear_down_was_run_ =
false;
82 void set_failure_in_set_up(FailureType
type) {
83 failure_in_set_up_ =
type;
87 bool set_up_was_run()
const {
return set_up_was_run_; }
90 bool tear_down_was_run()
const {
return tear_down_was_run_; }
93 FailureType failure_in_set_up_;
95 bool tear_down_was_run_;
108 void Check(
bool condition,
const char*
msg) {
121 env->set_failure_in_set_up(failure);
122 test_was_run =
false;
129 int main(
int argc,
char **argv) {
134 MyEnvironment*
const env =
new MyEnvironment;
136 "AddGlobalTestEnvironment() should return its argument.");
141 "RUN_ALL_TESTS() should return non-zero, as the global tear-down "
142 "should generate a failure.");
144 "The tests should run, as the global set-up should generate no "
147 "The global tear-down should run, as the global set-up was run.");
152 "RUN_ALL_TESTS() should return non-zero, as both the global set-up "
153 "and the global tear-down should generate a non-fatal failure.");
155 "The tests should run, as the global set-up should generate no "
158 "The global tear-down should run, as the global set-up was run.");
163 "RUN_ALL_TESTS() should return non-zero, as the global set-up "
164 "should generate a fatal failure.");
166 "The tests should not run, as the global set-up should generate "
169 "The global tear-down should run, as the global set-up was run.");
175 "RUN_ALL_TESTS() should return zero, as there is no test to run.");
177 "The global set-up should not run, as there is no test to run.");
179 "The global tear-down should not run, "
180 "as the global set-up was not run.");