18bf80f4bSopenharmony_ci/* 28bf80f4bSopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd. 38bf80f4bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48bf80f4bSopenharmony_ci * you may not use this file except in compliance with the License. 58bf80f4bSopenharmony_ci * You may obtain a copy of the License at 68bf80f4bSopenharmony_ci * 78bf80f4bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88bf80f4bSopenharmony_ci * 98bf80f4bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108bf80f4bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118bf80f4bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128bf80f4bSopenharmony_ci * See the License for the specific language governing permissions and 138bf80f4bSopenharmony_ci * limitations under the License. 148bf80f4bSopenharmony_ci */ 158bf80f4bSopenharmony_ci 168bf80f4bSopenharmony_ci#ifndef META_TEST_TESTING_OBJECTS_HEADER 178bf80f4bSopenharmony_ci#define META_TEST_TESTING_OBJECTS_HEADER 188bf80f4bSopenharmony_ci 198bf80f4bSopenharmony_ci#include <meta/api/make_callback.h> 208bf80f4bSopenharmony_ci#include <meta/base/types.h> 218bf80f4bSopenharmony_ci#include <meta/interface/interface_macros.h> 228bf80f4bSopenharmony_ci#include <meta/interface/intf_container.h> 238bf80f4bSopenharmony_ci#include <meta/interface/object_macros.h> 248bf80f4bSopenharmony_ci#include <meta/interface/property/intf_property.h> 258bf80f4bSopenharmony_ci#include <meta/interface/property/property_events.h> 268bf80f4bSopenharmony_ci 278bf80f4bSopenharmony_ci#include "meta/base/time_span.h" 288bf80f4bSopenharmony_ci#include "meta/interface/intf_startable.h" 298bf80f4bSopenharmony_ci 308bf80f4bSopenharmony_ciREGISTER_CLASS(EmbeddedTestType, "4a3bd491-1111-4a9a-bcad-92530493be09", ObjectCategoryBits::NO_CATEGORY) 318bf80f4bSopenharmony_ciREGISTER_CLASS(TestType, "766fadc7-1767-42fd-a60a-f974e25e6cc9", ObjectCategoryBits::NO_CATEGORY, "Test type") 328bf80f4bSopenharmony_ciREGISTER_CLASS( 338bf80f4bSopenharmony_ci TestAttachment, "0c45ff57-14f5-4d31-9a93-2e22eea99f75", ObjectCategoryBits::NO_CATEGORY, "Test attachment") 348bf80f4bSopenharmony_ciREGISTER_CLASS(TestStartable, "e9470f5b-97ce-404c-9d1e-b37a4f1ac594", ObjectCategoryBits::NO_CATEGORY, "Test startable") 358bf80f4bSopenharmony_ci 368bf80f4bSopenharmony_ciMETA_REGISTER_CLASS(TestContainer, "bb8fe547-6f70-4552-b269-9bcb55c27f8a", ObjectCategoryBits::NO_CATEGORY) 378bf80f4bSopenharmony_ciMETA_REGISTER_CLASS(TestFlatContainer, "cc9fe547-6f70-4552-b269-9bcb55c27f8a", ObjectCategoryBits::NO_CATEGORY) 388bf80f4bSopenharmony_ciMETA_REGISTER_CLASS(TestString, "96f87fd0-aabb-4223-8ccf-24662be1dec1", ObjectCategoryBits::NO_CATEGORY) 398bf80f4bSopenharmony_ciMETA_REGISTER_CLASS(TestPtrValue, "f77b3c6b-312a-4102-a8ed-a2442b2a8872", ObjectCategoryBits::NO_CATEGORY) 408bf80f4bSopenharmony_ci 418bf80f4bSopenharmony_ciREGISTER_INTERFACE(IEmbeddedTestType, "f66fbf28-ba2c-49dc-8521-c552cb104815") 428bf80f4bSopenharmony_ciREGISTER_INTERFACE(IEmbeddedTestType2, "f77fbf28-ba2c-49dc-8521-c552cb104815", "Some type") 438bf80f4bSopenharmony_ci 448bf80f4bSopenharmony_ciMETA_REGISTER_INTERFACE(ITestType, "7c327d8f-3930-478f-b91b-8ddef8a52f3e", "This is test type") 458bf80f4bSopenharmony_ciMETA_REGISTER_INTERFACE(ITestContainer, "456195cf-f539-4572-ba9d-3fd87e75ff08") 468bf80f4bSopenharmony_ciMETA_REGISTER_INTERFACE(ITestAttachment, "0af32c00-9037-47f9-b7dd-3e43679ffdfa", "This is test attachment") 478bf80f4bSopenharmony_ciMETA_REGISTER_INTERFACE(ITestStartable, "bb8188a9-aeca-4414-98c3-7a989d54d430", "This is test startable") 488bf80f4bSopenharmony_ciMETA_REGISTER_INTERFACE(ITestPtrValue, "55a8c04d-ae8f-4dfe-b604-2f31ea07e23b", "This is test type") 498bf80f4bSopenharmony_ci 508bf80f4bSopenharmony_ciusing BASE_NS::string; 518bf80f4bSopenharmony_ci 528bf80f4bSopenharmony_cistruct MyComparableTestType { 538bf80f4bSopenharmony_ci float i = 0; 548bf80f4bSopenharmony_ci 558bf80f4bSopenharmony_ci constexpr bool operator==(float value) const 568bf80f4bSopenharmony_ci { 578bf80f4bSopenharmony_ci return i == value; 588bf80f4bSopenharmony_ci } 598bf80f4bSopenharmony_ci constexpr bool operator!=(float value) const 608bf80f4bSopenharmony_ci { 618bf80f4bSopenharmony_ci return i != value; 628bf80f4bSopenharmony_ci } 638bf80f4bSopenharmony_ci 648bf80f4bSopenharmony_ci constexpr bool operator==(const MyComparableTestType& other) const 658bf80f4bSopenharmony_ci { 668bf80f4bSopenharmony_ci return i == other.i; 678bf80f4bSopenharmony_ci } 688bf80f4bSopenharmony_ci constexpr bool operator!=(const MyComparableTestType& other) const 698bf80f4bSopenharmony_ci { 708bf80f4bSopenharmony_ci return i != other.i; 718bf80f4bSopenharmony_ci } 728bf80f4bSopenharmony_ci 738bf80f4bSopenharmony_ci constexpr bool operator<(const MyComparableTestType& other) const 748bf80f4bSopenharmony_ci { 758bf80f4bSopenharmony_ci return i < other.i; 768bf80f4bSopenharmony_ci } 778bf80f4bSopenharmony_ci constexpr bool operator>(const MyComparableTestType& other) const 788bf80f4bSopenharmony_ci { 798bf80f4bSopenharmony_ci return i > other.i; 808bf80f4bSopenharmony_ci } 818bf80f4bSopenharmony_ci constexpr MyComparableTestType& operator*=(float value) 828bf80f4bSopenharmony_ci { 838bf80f4bSopenharmony_ci i *= value; 848bf80f4bSopenharmony_ci return *this; 858bf80f4bSopenharmony_ci } 868bf80f4bSopenharmony_ci constexpr MyComparableTestType& operator/=(float value) 878bf80f4bSopenharmony_ci { 888bf80f4bSopenharmony_ci i /= value; 898bf80f4bSopenharmony_ci return *this; 908bf80f4bSopenharmony_ci } 918bf80f4bSopenharmony_ci constexpr MyComparableTestType& operator+=(float value) 928bf80f4bSopenharmony_ci { 938bf80f4bSopenharmony_ci i += value; 948bf80f4bSopenharmony_ci return *this; 958bf80f4bSopenharmony_ci } 968bf80f4bSopenharmony_ci constexpr MyComparableTestType& operator-=(float value) 978bf80f4bSopenharmony_ci { 988bf80f4bSopenharmony_ci i -= value; 998bf80f4bSopenharmony_ci return *this; 1008bf80f4bSopenharmony_ci } 1018bf80f4bSopenharmony_ci constexpr MyComparableTestType operator*(float value) const 1028bf80f4bSopenharmony_ci { 1038bf80f4bSopenharmony_ci return MyComparableTestType { i * value }; 1048bf80f4bSopenharmony_ci } 1058bf80f4bSopenharmony_ci constexpr MyComparableTestType operator/(float value) const 1068bf80f4bSopenharmony_ci { 1078bf80f4bSopenharmony_ci return MyComparableTestType { i / value }; 1088bf80f4bSopenharmony_ci } 1098bf80f4bSopenharmony_ci constexpr MyComparableTestType operator+(float value) const 1108bf80f4bSopenharmony_ci { 1118bf80f4bSopenharmony_ci return MyComparableTestType { i + value }; 1128bf80f4bSopenharmony_ci } 1138bf80f4bSopenharmony_ci constexpr MyComparableTestType operator-(float value) const 1148bf80f4bSopenharmony_ci { 1158bf80f4bSopenharmony_ci return MyComparableTestType { i - value }; 1168bf80f4bSopenharmony_ci } 1178bf80f4bSopenharmony_ci 1188bf80f4bSopenharmony_ci constexpr MyComparableTestType operator*(MyComparableTestType value) const 1198bf80f4bSopenharmony_ci { 1208bf80f4bSopenharmony_ci return MyComparableTestType { i * value.i }; 1218bf80f4bSopenharmony_ci } 1228bf80f4bSopenharmony_ci constexpr MyComparableTestType operator/(MyComparableTestType value) const 1238bf80f4bSopenharmony_ci { 1248bf80f4bSopenharmony_ci return MyComparableTestType { i / value.i }; 1258bf80f4bSopenharmony_ci } 1268bf80f4bSopenharmony_ci constexpr MyComparableTestType operator+(MyComparableTestType value) const 1278bf80f4bSopenharmony_ci { 1288bf80f4bSopenharmony_ci return MyComparableTestType { i + value.i }; 1298bf80f4bSopenharmony_ci } 1308bf80f4bSopenharmony_ci constexpr MyComparableTestType operator-(MyComparableTestType value) const 1318bf80f4bSopenharmony_ci { 1328bf80f4bSopenharmony_ci return MyComparableTestType { i - value.i }; 1338bf80f4bSopenharmony_ci } 1348bf80f4bSopenharmony_ci}; 1358bf80f4bSopenharmony_ci 1368bf80f4bSopenharmony_ciclass IEmbeddedTestType : public CORE_NS::IInterface { 1378bf80f4bSopenharmony_ci META_INTERFACE(CORE_NS::IInterface, IEmbeddedTestType); 1388bf80f4bSopenharmony_ci 1398bf80f4bSopenharmony_cipublic: 1408bf80f4bSopenharmony_ci META_PROPERTY(int, Property) 1418bf80f4bSopenharmony_ci}; 1428bf80f4bSopenharmony_ci 1438bf80f4bSopenharmony_ciclass ITestAttachment : public CORE_NS::IInterface { 1448bf80f4bSopenharmony_ci META_INTERFACE(CORE_NS::IInterface, ITestAttachment); 1458bf80f4bSopenharmony_ci 1468bf80f4bSopenharmony_cipublic: 1478bf80f4bSopenharmony_ci META_PROPERTY(string, Name) 1488bf80f4bSopenharmony_ci virtual void SetName(const BASE_NS::string& name) = 0; 1498bf80f4bSopenharmony_ci virtual uint32_t GetAttachCount() const = 0; 1508bf80f4bSopenharmony_ci virtual uint32_t GetDetachCount() const = 0; 1518bf80f4bSopenharmony_ci}; 1528bf80f4bSopenharmony_ci 1538bf80f4bSopenharmony_ciclass ITestStartable : public ITestAttachment { 1548bf80f4bSopenharmony_ci META_INTERFACE(ITestAttachment, ITestStartable); 1558bf80f4bSopenharmony_ci 1568bf80f4bSopenharmony_cipublic: 1578bf80f4bSopenharmony_ci enum class Operation : uint32_t { 1588bf80f4bSopenharmony_ci ATTACH, 1598bf80f4bSopenharmony_ci START, 1608bf80f4bSopenharmony_ci STOP, 1618bf80f4bSopenharmony_ci DETACH, 1628bf80f4bSopenharmony_ci TICK, 1638bf80f4bSopenharmony_ci }; 1648bf80f4bSopenharmony_ci virtual void StartRecording() = 0; 1658bf80f4bSopenharmony_ci virtual BASE_NS::vector<Operation> StopRecording() = 0; 1668bf80f4bSopenharmony_ci virtual BASE_NS::vector<Operation> GetOps() const = 0; 1678bf80f4bSopenharmony_ci virtual TimeSpan GetLastTick() const = 0; 1688bf80f4bSopenharmony_ci 1698bf80f4bSopenharmony_ci META_EVENT(IOnChanged, OnStarted) 1708bf80f4bSopenharmony_ci META_EVENT(IOnChanged, OnStopped) 1718bf80f4bSopenharmony_ci META_EVENT(IOnChanged, OnTicked) 1728bf80f4bSopenharmony_ci 1738bf80f4bSopenharmony_ci template<class Callback> 1748bf80f4bSopenharmony_ci void AddOnStarted(Callback&& callback) 1758bf80f4bSopenharmony_ci { 1768bf80f4bSopenharmony_ci OnStarted()->AddHandler(MakeCallback<IOnChanged>(callback)); 1778bf80f4bSopenharmony_ci } 1788bf80f4bSopenharmony_ci 1798bf80f4bSopenharmony_ci template<class Callback> 1808bf80f4bSopenharmony_ci void AddOnStopped(Callback&& callback) 1818bf80f4bSopenharmony_ci { 1828bf80f4bSopenharmony_ci OnStopped()->AddHandler(MakeCallback<IOnChanged>(callback)); 1838bf80f4bSopenharmony_ci } 1848bf80f4bSopenharmony_ci 1858bf80f4bSopenharmony_ci template<class Callback> 1868bf80f4bSopenharmony_ci void AddOnTicked(Callback&& callback) 1878bf80f4bSopenharmony_ci { 1888bf80f4bSopenharmony_ci OnTicked()->AddHandler(MakeCallback<IOnChanged>(callback)); 1898bf80f4bSopenharmony_ci } 1908bf80f4bSopenharmony_ci}; 1918bf80f4bSopenharmony_ci 1928bf80f4bSopenharmony_cistd::ostream& operator<<(std::ostream& os, const META_NS::ITestStartable::Operation& op); 1938bf80f4bSopenharmony_ci 1948bf80f4bSopenharmony_ciclass ITestType : public CORE_NS::IInterface { 1958bf80f4bSopenharmony_ci META_INTERFACE(CORE_NS::IInterface, ITestType); 1968bf80f4bSopenharmony_ci 1978bf80f4bSopenharmony_cipublic: 1988bf80f4bSopenharmony_ci META_PROPERTY(int, First) 1998bf80f4bSopenharmony_ci META_PROPERTY(string, Second) 2008bf80f4bSopenharmony_ci META_READONLY_PROPERTY(int, Third) 2018bf80f4bSopenharmony_ci META_READONLY_PROPERTY(string, Fourth) 2028bf80f4bSopenharmony_ci 2038bf80f4bSopenharmony_ci META_PROPERTY(BASE_NS::Math::Vec3, Vec3Property1) 2048bf80f4bSopenharmony_ci META_PROPERTY(BASE_NS::Math::Vec3, Vec3Property2) 2058bf80f4bSopenharmony_ci META_PROPERTY(BASE_NS::Math::Vec3, Vec3Property3) 2068bf80f4bSopenharmony_ci 2078bf80f4bSopenharmony_ci META_PROPERTY(float, FloatProperty1) 2088bf80f4bSopenharmony_ci META_PROPERTY(float, FloatProperty2) 2098bf80f4bSopenharmony_ci 2108bf80f4bSopenharmony_ci META_PROPERTY(MyComparableTestType, MyTestTypeProperty1) 2118bf80f4bSopenharmony_ci META_PROPERTY(MyComparableTestType, MyTestTypeProperty2) 2128bf80f4bSopenharmony_ci 2138bf80f4bSopenharmony_ci META_PROPERTY(IEmbeddedTestType::Ptr, EmbeddedTestTypeProperty) 2148bf80f4bSopenharmony_ci 2158bf80f4bSopenharmony_ci META_ARRAY_PROPERTY(int, MyIntArray) 2168bf80f4bSopenharmony_ci 2178bf80f4bSopenharmony_ci META_READONLY_ARRAY_PROPERTY(int, MyConstIntArray) 2188bf80f4bSopenharmony_ci 2198bf80f4bSopenharmony_ci META_PROPERTY(string, Name) 2208bf80f4bSopenharmony_ci virtual void SetName(const BASE_NS::string& name) = 0; 2218bf80f4bSopenharmony_ci 2228bf80f4bSopenharmony_ci META_EVENT(IOnChanged, OnTest) 2238bf80f4bSopenharmony_ci 2248bf80f4bSopenharmony_ci virtual int NormalMember() = 0; 2258bf80f4bSopenharmony_ci virtual int OtherNormalMember(int, int) const = 0; 2268bf80f4bSopenharmony_ci}; 2278bf80f4bSopenharmony_ci 2288bf80f4bSopenharmony_ciclass ITestContainer : public CORE_NS::IInterface { 2298bf80f4bSopenharmony_ci META_INTERFACE(CORE_NS::IInterface, ITestContainer); 2308bf80f4bSopenharmony_ci 2318bf80f4bSopenharmony_cipublic: 2328bf80f4bSopenharmony_ci META_PROPERTY(string, Name) 2338bf80f4bSopenharmony_ci virtual void SetName(const BASE_NS::string& name) = 0; 2348bf80f4bSopenharmony_ci 2358bf80f4bSopenharmony_ci virtual void Increment() = 0; 2368bf80f4bSopenharmony_ci virtual int GetIncrement() const = 0; 2378bf80f4bSopenharmony_ci}; 2388bf80f4bSopenharmony_ci 2398bf80f4bSopenharmony_ciclass ITestString : public CORE_NS::IInterface { 2408bf80f4bSopenharmony_ci META_INTERFACE(CORE_NS::IInterface, ITestString, "3f05057d-95b3-4599-a88d-5983287a48e6"); 2418bf80f4bSopenharmony_ci 2428bf80f4bSopenharmony_cipublic: 2438bf80f4bSopenharmony_ci virtual BASE_NS::string GetString() const = 0; 2448bf80f4bSopenharmony_ci virtual void SetString(BASE_NS::string) = 0; 2458bf80f4bSopenharmony_ci}; 2468bf80f4bSopenharmony_ci 2478bf80f4bSopenharmony_ciclass ITestPtrValue : public CORE_NS::IInterface { 2488bf80f4bSopenharmony_ci META_INTERFACE(CORE_NS::IInterface, ITestPtrValue); 2498bf80f4bSopenharmony_ci 2508bf80f4bSopenharmony_cipublic: 2518bf80f4bSopenharmony_ci META_PROPERTY(ITestString::Ptr, Text); 2528bf80f4bSopenharmony_ci META_PROPERTY(ITestString::Ptr, String); 2538bf80f4bSopenharmony_ci}; 2548bf80f4bSopenharmony_ci 2558bf80f4bSopenharmony_civoid RegisterTestTypes(); 2568bf80f4bSopenharmony_civoid UnregisterTestTypes(); 2578bf80f4bSopenharmony_ci 2588bf80f4bSopenharmony_citemplate<class T> 2598bf80f4bSopenharmony_citypename T::Ptr CreateTestType(const BASE_NS::string_view name = {}) 2608bf80f4bSopenharmony_ci{ 2618bf80f4bSopenharmony_ci return interface_pointer_cast<T>(CreateTestType(name)); 2628bf80f4bSopenharmony_ci} 2638bf80f4bSopenharmony_ci 2648bf80f4bSopenharmony_citemplate<class T> 2658bf80f4bSopenharmony_citypename T::Ptr CreateTestContainer( 2668bf80f4bSopenharmony_ci const BASE_NS::string_view name = {}, ClassInfo type = META_NS::ClassId::TestContainer) 2678bf80f4bSopenharmony_ci{ 2688bf80f4bSopenharmony_ci return interface_pointer_cast<T>(CreateTestContainer(name, type)); 2698bf80f4bSopenharmony_ci} 2708bf80f4bSopenharmony_ci 2718bf80f4bSopenharmony_citemplate<class T> 2728bf80f4bSopenharmony_citypename T::Ptr CreateTestAttachment( 2738bf80f4bSopenharmony_ci const BASE_NS::string_view name = {}, ClassInfo type = META_NS::ClassId::TestContainer) 2748bf80f4bSopenharmony_ci{ 2758bf80f4bSopenharmony_ci return interface_pointer_cast<T>(CreateTestAttachment(name)); 2768bf80f4bSopenharmony_ci} 2778bf80f4bSopenharmony_ci 2788bf80f4bSopenharmony_citemplate<class T> 2798bf80f4bSopenharmony_citypename T::Ptr CreateTestStartable( 2808bf80f4bSopenharmony_ci const BASE_NS::string_view name = {}, ClassInfo type = META_NS::ClassId::TestStartable) 2818bf80f4bSopenharmony_ci{ 2828bf80f4bSopenharmony_ci return interface_pointer_cast<T>(CreateTestStartable(name)); 2838bf80f4bSopenharmony_ci} 2848bf80f4bSopenharmony_ci 2858bf80f4bSopenharmony_cistruct MyTestType { 2868bf80f4bSopenharmony_ci int i = 0; 2878bf80f4bSopenharmony_ci}; 2888bf80f4bSopenharmony_ci 2898bf80f4bSopenharmony_cienum TestEnum { TestEnumA = 1, TestEnumB = 2 }; 2908bf80f4bSopenharmony_ci 2918bf80f4bSopenharmony_ciMETA_INTERFACE_TYPE(META_NS::ITestString) 2928bf80f4bSopenharmony_ciMETA_INTERFACE_TYPE(META_NS::ITestPtrValue) 2938bf80f4bSopenharmony_ciMETA_INTERFACE_TYPE(META_NS::ITestType) 2948bf80f4bSopenharmony_ciMETA_INTERFACE_TYPE(META_NS::IEmbeddedTestType) 2958bf80f4bSopenharmony_ciMETA_TYPE(META_NS::MyTestType) 2968bf80f4bSopenharmony_ciMETA_TYPE(META_NS::MyComparableTestType) 2978bf80f4bSopenharmony_ciMETA_TYPE(META_NS::TestEnum) 2988bf80f4bSopenharmony_ci 2998bf80f4bSopenharmony_ci#endif