1 /*
2  * Copyright (C) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef META_TEST_MACROS_HEADER
17 #define META_TEST_MACROS_HEADER
18 
19 #include <chrono>
20 
21 #include <gtest/gtest.h>
22 
23 
24 #define META_WAIT_TRUE_TIMED(millis, arg)                                                \
25     {                                                                                    \
26         auto end = std::chrono::steady_clock::now() + std::chrono::milliseconds(millis); \
27         while (!(arg) && std::chrono::steady_clock::now() < end) {                       \
28             std::this_thread::sleep_for(std::chrono::milliseconds(1));                   \
29         }                                                                                \
30     }
31 
32 #define EXPECT_TRUE_TIMED(millis, arg) \
33     META_WAIT_TRUE_TIMED(millis, arg); \
34     EXPECT_TRUE(arg);
35 
36 #define EXPECT_EQ_TIMED(millis, arg, value)         \
37     META_WAIT_TRUE_TIMED(millis, (arg) == (value)); \
38     EXPECT_EQ(arg, value);
39 
40 #define EXPECT_THAT_TIMED(millis, arg, matcher)                    \
41     META_WAIT_TRUE_TIMED(millis, (testing::Matches(matcher)(arg))); \
42     EXPECT_THAT(arg, matcher);
43 
44 #endif