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 <functional>
17 
18 #include <gtest/gtest.h>
19 
20 #include <meta/base/ids.h>
21 
22 #include "src/test_runner.h"
23 
24 using namespace testing::ext;
25 
26 META_BEGIN_NAMESPACE()
27 
28 class IdsTest : public testing::Test {
29 public:
SetUpTestSuite()30     static void SetUpTestSuite()
31     {
32         SetTest();
33     }
TearDownTestSuite()34     static void TearDownTestSuite()
35     {
36         ResetTest();
37     }
38     void SetUp() override {}
39     void TearDown() override {}
40 };
41 
42 template<typename Id>
IdTest()43 void IdTest()
44 {
45     Id id1;
46     Id id2("29495e67-14a6-40aa-a16f-1923630af506");
47     Id id3(id2);
48     Id id4("29495e67-14a6-40aa-a16f-1923630af507");
49     EXPECT_FALSE(id1 == id2);
50     EXPECT_TRUE(id2 == id3);
51     EXPECT_TRUE(id1 != id2);
52     EXPECT_TRUE(id2 != id4);
53     EXPECT_FALSE(id2 != id3);
54     EXPECT_TRUE(id1 < id2);
55     EXPECT_TRUE(id2 < id4);
56     EXPECT_FALSE(id2 < id3);
57     EXPECT_EQ(id2.ToString(), "29495e67-14a6-40aa-a16f-1923630af506");
58     EXPECT_FALSE(id1.IsValid());
59     EXPECT_TRUE(id2.IsValid());
60     EXPECT_EQ(id3.ToUid(), BASE_NS::Uid { "29495e67-14a6-40aa-a16f-1923630af506" });
61     id1 = id2;
62     EXPECT_TRUE(id1 == id2);
63     EXPECT_TRUE(id1.Compare(id2) == 0);
64     EXPECT_TRUE(id2.Compare(id4) < 0);
65     EXPECT_TRUE(id4.Compare(id2) > 0);
66 }
67 
68 /**
69  * @tc.name: IdsTest
70  * @tc.desc: test TypeId function
71  * @tc.type: FUNC
72  * @tc.require: I7DMS1
73  */
74 HWTEST_F(IdsTest, TypeId, TestSize.Level1)
75 {
76     IdTest<TypeId>();
77 }
78 
79 /**
80  * @tc.name: IdsTest
81  * @tc.desc: test ObjectId function
82  * @tc.type: FUNC
83  * @tc.require: I7DMS1
84  */
85 HWTEST_F(IdsTest, ObjectId, TestSize.Level1)
86 {
87     IdTest<ObjectId>();
88 }
89 
90 /**
91  * @tc.name: IdsTest
92  * @tc.desc: test InstanceId function
93  * @tc.type: FUNC
94  * @tc.require: I7DMS1
95  */
96 HWTEST_F(IdsTest, InstanceId, TestSize.Level1)
97 {
98     IdTest<InstanceId>();
99 }
100 
101 META_END_NAMESPACE()