~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/gtest/include/gtest/internal/gtest-death-test-internal.h

  • Committer: mmach
  • Date: 2023-11-02 21:31:35 UTC
  • Revision ID: netbit73@gmail.com-20231102213135-18d4tzh7tj0uz752
2023-11-02 22:11:57

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
27
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
28
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 
//
 
29
 
30
30
// The Google C++ Testing and Mocking Framework (Google Test)
31
31
//
32
32
// This header file defines internal utilities needed for implementing
33
33
// death tests.  They are subject to change without notice.
34
 
// GOOGLETEST_CM0001 DO NOT DELETE
35
 
 
36
 
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
37
 
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
 
34
 
 
35
// IWYU pragma: private, include "gtest/gtest.h"
 
36
// IWYU pragma: friend gtest/.*
 
37
// IWYU pragma: friend gmock/.*
 
38
 
 
39
#ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
 
40
#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
 
41
 
 
42
#include <stdio.h>
 
43
 
 
44
#include <memory>
 
45
#include <string>
38
46
 
39
47
#include "gtest/gtest-matchers.h"
40
48
#include "gtest/internal/gtest-internal.h"
41
49
 
42
 
#include <stdio.h>
43
 
#include <memory>
 
50
GTEST_DECLARE_string_(internal_run_death_test);
44
51
 
45
52
namespace testing {
46
53
namespace internal {
47
54
 
48
 
GTEST_DECLARE_string_(internal_run_death_test);
49
 
 
50
55
// Names of the flags (needed for parsing Google Test flags).
51
56
const char kDeathTestStyleFlag[] = "death_test_style";
52
57
const char kDeathTestUseFork[] = "death_test_use_fork";
83
88
  static bool Create(const char* statement, Matcher<const std::string&> matcher,
84
89
                     const char* file, int line, DeathTest** test);
85
90
  DeathTest();
86
 
  virtual ~DeathTest() { }
 
91
  virtual ~DeathTest() {}
87
92
 
88
93
  // A helper class that aborts a death test when it's deleted.
89
94
  class ReturnSentinel {
90
95
   public:
91
 
    explicit ReturnSentinel(DeathTest* test) : test_(test) { }
 
96
    explicit ReturnSentinel(DeathTest* test) : test_(test) {}
92
97
    ~ReturnSentinel() { test_->Abort(TEST_ENCOUNTERED_RETURN_STATEMENT); }
 
98
 
93
99
   private:
94
100
    DeathTest* const test_;
95
 
    GTEST_DISALLOW_COPY_AND_ASSIGN_(ReturnSentinel);
96
 
  } GTEST_ATTRIBUTE_UNUSED_;
 
101
    ReturnSentinel(const ReturnSentinel&) = delete;
 
102
    ReturnSentinel& operator=(const ReturnSentinel&) = delete;
 
103
  };
97
104
 
98
105
  // An enumeration of possible roles that may be taken when a death
99
106
  // test is encountered.  EXECUTE means that the death test logic should
137
144
  // A string containing a description of the outcome of the last death test.
138
145
  static std::string last_death_test_message_;
139
146
 
140
 
  GTEST_DISALLOW_COPY_AND_ASSIGN_(DeathTest);
 
147
  DeathTest(const DeathTest&) = delete;
 
148
  DeathTest& operator=(const DeathTest&) = delete;
141
149
};
142
150
 
143
151
GTEST_DISABLE_MSC_WARNINGS_POP_()  //  4251
145
153
// Factory interface for death tests.  May be mocked out for testing.
146
154
class DeathTestFactory {
147
155
 public:
148
 
  virtual ~DeathTestFactory() { }
 
156
  virtual ~DeathTestFactory() {}
149
157
  virtual bool Create(const char* statement,
150
158
                      Matcher<const std::string&> matcher, const char* file,
151
159
                      int line, DeathTest** test) = 0;
186
194
 
187
195
// Traps C++ exceptions escaping statement and reports them as test
188
196
// failures. Note that trapping SEH exceptions is not implemented here.
189
 
# if GTEST_HAS_EXCEPTIONS
190
 
#  define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \
191
 
  try { \
192
 
    GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
193
 
  } catch (const ::std::exception& gtest_exception) { \
194
 
    fprintf(\
195
 
        stderr, \
196
 
        "\n%s: Caught std::exception-derived exception escaping the " \
197
 
        "death test statement. Exception message: %s\n", \
 
197
#if GTEST_HAS_EXCEPTIONS
 
198
#define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test)           \
 
199
  try {                                                                      \
 
200
    GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement);               \
 
201
  } catch (const ::std::exception& gtest_exception) {                        \
 
202
    fprintf(                                                                 \
 
203
        stderr,                                                              \
 
204
        "\n%s: Caught std::exception-derived exception escaping the "        \
 
205
        "death test statement. Exception message: %s\n",                     \
198
206
        ::testing::internal::FormatFileLocation(__FILE__, __LINE__).c_str(), \
199
 
        gtest_exception.what()); \
200
 
    fflush(stderr); \
 
207
        gtest_exception.what());                                             \
 
208
    fflush(stderr);                                                          \
201
209
    death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \
202
 
  } catch (...) { \
 
210
  } catch (...) {                                                            \
203
211
    death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \
204
212
  }
205
213
 
206
 
# else
207
 
#  define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \
 
214
#else
 
215
#define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \
208
216
  GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
209
217
 
210
 
# endif
 
218
#endif
211
219
 
212
220
// This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*,
213
221
// ASSERT_EXIT*, and EXPECT_EXIT*.
236
244
          gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE);   \
237
245
          break;                                                               \
238
246
        }                                                                      \
239
 
        default:                                                               \
240
 
          break;                                                               \
241
247
      }                                                                        \
242
248
    }                                                                          \
243
249
  } else                                                                       \
265
271
// RUN_ALL_TESTS was called.
266
272
class InternalRunDeathTestFlag {
267
273
 public:
268
 
  InternalRunDeathTestFlag(const std::string& a_file,
269
 
                           int a_line,
270
 
                           int an_index,
 
274
  InternalRunDeathTestFlag(const std::string& a_file, int a_line, int an_index,
271
275
                           int a_write_fd)
272
 
      : file_(a_file), line_(a_line), index_(an_index),
273
 
        write_fd_(a_write_fd) {}
 
276
      : file_(a_file), line_(a_line), index_(an_index), write_fd_(a_write_fd) {}
274
277
 
275
278
  ~InternalRunDeathTestFlag() {
276
 
    if (write_fd_ >= 0)
277
 
      posix::Close(write_fd_);
 
279
    if (write_fd_ >= 0) posix::Close(write_fd_);
278
280
  }
279
281
 
280
282
  const std::string& file() const { return file_; }
288
290
  int index_;
289
291
  int write_fd_;
290
292
 
291
 
  GTEST_DISALLOW_COPY_AND_ASSIGN_(InternalRunDeathTestFlag);
 
293
  InternalRunDeathTestFlag(const InternalRunDeathTestFlag&) = delete;
 
294
  InternalRunDeathTestFlag& operator=(const InternalRunDeathTestFlag&) = delete;
292
295
};
293
296
 
294
297
// Returns a newly created InternalRunDeathTestFlag object with fields
301
304
}  // namespace internal
302
305
}  // namespace testing
303
306
 
304
 
#endif  // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
 
307
#endif  // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_