1 /*
2 * Copyright (c) 2022 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_UTIL_HEADER
17 #define META_TEST_UTIL_HEADER
18
19 #include <base/containers/vector.h>
20 #include <core/log.h>
21
22 #include <meta/interface/intf_object_registry.h>
23 #include <meta/interface/property/construct_property.h>
24
META_BEGIN_NAMESPACE()25 META_BEGIN_NAMESPACE()
26
27 template<typename T>
28 typename META_NS::Property<T> CreateProperty(BASE_NS::string_view name = "", T value = {})
29 {
30 return ConstructProperty<T>(name, value);
31 }
32
33 META_END_NAMESPACE()
34
35 BASE_BEGIN_NAMESPACE()
36
37 // our vector does not have op==
38 template<typename T>
39 bool operator==(const BASE_NS::vector<T>& l, const BASE_NS::vector<T>& r)
40 {
41 if (l.size() != r.size()) {
42 return false;
43 }
44 auto it1 = l.begin();
45 auto it2 = r.begin();
46 for (; it1 != l.end(); ++it1, ++it2) {
47 if constexpr (META_NS::HasEqualOperator_v<T>) {
48 if (!(*it1 == *it2)) {
49 return false;
50 }
51 } else {
52 return false;
53 }
54 }
55 return true;
56 }
57
58 template<typename T>
59 bool operator!=(const BASE_NS::vector<T>& l, const BASE_NS::vector<T>& r)
60 {
61 return !(l == r);
62 }
63
64 BASE_END_NAMESPACE()
65
66 #endif // META_TEST_UTIL_HEADER
67