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