• 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_TEST_DATA_HELPERS_H
17 #define META_TEST_TEST_DATA_HELPERS_H
18 
19 #include <tuple>
20 #include <type_traits>
21 
22 #include <gtest/gtest.h>
23 
24 #include <base/containers/type_traits.h>
25 #include <base/containers/vector.h>
26 
27 #include <meta/base/namespace.h>
28 
29 META_BEGIN_NAMESPACE()
30 
31 template<typename T>
32 struct TType {
33     using Type = T;
34     BASE_NS::vector<std::function<Type()>> values;
35 
36     template<typename... Args, typename = BASE_NS::enable_if_t<std::conjunction_v<std::is_convertible<Args, Type>...>>>
TTypeTType37     TType(Args... args) : values { [args] { return static_cast<T>(args); }... }
38     {}
39 
TTypeTType40     TType(std::initializer_list<std::function<Type()>> values) : values { values } {}
41 };
42 
43 template<typename... T>
44 struct TestTypes {
45     using Types = ::testing::Types<T...>;
46     using Tuple = std::tuple<TType<T>...>;
47 
TestTypesTestTypes48     TestTypes(TType<T>... v) : values { v... } {}
49 
50     template<typename Type>
GetValueTestTypes51     auto GetValue(size_t index) const
52     {
53         auto v = std::get<TType<Type>>(values);
54         CORE_ASSERT_MSG(index < v.values.size(), "invalid test values");
55         return v.values[index]();
56     }
57 
58     Tuple values;
59 };
60 
61 META_END_NAMESPACE()
62 
63 #endif // META_TEST_TEST_DATA_HELPERS_H
64