37 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ 38 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ 54 #if GTEST_HAS_DEATH_TEST 79 static bool Create(
const char* statement,
const RE* regex,
80 const char* file,
int line, DeathTest** test);
82 virtual ~DeathTest() { }
85 class ReturnSentinel {
87 explicit ReturnSentinel(DeathTest* test) : test_(test) { }
88 ~ReturnSentinel() { test_->Abort(TEST_ENCOUNTERED_RETURN_STATEMENT); }
90 DeathTest*
const test_;
99 enum TestRole { OVERSEE_TEST, EXECUTE_TEST };
103 TEST_ENCOUNTERED_RETURN_STATEMENT,
104 TEST_THREW_EXCEPTION,
109 virtual TestRole AssumeRole() = 0;
112 virtual int Wait() = 0;
121 virtual bool Passed(
bool exit_status_ok) = 0;
124 virtual void Abort(AbortReason reason) = 0;
128 static const char* LastMessage();
130 static void set_last_death_test_message(
const String&
message);
134 static String last_death_test_message_;
140 class DeathTestFactory {
142 virtual ~DeathTestFactory() { }
143 virtual bool Create(
const char* statement,
const RE* regex,
144 const char* file,
int line, DeathTest** test) = 0;
148 class DefaultDeathTestFactory :
public DeathTestFactory {
150 virtual bool Create(
const char* statement,
const RE* regex,
151 const char* file,
int line, DeathTest** test);
156 GTEST_API_ bool ExitedUnsuccessfully(
int exit_status);
160 # if GTEST_HAS_EXCEPTIONS 161 # define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ 163 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ 164 } catch (const ::std::exception& gtest_exception) { \ 167 "\n%s: Caught std::exception-derived exception escaping the " \ 168 "death test statement. Exception message: %s\n", \ 169 ::testing::internal::FormatFileLocation(__FILE__, __LINE__).c_str(), \ 170 gtest_exception.what()); \ 172 death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \ 174 death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \ 178 # define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ 179 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) 185 # define GTEST_DEATH_TEST_(statement, predicate, regex, fail) \ 186 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 187 if (::testing::internal::AlwaysTrue()) { \ 188 const ::testing::internal::RE& gtest_regex = (regex); \ 189 ::testing::internal::DeathTest* gtest_dt; \ 190 if (!::testing::internal::DeathTest::Create(#statement, >est_regex, \ 191 __FILE__, __LINE__, >est_dt)) { \ 192 goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \ 194 if (gtest_dt != NULL) { \ 195 ::testing::internal::scoped_ptr< ::testing::internal::DeathTest> \ 196 gtest_dt_ptr(gtest_dt); \ 197 switch (gtest_dt->AssumeRole()) { \ 198 case ::testing::internal::DeathTest::OVERSEE_TEST: \ 199 if (!gtest_dt->Passed(predicate(gtest_dt->Wait()))) { \ 200 goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \ 203 case ::testing::internal::DeathTest::EXECUTE_TEST: { \ 204 ::testing::internal::DeathTest::ReturnSentinel \ 205 gtest_sentinel(gtest_dt); \ 206 GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \ 207 gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \ 215 GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__): \ 216 fail(::testing::internal::DeathTest::LastMessage()) 223 class InternalRunDeathTestFlag {
225 InternalRunDeathTestFlag(
const String& a_file,
229 : file_(a_file), line_(a_line), index_(an_index),
230 write_fd_(a_write_fd) {}
232 ~InternalRunDeathTestFlag() {
237 String file()
const {
return file_; }
238 int line()
const {
return line_; }
239 int index()
const {
return index_; }
240 int write_fd()
const {
return write_fd_; }
254 InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag();
256 #else // GTEST_HAS_DEATH_TEST 290 # define GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, terminator) \ 291 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 292 if (::testing::internal::AlwaysTrue()) { \ 293 GTEST_LOG_(WARNING) \ 294 << "Death tests are not supported on this platform.\n" \ 295 << "Statement '" #statement "' cannot be verified."; \ 296 } else if (::testing::internal::AlwaysFalse()) { \ 297 ::testing::internal::RE::PartialMatch(".*", (regex)); \ 298 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ 303 #endif // GTEST_HAS_DEATH_TEST 308 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ Definition: gmock-actions.h:49
class GTEST_API_ testing::internal::ScopedTrace GTEST_ATTRIBUTE_UNUSED_
const char kDeathTestUseFork[]
Definition: gtest-death-test-internal.h:51
#define GTEST_API_
Definition: gtest-port.h:662
Output level, used for messages directed to the user (e.g. "Press any key to continue") ...
Definition: OutputDefinitions.h:89
const char kInternalRunDeathTestFlag[]
Definition: gtest-death-test-internal.h:52
const char kDeathTestStyleFlag[]
Definition: gtest-death-test-internal.h:50
GTEST_DECLARE_string_(internal_run_death_test)
Definition: gtest-string.h:81
Definition: gtest-port.h:809
int Close(int fd)
Definition: gtest-port.h:1637
void Abort()
Definition: gtest-port.h:1664
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
Definition: gtest-port.h:620