36#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
37#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
53#if GTEST_HAS_DEATH_TEST
78 static bool Create(
const char* statement,
const RE* regex,
79 const char* file,
int line, DeathTest** test);
81 virtual ~DeathTest() { }
84 class ReturnSentinel {
86 explicit ReturnSentinel(DeathTest* test) : test_(test) { }
87 ~ReturnSentinel() { test_->Abort(TEST_ENCOUNTERED_RETURN_STATEMENT); }
89 DeathTest*
const test_;
98 enum TestRole { OVERSEE_TEST, EXECUTE_TEST };
102 TEST_ENCOUNTERED_RETURN_STATEMENT,
103 TEST_THREW_EXCEPTION,
108 virtual TestRole AssumeRole() = 0;
111 virtual int Wait() = 0;
120 virtual bool Passed(
bool exit_status_ok) = 0;
123 virtual void Abort(AbortReason reason) = 0;
127 static const char* LastMessage();
129 static void set_last_death_test_message(
const std::string& message);
133 static std::string last_death_test_message_;
139class DeathTestFactory {
141 virtual ~DeathTestFactory() { }
142 virtual bool Create(
const char* statement,
const RE* regex,
143 const char* file,
int line, DeathTest** test) = 0;
147class DefaultDeathTestFactory :
public DeathTestFactory {
149 virtual bool Create(
const char* statement,
const RE* regex,
150 const char* file,
int line, DeathTest** test);
155GTEST_API_ bool ExitedUnsuccessfully(
int exit_status);
159# if GTEST_HAS_EXCEPTIONS
160# define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \
162 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
163 } catch (const ::std::exception& gtest_exception) { \
166 "\n%s: Caught std::exception-derived exception escaping the " \
167 "death test statement. Exception message: %s\n", \
168 ::testing::internal::FormatFileLocation(__FILE__, __LINE__).c_str(), \
169 gtest_exception.what()); \
171 death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \
173 death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \
177# define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \
178 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
184# define GTEST_DEATH_TEST_(statement, predicate, regex, fail) \
185 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
186 if (::testing::internal::AlwaysTrue()) { \
187 const ::testing::internal::RE& gtest_regex = (regex); \
188 ::testing::internal::DeathTest* gtest_dt; \
189 if (!::testing::internal::DeathTest::Create(#statement, >est_regex, \
190 __FILE__, __LINE__, >est_dt)) { \
191 goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \
193 if (gtest_dt != NULL) { \
194 ::testing::internal::scoped_ptr< ::testing::internal::DeathTest> \
195 gtest_dt_ptr(gtest_dt); \
196 switch (gtest_dt->AssumeRole()) { \
197 case ::testing::internal::DeathTest::OVERSEE_TEST: \
198 if (!gtest_dt->Passed(predicate(gtest_dt->Wait()))) { \
199 goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \
202 case ::testing::internal::DeathTest::EXECUTE_TEST: { \
203 ::testing::internal::DeathTest::ReturnSentinel \
204 gtest_sentinel(gtest_dt); \
205 GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \
206 gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \
214 GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__): \
215 fail(::testing::internal::DeathTest::LastMessage())
224#define GTEST_EXECUTE_STATEMENT_(statement, regex) \
225 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
226 if (::testing::internal::AlwaysTrue()) { \
227 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
228 } else if (!::testing::internal::AlwaysTrue()) { \
229 const ::testing::internal::RE& gtest_regex = (regex); \
230 static_cast<void>(gtest_regex); \
237class InternalRunDeathTestFlag {
239 InternalRunDeathTestFlag(
const std::string& a_file,
243 : file_(a_file), line_(a_line), index_(an_index),
244 write_fd_(a_write_fd) {}
246 ~InternalRunDeathTestFlag() {
251 const std::string& file()
const {
return file_; }
252 int line()
const {
return line_; }
253 int index()
const {
return index_; }
254 int write_fd()
const {
return write_fd_; }
268InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag();
#define GTEST_ATTRIBUTE_UNUSED_
#define GTEST_DECLARE_string_(name)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
const char kDeathTestStyleFlag[]
const char kDeathTestUseFork[]
const char kInternalRunDeathTestFlag[]