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 #include <unistd.h>
18 #include "ipc_skeleton.h"
19 #include "message_parcel_warp.h"
20 #include "pasteboard_error.h"
21 #include "pasteboard_hilog.h"
22 #include "pasteboard_service.h"
23 #include "paste_data_entry.h"
24 #include <thread>
25
26 using namespace testing;
27 using namespace testing::ext;
28 using namespace OHOS;
29 using namespace OHOS::MiscServices;
30 using namespace std::chrono;
31 using namespace OHOS::Security::AccessToken;
32
33 namespace OHOS {
34 namespace {
35 const int INT_ONE = 1;
36 const int32_t INT32_NEGATIVE_NUMBER = -1;
37 constexpr int32_t SET_VALUE_SUCCESS = 1;
38 const int INT_THREETHREETHREE = 333;
39 const uint32_t MAX_RECOGNITION_LENGTH = 1000;
40 const int32_t ACCOUNT_IDS_RANDOM = 1121;
41 const uint32_t UINT32_ONE = 1;
42 constexpr int64_t MIN_ASHMEM_DATA_SIZE = 32 * 1024;
43 constexpr uint32_t EVENT_TIME_OUT = 2000;
44 const std::string TEST_ENTITY_TEXT =
45 "清晨,从杭州市中心出发,沿着湖滨路缓缓前行。湖滨路是杭州市中心通往西湖的主要街道之一,两旁绿树成荫,湖光山色尽收眼"
46 "底。你可以选择步行或骑行,感受微风拂面的惬意。湖滨路的尽头是南山路,这里有一片开阔的广场,是欣赏西湖全景的绝佳位置"
47 "。进入南山路后,继续前行,雷峰塔的轮廓会逐渐映入眼帘。雷峰塔是西湖的标志性建筑之一,矗立在南屏山下,与西湖相映成趣"
48 "。你可以在这里稍作停留,欣赏塔的雄伟与湖水的柔美。南山路两旁有许多咖啡馆和餐厅,是补充能量的好去处。离开雷峰塔,沿"
49 "着南山路继续前行,你会看到一条蜿蜒的堤岸——杨公堤。杨公堤是西湖十景之一,堤岸两旁种满了柳树和桃树,春夏之交,柳绿桃"
50 "红,美不胜收。你可以选择沿着堤岸漫步,感受湖水的宁静与柳树的轻柔。杨公堤的尽头是湖心亭,这里是西湖的中心地带,也是"
51 "观赏西湖全景的最佳位置之一。从湖心亭出发,沿着湖畔步行至北山街。北山街是西湖北部的一条主要街道,两旁有许多历史建筑"
52 "和文化遗址。继续前行,你会看到保俶塔矗立在宝石流霞景区。保俶塔是西湖的另一座标志性建筑,与雷峰塔遥相呼应,形成“一"
53 "南一北”的独特景观。离开保俶塔,沿着北山街继续前行,你会到达断桥。断桥是西湖十景之一,冬季可欣赏断桥残雪的美景。断"
54 "桥的两旁种满了柳树,湖水清澈见底,是拍照留念的好地方。断桥的尽头是平湖秋月,这里是观赏西湖夜景的绝佳地点,夜晚灯光"
55 "亮起时,湖面倒映着月光,美轮美奂。游览结束后,沿着湖畔返回杭州市中心。沿途可以再次欣赏西湖的湖光山色,感受大自然的"
56 "和谐与宁静。如果你时间充裕,可以选择在湖畔的咖啡馆稍作休息,回味这一天的旅程。这条路线涵盖了西湖的主要经典景点,从"
57 "湖滨路到南山路,再到杨公堤、北山街,最后回到杭州市中心,整个行程大约需要一天时间。沿着这条路线,你可以领略西湖的自"
58 "然风光和文化底蕴,感受人间天堂的独特魅力。";
59 const int64_t DEFAULT_MAX_RAW_DATA_SIZE = 128 * 1024 * 1024;
60 constexpr int32_t MIMETYPE_MAX_SIZE = 1024;
61 static constexpr uint64_t ONE_HOUR_MILLISECONDS = 60 * 60 * 1000;
62 } // namespace
63
64 class MyTestEntityRecognitionObserver : public IEntityRecognitionObserver {
OnRecognitionEvent(EntityType entityType,std::string & entity)65 void OnRecognitionEvent(EntityType entityType, std::string &entity)
66 {
67 return;
68 }
AsObject()69 sptr<IRemoteObject> AsObject()
70 {
71 return nullptr;
72 }
73 };
74
75 class MyTestPasteboardChangedObserver : public IPasteboardChangedObserver {
OnPasteboardChanged()76 void OnPasteboardChanged()
77 {
78 return;
79 }
OnPasteboardEvent(std::string bundleName,int32_t status)80 void OnPasteboardEvent(std::string bundleName, int32_t status)
81 {
82 return;
83 }
AsObject()84 sptr<IRemoteObject> AsObject()
85 {
86 return nullptr;
87 }
88 };
89
90 class PasteboardEntryGetterImpl : public IPasteboardEntryGetter {
91 public:
PasteboardEntryGetterImpl()92 PasteboardEntryGetterImpl() {};
~PasteboardEntryGetterImpl()93 ~PasteboardEntryGetterImpl() {};
GetRecordValueByType(uint32_t recordId,PasteDataEntry & value)94 int32_t GetRecordValueByType(uint32_t recordId, PasteDataEntry &value)
95 {
96 return 0;
97 };
AsObject()98 sptr<IRemoteObject> AsObject()
99 {
100 return nullptr;
101 };
102 };
103
104 class PasteboardDelayGetterImpl : public IPasteboardDelayGetter {
105 public:
PasteboardDelayGetterImpl()106 PasteboardDelayGetterImpl() {};
~PasteboardDelayGetterImpl()107 ~PasteboardDelayGetterImpl() {};
GetPasteData(const std::string & type,PasteData & data)108 void GetPasteData(const std::string &type, PasteData &data) {};
GetUnifiedData(const std::string & type,UDMF::UnifiedData & data)109 void GetUnifiedData(const std::string &type, UDMF::UnifiedData &data) {};
AsObject()110 sptr<IRemoteObject> AsObject()
111 {
112 return nullptr;
113 };
114 };
115
116 class RemoteObjectTest : public IRemoteObject {
117 public:
RemoteObjectTest(std::u16string descriptor)118 explicit RemoteObjectTest(std::u16string descriptor) : IRemoteObject(descriptor) { }
~RemoteObjectTest()119 ~RemoteObjectTest() { }
120
GetObjectRefCount()121 int32_t GetObjectRefCount()
122 {
123 return 0;
124 }
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)125 int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
126 {
127 return 0;
128 }
AddDeathRecipient(const sptr<DeathRecipient> & recipient)129 bool AddDeathRecipient(const sptr<DeathRecipient> &recipient)
130 {
131 return true;
132 }
RemoveDeathRecipient(const sptr<DeathRecipient> & recipient)133 bool RemoveDeathRecipient(const sptr<DeathRecipient> &recipient)
134 {
135 return true;
136 }
Dump(int fd,const std::vector<std::u16string> & args)137 int Dump(int fd, const std::vector<std::u16string> &args)
138 {
139 return 0;
140 }
141 };
142
143 class PasteboardServiceSetDataTest : public testing::Test {
144 public:
145 static void SetUpTestCase(void);
146 static void TearDownTestCase(void);
147 void SetUp();
148 void TearDown();
149 int32_t WritePasteData(PasteData &pasteData, std::vector<uint8_t> &buffer, int &fd,
150 int64_t &tlvSize, MessageParcelWarp &messageData, MessageParcel &parcelPata);
151 using TestEvent = ClipPlugin::GlobalEvent;
152 using TaskContext = PasteboardService::RemoteDataTaskManager::TaskContext;
153 };
154
SetUpTestCase(void)155 void PasteboardServiceSetDataTest::SetUpTestCase(void) { }
156
TearDownTestCase(void)157 void PasteboardServiceSetDataTest::TearDownTestCase(void) { }
158
SetUp(void)159 void PasteboardServiceSetDataTest::SetUp(void) { }
160
TearDown(void)161 void PasteboardServiceSetDataTest::TearDown(void) { }
162
WritePasteData(PasteData & pasteData,std::vector<uint8_t> & buffer,int & fd,int64_t & tlvSize,MessageParcelWarp & messageData,MessageParcel & parcelPata)163 int32_t PasteboardServiceSetDataTest::WritePasteData(PasteData &pasteData, std::vector<uint8_t> &buffer, int &fd,
164 int64_t &tlvSize, MessageParcelWarp &messageData, MessageParcel &parcelPata)
165 {
166 std::vector<uint8_t> pasteDataTlv(0);
167 bool result = pasteData.Encode(pasteDataTlv);
168 if (!result) {
169 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "paste data encode failed.");
170 return static_cast<int32_t>(PasteboardError::SERIALIZATION_ERROR);
171 }
172 tlvSize = static_cast<int64_t>(pasteDataTlv.size());
173 if (tlvSize > MIN_ASHMEM_DATA_SIZE) {
174 if (!messageData.WriteRawData(parcelPata, pasteDataTlv.data(), pasteDataTlv.size())) {
175 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "Failed to WriteRawData");
176 return static_cast<int32_t>(PasteboardError::SERIALIZATION_ERROR);
177 }
178 fd = messageData.GetWriteDataFd();
179 pasteDataTlv.clear();
180 } else {
181 fd = messageData.CreateTmpFd();
182 if (fd < 0) {
183 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "Failed to create tmp fd");
184 return static_cast<int32_t>(PasteboardError::SERIALIZATION_ERROR);
185 }
186 }
187 buffer = std::move(pasteDataTlv);
188 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "set: fd:%{public}d, size:%{public}" PRId64, fd, tlvSize);
189 return static_cast<int32_t>(PasteboardError::E_OK);
190 }
191
192 namespace MiscServices {
193 /**
194 * @tc.name: SetPasteDataTest001
195 * @tc.desc: test Func SetPasteData
196 * @tc.type: FUNC
197 */
198 HWTEST_F(PasteboardServiceSetDataTest, SetPasteDataTest001, TestSize.Level1)
199 {
200 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataTest001 start");
201 int fd = -1;
202 int64_t rawDataSize = 0;
203 std::vector<uint8_t> buffer = { 'h', 'e', 'l', 'l', 'o' };
204 sptr<PasteboardDelayGetterImpl> delayGetter = sptr<PasteboardDelayGetterImpl>::MakeSptr();
205 EXPECT_NE(delayGetter, nullptr);
206 sptr<PasteboardEntryGetterImpl> entryGetter = sptr<PasteboardEntryGetterImpl>::MakeSptr();
207 EXPECT_NE(entryGetter, nullptr);
208
209 auto tempPasteboard = std::make_shared<PasteboardService>();
210 EXPECT_NE(tempPasteboard, nullptr);
211 int32_t result = tempPasteboard->SetPasteData(dup(fd), rawDataSize, buffer, delayGetter, entryGetter);
212 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR));
213 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataTest001 end");
214 }
215
216 /**
217 * @tc.name: SetPasteDataTest002
218 * @tc.desc: test Func SetPasteData
219 * @tc.type: FUNC
220 */
221 HWTEST_F(PasteboardServiceSetDataTest, SetPasteDataTest002, TestSize.Level1)
222 {
223 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataTest002 start");
224 int fd = -1;
225 int64_t rawDataSize = DEFAULT_MAX_RAW_DATA_SIZE + 1;
226 std::vector<uint8_t> buffer = { 'h', 'e', 'l', 'l', 'o' };
227 sptr<PasteboardDelayGetterImpl> delayGetter = sptr<PasteboardDelayGetterImpl>::MakeSptr();
228 EXPECT_NE(delayGetter, nullptr);
229 sptr<PasteboardEntryGetterImpl> entryGetter = sptr<PasteboardEntryGetterImpl>::MakeSptr();
230 EXPECT_NE(entryGetter, nullptr);
231
232 auto tempPasteboard = std::make_shared<PasteboardService>();
233 EXPECT_NE(tempPasteboard, nullptr);
234 int32_t result = tempPasteboard->SetPasteData(dup(fd), rawDataSize, buffer, delayGetter, entryGetter);
235 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR));
236 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataTest002 end");
237 }
238
239 /**
240 * @tc.name: SetPasteDataTest003
241 * @tc.desc: test Func SetPasteData
242 * @tc.type: FUNC
243 */
244 HWTEST_F(PasteboardServiceSetDataTest, SetPasteDataTest003, TestSize.Level1)
245 {
246 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataTest003 start");
247 int fd = -1;
248 int64_t rawDataSize = DEFAULT_MAX_RAW_DATA_SIZE;
249 std::vector<uint8_t> buffer = { 'h', 'e', 'l', 'l', 'o' };
250 sptr<PasteboardDelayGetterImpl> delayGetter = sptr<PasteboardDelayGetterImpl>::MakeSptr();
251 EXPECT_NE(delayGetter, nullptr);
252 sptr<PasteboardEntryGetterImpl> entryGetter = sptr<PasteboardEntryGetterImpl>::MakeSptr();
253 EXPECT_NE(entryGetter, nullptr);
254
255 auto tempPasteboard = std::make_shared<PasteboardService>();
256 EXPECT_NE(tempPasteboard, nullptr);
257 int32_t result = tempPasteboard->SetPasteData(dup(fd), rawDataSize, buffer, delayGetter, entryGetter);
258 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::INVALID_DATA_ERROR));
259 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataTest003 end");
260 }
261
262 /**
263 * @tc.name: SetPasteDataTest004
264 * @tc.desc: test Func SetPasteData
265 * @tc.type: FUNC
266 */
267 HWTEST_F(PasteboardServiceSetDataTest, SetPasteDataTest004, TestSize.Level1)
268 {
269 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataTest004 start");
270 int fd = -1;
271 int64_t rawDataSize = 1;
272 std::vector<uint8_t> buffer = { 'h', 'e', 'l', 'l', 'o' };
273 sptr<PasteboardDelayGetterImpl> delayGetter = sptr<PasteboardDelayGetterImpl>::MakeSptr();
274 EXPECT_NE(delayGetter, nullptr);
275 sptr<PasteboardEntryGetterImpl> entryGetter = sptr<PasteboardEntryGetterImpl>::MakeSptr();
276 EXPECT_NE(entryGetter, nullptr);
277
278 auto tempPasteboard = std::make_shared<PasteboardService>();
279 EXPECT_NE(tempPasteboard, nullptr);
280 int32_t result = tempPasteboard->SetPasteData(dup(fd), rawDataSize, buffer, delayGetter, entryGetter);
281 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::NO_DATA_ERROR));
282 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataTest004 end");
283 }
284
285 /**
286 * @tc.name: SetPasteDataTest005
287 * @tc.desc: test Func SetPasteData
288 * @tc.type: FUNC
289 * @tc.require:
290 * @tc.author:
291 */
292 HWTEST_F(PasteboardServiceSetDataTest, SetPasteDataTest005, TestSize.Level0)
293 {
294 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataTest005 start");
295 auto tempPasteboard = std::make_shared<PasteboardService>();
296 int32_t syncTime = 0;
297 int fd = -1;
298 int64_t rawDataSize = 0;
299 std::vector<uint8_t> recvTLV;
300 auto ret = tempPasteboard->SetPasteData(dup(fd), rawDataSize, recvTLV, nullptr, nullptr);
301 EXPECT_EQ(static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR), ret);
302 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataTest005 end");
303 }
304
305 /**
306 * @tc.name: SetPasteDataDelayDataTest001
307 * @tc.desc: test Func SetPasteDataDelayData, return INVALID_PARAM_ERROR.
308 * @tc.type: FUNC
309 */
310 HWTEST_F(PasteboardServiceSetDataTest, SetPasteDataDelayDataTest001, TestSize.Level0)
311 {
312 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataDelayDataTest001 start");
313 int fd = -1;
314 int64_t rawDataSize = 0;
315 std::vector<uint8_t> buffer = { 'h', 'e', 'l', 'l', 'o' };
316 sptr<IPasteboardDelayGetter> delayGetter = nullptr;
317 auto tempPasteboard = std::make_shared<PasteboardService>();
318 EXPECT_NE(tempPasteboard, nullptr);
319
320 int32_t result = tempPasteboard->SetPasteDataDelayData(dup(fd), rawDataSize, buffer, delayGetter);
321 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR));
322 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataDelayDataTest001 end");
323 }
324
325 /**
326 * @tc.name: SetPasteDataDelayDataTest002
327 * @tc.desc: test Func SetPasteDataDelayData, return INVALID_PARAM_ERROR.
328 * @tc.type: FUNC
329 */
330 HWTEST_F(PasteboardServiceSetDataTest, SetPasteDataDelayDataTest002, TestSize.Level0)
331 {
332 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataDelayDataTest002 start");
333 int fd = -1;
334 int64_t rawDataSize = INT64_MAX;
335 std::vector<uint8_t> buffer = { 'h', 'e', 'l', 'l', 'o' };
336 sptr<IPasteboardDelayGetter> delayGetter = nullptr;
337 auto tempPasteboard = std::make_shared<PasteboardService>();
338 EXPECT_NE(tempPasteboard, nullptr);
339
340 int32_t result = tempPasteboard->SetPasteDataDelayData(dup(fd), rawDataSize, buffer, delayGetter);
341 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR));
342 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataDelayDataTest002 end");
343 }
344
345 /**
346 * @tc.name: SetPasteDataDelayDataTest003
347 * @tc.desc: test Func SetPasteDataDelayData, fd is error, map failed, return INVALID_DATA_ERROR.
348 * @tc.type: FUNC
349 */
350 HWTEST_F(PasteboardServiceSetDataTest, SetPasteDataDelayDataTest003, TestSize.Level0)
351 {
352 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataDelayDataTest003 start");
353 int fd = -1;
354 int64_t rawDataSize = USHRT_MAX;
355 std::vector<uint8_t> buffer = { 'h', 'e', 'l', 'l', 'o' };
356 sptr<IPasteboardDelayGetter> delayGetter = nullptr;
357 auto tempPasteboard = std::make_shared<PasteboardService>();
358 EXPECT_NE(tempPasteboard, nullptr);
359
360 int32_t result = tempPasteboard->SetPasteDataDelayData(dup(fd), rawDataSize, buffer, delayGetter);
361 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::INVALID_DATA_ERROR));
362 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataDelayDataTest003 end");
363 }
364
365 /**
366 * @tc.name: SetPasteDataDelayDataTest004
367 * @tc.desc: test Func SetPasteDataDelayData, fd is right, but buffer is empty, return NO_DATA_ERROR.
368 * @tc.type: FUNC
369 */
370 HWTEST_F(PasteboardServiceSetDataTest, SetPasteDataDelayDataTest004, TestSize.Level0)
371 {
372 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataDelayDataTest004 start");
373 int fd = 0XF;
374 int64_t rawDataSize = USHRT_MAX;
375 std::vector<uint8_t> buffer;
376 sptr<IPasteboardDelayGetter> delayGetter = nullptr;
377 auto tempPasteboard = std::make_shared<PasteboardService>();
378 EXPECT_NE(tempPasteboard, nullptr);
379
380 int32_t result = tempPasteboard->SetPasteDataDelayData(dup(fd), rawDataSize, buffer, delayGetter);
381 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::INVALID_DATA_ERROR));
382 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataDelayDataTest004 end");
383 }
384
385 /**
386 * @tc.name: SetPasteDataDelayDataTest005
387 * @tc.desc: test Func SetPasteDataDelayData, NOT goto map and buffer is empty, return ERR_OK.
388 * @tc.type: FUNC
389 */
390 HWTEST_F(PasteboardServiceSetDataTest, SetPasteDataDelayDataTest005, TestSize.Level0)
391 {
392 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataDelayDataTest005 start");
393 int fd = -1;
394 int64_t rawDataSize = UINT8_MAX;
395 std::vector<uint8_t> buffer;
396 sptr<IPasteboardDelayGetter> delayGetter = nullptr;
397 auto tempPasteboard = std::make_shared<PasteboardService>();
398 EXPECT_NE(tempPasteboard, nullptr);
399
400 int32_t result = tempPasteboard->SetPasteDataDelayData(dup(fd), rawDataSize, buffer, delayGetter);
401 EXPECT_EQ(result, ERR_OK);
402 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataDelayDataTest005 end");
403 }
404
405 /**
406 * @tc.name: SetPasteDataDelayDataTest006
407 * @tc.desc: test Func SetPasteDataDelayData, NOT goto map and buffer is NOT empty, return ERR_OK.
408 * @tc.type: FUNC
409 */
410 HWTEST_F(PasteboardServiceSetDataTest, SetPasteDataDelayDataTest006, TestSize.Level0)
411 {
412 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataDelayDataTest006 start");
413 int fd = -1;
414 int64_t rawDataSize = UINT8_MAX;
415 std::vector<uint8_t> buffer { 'h', 'e', 'l', 'l', 'o' };
416 sptr<IPasteboardDelayGetter> delayGetter = nullptr;
417 auto tempPasteboard = std::make_shared<PasteboardService>();
418 EXPECT_NE(tempPasteboard, nullptr);
419
420 int32_t result = tempPasteboard->SetPasteDataDelayData(dup(fd), rawDataSize, buffer, delayGetter);
421 EXPECT_NE(result, ERR_OK);
422 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataDelayDataTest006 end");
423 }
424
425 /**
426 * @tc.name: SetPasteDataEntryDataTest001
427 * @tc.desc: test Func SetPasteDataEntryData, NOT goto map and buffer is NOT empty.
428 * @tc.type: FUNC
429 */
430 HWTEST_F(PasteboardServiceSetDataTest, SetPasteDataEntryDataTest001, TestSize.Level0)
431 {
432 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataEntryDataTest001 start");
433 int fd = -1;
434 int64_t rawDataSize = UINT8_MAX;
435 std::vector<uint8_t> buffer { 'h', 'e', 'l', 'l', 'o' };
436 sptr<IPasteboardEntryGetter> entryGetter = nullptr;
437 auto tempPasteboard = std::make_shared<PasteboardService>();
438 EXPECT_NE(tempPasteboard, nullptr);
439
440 int32_t result = tempPasteboard->SetPasteDataEntryData(dup(fd), rawDataSize, buffer, entryGetter);
441 EXPECT_NE(result, ERR_OK);
442 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataEntryDataTest001 end");
443 }
444
445 /**
446 * @tc.name: SetPasteDataOnlyTest001
447 * @tc.desc: test Func SetPasteDataOnly, it will be return INVALID_PARAM_ERROR.
448 * @tc.type: FUNC
449 */
450 HWTEST_F(PasteboardServiceSetDataTest, SetPasteDataOnlyTest001, TestSize.Level0)
451 {
452 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataOnlyTest001 start");
453 auto mpw = std::make_shared<MessageParcelWarp>();
454 EXPECT_NE(mpw, nullptr);
455
456 auto service = std::make_shared<PasteboardService>();
457 EXPECT_NE(service, nullptr);
458
459 int64_t rawDataSize = 0;
460 std::vector<uint8_t> buffer;
461 int fd = mpw->CreateTmpFd();
462 int32_t result = service->SetPasteDataOnly(dup(fd), rawDataSize, buffer);
463 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR));
464 mpw->writeRawDataFd_ = -1;
465 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataOnlyTest001 end");
466 }
467
468 /**
469 * @tc.name: SetPasteDataInfoTest001
470 * @tc.desc: test Func SetPasteDataInfo
471 * @tc.type: FUNC
472 * @tc.require:
473 * @tc.author:
474 */
475 HWTEST_F(PasteboardServiceSetDataTest, SetPasteDataInfoTest001, TestSize.Level0)
476 {
477 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataInfoTest001 start");
478 std::string bundleName = "com.pastboard.test";
479 int32_t appIndex = 1;
480 PasteData pasteData;
481 AppInfo appInfo;
482 appInfo.bundleName = bundleName;
483 appInfo.appIndex = appIndex;
484 auto tokenId = IPCSkeleton::GetCallingTokenID();
485 auto tempPasteboard = std::make_shared<PasteboardService>();
486 EXPECT_NE(tempPasteboard, nullptr);
487
488 tempPasteboard->SetPasteDataInfo(pasteData, appInfo, tokenId);
489 std::pair<std::string, int32_t> originAuthority;
490 originAuthority.first = bundleName;
491 originAuthority.second = appIndex;
492 EXPECT_EQ(pasteData.GetBundleName(), bundleName);
493 EXPECT_EQ(pasteData.GetAppIndex(), appIndex);
494 EXPECT_EQ(pasteData.GetOriginAuthority(), originAuthority);
495 EXPECT_EQ(pasteData.GetTokenId(), tokenId);
496 EXPECT_EQ(pasteData.GetDataId(), 1);
497 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataInfoTest001 end");
498 }
499
500 /**
501 * @tc.name: SetPasteDataDotTest001
502 * @tc.desc: test Func SetPasteDataDot
503 * @tc.type: FUNC
504 */
505 HWTEST_F(PasteboardServiceSetDataTest, SetPasteDataDotTest001, TestSize.Level0)
506 {
507 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataDotTest001 start");
508 PasteData pasteData;
509 auto tempPasteboard = std::make_shared<PasteboardService>();
510 EXPECT_NE(tempPasteboard, nullptr);
511
512 tempPasteboard->SetPasteDataDot(pasteData);
513 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteDataDotTest001 end");
514 }
515
516 /**
517 * @tc.name: SetDistributedDataTest001
518 * @tc.desc: test Func SetDistributedData
519 * @tc.type: FUNC
520 */
521 HWTEST_F(PasteboardServiceSetDataTest, SetDistributedDataTest001, TestSize.Level0)
522 {
523 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetDistributedDataTest001 start");
524 int32_t user = ACCOUNT_IDS_RANDOM;
525 PasteData pasteData;
526 auto tempPasteboard = std::make_shared<PasteboardService>();
527 EXPECT_NE(tempPasteboard, nullptr);
528
529 tempPasteboard->SetDistributedData(user, pasteData);
530 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetDistributedDataTest001 end");
531 }
532
533 /**
534 * @tc.name: SetCurrentDataTest001
535 * @tc.desc: test Func SetCurrentData
536 * @tc.type: FUNC
537 */
538 HWTEST_F(PasteboardServiceSetDataTest, SetCurrentDataTest001, TestSize.Level0)
539 {
540 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetCurrentDataTest001 start");
541 PasteData pasteData;
542 ClipPlugin::GlobalEvent event {};
543 auto tempPasteboard = std::make_shared<PasteboardService>();
544 EXPECT_NE(tempPasteboard, nullptr);
545
546 tempPasteboard->SetCurrentData(event, pasteData);
547 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetCurrentDataTest001 end");
548 }
549
550 } // namespace MiscServices
551 } // namespace OHOS