• 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 
16 #include <iostream>
17 #include <chrono>
18 #include <thread>
19 #include <vector>
20 
21 #include <gtest/gtest.h>
22 #include "iservice_registry.h"
23 #include "if_system_ability_manager.h"
24 #include "foo_ptr_client.h"
25 #include "my_seq.h"
26 
27 using namespace testing;
28 using namespace testing::ext;
29 
30 namespace OHOS {
31 namespace Idl {
32 
33 class IdlSaUnitTestPtr : public testing::Test {
34 public:
IdlSaUnitTestPtr()35     IdlSaUnitTestPtr() {}
36 
~IdlSaUnitTestPtr()37     virtual ~IdlSaUnitTestPtr() {}
38 
39     static void SetUpTestCase();
40 
41     static void TearDownTestCase();
42 
43     void SetUp();
44 
45     void TearDown();
46 };
47 
SetUpTestCase()48 void IdlSaUnitTestPtr::SetUpTestCase() {}
49 
TearDownTestCase()50 void IdlSaUnitTestPtr::TearDownTestCase() {}
51 
SetUp()52 void IdlSaUnitTestPtr::SetUp() {}
53 
TearDown()54 void IdlSaUnitTestPtr::TearDown() {}
55 
56 /*
57  * @tc.name: IdlSaProxyPtrTest001
58  * @tc.desc: shared_ptr run
59  * @tc.type: FUNC
60  */
61 HWTEST_F(IdlSaUnitTestPtr, IdlSaProxyPtrTest001, TestSize.Level1)
62 {
63     std::cout << "IdlSaProxyPtrTest001 start" << std::endl;
64 
65     FooPtrClient* client_ = new FooPtrClient(TEST_SAID);
66     ASSERT_NE(client_, nullptr);
67 
68     // sync func
69     MySeq* inParamTmp = new MySeq();
70     inParamTmp->size = TEST_IN_SIZE_FIVE;
71     std::shared_ptr<MySeq> inParam = std::shared_ptr<MySeq>(inParamTmp);
72     MySeq* inoutParamTmp = new MySeq();
73     inoutParamTmp->size = TEST_IN_SIZE_SEVEN;
74     std::shared_ptr<MySeq> inoutParam = std::shared_ptr<MySeq>(inoutParamTmp);
75     std::shared_ptr<MySeq> outParam;
76     std::shared_ptr<MySeq> funcResult;
77     int32_t ret = client_->sharedptr_seq_func(inParam, inoutParam, outParam, funcResult);
78     std::cout << "sharedptr_seq_func client" << std::endl;
79     ASSERT_NE(outParam, nullptr);
80     ASSERT_NE(funcResult, nullptr);
81     EXPECT_EQ(TEST_IN_SIZE_TWENTY, outParam->size);
82     EXPECT_EQ(TEST_IN_SIZE_FIFTY, funcResult->size);
83     EXPECT_EQ(ret, ERR_OK);
84     delete client_;
85 }
86 
87 /*
88  * @tc.name: IdlSaProxyPtrTest002
89  * @tc.desc: unique_ptr run
90  * @tc.type: FUNC
91  */
92 HWTEST_F(IdlSaUnitTestPtr, IdlSaProxyPtrTest002, TestSize.Level1)
93 {
94     std::cout << "IdlSaProxyPtrTest002 start" << std::endl;
95 
96     FooPtrClient* client_ = new FooPtrClient(TEST_SAID);
97     ASSERT_NE(client_, nullptr);
98 
99     // sync func
100     MySeq* inParamTmp = new MySeq();
101     inParamTmp->size = TEST_IN_SIZE_FIVE;
102     std::unique_ptr<MySeq> inParam = std::unique_ptr<MySeq>(inParamTmp);
103     MySeq* inoutParamTmp = new MySeq();
104     inoutParamTmp->size = TEST_IN_SIZE_SEVEN;
105     std::unique_ptr<MySeq> inoutParam = std::unique_ptr<MySeq>(inoutParamTmp);
106     std::unique_ptr<MySeq> outParam;
107     std::unique_ptr<MySeq> funcResult;
108     int32_t ret = client_->uniqueptr_seq_func(inParam, inoutParam, outParam, funcResult);
109     std::cout << "sharedptr_seq_func client" << std::endl;
110     ASSERT_NE(outParam, nullptr);
111     ASSERT_NE(funcResult, nullptr);
112     EXPECT_EQ(TEST_IN_SIZE_TWENTY, outParam->size);
113     EXPECT_EQ(TEST_IN_SIZE_FIFTY, funcResult->size);
114     EXPECT_EQ(ret, ERR_OK);
115     delete client_;
116 }
117 
118 /*
119  * @tc.name: IdlSaProxyPtrTest003
120  * @tc.desc: sptr run
121  * @tc.type: FUNC
122  */
123 HWTEST_F(IdlSaUnitTestPtr, IdlSaProxyPtrTest003, TestSize.Level1)
124 {
125     std::cout << "IdlSaProxyPtrTest003 start" << std::endl;
126 
127     FooPtrClient* client_ = new FooPtrClient(TEST_SAID);
128     ASSERT_NE(client_, nullptr);
129 
130     // sync func
131     MySeq* inParamTmp = new MySeq();
132     inParamTmp->size = TEST_IN_SIZE_FIVE;
133     sptr<MySeq> inParam = sptr<MySeq>(inParamTmp);
134     MySeq* inoutParamTmp = new MySeq();
135     inoutParamTmp->size = TEST_IN_SIZE_SEVEN;
136     sptr<MySeq> inoutParam = sptr<MySeq>(inoutParamTmp);
137     sptr<MySeq> outParam;
138     sptr<MySeq> funcResult;
139     int32_t ret = client_->sptr_seq_func(inParam, inoutParam, outParam, funcResult);
140     std::cout << "sharedptr_seq_func client" << std::endl;
141     ASSERT_NE(outParam, nullptr);
142     ASSERT_NE(funcResult, nullptr);
143     EXPECT_EQ(TEST_IN_SIZE_TWENTY, outParam->size);
144     EXPECT_EQ(TEST_IN_SIZE_FIFTY, funcResult->size);
145     EXPECT_EQ(ret, ERR_OK);
146     delete client_;
147 }
148 
149 } // namespace idl
150 } // namespace OHOS