38 #define GTEST_IMPLEMENTATION_ 1 // Required for the next #include. 40 #undef GTEST_IMPLEMENTATION_ 49 NO_FAILURE, NON_FATAL_FAILURE, FATAL_FAILURE
55 MyEnvironment() { Reset(); }
60 virtual void SetUp() {
61 set_up_was_run_ =
true;
63 switch (failure_in_set_up_) {
64 case NON_FATAL_FAILURE:
65 ADD_FAILURE() <<
"Expected non-fatal failure in global set-up.";
68 FAIL() <<
"Expected fatal failure in global set-up.";
76 virtual void TearDown() {
77 tear_down_was_run_ =
true;
78 ADD_FAILURE() <<
"Expected non-fatal failure in global tear-down.";
83 failure_in_set_up_ = NO_FAILURE;
84 set_up_was_run_ =
false;
85 tear_down_was_run_ =
false;
91 failure_in_set_up_ = type;
95 bool set_up_was_run()
const {
return set_up_was_run_; }
98 bool tear_down_was_run()
const {
return tear_down_was_run_; }
102 bool set_up_was_run_;
103 bool tear_down_was_run_;
116 void Check(
bool condition,
const char* msg) {
118 printf(
"FAILED: %s\n", msg);
129 env->set_failure_in_set_up(failure);
130 test_was_run =
false;
137 int main(
int argc,
char **argv) {
142 MyEnvironment*
const env =
new MyEnvironment;
144 "AddGlobalTestEnvironment() should return its argument.");
149 "RUN_ALL_TESTS() should return non-zero, as the global tear-down " 150 "should generate a failure.");
152 "The tests should run, as the global set-up should generate no " 154 Check(env->tear_down_was_run(),
155 "The global tear-down should run, as the global set-up was run.");
160 "RUN_ALL_TESTS() should return non-zero, as both the global set-up " 161 "and the global tear-down should generate a non-fatal failure.");
163 "The tests should run, as the global set-up should generate no " 165 Check(env->tear_down_was_run(),
166 "The global tear-down should run, as the global set-up was run.");
171 "RUN_ALL_TESTS() should return non-zero, as the global set-up " 172 "should generate a fatal failure.");
174 "The tests should not run, as the global set-up should generate " 176 Check(env->tear_down_was_run(),
177 "The global tear-down should run, as the global set-up was run.");
183 "RUN_ALL_TESTS() should return zero, as there is no test to run.");
184 Check(!env->set_up_was_run(),
185 "The global set-up should not run, as there is no test to run.");
186 Check(!env->tear_down_was_run(),
187 "The global tear-down should not run, " 188 "as the global set-up was not run.");
class UnitTestImpl * GetUnitTestImpl()
Environment * AddGlobalTestEnvironment(Environment *env)
void ClearAdHocTestResult()
bool GTEST_FLAG(internal_skip_environment_and_ad_hoc_tests)
GTEST_DECLARE_string_(death_test_style)
TEST(GTestEnvVarTest, Dummy)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
int main(int argc, char **argv)