46 NO_FAILURE, NON_FATAL_FAILURE, FATAL_FAILURE
52 MyEnvironment() {
Reset(); }
57 virtual void SetUp() {
58 set_up_was_run_ =
true;
60 switch (failure_in_set_up_) {
61 case NON_FATAL_FAILURE:
62 ADD_FAILURE() <<
"Expected non-fatal failure in global set-up.";
65 FAIL() <<
"Expected fatal failure in global set-up.";
73 virtual void TearDown() {
74 tear_down_was_run_ =
true;
75 ADD_FAILURE() <<
"Expected non-fatal failure in global tear-down.";
80 failure_in_set_up_ = NO_FAILURE;
81 set_up_was_run_ =
false;
82 tear_down_was_run_ =
false;
87 void set_failure_in_set_up(FailureType type) {
88 failure_in_set_up_ =
type;
92 bool set_up_was_run()
const {
return set_up_was_run_; }
95 bool tear_down_was_run()
const {
return tear_down_was_run_; }
98 FailureType failure_in_set_up_;
100 bool tear_down_was_run_;
113void Check(
bool condition,
const char* msg) {
115 printf(
"FAILED: %s\n", msg);
124int RunAllTests(MyEnvironment* env, FailureType failure) {
126 env->set_failure_in_set_up(failure);
127 test_was_run =
false;
139 MyEnvironment*
const env =
new MyEnvironment;
141 "AddGlobalTestEnvironment() should return its argument.");
146 "RUN_ALL_TESTS() should return non-zero, as the global tear-down "
147 "should generate a failure.");
149 "The tests should run, as the global set-up should generate no "
151 Check(env->tear_down_was_run(),
152 "The global tear-down should run, as the global set-up was run.");
157 "RUN_ALL_TESTS() should return non-zero, as both the global set-up "
158 "and the global tear-down should generate a non-fatal failure.");
160 "The tests should run, as the global set-up should generate no "
162 Check(env->tear_down_was_run(),
163 "The global tear-down should run, as the global set-up was run.");
168 "RUN_ALL_TESTS() should return non-zero, as the global set-up "
169 "should generate a fatal failure.");
171 "The tests should not run, as the global set-up should generate "
173 Check(env->tear_down_was_run(),
174 "The global tear-down should run, as the global set-up was run.");
178 testing::GTEST_FLAG(filter) =
"-*";
180 "RUN_ALL_TESTS() should return zero, as there is no test to run.");
181 Check(!env->set_up_was_run(),
182 "The global set-up should not run, as there is no test to run.");
183 Check(!env->tear_down_was_run(),
184 "The global tear-down should not run, "
185 "as the global set-up was not run.");
void ClearAdHocTestResult()
#define GTEST_DECLARE_string_(name)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
#define TEST(test_case_name, test_name)
LOGGING_API void printf(Category category, const char *format,...)
class UnitTestImpl * GetUnitTestImpl()
Environment * AddGlobalTestEnvironment(Environment *env)
GTEST_API_ void InitGoogleTest(int *argc, char **argv)