• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <functional>
16 
17 #include <gtest/gtest.h>
18 
19 #include <meta/base/ids.h>
20 
21 #include "TestRunner.h"
22 
23 using namespace testing::ext;
24 
25 META_BEGIN_NAMESPACE()
26 
27 class IdTests : public testing::Test {
28 public:
SetUpTestSuite()29     static void SetUpTestSuite()
30     {
31         SetTest();
32     }
TearDownTestSuite()33     static void TearDownTestSuite()
34     {
35         TearDownTest();
36     }
SetUp()37     void SetUp() {}
TearDown()38     void TearDown() {}
39 };
40 
41 template<typename Id>
IdTest()42 void IdTest()
43 {
44     Id id1;
45     Id id2("29495e67-14a6-40aa-a16f-1923630af506");
46     Id id3(id2);
47     Id id4("29495e67-14a6-40aa-a16f-1923630af507");
48     EXPECT_FALSE(id1 == id2);
49     EXPECT_TRUE(id2 == id3);
50     EXPECT_TRUE(id1 != id2);
51     EXPECT_TRUE(id2 != id4);
52     EXPECT_FALSE(id2 != id3);
53     EXPECT_TRUE(id1 < id2);
54     EXPECT_TRUE(id2 < id4);
55     EXPECT_FALSE(id2 < id3);
56     EXPECT_EQ(id2.ToString(), "29495e67-14a6-40aa-a16f-1923630af506");
57     EXPECT_FALSE(id1.IsValid());
58     EXPECT_TRUE(id2.IsValid());
59     EXPECT_EQ(id3.ToUid(), BASE_NS::Uid { "29495e67-14a6-40aa-a16f-1923630af506" });
60     id1 = id2;
61     EXPECT_TRUE(id1 == id2);
62     EXPECT_TRUE(id1.Compare(id2) == 0);
63     EXPECT_TRUE(id2.Compare(id4) < 0);
64     EXPECT_TRUE(id4.Compare(id2) > 0);
65 }
66 
67 HWTEST_F(IdTests, TypeId, TestSize.Level1)
68 {
69     IdTest<TypeId>();
70 }
71 HWTEST_F(IdTests, ObjectId, TestSize.Level1)
72 {
73     IdTest<ObjectId>();
74 }
75 HWTEST_F(IdTests, InstanceId, TestSize.Level1)
76 {
77     IdTest<InstanceId>();
78 }
79 
80 META_END_NAMESPACE()
81