summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Gao2017-04-27 21:48:44 -0500
committerJosh Gao2017-12-19 19:16:12 -0600
commit30171a8b475df2989276f65dcc80fbaa786e1fba (patch)
treece803dcca3337951975fa15c1d5759a313849f57 /base/include/android-base/test_utils.h
parent51c2088f3be507f83c7580dd06c5e3c271116285 (diff)
downloadplatform-system-core-30171a8b475df2989276f65dcc80fbaa786e1fba.tar.gz
platform-system-core-30171a8b475df2989276f65dcc80fbaa786e1fba.tar.xz
platform-system-core-30171a8b475df2989276f65dcc80fbaa786e1fba.zip
base: extract {ASSERT,EXPECT}_MATCH helpers from debuggerd_test.
Add some helper macros that perform regex string matching to <android-base/test_utils.h>. Test: libbase_test32/64 on host Change-Id: I1b0f03dc73f8b4fdfb8ac6c75d59ef421e0e9640
Diffstat (limited to 'base/include/android-base/test_utils.h')
-rw-r--r--base/include/android-base/test_utils.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/base/include/android-base/test_utils.h b/base/include/android-base/test_utils.h
index 4cfa06ba5..2edafe344 100644
--- a/base/include/android-base/test_utils.h
+++ b/base/include/android-base/test_utils.h
@@ -17,6 +17,7 @@
17#ifndef ANDROID_BASE_TEST_UTILS_H 17#ifndef ANDROID_BASE_TEST_UTILS_H
18#define ANDROID_BASE_TEST_UTILS_H 18#define ANDROID_BASE_TEST_UTILS_H
19 19
20#include <regex>
20#include <string> 21#include <string>
21 22
22#include <android-base/macros.h> 23#include <android-base/macros.h>
@@ -70,4 +71,32 @@ class CapturedStderr {
70 DISALLOW_COPY_AND_ASSIGN(CapturedStderr); 71 DISALLOW_COPY_AND_ASSIGN(CapturedStderr);
71}; 72};
72 73
74#define ASSERT_MATCH(str, pattern) \
75 do { \
76 if (!std::regex_search((str), std::regex((pattern)))) { \
77 FAIL() << "regex mismatch: expected " << (pattern) << " in:\n" << (str); \
78 } \
79 } while (0)
80
81#define ASSERT_NOT_MATCH(str, pattern) \
82 do { \
83 if (std::regex_search((str), std::regex((pattern)))) { \
84 FAIL() << "regex mismatch: expected to not find " << (pattern) << " in:\n" << (str); \
85 } \
86 } while (0)
87
88#define EXPECT_MATCH(str, pattern) \
89 do { \
90 if (!std::regex_search((str), std::regex((pattern)))) { \
91 ADD_FAILURE() << "regex mismatch: expected " << (pattern) << " in:\n" << (str); \
92 } \
93 } while (0)
94
95#define EXPECT_NOT_MATCH(str, pattern) \
96 do { \
97 if (std::regex_search((str), std::regex((pattern)))) { \
98 ADD_FAILURE() << "regex mismatch: expected to not find " << (pattern) << " in:\n" << (str); \
99 } \
100 } while (0)
101
73#endif // ANDROID_BASE_TEST_UTILS_H 102#endif // ANDROID_BASE_TEST_UTILS_H