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 #include "TestRunner.h" 16 #include <src/testing_objects.h> 17 18 #include <gmock/gmock-matchers.h> 19 #include <gtest/gtest.h> 20 21 #include <meta/api/number.h> 22 #include <meta/interface/detail/any.h> 23 24 using namespace testing; 25 using namespace testing::ext; 26 27 META_BEGIN_NAMESPACE() 28 29 enum MyEnum : int16_t { ONE = 1, TWO, THREE }; 30 31 class NumberTest : public testing::Test { 32 public: SetUpTestSuite()33 static void SetUpTestSuite() 34 { 35 SetTest(); 36 } TearDownTestSuite()37 static void TearDownTestSuite() 38 { 39 TearDownTest(); 40 } SetUp()41 void SetUp() {} TearDown()42 void TearDown() {} 43 }; 44 45 /** 46 * @tc.name: Values 47 * @tc.desc: test Values 48 * @tc.type:FUNC 49 * @tc.require: 50 */ 51 HWTEST_F(NumberTest, Values, TestSize.Level1) 52 { 53 Number n = 1; 54 EXPECT_EQ(n.Get<uint32_t>(), 1); 55 EXPECT_EQ(n.Get<int32_t>(), 1); 56 EXPECT_EQ(n.Get<float>(), 1); 57 EXPECT_EQ(n.Get<MyEnum>(), MyEnum::ONE); 58 59 n = Any<uint64_t>(10); 60 EXPECT_EQ(n.Get<uint32_t>(), 10); 61 62 n = 1.2f; 63 EXPECT_EQ(n.Get<uint32_t>(), 1); 64 EXPECT_EQ(n.Get<int32_t>(), 1); 65 EXPECT_NEAR(n.Get<float>(), 1.2, 0.0001); 66 67 Number en = MyEnum::TWO; 68 EXPECT_EQ(en.Get<uint32_t>(), 2); 69 EXPECT_EQ(en.Get<MyEnum>(), MyEnum::TWO); 70 } 71 72 META_END_NAMESPACE() 73