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 #define LOG_TAG "UdmfClientAbnormalTest"
16
17 #include <unistd.h>
18 #include <gtest/gtest.h>
19 #include <gmock/gmock.h>
20 #include <string>
21
22 #include "logger.h"
23 #include "udmf_capi_common.h"
24 #include "udmf_client.h"
25 #include "udmf_service_client_mock.h"
26
27 using namespace testing::ext;
28 using namespace OHOS::UDMF;
29 using namespace OHOS;
30 namespace OHOS::Test {
31 using namespace std;
32 using namespace testing;
33
34 class UdmfClientAbnormalTest : public testing::Test {
35 public:
36 static void SetUpTestCase();
37 static void TearDownTestCase();
38 void SetUp() override;
39 void TearDown() override;
40
41 static inline shared_ptr<UdmfServiceClientMock> mock_ = nullptr;
42 };
43
SetUpTestCase()44 void UdmfClientAbnormalTest::SetUpTestCase()
45 {
46 }
47
TearDownTestCase()48 void UdmfClientAbnormalTest::TearDownTestCase()
49 {
50 }
51
SetUp()52 void UdmfClientAbnormalTest::SetUp()
53 {
54 mock_ = make_shared<UdmfServiceClientMock>();
55 MUdmfServiceClient::udmfServiceClient = mock_;
56 }
57
TearDown()58 void UdmfClientAbnormalTest::TearDown()
59 {
60 mock_ = nullptr;
61 MUdmfServiceClient::udmfServiceClient = nullptr;
62 }
63
64 /**
65 * @tc.name: SetData001
66 * @tc.desc: Abnrmal testcase of SetData, the return value of GetInstance() is nullptr
67 * @tc.type: FUNC
68 */
69 HWTEST_F(UdmfClientAbnormalTest, SetData001, TestSize.Level1)
70 {
71 LOG_INFO(UDMF_TEST, "SetData001 begin.");
72 EXPECT_CALL(*mock_, GetInstance()).WillOnce(Return(nullptr));
73
74 UdmfClient client;
75 UnifiedData unifiedData;
76 CustomOption option;
77 std::string key = "testKey";
78
79 Status ret = client.SetData(option, unifiedData, key);
80 EXPECT_EQ(ret, Status::E_IPC);
81 LOG_INFO(UDMF_TEST, "SetData001 end.");
82 }
83
84 /**
85 * @tc.name: GetData001
86 * @tc.desc: Abnrmal testcase of GetData, the return value of GetInstance() is nullptr
87 * @tc.type: FUNC
88 */
89 HWTEST_F(UdmfClientAbnormalTest, GetData001, TestSize.Level1)
90 {
91 LOG_INFO(UDMF_TEST, "GetData001 begin.");
92 EXPECT_CALL(*mock_, GetInstance()).WillOnce(Return(nullptr));
93
94 UdmfClient client;
95 const QueryOption query;
96 UnifiedData unifiedData;
97
98 Status ret = client.GetData(query, unifiedData);
99 EXPECT_EQ(ret, Status::E_IPC);
100 LOG_INFO(UDMF_TEST, "GetData001 end.");
101 }
102
103 /**
104 * @tc.name: GetBatchData001
105 * @tc.desc: Abnrmal testcase of GetBatchData, the return value of GetInstance() is nullptr
106 * @tc.type: FUNC
107 */
108 HWTEST_F(UdmfClientAbnormalTest, GetBatchData001, TestSize.Level1)
109 {
110 LOG_INFO(UDMF_TEST, "GetBatchData001 begin.");
111 EXPECT_CALL(*mock_, GetInstance()).WillOnce(Return(nullptr));
112
113 UdmfClient client;
114 const QueryOption query;
115 std::vector<UnifiedData> unifiedDataSet;
116
117 Status ret = client.GetBatchData(query, unifiedDataSet);
118 EXPECT_EQ(ret, Status::E_IPC);
119 LOG_INFO(UDMF_TEST, "GetBatchData001 end.");
120 }
121
122 /**
123 * @tc.name: UpdateData001
124 * @tc.desc: Abnrmal testcase of UpdateData, the return value of GetInstance() is nullptr
125 * @tc.type: FUNC
126 */
127 HWTEST_F(UdmfClientAbnormalTest, UpdateData001, TestSize.Level1)
128 {
129 LOG_INFO(UDMF_TEST, "UpdateData001 begin.");
130 EXPECT_CALL(*mock_, GetInstance()).WillOnce(Return(nullptr));
131
132 UdmfClient client;
133 const QueryOption query;
134 UnifiedData unifiedData;
135
136 Status ret = client.UpdateData(query, unifiedData);
137 EXPECT_EQ(ret, Status::E_IPC);
138 LOG_INFO(UDMF_TEST, "UpdateData001 end.");
139 }
140
141 /**
142 * @tc.name: DeleteData001
143 * @tc.desc: Abnrmal testcase of DeleteData, the return value of GetInstance() is nullptr
144 * @tc.type: FUNC
145 */
146 HWTEST_F(UdmfClientAbnormalTest, DeleteData001, TestSize.Level1)
147 {
148 LOG_INFO(UDMF_TEST, "DeleteData001 begin.");
149 EXPECT_CALL(*mock_, GetInstance()).WillOnce(Return(nullptr));
150
151 UdmfClient client;
152 const QueryOption query;
153 std::vector<UnifiedData> unifiedDataSet;
154
155 Status ret = client.DeleteData(query, unifiedDataSet);
156 EXPECT_EQ(ret, Status::E_IPC);
157 LOG_INFO(UDMF_TEST, "DeleteData001 end.");
158 }
159
160 /**
161 * @tc.name: AddPrivilege001
162 * @tc.desc: Abnrmal testcase of AddPrivilege, the return value of GetInstance() is nullptr
163 * @tc.type: FUNC
164 */
165 HWTEST_F(UdmfClientAbnormalTest, AddPrivilege001, TestSize.Level1)
166 {
167 LOG_INFO(UDMF_TEST, "AddPrivilege001 begin.");
168 EXPECT_CALL(*mock_, GetInstance()).WillOnce(Return(nullptr));
169
170 UdmfClient client;
171 const QueryOption query;
172 Privilege privilege;
173
174 Status ret = client.AddPrivilege(query, privilege);
175 EXPECT_EQ(ret, Status::E_IPC);
176 LOG_INFO(UDMF_TEST, "AddPrivilege001 end.");
177 }
178
179 /**
180 * @tc.name: Sync001
181 * @tc.desc: Abnrmal testcase of Sync, the return value of GetInstance() is nullptr
182 * @tc.type: FUNC
183 */
184 HWTEST_F(UdmfClientAbnormalTest, Sync001, TestSize.Level1)
185 {
186 LOG_INFO(UDMF_TEST, "Sync001 begin.");
187 EXPECT_CALL(*mock_, GetInstance()).WillOnce(Return(nullptr));
188
189 UdmfClient client;
190 const QueryOption query;
191 const std::vector<std::string> devices;
192
193 Status ret = client.Sync(query, devices);
194 EXPECT_EQ(ret, Status::E_IPC);
195 LOG_INFO(UDMF_TEST, "Sync001 end.");
196 }
197
198 /**
199 * @tc.name: IsRemoteData001
200 * @tc.desc: Abnrmal testcase of IsRemoteData, the return value of GetInstance() is nullptr
201 * @tc.type: FUNC
202 */
203 HWTEST_F(UdmfClientAbnormalTest, IsRemoteData001, TestSize.Level1)
204 {
205 LOG_INFO(UDMF_TEST, "IsRemoteData001 begin.");
206 EXPECT_CALL(*mock_, GetInstance()).WillOnce(Return(nullptr));
207
208 UdmfClient client;
209 const QueryOption query;
210 bool result = true;
211
212 Status ret = client.IsRemoteData(query, result);
213 EXPECT_EQ(ret, Status::E_IPC);
214 LOG_INFO(UDMF_TEST, "IsRemoteData001 end.");
215 }
216
217 /**
218 * @tc.name: SetAppShareOption001
219 * @tc.desc: Abnrmal testcase of SetAppShareOption, the return value of GetInstance() is nullptr
220 * @tc.type: FUNC
221 */
222 HWTEST_F(UdmfClientAbnormalTest, SetAppShareOption001, TestSize.Level1)
223 {
224 LOG_INFO(UDMF_TEST, "SetAppShareOption001 begin.");
225 EXPECT_CALL(*mock_, GetInstance()).WillOnce(Return(nullptr));
226
227 UdmfClient client;
228 const std::string intention = "intention";
229 enum ShareOptions shareOption = ShareOptions::IN_APP;
230
231 Status ret = client.SetAppShareOption(intention, shareOption);
232 EXPECT_EQ(ret, Status::E_IPC);
233 LOG_INFO(UDMF_TEST, "SetAppShareOption001 end.");
234 }
235
236 /**
237 * @tc.name: GetAppShareOption001
238 * @tc.desc: Abnrmal testcase of GetAppShareOption, the return value of GetInstance() is nullptr
239 * @tc.type: FUNC
240 */
241 HWTEST_F(UdmfClientAbnormalTest, GetAppShareOption001, TestSize.Level1)
242 {
243 LOG_INFO(UDMF_TEST, "GetAppShareOption001 begin.");
244 EXPECT_CALL(*mock_, GetInstance()).WillOnce(Return(nullptr));
245
246 UdmfClient client;
247 const std::string intention = "intention";
248 enum ShareOptions shareOption = ShareOptions::IN_APP;
249
250 Status ret = client.SetAppShareOption(intention, shareOption);
251 EXPECT_EQ(ret, Status::E_IPC);
252 LOG_INFO(UDMF_TEST, "GetAppShareOption001 end.");
253 }
254
255 /**
256 * @tc.name: RemoveAppShareOption001
257 * @tc.desc: Abnrmal testcase of RemoveAppShareOption, the return value of GetInstance() is nullptr
258 * @tc.type: FUNC
259 */
260 HWTEST_F(UdmfClientAbnormalTest, RemoveAppShareOption001, TestSize.Level1)
261 {
262 LOG_INFO(UDMF_TEST, "RemoveAppShareOption001 begin.");
263 EXPECT_CALL(*mock_, GetInstance()).WillOnce(Return(nullptr));
264
265 UdmfClient client;
266 const std::string intention = "intention";
267
268 Status ret = client.RemoveAppShareOption(intention);
269 EXPECT_EQ(ret, Status::E_IPC);
270 LOG_INFO(UDMF_TEST, "RemoveAppShareOption001 end.");
271 }
272 } // OHOS::Test