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 <gtest/gtest.h> 178bf80f4bSopenharmony_ci 188bf80f4bSopenharmony_ci#include <meta/api/object.h> 198bf80f4bSopenharmony_ci#include <meta/interface/property/property.h> 208bf80f4bSopenharmony_ci 218bf80f4bSopenharmony_ci#include "src/test_runner.h" 228bf80f4bSopenharmony_ci#include "src/testing_objects.h" 238bf80f4bSopenharmony_ci#include "src/util.h" 248bf80f4bSopenharmony_ci 258bf80f4bSopenharmony_ciusing namespace testing::ext; 268bf80f4bSopenharmony_ci 278bf80f4bSopenharmony_ciMETA_BEGIN_NAMESPACE() 288bf80f4bSopenharmony_ci 298bf80f4bSopenharmony_ciclass ObjectApiTest : public testing::Test { 308bf80f4bSopenharmony_cipublic: 318bf80f4bSopenharmony_ci static void SetUpTestSuite() 328bf80f4bSopenharmony_ci { 338bf80f4bSopenharmony_ci SetTest(); 348bf80f4bSopenharmony_ci } 358bf80f4bSopenharmony_ci static void TearDownTestSuite() 368bf80f4bSopenharmony_ci { 378bf80f4bSopenharmony_ci ResetTest(); 388bf80f4bSopenharmony_ci } 398bf80f4bSopenharmony_ci void SetUp() override {} 408bf80f4bSopenharmony_ci void TearDown() override {} 418bf80f4bSopenharmony_ci}; 428bf80f4bSopenharmony_ci 438bf80f4bSopenharmony_ciclass TestInterfaceAPI : public Internal::ObjectInterfaceAPI<TestInterfaceAPI, ClassId::TestType> { 448bf80f4bSopenharmony_ci META_API(TestInterfaceAPI); 458bf80f4bSopenharmony_ci META_API_OBJECT_CONVERTIBLE(ITestType) 468bf80f4bSopenharmony_ci META_API_CACHE_INTERFACE(ITestType, Test) 478bf80f4bSopenharmony_ci 488bf80f4bSopenharmony_cipublic: 498bf80f4bSopenharmony_ci META_API_INTERFACE_PROPERTY_CACHED(Test, First, int) 508bf80f4bSopenharmony_ci META_API_INTERFACE_READONLY_PROPERTY_CACHED(Test, Third, int) 518bf80f4bSopenharmony_ci META_API_INTERFACE_ARRAY_PROPERTY_CACHED(Test, MyIntArray, int) 528bf80f4bSopenharmony_ci META_API_INTERFACE_READONLY_ARRAY_PROPERTY_CACHED(Test, MyConstIntArray, int) 538bf80f4bSopenharmony_ci}; 548bf80f4bSopenharmony_ci 558bf80f4bSopenharmony_ci/** 568bf80f4bSopenharmony_ci * @tc.name: ObjectApiTest 578bf80f4bSopenharmony_ci * @tc.desc: test Values function 588bf80f4bSopenharmony_ci * @tc.type: FUNC 598bf80f4bSopenharmony_ci * @tc.require: I7DMS1 608bf80f4bSopenharmony_ci */ 618bf80f4bSopenharmony_ciHWTEST_F(ObjectApiTest, Properties, TestSize.Level1) 628bf80f4bSopenharmony_ci{ 638bf80f4bSopenharmony_ci TestInterfaceAPI test; 648bf80f4bSopenharmony_ci test.First(1); 658bf80f4bSopenharmony_ci EXPECT_EQ(test.First()->GetValue(), 1); 668bf80f4bSopenharmony_ci EXPECT_EQ(test.Third()->GetValue(), 0); 678bf80f4bSopenharmony_ci test.MyIntArray({ 1, 2 }); 688bf80f4bSopenharmony_ci EXPECT_EQ(test.MyIntArray()->GetValue(), (BASE_NS::vector<int> { 1, 2 })); 698bf80f4bSopenharmony_ci EXPECT_EQ(test.MyConstIntArray()->GetValue(), (BASE_NS::vector<int> { 1, 2, 3, 4, 5 })); 708bf80f4bSopenharmony_ci test.First(GetValue(test.Third())); 718bf80f4bSopenharmony_ci EXPECT_EQ(test.First()->GetValue(), 0); 728bf80f4bSopenharmony_ci test.MyIntArray(test.MyConstIntArray()->GetValue()); 738bf80f4bSopenharmony_ci EXPECT_EQ(test.MyIntArray()->GetValue(), (BASE_NS::vector<int> { 1, 2, 3, 4, 5 })); 748bf80f4bSopenharmony_ci} 758bf80f4bSopenharmony_ciMETA_END_NAMESPACE()