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 #include <TestRunner.h> 17 #include <src/testing_objects.h> 18 19 #include <gtest/gtest.h> 20 21 #include <meta/api/property/property_info.h> 22 #include <meta/interface/detail/enum.h> 23 #include <meta/interface/enum_macros.h> 24 #include <meta/interface/property/construct_property.h> 25 26 using namespace testing; 27 using namespace testing::ext; 28 29 META_BEGIN_NAMESPACE() 30 enum class MyPropEnum { 31 A = 1, 32 B = 2, 33 }; 34 35 META_BEGIN_ENUM(MyPropEnum, "Nice Enum", MyPropEnum::A) 36 META_ENUM_VALUE(MyPropEnum::A, "MyA", "My A enumerator") 37 META_ENUM_VALUE(MyPropEnum::B, "MyB", "My B enumerator") 38 META_END_ENUM() 39 40 META_ENUM_TYPE(MyPropEnum) 41 42 class PropertyInfoTest : public testing::Test { 43 public: SetUpTestSuite()44 static void SetUpTestSuite() 45 { 46 SetTest(); 47 } TearDownTestSuite()48 static void TearDownTestSuite() 49 { 50 TearDownTest(); 51 } SetUp()52 void SetUp() {} TearDown()53 void TearDown() {} 54 }; 55 56 /** 57 * @tc.name: Info 58 * @tc.desc: test Info 59 * @tc.type:FUNC 60 * @tc.require: 61 */ 62 HWTEST_F(PropertyInfoTest, Info, TestSize.Level1) 63 { 64 auto p = ConstructProperty<MyPropEnum>("test"); 65 PropertyInfo info(p); 66 ASSERT_TRUE(info); 67 EXPECT_EQ(info->GetName(), "MyPropEnum"); 68 EXPECT_EQ(info->GetDescription(), "Nice Enum"); 69 } 70 71 /** 72 * @tc.name: ConstEnum 73 * @tc.desc: test ConstEnum 74 * @tc.type:FUNC 75 * @tc.require: 76 */ 77 HWTEST_F(PropertyInfoTest, ConstEnum, TestSize.Level1) 78 { 79 auto p = ConstructProperty<MyPropEnum>("test"); 80 ConstPropertyEnumInfo info(p); 81 ASSERT_TRUE(info); 82 EXPECT_EQ(info->GetName(), "MyPropEnum"); 83 EXPECT_EQ(info->GetDescription(), "Nice Enum"); 84 EXPECT_EQ(info->GetEnumType(), EnumType::SINGLE_VALUE); 85 EXPECT_EQ(info->GetValueIndex(), 0); 86 EXPECT_EQ(info->GetValues().size(), 2); 87 } 88 89 /** 90 * @tc.name: Enum 91 * @tc.desc: test Enum 92 * @tc.type:FUNC 93 * @tc.require: 94 */ 95 HWTEST_F(PropertyInfoTest, Enum, TestSize.Level1) 96 { 97 auto p = ConstructProperty<MyPropEnum>("test"); 98 PropertyEnumInfo info(p); 99 ASSERT_TRUE(info); 100 EXPECT_TRUE(info->SetValueIndex(1)); 101 EXPECT_EQ(info->GetValueIndex(), 1); 102 EXPECT_EQ(p->GetValue(), MyPropEnum::B); 103 } 104 105 META_END_NAMESPACE() 106