• 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 #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     option.intention = Intention::UD_INTENTION_DATA_HUB;
78     std::string key = "testKey";
79 
80     Status ret = client.SetData(option, unifiedData, key);
81     EXPECT_EQ(ret, Status::E_IPC);
82     LOG_INFO(UDMF_TEST, "SetData001 end.");
83 }
84 
85 /**
86 * @tc.name: GetData001
87 * @tc.desc: Abnrmal testcase of GetData, the return value of GetInstance() is nullptr
88 * @tc.type: FUNC
89 */
90 HWTEST_F(UdmfClientAbnormalTest, GetData001, TestSize.Level1)
91 {
92     LOG_INFO(UDMF_TEST, "GetData001 begin.");
93     EXPECT_CALL(*mock_, GetInstance()).WillOnce(Return(nullptr));
94 
95     UdmfClient client;
96     const QueryOption query;
97     UnifiedData unifiedData;
98 
99     Status ret = client.GetData(query, unifiedData);
100     EXPECT_EQ(ret, Status::E_IPC);
101     LOG_INFO(UDMF_TEST, "GetData001 end.");
102 }
103 
104 /**
105 * @tc.name: GetBatchData001
106 * @tc.desc: Abnrmal testcase of GetBatchData, the return value of GetInstance() is nullptr
107 * @tc.type: FUNC
108 */
109 HWTEST_F(UdmfClientAbnormalTest, GetBatchData001, TestSize.Level1)
110 {
111     LOG_INFO(UDMF_TEST, "GetBatchData001 begin.");
112     EXPECT_CALL(*mock_, GetInstance()).WillOnce(Return(nullptr));
113 
114     UdmfClient client;
115     const QueryOption query;
116     std::vector<UnifiedData> unifiedDataSet;
117 
118     Status ret = client.GetBatchData(query, unifiedDataSet);
119     EXPECT_EQ(ret, Status::E_IPC);
120     LOG_INFO(UDMF_TEST, "GetBatchData001 end.");
121 }
122 
123 /**
124 * @tc.name: UpdateData001
125 * @tc.desc: Abnrmal testcase of UpdateData, the return value of GetInstance() is nullptr
126 * @tc.type: FUNC
127 */
128 HWTEST_F(UdmfClientAbnormalTest, UpdateData001, TestSize.Level1)
129 {
130     LOG_INFO(UDMF_TEST, "UpdateData001 begin.");
131     EXPECT_CALL(*mock_, GetInstance()).WillOnce(Return(nullptr));
132 
133     UdmfClient client;
134     const QueryOption query;
135     UnifiedData unifiedData;
136 
137     Status ret = client.UpdateData(query, unifiedData);
138     EXPECT_EQ(ret, Status::E_IPC);
139     LOG_INFO(UDMF_TEST, "UpdateData001 end.");
140 }
141 
142 /**
143 * @tc.name: DeleteData001
144 * @tc.desc: Abnrmal testcase of DeleteData, the return value of GetInstance() is nullptr
145 * @tc.type: FUNC
146 */
147 HWTEST_F(UdmfClientAbnormalTest, DeleteData001, TestSize.Level1)
148 {
149     LOG_INFO(UDMF_TEST, "DeleteData001 begin.");
150     EXPECT_CALL(*mock_, GetInstance()).WillOnce(Return(nullptr));
151 
152     UdmfClient client;
153     const QueryOption query;
154     std::vector<UnifiedData> unifiedDataSet;
155 
156     Status ret = client.DeleteData(query, unifiedDataSet);
157     EXPECT_EQ(ret, Status::E_IPC);
158     LOG_INFO(UDMF_TEST, "DeleteData001 end.");
159 }
160 
161 /**
162 * @tc.name: AddPrivilege001
163 * @tc.desc: Abnrmal testcase of AddPrivilege, the return value of GetInstance() is nullptr
164 * @tc.type: FUNC
165 */
166 HWTEST_F(UdmfClientAbnormalTest, AddPrivilege001, TestSize.Level1)
167 {
168     LOG_INFO(UDMF_TEST, "AddPrivilege001 begin.");
169     EXPECT_CALL(*mock_, GetInstance()).WillOnce(Return(nullptr));
170 
171     UdmfClient client;
172     const QueryOption query;
173     Privilege privilege;
174 
175     Status ret = client.AddPrivilege(query, privilege);
176     EXPECT_EQ(ret, Status::E_IPC);
177     LOG_INFO(UDMF_TEST, "AddPrivilege001 end.");
178 }
179 
180 /**
181 * @tc.name: Sync001
182 * @tc.desc: Abnrmal testcase of Sync, the return value of GetInstance() is nullptr
183 * @tc.type: FUNC
184 */
185 HWTEST_F(UdmfClientAbnormalTest, Sync001, TestSize.Level1)
186 {
187     LOG_INFO(UDMF_TEST, "Sync001 begin.");
188     EXPECT_CALL(*mock_, GetInstance()).WillOnce(Return(nullptr));
189 
190     UdmfClient client;
191     const QueryOption query;
192     const std::vector<std::string> devices;
193 
194     Status ret = client.Sync(query, devices);
195     EXPECT_EQ(ret, Status::E_IPC);
196     LOG_INFO(UDMF_TEST, "Sync001 end.");
197 }
198 
199 /**
200 * @tc.name: IsRemoteData001
201 * @tc.desc: Abnrmal testcase of IsRemoteData, the return value of GetInstance() is nullptr
202 * @tc.type: FUNC
203 */
204 HWTEST_F(UdmfClientAbnormalTest, IsRemoteData001, TestSize.Level1)
205 {
206     LOG_INFO(UDMF_TEST, "IsRemoteData001 begin.");
207     EXPECT_CALL(*mock_, GetInstance()).WillOnce(Return(nullptr));
208 
209     UdmfClient client;
210     const QueryOption query;
211     bool result = true;
212 
213     Status ret = client.IsRemoteData(query, result);
214     EXPECT_EQ(ret, Status::E_IPC);
215     LOG_INFO(UDMF_TEST, "IsRemoteData001 end.");
216 }
217 
218 /**
219 * @tc.name: SetAppShareOption001
220 * @tc.desc: Abnrmal testcase of SetAppShareOption, the return value of GetInstance() is nullptr
221 * @tc.type: FUNC
222 */
223 HWTEST_F(UdmfClientAbnormalTest, SetAppShareOption001, TestSize.Level1)
224 {
225     LOG_INFO(UDMF_TEST, "SetAppShareOption001 begin.");
226     EXPECT_CALL(*mock_, GetInstance()).WillOnce(Return(nullptr));
227 
228     UdmfClient client;
229     const std::string intention = "intention";
230     enum ShareOptions shareOption = ShareOptions::IN_APP;
231 
232     Status ret = client.SetAppShareOption(intention, shareOption);
233     EXPECT_EQ(ret, Status::E_IPC);
234     LOG_INFO(UDMF_TEST, "SetAppShareOption001 end.");
235 }
236 
237 /**
238 * @tc.name: GetAppShareOption001
239 * @tc.desc: Abnrmal testcase of GetAppShareOption, the return value of GetInstance() is nullptr
240 * @tc.type: FUNC
241 */
242 HWTEST_F(UdmfClientAbnormalTest, GetAppShareOption001, TestSize.Level1)
243 {
244     LOG_INFO(UDMF_TEST, "GetAppShareOption001 begin.");
245     EXPECT_CALL(*mock_, GetInstance()).WillOnce(Return(nullptr));
246 
247     UdmfClient client;
248     const std::string intention = "intention";
249     enum ShareOptions shareOption = ShareOptions::IN_APP;
250 
251     Status ret = client.SetAppShareOption(intention, shareOption);
252     EXPECT_EQ(ret, Status::E_IPC);
253     LOG_INFO(UDMF_TEST, "GetAppShareOption001 end.");
254 }
255 
256 /**
257 * @tc.name: RemoveAppShareOption001
258 * @tc.desc: Abnrmal testcase of RemoveAppShareOption, the return value of GetInstance() is nullptr
259 * @tc.type: FUNC
260 */
261 HWTEST_F(UdmfClientAbnormalTest, RemoveAppShareOption001, TestSize.Level1)
262 {
263     LOG_INFO(UDMF_TEST, "RemoveAppShareOption001 begin.");
264     EXPECT_CALL(*mock_, GetInstance()).WillOnce(Return(nullptr));
265 
266     UdmfClient client;
267     const std::string intention = "intention";
268 
269     Status ret = client.RemoveAppShareOption(intention);
270     EXPECT_EQ(ret, Status::E_IPC);
271     LOG_INFO(UDMF_TEST, "RemoveAppShareOption001 end.");
272 }
273 } // OHOS::Test