Flutter Engine
The Flutter Engine
gtest_util.h
Go to the documentation of this file.
1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BASE_TEST_GTEST_UTIL_H_
6#define BASE_TEST_GTEST_UTIL_H_
7
8#include <string>
9#include <utility>
10#include <vector>
11
13#include "build/build_config.h"
14#include "gtest/gtest.h"
15
16// EXPECT/ASSERT_DCHECK_DEATH is intended to replace EXPECT/ASSERT_DEBUG_DEATH
17// when the death is expected to be caused by a DCHECK. Contrary to
18// EXPECT/ASSERT_DEBUG_DEATH however, it doesn't execute the statement in non-
19// dcheck builds as DCHECKs are intended to catch things that should never
20// happen and as such executing the statement results in undefined behavior
21// (|statement| is compiled in unsupported configurations nonetheless).
22// Death tests misbehave on Android.
23// TODO(gw280): once https://github.com/flutter/flutter/issues/78491 is resolved
24// we can potentially remove the condition on NDEBUG here.
25#if defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) && !defined(NDEBUG)
26
27// EXPECT/ASSERT_DCHECK_DEATH tests verify that a DCHECK is hit ("Check failed"
28// is part of the error message), but intentionally do not expose the gtest
29// death test's full |regex| parameter to avoid users having to verify the exact
30// syntax of the error message produced by the DCHECK.
31#define EXPECT_DCHECK_DEATH(statement) EXPECT_DEATH(statement, "Check failed")
32#define ASSERT_DCHECK_DEATH(statement) ASSERT_DEATH(statement, "Check failed")
33
34#else
35// defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) && !defined(NDEBUG)
36
37#define EXPECT_DCHECK_DEATH(statement) \
38 GTEST_UNSUPPORTED_DEATH_TEST(statement, "Check failed", )
39#define ASSERT_DCHECK_DEATH(statement) \
40 GTEST_UNSUPPORTED_DEATH_TEST(statement, "Check failed", return)
41
42#endif
43// defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) && !defined(NDEBUG)
44
45// As above, but for CHECK().
46#if defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
47
48// Official builds will eat stream parameters, so don't check the error message.
49#if defined(OFFICIAL_BUILD) && defined(NDEBUG)
50#define EXPECT_CHECK_DEATH(statement) EXPECT_DEATH(statement, "")
51#define ASSERT_CHECK_DEATH(statement) ASSERT_DEATH(statement, "")
52#else
53#define EXPECT_CHECK_DEATH(statement) EXPECT_DEATH(statement, "Check failed")
54#define ASSERT_CHECK_DEATH(statement) ASSERT_DEATH(statement, "Check failed")
55#endif // defined(OFFICIAL_BUILD) && defined(NDEBUG)
56
57#else // defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
58
59// Note GTEST_UNSUPPORTED_DEATH_TEST takes a |regex| only to see whether it is a
60// valid regex. It is never evaluated.
61#define EXPECT_CHECK_DEATH(statement) \
62 GTEST_UNSUPPORTED_DEATH_TEST(statement, "", )
63#define ASSERT_CHECK_DEATH(statement) \
64 GTEST_UNSUPPORTED_DEATH_TEST(statement, "", return)
65
66#endif // defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
67
68#endif // BASE_TEST_GTEST_UTIL_H_