• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "TestRunner.h"
16 #include <src/testing_objects.h>
17 
18 #include <gtest/gtest.h>
19 
20 #include <meta/api/object.h>
21 #include <meta/interface/property/property.h>
22 
23 #include "src/util.h"
24 
25 using namespace testing;
26 using namespace testing::ext;
27 
28 META_BEGIN_NAMESPACE()
29 
30 class TestInterfaceAPI : public Internal::ObjectInterfaceAPI<TestInterfaceAPI, ClassId::TestType> {
31     META_API(TestInterfaceAPI)
32     META_API_OBJECT_CONVERTIBLE(ITestType)
33     META_API_CACHE_INTERFACE(ITestType, Test)
34 
35 public:
36     META_API_INTERFACE_PROPERTY_CACHED(Test, First, int)
37     META_API_INTERFACE_READONLY_PROPERTY_CACHED(Test, Third, int)
38     META_API_INTERFACE_ARRAY_PROPERTY_CACHED(Test, MyIntArray, int)
39     META_API_INTERFACE_READONLY_ARRAY_PROPERTY_CACHED(Test, MyConstIntArray, int)
40 };
41 
42 class ObjectApiTest : public testing::Test {
43 public:
SetUpTestSuite()44     static void SetUpTestSuite()
45     {
46         SetTest();
47     }
TearDownTestSuite()48     static void TearDownTestSuite()
49     {
50         TearDownTest();
51     }
SetUp()52     void SetUp() {}
TearDown()53     void TearDown() {}
54 };
55 
56 /**
57  * @tc.name: Properties
58  * @tc.desc: test Properties
59  * @tc.type:FUNC
60  * @tc.require:
61  */
62 HWTEST_F(ObjectApiTest, Properties, TestSize.Level1)
63 {
64     TestInterfaceAPI test;
65     test.First(1);
66     EXPECT_EQ(test.First()->GetValue(), 1);
67     EXPECT_EQ(test.Third()->GetValue(), 0);
68     test.MyIntArray({ 1, 2 });
69     EXPECT_EQ(test.MyIntArray()->GetValue(), (BASE_NS::vector<int> { 1, 2 }));
70     EXPECT_EQ(test.MyConstIntArray()->GetValue(), (BASE_NS::vector<int> { 1, 2, 3, 4, 5 }));
71     test.First(GetValue(test.Third()));
72     EXPECT_EQ(test.First()->GetValue(), 0);
73     test.MyIntArray(test.MyConstIntArray()->GetValue());
74     EXPECT_EQ(test.MyIntArray()->GetValue(), (BASE_NS::vector<int> { 1, 2, 3, 4, 5 }));
75 }
76 
77 META_END_NAMESPACE()
78