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