18bf80f4bSopenharmony_ci/* 28bf80f4bSopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd. 38bf80f4bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48bf80f4bSopenharmony_ci * you may not use this file except in compliance with the License. 58bf80f4bSopenharmony_ci * You may obtain a copy of the License at 68bf80f4bSopenharmony_ci * 78bf80f4bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88bf80f4bSopenharmony_ci * 98bf80f4bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108bf80f4bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118bf80f4bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128bf80f4bSopenharmony_ci * See the License for the specific language governing permissions and 138bf80f4bSopenharmony_ci * limitations under the License. 148bf80f4bSopenharmony_ci */ 158bf80f4bSopenharmony_ci 168bf80f4bSopenharmony_ci#include <functional> 178bf80f4bSopenharmony_ci 188bf80f4bSopenharmony_ci#include <gtest/gtest.h> 198bf80f4bSopenharmony_ci 208bf80f4bSopenharmony_ci#include <meta/base/ids.h> 218bf80f4bSopenharmony_ci 228bf80f4bSopenharmony_ci#include "src/test_runner.h" 238bf80f4bSopenharmony_ci 248bf80f4bSopenharmony_ciusing namespace testing::ext; 258bf80f4bSopenharmony_ci 268bf80f4bSopenharmony_ciMETA_BEGIN_NAMESPACE() 278bf80f4bSopenharmony_ci 288bf80f4bSopenharmony_ciclass IdsTest : public testing::Test { 298bf80f4bSopenharmony_cipublic: 308bf80f4bSopenharmony_ci static void SetUpTestSuite() 318bf80f4bSopenharmony_ci { 328bf80f4bSopenharmony_ci SetTest(); 338bf80f4bSopenharmony_ci } 348bf80f4bSopenharmony_ci static void TearDownTestSuite() 358bf80f4bSopenharmony_ci { 368bf80f4bSopenharmony_ci ResetTest(); 378bf80f4bSopenharmony_ci } 388bf80f4bSopenharmony_ci void SetUp() override {} 398bf80f4bSopenharmony_ci void TearDown() override {} 408bf80f4bSopenharmony_ci}; 418bf80f4bSopenharmony_ci 428bf80f4bSopenharmony_citemplate<typename Id> 438bf80f4bSopenharmony_civoid IdTest() 448bf80f4bSopenharmony_ci{ 458bf80f4bSopenharmony_ci Id id1; 468bf80f4bSopenharmony_ci Id id2("29495e67-14a6-40aa-a16f-1923630af506"); 478bf80f4bSopenharmony_ci Id id3(id2); 488bf80f4bSopenharmony_ci Id id4("29495e67-14a6-40aa-a16f-1923630af507"); 498bf80f4bSopenharmony_ci EXPECT_FALSE(id1 == id2); 508bf80f4bSopenharmony_ci EXPECT_TRUE(id2 == id3); 518bf80f4bSopenharmony_ci EXPECT_TRUE(id1 != id2); 528bf80f4bSopenharmony_ci EXPECT_TRUE(id2 != id4); 538bf80f4bSopenharmony_ci EXPECT_FALSE(id2 != id3); 548bf80f4bSopenharmony_ci EXPECT_TRUE(id1 < id2); 558bf80f4bSopenharmony_ci EXPECT_TRUE(id2 < id4); 568bf80f4bSopenharmony_ci EXPECT_FALSE(id2 < id3); 578bf80f4bSopenharmony_ci EXPECT_EQ(id2.ToString(), "29495e67-14a6-40aa-a16f-1923630af506"); 588bf80f4bSopenharmony_ci EXPECT_FALSE(id1.IsValid()); 598bf80f4bSopenharmony_ci EXPECT_TRUE(id2.IsValid()); 608bf80f4bSopenharmony_ci EXPECT_EQ(id3.ToUid(), BASE_NS::Uid { "29495e67-14a6-40aa-a16f-1923630af506" }); 618bf80f4bSopenharmony_ci id1 = id2; 628bf80f4bSopenharmony_ci EXPECT_TRUE(id1 == id2); 638bf80f4bSopenharmony_ci EXPECT_TRUE(id1.Compare(id2) == 0); 648bf80f4bSopenharmony_ci EXPECT_TRUE(id2.Compare(id4) < 0); 658bf80f4bSopenharmony_ci EXPECT_TRUE(id4.Compare(id2) > 0); 668bf80f4bSopenharmony_ci} 678bf80f4bSopenharmony_ci 688bf80f4bSopenharmony_ci/** 698bf80f4bSopenharmony_ci * @tc.name: IdsTest 708bf80f4bSopenharmony_ci * @tc.desc: test TypeId function 718bf80f4bSopenharmony_ci * @tc.type: FUNC 728bf80f4bSopenharmony_ci * @tc.require: I7DMS1 738bf80f4bSopenharmony_ci */ 748bf80f4bSopenharmony_ciHWTEST_F(IdsTest, TypeId, TestSize.Level1) 758bf80f4bSopenharmony_ci{ 768bf80f4bSopenharmony_ci IdTest<TypeId>(); 778bf80f4bSopenharmony_ci} 788bf80f4bSopenharmony_ci 798bf80f4bSopenharmony_ci/** 808bf80f4bSopenharmony_ci * @tc.name: IdsTest 818bf80f4bSopenharmony_ci * @tc.desc: test ObjectId function 828bf80f4bSopenharmony_ci * @tc.type: FUNC 838bf80f4bSopenharmony_ci * @tc.require: I7DMS1 848bf80f4bSopenharmony_ci */ 858bf80f4bSopenharmony_ciHWTEST_F(IdsTest, ObjectId, TestSize.Level1) 868bf80f4bSopenharmony_ci{ 878bf80f4bSopenharmony_ci IdTest<ObjectId>(); 888bf80f4bSopenharmony_ci} 898bf80f4bSopenharmony_ci 908bf80f4bSopenharmony_ci/** 918bf80f4bSopenharmony_ci * @tc.name: IdsTest 928bf80f4bSopenharmony_ci * @tc.desc: test InstanceId function 938bf80f4bSopenharmony_ci * @tc.type: FUNC 948bf80f4bSopenharmony_ci * @tc.require: I7DMS1 958bf80f4bSopenharmony_ci */ 968bf80f4bSopenharmony_ciHWTEST_F(IdsTest, InstanceId, TestSize.Level1) 978bf80f4bSopenharmony_ci{ 988bf80f4bSopenharmony_ci IdTest<InstanceId>(); 998bf80f4bSopenharmony_ci} 1008bf80f4bSopenharmony_ci 1018bf80f4bSopenharmony_ciMETA_END_NAMESPACE()