• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_TESTING_MACROS_HEADER
17 #define META_TEST_TESTING_MACROS_HEADER
18 
19 #include <chrono>
20 #include <thread>
21 
22 #include <gtest/gtest.h>
23 
24 #define META_WAIT_TIMED(millis) std::this_thread::sleep_for(std::chrono::milliseconds(millis));
25 
26 #define META_WAIT_TRUE_TIMED(millis, arg)                                                \
27     {                                                                                    \
28         auto end = std::chrono::steady_clock::now() + std::chrono::milliseconds(millis); \
29         while (!(arg) && std::chrono::steady_clock::now() < end) {                       \
30             std::this_thread::sleep_for(std::chrono::milliseconds(1));                   \
31         }                                                                                \
32     }
33 
34 #define EXPECT_TRUE_TIMED(millis, arg) \
35     META_WAIT_TRUE_TIMED(millis, arg); \
36     EXPECT_TRUE(arg);
37 
38 #define EXPECT_EQ_TIMED(millis, arg, value)         \
39     META_WAIT_TRUE_TIMED(millis, (arg) == (value)); \
40     EXPECT_EQ(arg, value);
41 
42 #define EXPECT_THAT_TIMED(millis, arg, matcher)                     \
43     META_WAIT_TRUE_TIMED(millis, (testing::Matches(matcher)(arg))); \
44     EXPECT_THAT(arg, matcher);
45 
46 #endif // META_TEST_TESTING_MACROS_HEADER
47