blob: df01a9a81430569c5bc162e031240ba9a56e1f54 [file] [log] [blame]
Jiakai Zhang7b6aef72022-12-12 19:30:44 +00001/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_ARTD_TESTING_H_
18#define ART_ARTD_TESTING_H_
19
20// Returns the value of the given `android::base::Result`, or reports the error as a gMock matcher
21// mismatch. This is only to be used in a gMock matcher.
22#define OR_MISMATCH(expr) \
23 ({ \
24 decltype(expr)&& tmp__ = (expr); \
25 if (!tmp__.ok()) { \
26 *result_listener << tmp__.error().message(); \
27 return false; \
28 } \
29 std::move(tmp__).value(); \
30 })
31
32// Returns the value of the given `android::base::Result`, or fails the GoogleTest.
33#define OR_FAIL(expr) \
34 ({ \
35 decltype(expr)&& tmp__ = (expr); \
36 ASSERT_TRUE(tmp__.ok()) << tmp__.error().message(); \
37 std::move(tmp__).value(); \
38 })
39
40#endif // ART_ARTD_TESTING_H_