1bc03f14fSopenharmony_ci/* 2bc03f14fSopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3bc03f14fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4bc03f14fSopenharmony_ci * you may not use this file except in compliance with the License. 5bc03f14fSopenharmony_ci * You may obtain a copy of the License at 6bc03f14fSopenharmony_ci * 7bc03f14fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8bc03f14fSopenharmony_ci * 9bc03f14fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10bc03f14fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11bc03f14fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12bc03f14fSopenharmony_ci * See the License for the specific language governing permissions and 13bc03f14fSopenharmony_ci * limitations under the License. 14bc03f14fSopenharmony_ci */ 15bc03f14fSopenharmony_ci#include <chrono> 16bc03f14fSopenharmony_ci#include <cstdint> 17bc03f14fSopenharmony_ci#include <gtest/gtest.h> 18bc03f14fSopenharmony_ci#include <thread> 19bc03f14fSopenharmony_ci#include <unistd.h> 20bc03f14fSopenharmony_ci#include <vector> 21bc03f14fSopenharmony_ci 22bc03f14fSopenharmony_ci#include "access_token.h" 23bc03f14fSopenharmony_ci#include "accesstoken_kit.h" 24bc03f14fSopenharmony_ci#include "hap_token_info.h" 25bc03f14fSopenharmony_ci#include "os_account_manager.h" 26bc03f14fSopenharmony_ci#include "pasteboard_client.h" 27bc03f14fSopenharmony_ci#include "pasteboard_error.h" 28bc03f14fSopenharmony_ci#include "pasteboard_hilog.h" 29bc03f14fSopenharmony_ci#include "pasteboard_observer_callback.h" 30bc03f14fSopenharmony_ci#include "permission_state_full.h" 31bc03f14fSopenharmony_ci#include "pixel_map.h" 32bc03f14fSopenharmony_ci#include "token_setproc.h" 33bc03f14fSopenharmony_ci#include "uri.h" 34bc03f14fSopenharmony_ci#include "want.h" 35bc03f14fSopenharmony_ci 36bc03f14fSopenharmony_cinamespace OHOS::MiscServices { 37bc03f14fSopenharmony_ciusing namespace testing::ext; 38bc03f14fSopenharmony_ciusing namespace OHOS::Media; 39bc03f14fSopenharmony_ciusing namespace OHOS::Security::AccessToken; 40bc03f14fSopenharmony_ciconstexpr const char *CMD = "hidumper -s 3701 -a --data"; 41bc03f14fSopenharmony_ciconstexpr const uint16_t EACH_LINE_LENGTH = 50; 42bc03f14fSopenharmony_ciconstexpr const uint16_t TOTAL_LENGTH = 500; 43bc03f14fSopenharmony_ciconst uint64_t SYSTEM_APP_MASK = (static_cast<uint64_t>(1) << 32); 44bc03f14fSopenharmony_cistd::string g_webviewPastedataTag = "WebviewPasteDataTag"; 45bc03f14fSopenharmony_ciclass PasteboardServiceTest : public testing::Test { 46bc03f14fSopenharmony_cipublic: 47bc03f14fSopenharmony_ci static void SetUpTestCase(void); 48bc03f14fSopenharmony_ci static void TearDownTestCase(void); 49bc03f14fSopenharmony_ci void SetUp(); 50bc03f14fSopenharmony_ci void TearDown(); 51bc03f14fSopenharmony_ci static bool ExecuteCmd(std::string &result); 52bc03f14fSopenharmony_ci 53bc03f14fSopenharmony_ci static void AllocTestTokenId(); 54bc03f14fSopenharmony_ci static void DeleteTestTokenId(); 55bc03f14fSopenharmony_ci static void RestoreSelfTokenId(); 56bc03f14fSopenharmony_ci static void CommonTest(PasteData &oldPasteData, PasteData &newPasteData); 57bc03f14fSopenharmony_ci static sptr<PasteboardObserver> pasteboardObserver_; 58bc03f14fSopenharmony_ci static sptr<PasteboardObserver> pasteboardEventObserver_; 59bc03f14fSopenharmony_ci static std::atomic_bool pasteboardChangedFlag_; 60bc03f14fSopenharmony_ci static std::atomic_int32_t pasteboardEventStatus_; 61bc03f14fSopenharmony_ci static uint64_t selfTokenId_; 62bc03f14fSopenharmony_ci static AccessTokenID testTokenId_; 63bc03f14fSopenharmony_ci}; 64bc03f14fSopenharmony_cistd::atomic_bool PasteboardServiceTest::pasteboardChangedFlag_ = false; 65bc03f14fSopenharmony_cistd::atomic_int32_t PasteboardServiceTest::pasteboardEventStatus_ = -1; 66bc03f14fSopenharmony_cisptr<PasteboardObserver> PasteboardServiceTest::pasteboardObserver_ = nullptr; 67bc03f14fSopenharmony_cisptr<PasteboardObserver> PasteboardServiceTest::pasteboardEventObserver_ = nullptr; 68bc03f14fSopenharmony_ciuint64_t PasteboardServiceTest::selfTokenId_ = 0; 69bc03f14fSopenharmony_ciAccessTokenID PasteboardServiceTest::testTokenId_ = 0; 70bc03f14fSopenharmony_ci 71bc03f14fSopenharmony_civoid PasteboardServiceTest::SetUpTestCase(void) 72bc03f14fSopenharmony_ci{ 73bc03f14fSopenharmony_ci selfTokenId_ = GetSelfTokenID(); 74bc03f14fSopenharmony_ci AllocTestTokenId(); 75bc03f14fSopenharmony_ci} 76bc03f14fSopenharmony_ci 77bc03f14fSopenharmony_civoid PasteboardServiceTest::TearDownTestCase(void) 78bc03f14fSopenharmony_ci{ 79bc03f14fSopenharmony_ci DeleteTestTokenId(); 80bc03f14fSopenharmony_ci} 81bc03f14fSopenharmony_ci 82bc03f14fSopenharmony_civoid PasteboardServiceTest::SetUp(void) {} 83bc03f14fSopenharmony_ci 84bc03f14fSopenharmony_civoid PasteboardServiceTest::TearDown(void) 85bc03f14fSopenharmony_ci{ 86bc03f14fSopenharmony_ci if (PasteboardServiceTest::pasteboardObserver_ != nullptr) { 87bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->RemovePasteboardEventObserver(PasteboardServiceTest::pasteboardObserver_); 88bc03f14fSopenharmony_ci } 89bc03f14fSopenharmony_ci if (PasteboardServiceTest::pasteboardEventObserver_ != nullptr) { 90bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->RemovePasteboardEventObserver(PasteboardServiceTest::pasteboardEventObserver_); 91bc03f14fSopenharmony_ci } 92bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 93bc03f14fSopenharmony_ci PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "TearDown."); 94bc03f14fSopenharmony_ci} 95bc03f14fSopenharmony_ci 96bc03f14fSopenharmony_civoid PasteboardObserverCallback::OnPasteboardChanged() 97bc03f14fSopenharmony_ci{ 98bc03f14fSopenharmony_ci PasteboardServiceTest::pasteboardChangedFlag_ = true; 99bc03f14fSopenharmony_ci PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "test changed callback."); 100bc03f14fSopenharmony_ci} 101bc03f14fSopenharmony_ci 102bc03f14fSopenharmony_civoid PasteboardEventObserverCallback::OnPasteboardEvent(std::string bundleName, int32_t status) 103bc03f14fSopenharmony_ci{ 104bc03f14fSopenharmony_ci PasteboardServiceTest::pasteboardEventStatus_ = status; 105bc03f14fSopenharmony_ci PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "test event callback bundleName: %{public}s,status:%{public}d", 106bc03f14fSopenharmony_ci bundleName.c_str(), status); 107bc03f14fSopenharmony_ci} 108bc03f14fSopenharmony_ci 109bc03f14fSopenharmony_cibool PasteboardServiceTest::ExecuteCmd(std::string &result) 110bc03f14fSopenharmony_ci{ 111bc03f14fSopenharmony_ci char buff[EACH_LINE_LENGTH] = { 0x00 }; 112bc03f14fSopenharmony_ci char output[TOTAL_LENGTH] = { 0x00 }; 113bc03f14fSopenharmony_ci FILE *ptr = nullptr; 114bc03f14fSopenharmony_ci if ((ptr = popen(CMD, "r")) != nullptr) { 115bc03f14fSopenharmony_ci while (fgets(buff, sizeof(buff), ptr) != nullptr) { 116bc03f14fSopenharmony_ci if (strcat_s(output, sizeof(output), buff) != 0) { 117bc03f14fSopenharmony_ci pclose(ptr); 118bc03f14fSopenharmony_ci ptr = nullptr; 119bc03f14fSopenharmony_ci return false; 120bc03f14fSopenharmony_ci } 121bc03f14fSopenharmony_ci } 122bc03f14fSopenharmony_ci pclose(ptr); 123bc03f14fSopenharmony_ci ptr = nullptr; 124bc03f14fSopenharmony_ci } else { 125bc03f14fSopenharmony_ci return false; 126bc03f14fSopenharmony_ci } 127bc03f14fSopenharmony_ci result = std::string(output); 128bc03f14fSopenharmony_ci return true; 129bc03f14fSopenharmony_ci} 130bc03f14fSopenharmony_ci 131bc03f14fSopenharmony_civoid PasteboardServiceTest::AllocTestTokenId() 132bc03f14fSopenharmony_ci{ 133bc03f14fSopenharmony_ci std::vector<int32_t> ids; 134bc03f14fSopenharmony_ci auto ret = AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids); 135bc03f14fSopenharmony_ci if (ret != ERR_OK || ids.empty()) { 136bc03f14fSopenharmony_ci PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "query active user failed errCode = %{public}d", ret); 137bc03f14fSopenharmony_ci return; 138bc03f14fSopenharmony_ci } 139bc03f14fSopenharmony_ci HapInfoParams infoParams = { .userID = ids[0], 140bc03f14fSopenharmony_ci .bundleName = "ohos.privacy_test.pasteboard", 141bc03f14fSopenharmony_ci .instIndex = 0, 142bc03f14fSopenharmony_ci .appIDDesc = "privacy_test.pasteboard" }; 143bc03f14fSopenharmony_ci PermissionStateFull testState = { .permissionName = "ohos.permission.DUMP", 144bc03f14fSopenharmony_ci .isGeneral = true, 145bc03f14fSopenharmony_ci .resDeviceID = { "local" }, 146bc03f14fSopenharmony_ci .grantStatus = { PermissionState::PERMISSION_GRANTED }, 147bc03f14fSopenharmony_ci .grantFlags = { 1 } }; 148bc03f14fSopenharmony_ci HapPolicyParams policyParams = { .apl = APL_NORMAL, 149bc03f14fSopenharmony_ci .domain = "test.domain.pasteboard", 150bc03f14fSopenharmony_ci .permList = {}, 151bc03f14fSopenharmony_ci .permStateList = { testState } }; 152bc03f14fSopenharmony_ci 153bc03f14fSopenharmony_ci AccessTokenKit::AllocHapToken(infoParams, policyParams); 154bc03f14fSopenharmony_ci testTokenId_ = Security::AccessToken::AccessTokenKit::GetHapTokenID( 155bc03f14fSopenharmony_ci infoParams.userID, infoParams.bundleName, infoParams.instIndex); 156bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "userID = %{public}d, testTokenId = 0x%{public}x.", infoParams.userID, 157bc03f14fSopenharmony_ci testTokenId_); 158bc03f14fSopenharmony_ci} 159bc03f14fSopenharmony_ci 160bc03f14fSopenharmony_civoid PasteboardServiceTest::DeleteTestTokenId() 161bc03f14fSopenharmony_ci{ 162bc03f14fSopenharmony_ci AccessTokenKit::DeleteToken(testTokenId_); 163bc03f14fSopenharmony_ci} 164bc03f14fSopenharmony_ci 165bc03f14fSopenharmony_civoid PasteboardServiceTest::RestoreSelfTokenId() 166bc03f14fSopenharmony_ci{ 167bc03f14fSopenharmony_ci auto ret = SetSelfTokenID(selfTokenId_); 168bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "ret = %{public}d!", ret); 169bc03f14fSopenharmony_ci} 170bc03f14fSopenharmony_ci 171bc03f14fSopenharmony_civoid PasteboardServiceTest::CommonTest(PasteData &oldPasteData, PasteData &newPasteData) 172bc03f14fSopenharmony_ci{ 173bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "start."); 174bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 175bc03f14fSopenharmony_ci auto hasPasteData = PasteboardClient::GetInstance()->HasPasteData(); 176bc03f14fSopenharmony_ci ASSERT_TRUE(hasPasteData != true); 177bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(oldPasteData); 178bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 179bc03f14fSopenharmony_ci hasPasteData = PasteboardClient::GetInstance()->HasPasteData(); 180bc03f14fSopenharmony_ci ASSERT_TRUE(hasPasteData == true); 181bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->GetPasteData(newPasteData); 182bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 183bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "end."); 184bc03f14fSopenharmony_ci} 185bc03f14fSopenharmony_ci 186bc03f14fSopenharmony_cistring GetTime() 187bc03f14fSopenharmony_ci{ 188bc03f14fSopenharmony_ci time_t curtime; 189bc03f14fSopenharmony_ci time(&curtime); 190bc03f14fSopenharmony_ci tm *nowtime = localtime(&curtime); 191bc03f14fSopenharmony_ci std::string targetTime = std::to_string(1900 + nowtime->tm_year) + "-" + std::to_string(1 + nowtime->tm_mon) + 192bc03f14fSopenharmony_ci "-" + std::to_string(nowtime->tm_mday) + " " + std::to_string(nowtime->tm_hour) + ":" + 193bc03f14fSopenharmony_ci std::to_string(nowtime->tm_min) + ":" + std::to_string(nowtime->tm_sec); 194bc03f14fSopenharmony_ci return targetTime; 195bc03f14fSopenharmony_ci} 196bc03f14fSopenharmony_ci 197bc03f14fSopenharmony_ci/** 198bc03f14fSopenharmony_ci* @tc.name: PasteboardTest001 199bc03f14fSopenharmony_ci* @tc.desc: Create paste board test. 200bc03f14fSopenharmony_ci* @tc.type: FUNC 201bc03f14fSopenharmony_ci*/ 202bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteboardTest001, TestSize.Level0) 203bc03f14fSopenharmony_ci{ 204bc03f14fSopenharmony_ci auto record = PasteboardClient::GetInstance()->CreatePlainTextRecord("paste record1"); 205bc03f14fSopenharmony_ci ASSERT_TRUE(record != nullptr); 206bc03f14fSopenharmony_ci std::string plainText = "plain text"; 207bc03f14fSopenharmony_ci auto data = PasteboardClient::GetInstance()->CreatePlainTextData(plainText); 208bc03f14fSopenharmony_ci ASSERT_TRUE(data != nullptr); 209bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*data); 210bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 211bc03f14fSopenharmony_ci auto has = PasteboardClient::GetInstance()->HasPasteData(); 212bc03f14fSopenharmony_ci ASSERT_TRUE(has == true); 213bc03f14fSopenharmony_ci PasteData pasteData; 214bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->GetPasteData(pasteData); 215bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 216bc03f14fSopenharmony_ci PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "get."); 217bc03f14fSopenharmony_ci auto primaryText = pasteData.GetPrimaryText(); 218bc03f14fSopenharmony_ci ASSERT_TRUE(primaryText != nullptr); 219bc03f14fSopenharmony_ci ASSERT_TRUE(*primaryText == plainText); 220bc03f14fSopenharmony_ci} 221bc03f14fSopenharmony_ci 222bc03f14fSopenharmony_ci/** 223bc03f14fSopenharmony_ci* @tc.name: PasteRecordTest001 224bc03f14fSopenharmony_ci* @tc.desc: Create paste board record test. 225bc03f14fSopenharmony_ci* @tc.type: FUNC 226bc03f14fSopenharmony_ci*/ 227bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteRecordTest001, TestSize.Level0) 228bc03f14fSopenharmony_ci{ 229bc03f14fSopenharmony_ci std::string plainText = "helloWorld"; 230bc03f14fSopenharmony_ci auto record = PasteboardClient::GetInstance()->CreatePlainTextRecord(plainText); 231bc03f14fSopenharmony_ci ASSERT_TRUE(record != nullptr); 232bc03f14fSopenharmony_ci auto newPlainText = record->GetPlainText(); 233bc03f14fSopenharmony_ci ASSERT_TRUE(newPlainText != nullptr); 234bc03f14fSopenharmony_ci ASSERT_TRUE(*newPlainText == plainText); 235bc03f14fSopenharmony_ci} 236bc03f14fSopenharmony_ci 237bc03f14fSopenharmony_ci/** 238bc03f14fSopenharmony_ci* @tc.name: PasteRecordTest002 239bc03f14fSopenharmony_ci* @tc.desc: Create paste board record test. 240bc03f14fSopenharmony_ci* @tc.type: FUNC 241bc03f14fSopenharmony_ci*/ 242bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteRecordTest002, TestSize.Level0) 243bc03f14fSopenharmony_ci{ 244bc03f14fSopenharmony_ci std::string htmlText = "<div class='disabled item tip user-programs'>"; 245bc03f14fSopenharmony_ci auto record = PasteboardClient::GetInstance()->CreateHtmlTextRecord(htmlText); 246bc03f14fSopenharmony_ci ASSERT_TRUE(record != nullptr); 247bc03f14fSopenharmony_ci auto newHtmlText = record->GetHtmlText(); 248bc03f14fSopenharmony_ci ASSERT_TRUE(newHtmlText != nullptr); 249bc03f14fSopenharmony_ci ASSERT_TRUE(*newHtmlText == htmlText); 250bc03f14fSopenharmony_ci} 251bc03f14fSopenharmony_ci 252bc03f14fSopenharmony_ci/** 253bc03f14fSopenharmony_ci* @tc.name: PasteRecordTest003 254bc03f14fSopenharmony_ci* @tc.desc: Create paste board record test. 255bc03f14fSopenharmony_ci* @tc.type: FUNC 256bc03f14fSopenharmony_ci*/ 257bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteRecordTest003, TestSize.Level0) 258bc03f14fSopenharmony_ci{ 259bc03f14fSopenharmony_ci using namespace OHOS::AAFwk; 260bc03f14fSopenharmony_ci std::shared_ptr<Want> want = std::make_shared<Want>(); 261bc03f14fSopenharmony_ci std::string key = "id"; 262bc03f14fSopenharmony_ci int32_t id = 456; 263bc03f14fSopenharmony_ci Want wantIn = want->SetParam(key, id); 264bc03f14fSopenharmony_ci auto record = PasteboardClient::GetInstance()->CreateWantRecord(want); 265bc03f14fSopenharmony_ci ASSERT_TRUE(record != nullptr); 266bc03f14fSopenharmony_ci auto newWant = record->GetWant(); 267bc03f14fSopenharmony_ci ASSERT_TRUE(newWant != nullptr); 268bc03f14fSopenharmony_ci int32_t defaultValue = 333; 269bc03f14fSopenharmony_ci ASSERT_TRUE(newWant->GetIntParam(key, defaultValue) == id); 270bc03f14fSopenharmony_ci} 271bc03f14fSopenharmony_ci 272bc03f14fSopenharmony_ci/** 273bc03f14fSopenharmony_ci* @tc.name: PasteRecordTest004 274bc03f14fSopenharmony_ci* @tc.desc: Create paste board record test. 275bc03f14fSopenharmony_ci* @tc.type: FUNC 276bc03f14fSopenharmony_ci*/ 277bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteRecordTest004, TestSize.Level0) 278bc03f14fSopenharmony_ci{ 279bc03f14fSopenharmony_ci OHOS::Uri uri("uri"); 280bc03f14fSopenharmony_ci auto record = PasteboardClient::GetInstance()->CreateUriRecord(uri); 281bc03f14fSopenharmony_ci ASSERT_TRUE(record != nullptr); 282bc03f14fSopenharmony_ci auto newUri = record->GetUri(); 283bc03f14fSopenharmony_ci ASSERT_TRUE(newUri != nullptr); 284bc03f14fSopenharmony_ci ASSERT_TRUE(newUri->ToString() == uri.ToString()); 285bc03f14fSopenharmony_ci} 286bc03f14fSopenharmony_ci 287bc03f14fSopenharmony_ci/** 288bc03f14fSopenharmony_ci* @tc.name: PasteRecordTest005 289bc03f14fSopenharmony_ci* @tc.desc: Create paste board record test. 290bc03f14fSopenharmony_ci* @tc.type: FUNC 291bc03f14fSopenharmony_ci* @tc.require: AR000H5GKU 292bc03f14fSopenharmony_ci*/ 293bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteRecordTest005, TestSize.Level0) 294bc03f14fSopenharmony_ci{ 295bc03f14fSopenharmony_ci uint32_t color[100] = { 3, 7, 9, 9, 7, 6 }; 296bc03f14fSopenharmony_ci InitializationOptions opts = { { 5, 7 }, PixelFormat::ARGB_8888, PixelFormat::ARGB_8888 }; 297bc03f14fSopenharmony_ci std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(color, 100, opts); 298bc03f14fSopenharmony_ci std::shared_ptr<PixelMap> pixelMapIn = move(pixelMap); 299bc03f14fSopenharmony_ci auto pasteDataRecord = PasteboardClient::GetInstance()->CreatePixelMapRecord(pixelMapIn); 300bc03f14fSopenharmony_ci ASSERT_TRUE(pasteDataRecord != nullptr); 301bc03f14fSopenharmony_ci auto newPixelMap = pasteDataRecord->GetPixelMap(); 302bc03f14fSopenharmony_ci ASSERT_TRUE(newPixelMap != nullptr); 303bc03f14fSopenharmony_ci ImageInfo imageInfo = {}; 304bc03f14fSopenharmony_ci newPixelMap->GetImageInfo(imageInfo); 305bc03f14fSopenharmony_ci ASSERT_TRUE(imageInfo.size.height == opts.size.height); 306bc03f14fSopenharmony_ci ASSERT_TRUE(imageInfo.size.width == opts.size.width); 307bc03f14fSopenharmony_ci ASSERT_TRUE(imageInfo.pixelFormat == opts.pixelFormat); 308bc03f14fSopenharmony_ci pasteDataRecord->ClearPixelMap(); 309bc03f14fSopenharmony_ci ASSERT_TRUE(pasteDataRecord->GetPixelMap() == nullptr); 310bc03f14fSopenharmony_ci} 311bc03f14fSopenharmony_ci 312bc03f14fSopenharmony_ci/** 313bc03f14fSopenharmony_ci* @tc.name: PasteRecordTest006 314bc03f14fSopenharmony_ci* @tc.desc: Create paste board record test. 315bc03f14fSopenharmony_ci* @tc.type: FUNC 316bc03f14fSopenharmony_ci* @tc.require: AR000H5GKU 317bc03f14fSopenharmony_ci*/ 318bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteRecordTest006, TestSize.Level0) 319bc03f14fSopenharmony_ci{ 320bc03f14fSopenharmony_ci uint32_t color[100] = { 3, 7, 9, 9, 7, 6 }; 321bc03f14fSopenharmony_ci InitializationOptions opts = { { 5, 7 }, PixelFormat::ARGB_8888, PixelFormat::ARGB_8888 }; 322bc03f14fSopenharmony_ci std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(color, sizeof(color) / sizeof(color[0]), opts); 323bc03f14fSopenharmony_ci std::shared_ptr<PixelMap> pixelMapIn = move(pixelMap); 324bc03f14fSopenharmony_ci auto pasteDataRecord = PasteboardClient::GetInstance()->CreatePixelMapRecord(pixelMapIn); 325bc03f14fSopenharmony_ci ASSERT_TRUE(pasteDataRecord != nullptr); 326bc03f14fSopenharmony_ci InitializationOptions opts1 = { { 6, 9 }, PixelFormat::RGB_565, PixelFormat::RGB_565 }; 327bc03f14fSopenharmony_ci std::unique_ptr<PixelMap> pixelMap1 = PixelMap::Create(color, sizeof(color) / sizeof(color[0]), opts1); 328bc03f14fSopenharmony_ci std::shared_ptr<PixelMap> pixelMapIn1 = move(pixelMap1); 329bc03f14fSopenharmony_ci pasteDataRecord = pasteDataRecord->NewPixelMapRecord(pixelMapIn1); 330bc03f14fSopenharmony_ci ASSERT_TRUE(pasteDataRecord != nullptr); 331bc03f14fSopenharmony_ci auto newPixelMap = pasteDataRecord->GetPixelMap(); 332bc03f14fSopenharmony_ci ASSERT_TRUE(newPixelMap != nullptr); 333bc03f14fSopenharmony_ci ImageInfo imageInfo = {}; 334bc03f14fSopenharmony_ci newPixelMap->GetImageInfo(imageInfo); 335bc03f14fSopenharmony_ci ASSERT_TRUE(imageInfo.size.height == opts1.size.height); 336bc03f14fSopenharmony_ci ASSERT_TRUE(imageInfo.size.width == opts1.size.width); 337bc03f14fSopenharmony_ci ASSERT_TRUE(imageInfo.pixelFormat == opts1.pixelFormat); 338bc03f14fSopenharmony_ci} 339bc03f14fSopenharmony_ci 340bc03f14fSopenharmony_ci/** 341bc03f14fSopenharmony_ci* @tc.name: PasteRecordTest007 342bc03f14fSopenharmony_ci* @tc.desc: Create paste board record test. 343bc03f14fSopenharmony_ci* @tc.type: FUNC 344bc03f14fSopenharmony_ci* @tc.require: AR000HEECD 345bc03f14fSopenharmony_ci*/ 346bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteRecordTest007, TestSize.Level0) 347bc03f14fSopenharmony_ci{ 348bc03f14fSopenharmony_ci std::vector<uint8_t> arrayBuffer(46); 349bc03f14fSopenharmony_ci arrayBuffer = { 2, 7, 6, 8, 9 }; 350bc03f14fSopenharmony_ci std::string mimeType = "image/jpg"; 351bc03f14fSopenharmony_ci auto pasteDataRecord = PasteboardClient::GetInstance()->CreateKvRecord(mimeType, arrayBuffer); 352bc03f14fSopenharmony_ci ASSERT_TRUE(pasteDataRecord != nullptr); 353bc03f14fSopenharmony_ci auto customData = pasteDataRecord->GetCustomData(); 354bc03f14fSopenharmony_ci ASSERT_TRUE(customData != nullptr); 355bc03f14fSopenharmony_ci auto itemData = customData->GetItemData(); 356bc03f14fSopenharmony_ci ASSERT_TRUE(itemData.size() == 1); 357bc03f14fSopenharmony_ci auto item = itemData.find(mimeType); 358bc03f14fSopenharmony_ci ASSERT_TRUE(item != itemData.end()); 359bc03f14fSopenharmony_ci ASSERT_TRUE(item->second == arrayBuffer); 360bc03f14fSopenharmony_ci} 361bc03f14fSopenharmony_ci 362bc03f14fSopenharmony_ci/** 363bc03f14fSopenharmony_ci* @tc.name: PasteRecordTest008 364bc03f14fSopenharmony_ci* @tc.desc: Create paste board record test. 365bc03f14fSopenharmony_ci* @tc.type: FUNC 366bc03f14fSopenharmony_ci* @tc.require: AR000HEECD 367bc03f14fSopenharmony_ci*/ 368bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteRecordTest008, TestSize.Level0) 369bc03f14fSopenharmony_ci{ 370bc03f14fSopenharmony_ci std::vector<uint8_t> arrayBuffer(46); 371bc03f14fSopenharmony_ci arrayBuffer = { 2, 7, 6, 8, 9 }; 372bc03f14fSopenharmony_ci std::string mimeType = "image/jpg"; 373bc03f14fSopenharmony_ci auto pasteDataRecord = PasteboardClient::GetInstance()->CreateKvRecord(mimeType, arrayBuffer); 374bc03f14fSopenharmony_ci ASSERT_TRUE(pasteDataRecord != nullptr); 375bc03f14fSopenharmony_ci std::string mimeType1 = "img/png"; 376bc03f14fSopenharmony_ci std::vector<uint8_t> arrayBuffer1(46); 377bc03f14fSopenharmony_ci arrayBuffer1 = { 2, 7, 6, 8, 9 }; 378bc03f14fSopenharmony_ci pasteDataRecord = pasteDataRecord->NewKvRecord(mimeType1, arrayBuffer1); 379bc03f14fSopenharmony_ci auto customData = pasteDataRecord->GetCustomData(); 380bc03f14fSopenharmony_ci ASSERT_TRUE(customData != nullptr); 381bc03f14fSopenharmony_ci auto itemData = customData->GetItemData(); 382bc03f14fSopenharmony_ci ASSERT_TRUE(itemData.size() == 1); 383bc03f14fSopenharmony_ci auto item = itemData.find(mimeType1); 384bc03f14fSopenharmony_ci ASSERT_TRUE(item != itemData.end()); 385bc03f14fSopenharmony_ci ASSERT_TRUE(item->second == arrayBuffer1); 386bc03f14fSopenharmony_ci} 387bc03f14fSopenharmony_ci 388bc03f14fSopenharmony_ci/** 389bc03f14fSopenharmony_ci* @tc.name: PasteRecordTest009 390bc03f14fSopenharmony_ci* @tc.desc: Create paste board html local url 391bc03f14fSopenharmony_ci* @tc.type: FUNC 392bc03f14fSopenharmony_ci*/ 393bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteRecordTest009, TestSize.Level0) 394bc03f14fSopenharmony_ci{ 395bc03f14fSopenharmony_ci std::string htmlText = "<div class='item'><img data-ohos='clipboard' " 396bc03f14fSopenharmony_ci "src='file:///com.example.webview/data/storage/el1/base/test.png'></div>"; 397bc03f14fSopenharmony_ci auto data = PasteboardClient::GetInstance()->CreateHtmlData(htmlText); 398bc03f14fSopenharmony_ci ASSERT_TRUE(data != nullptr); 399bc03f14fSopenharmony_ci data->SetTag(g_webviewPastedataTag); 400bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*data); 401bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 402bc03f14fSopenharmony_ci auto has = PasteboardClient::GetInstance()->HasPasteData(); 403bc03f14fSopenharmony_ci ASSERT_TRUE(has == true); 404bc03f14fSopenharmony_ci PasteData newPasteData; 405bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->GetPasteData(newPasteData); 406bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 407bc03f14fSopenharmony_ci auto record = newPasteData.GetPrimaryHtml(); 408bc03f14fSopenharmony_ci ASSERT_TRUE(record != nullptr); 409bc03f14fSopenharmony_ci} 410bc03f14fSopenharmony_ci 411bc03f14fSopenharmony_ci/** 412bc03f14fSopenharmony_ci* @tc.name: PasteRecordTest0010 413bc03f14fSopenharmony_ci* @tc.desc: Create paste board html distributed uri. 414bc03f14fSopenharmony_ci* @tc.type: FUNC 415bc03f14fSopenharmony_ci*/ 416bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteRecordTest0010, TestSize.Level0) 417bc03f14fSopenharmony_ci{ 418bc03f14fSopenharmony_ci std::string htmlText = "<div class='item'><img data-ohos='clipboard' " 419bc03f14fSopenharmony_ci "src='file://com.byy.testdpb/data/storage/el2/distributedfiles/" 420bc03f14fSopenharmony_ci ".remote_share/data/storage/el2/base/haps/entry/cache/t1.jpg'></div>"; 421bc03f14fSopenharmony_ci auto data = PasteboardClient::GetInstance()->CreateHtmlData(htmlText); 422bc03f14fSopenharmony_ci ASSERT_TRUE(data != nullptr); 423bc03f14fSopenharmony_ci data->SetTag(g_webviewPastedataTag); 424bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*data); 425bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 426bc03f14fSopenharmony_ci auto has = PasteboardClient::GetInstance()->HasPasteData(); 427bc03f14fSopenharmony_ci ASSERT_TRUE(has == true); 428bc03f14fSopenharmony_ci PasteData newPasteData2; 429bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->GetPasteData(newPasteData2); 430bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 431bc03f14fSopenharmony_ci auto record = newPasteData2.GetPrimaryHtml(); 432bc03f14fSopenharmony_ci ASSERT_TRUE(record != nullptr); 433bc03f14fSopenharmony_ci ASSERT_TRUE(*record == htmlText); 434bc03f14fSopenharmony_ci} 435bc03f14fSopenharmony_ci 436bc03f14fSopenharmony_ci/** 437bc03f14fSopenharmony_ci* @tc.name: PasteRecordTest0011 438bc03f14fSopenharmony_ci* @tc.desc: Create paste board html distributed uri. 439bc03f14fSopenharmony_ci* @tc.type: FUNC 440bc03f14fSopenharmony_ci*/ 441bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteRecordTest0011, TestSize.Level0) 442bc03f14fSopenharmony_ci{ 443bc03f14fSopenharmony_ci std::string htmlText = "<div class='item'><img " 444bc03f14fSopenharmony_ci "src='file://com.byy.testdpb/data/storage/el2/distributedfiles/" 445bc03f14fSopenharmony_ci ".remote_share/data/storage/el2/base/haps/entry/cache/t1.jpg'></div>"; 446bc03f14fSopenharmony_ci auto data = PasteboardClient::GetInstance()->CreateHtmlData(htmlText); 447bc03f14fSopenharmony_ci ASSERT_TRUE(data != nullptr); 448bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*data); 449bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 450bc03f14fSopenharmony_ci auto has = PasteboardClient::GetInstance()->HasPasteData(); 451bc03f14fSopenharmony_ci ASSERT_TRUE(has == true); 452bc03f14fSopenharmony_ci PasteData newPasteData2; 453bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->GetPasteData(newPasteData2); 454bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 455bc03f14fSopenharmony_ci auto record = newPasteData2.GetPrimaryHtml(); 456bc03f14fSopenharmony_ci ASSERT_TRUE(record != nullptr); 457bc03f14fSopenharmony_ci ASSERT_TRUE(*record == htmlText); 458bc03f14fSopenharmony_ci} 459bc03f14fSopenharmony_ci 460bc03f14fSopenharmony_ci/** 461bc03f14fSopenharmony_ci* @tc.name: PasteRecordTest0012 462bc03f14fSopenharmony_ci* @tc.desc: Create paste board html local url 463bc03f14fSopenharmony_ci* @tc.type: FUNC 464bc03f14fSopenharmony_ci*/ 465bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteRecordTest0012, TestSize.Level0) 466bc03f14fSopenharmony_ci{ 467bc03f14fSopenharmony_ci std::string htmlText = "<div class='item'><img data-ohos='clipboard' " 468bc03f14fSopenharmony_ci "src='file:///com.example.webview/data/storage/el1/base/test.png'></div>"; 469bc03f14fSopenharmony_ci auto data = PasteboardClient::GetInstance()->CreateHtmlData(htmlText); 470bc03f14fSopenharmony_ci ASSERT_TRUE(data != nullptr); 471bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*data); 472bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 473bc03f14fSopenharmony_ci auto has = PasteboardClient::GetInstance()->HasPasteData(); 474bc03f14fSopenharmony_ci ASSERT_TRUE(has == true); 475bc03f14fSopenharmony_ci PasteData newPasteData; 476bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->GetPasteData(newPasteData); 477bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 478bc03f14fSopenharmony_ci auto record = newPasteData.GetPrimaryHtml(); 479bc03f14fSopenharmony_ci ASSERT_TRUE(record != nullptr); 480bc03f14fSopenharmony_ci} 481bc03f14fSopenharmony_ci 482bc03f14fSopenharmony_ci/** 483bc03f14fSopenharmony_ci* @tc.name: PasteDataTest001 484bc03f14fSopenharmony_ci* @tc.desc: Create paste board data test. 485bc03f14fSopenharmony_ci* @tc.type: FUNC 486bc03f14fSopenharmony_ci*/ 487bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteDataTest001, TestSize.Level0) 488bc03f14fSopenharmony_ci{ 489bc03f14fSopenharmony_ci using namespace OHOS::AAFwk; 490bc03f14fSopenharmony_ci std::shared_ptr<Want> want = std::make_shared<Want>(); 491bc03f14fSopenharmony_ci std::string key = "id"; 492bc03f14fSopenharmony_ci int32_t id = 456; 493bc03f14fSopenharmony_ci Want wantIn = want->SetParam(key, id); 494bc03f14fSopenharmony_ci auto data = PasteboardClient::GetInstance()->CreateWantData(std::make_shared<Want>(wantIn)); 495bc03f14fSopenharmony_ci ASSERT_TRUE(data != nullptr); 496bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 497bc03f14fSopenharmony_ci auto has = PasteboardClient::GetInstance()->HasPasteData(); 498bc03f14fSopenharmony_ci ASSERT_TRUE(has != true); 499bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*data); 500bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 501bc03f14fSopenharmony_ci has = PasteboardClient::GetInstance()->HasPasteData(); 502bc03f14fSopenharmony_ci ASSERT_TRUE(has == true); 503bc03f14fSopenharmony_ci PasteData pasteData; 504bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->GetPasteData(pasteData); 505bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 506bc03f14fSopenharmony_ci auto record = pasteData.GetPrimaryWant(); 507bc03f14fSopenharmony_ci ASSERT_TRUE(record != nullptr); 508bc03f14fSopenharmony_ci int32_t defaultValue = 333; 509bc03f14fSopenharmony_ci ASSERT_TRUE(record->GetIntParam(key, defaultValue) == id); 510bc03f14fSopenharmony_ci} 511bc03f14fSopenharmony_ci 512bc03f14fSopenharmony_ci/** 513bc03f14fSopenharmony_ci* @tc.name: PasteDataTest002 514bc03f14fSopenharmony_ci* @tc.desc: Create paste board data test. 515bc03f14fSopenharmony_ci* @tc.type: FUNC 516bc03f14fSopenharmony_ci*/ 517bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteDataTest002, TestSize.Level0) 518bc03f14fSopenharmony_ci{ 519bc03f14fSopenharmony_ci OHOS::Uri uri("uri"); 520bc03f14fSopenharmony_ci auto data = PasteboardClient::GetInstance()->CreateUriData(uri); 521bc03f14fSopenharmony_ci ASSERT_TRUE(data != nullptr); 522bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 523bc03f14fSopenharmony_ci auto has = PasteboardClient::GetInstance()->HasPasteData(); 524bc03f14fSopenharmony_ci ASSERT_TRUE(has != true); 525bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*data); 526bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 527bc03f14fSopenharmony_ci has = PasteboardClient::GetInstance()->HasPasteData(); 528bc03f14fSopenharmony_ci ASSERT_TRUE(has == true); 529bc03f14fSopenharmony_ci PasteData pasteData; 530bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->GetPasteData(pasteData); 531bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 532bc03f14fSopenharmony_ci auto record = pasteData.GetPrimaryUri(); 533bc03f14fSopenharmony_ci ASSERT_TRUE(record != nullptr); 534bc03f14fSopenharmony_ci ASSERT_TRUE(record->ToString() == uri.ToString()); 535bc03f14fSopenharmony_ci} 536bc03f14fSopenharmony_ci 537bc03f14fSopenharmony_ci/** 538bc03f14fSopenharmony_ci* @tc.name: PasteDataTest003 539bc03f14fSopenharmony_ci* @tc.desc: Create paste board data test. 540bc03f14fSopenharmony_ci* @tc.type: FUNC 541bc03f14fSopenharmony_ci*/ 542bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteDataTest003, TestSize.Level0) 543bc03f14fSopenharmony_ci{ 544bc03f14fSopenharmony_ci std::string text = "plain text"; 545bc03f14fSopenharmony_ci auto data = PasteboardClient::GetInstance()->CreatePlainTextData(text); 546bc03f14fSopenharmony_ci ASSERT_TRUE(data != nullptr); 547bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 548bc03f14fSopenharmony_ci auto has = PasteboardClient::GetInstance()->HasPasteData(); 549bc03f14fSopenharmony_ci ASSERT_TRUE(has != true); 550bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*data); 551bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 552bc03f14fSopenharmony_ci has = PasteboardClient::GetInstance()->HasPasteData(); 553bc03f14fSopenharmony_ci ASSERT_TRUE(has == true); 554bc03f14fSopenharmony_ci PasteData pasteData; 555bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->GetPasteData(pasteData); 556bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 557bc03f14fSopenharmony_ci auto record = pasteData.GetPrimaryText(); 558bc03f14fSopenharmony_ci ASSERT_TRUE(record != nullptr); 559bc03f14fSopenharmony_ci ASSERT_TRUE(*record == text); 560bc03f14fSopenharmony_ci} 561bc03f14fSopenharmony_ci 562bc03f14fSopenharmony_ci/** 563bc03f14fSopenharmony_ci* @tc.name: PasteDataTest004 564bc03f14fSopenharmony_ci* @tc.desc: Create paste board data test. 565bc03f14fSopenharmony_ci* @tc.type: FUNC 566bc03f14fSopenharmony_ci*/ 567bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteDataTest004, TestSize.Level0) 568bc03f14fSopenharmony_ci{ 569bc03f14fSopenharmony_ci std::string htmlText = "<div class='disabled item tip user-programs'>"; 570bc03f14fSopenharmony_ci auto data = PasteboardClient::GetInstance()->CreateHtmlData(htmlText); 571bc03f14fSopenharmony_ci ASSERT_TRUE(data != nullptr); 572bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 573bc03f14fSopenharmony_ci auto has = PasteboardClient::GetInstance()->HasPasteData(); 574bc03f14fSopenharmony_ci ASSERT_TRUE(has != true); 575bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*data); 576bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 577bc03f14fSopenharmony_ci has = PasteboardClient::GetInstance()->HasPasteData(); 578bc03f14fSopenharmony_ci ASSERT_TRUE(has == true); 579bc03f14fSopenharmony_ci PasteData pasteData; 580bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->GetPasteData(pasteData); 581bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 582bc03f14fSopenharmony_ci auto record = pasteData.GetPrimaryHtml(); 583bc03f14fSopenharmony_ci ASSERT_TRUE(record != nullptr); 584bc03f14fSopenharmony_ci ASSERT_TRUE(*record == htmlText); 585bc03f14fSopenharmony_ci} 586bc03f14fSopenharmony_ci 587bc03f14fSopenharmony_ci/** 588bc03f14fSopenharmony_ci* @tc.name: PasteDataTest005 589bc03f14fSopenharmony_ci* @tc.desc: CreateHtmlData test. 590bc03f14fSopenharmony_ci* @tc.type: FUNC 591bc03f14fSopenharmony_ci* @tc.require: AR000HEECD 592bc03f14fSopenharmony_ci*/ 593bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteDataTest005, TestSize.Level0) 594bc03f14fSopenharmony_ci{ 595bc03f14fSopenharmony_ci std::string htmlText = "<div class='disabled item tip user-programs'>"; 596bc03f14fSopenharmony_ci auto pasteData = PasteboardClient::GetInstance()->CreateHtmlData(htmlText); 597bc03f14fSopenharmony_ci ASSERT_TRUE(pasteData != nullptr); 598bc03f14fSopenharmony_ci std::string plainText = "plain text"; 599bc03f14fSopenharmony_ci PasteDataRecord::Builder builder(MIMETYPE_TEXT_HTML); 600bc03f14fSopenharmony_ci std::string mimeType = MIMETYPE_TEXT_PLAIN; 601bc03f14fSopenharmony_ci std::vector<uint8_t> arrayBuffer(46); 602bc03f14fSopenharmony_ci arrayBuffer = { 2, 7, 6, 8, 9 }; 603bc03f14fSopenharmony_ci std::string mimeType1 = "image/jpg"; 604bc03f14fSopenharmony_ci std::shared_ptr<MineCustomData> customData = std::make_shared<MineCustomData>(); 605bc03f14fSopenharmony_ci customData->AddItemData(mimeType1, arrayBuffer); 606bc03f14fSopenharmony_ci std::shared_ptr<PasteDataRecord> pasteDataRecord = builder.SetMimeType(mimeType) 607bc03f14fSopenharmony_ci .SetPlainText(std::make_shared<std::string>(plainText)) 608bc03f14fSopenharmony_ci .SetHtmlText(std::make_shared<std::string>(htmlText)) 609bc03f14fSopenharmony_ci .SetCustomData(customData) 610bc03f14fSopenharmony_ci .Build(); 611bc03f14fSopenharmony_ci pasteData->AddRecord(pasteDataRecord); 612bc03f14fSopenharmony_ci PasteData newPasteData; 613bc03f14fSopenharmony_ci PasteboardServiceTest::CommonTest(*pasteData, newPasteData); 614bc03f14fSopenharmony_ci auto primaryHtml = newPasteData.GetPrimaryHtml(); 615bc03f14fSopenharmony_ci ASSERT_TRUE(primaryHtml != nullptr); 616bc03f14fSopenharmony_ci ASSERT_TRUE(*primaryHtml == htmlText); 617bc03f14fSopenharmony_ci auto firstRecord = newPasteData.GetRecordAt(0); 618bc03f14fSopenharmony_ci ASSERT_TRUE(firstRecord != nullptr); 619bc03f14fSopenharmony_ci ASSERT_TRUE(firstRecord->GetMimeType() == mimeType); 620bc03f14fSopenharmony_ci auto newPlainText = firstRecord->GetPlainText(); 621bc03f14fSopenharmony_ci ASSERT_TRUE(newPlainText != nullptr); 622bc03f14fSopenharmony_ci ASSERT_TRUE(*newPlainText == plainText); 623bc03f14fSopenharmony_ci auto newHtmlText = firstRecord->GetHtmlText(); 624bc03f14fSopenharmony_ci ASSERT_TRUE(newHtmlText != nullptr); 625bc03f14fSopenharmony_ci ASSERT_TRUE(*newHtmlText == htmlText); 626bc03f14fSopenharmony_ci customData = pasteDataRecord->GetCustomData(); 627bc03f14fSopenharmony_ci ASSERT_TRUE(customData != nullptr); 628bc03f14fSopenharmony_ci auto itemData = customData->GetItemData(); 629bc03f14fSopenharmony_ci ASSERT_TRUE(itemData.size() == 1); 630bc03f14fSopenharmony_ci auto item = itemData.find(mimeType1); 631bc03f14fSopenharmony_ci ASSERT_TRUE(item != itemData.end()); 632bc03f14fSopenharmony_ci ASSERT_TRUE(item->second == arrayBuffer); 633bc03f14fSopenharmony_ci} 634bc03f14fSopenharmony_ci 635bc03f14fSopenharmony_ci/** 636bc03f14fSopenharmony_ci* @tc.name: PasteDataTest006 637bc03f14fSopenharmony_ci* @tc.desc: CreatePlainTextData test. 638bc03f14fSopenharmony_ci* @tc.type: FUNC 639bc03f14fSopenharmony_ci*/ 640bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteDataTest006, TestSize.Level0) 641bc03f14fSopenharmony_ci{ 642bc03f14fSopenharmony_ci using namespace OHOS::AAFwk; 643bc03f14fSopenharmony_ci std::string plainText = "helloWorld"; 644bc03f14fSopenharmony_ci auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText); 645bc03f14fSopenharmony_ci ASSERT_TRUE(pasteData != nullptr); 646bc03f14fSopenharmony_ci std::shared_ptr<Want> want = std::make_shared<Want>(); 647bc03f14fSopenharmony_ci std::string key = "id"; 648bc03f14fSopenharmony_ci int32_t id = 456; 649bc03f14fSopenharmony_ci Want wantIn = want->SetParam(key, id); 650bc03f14fSopenharmony_ci PasteDataRecord::Builder builder(MIMETYPE_TEXT_WANT); 651bc03f14fSopenharmony_ci std::shared_ptr<PasteDataRecord> pasteDataRecord = 652bc03f14fSopenharmony_ci builder.SetWant(std::make_shared<Want>(wantIn)).SetPlainText(std::make_shared<std::string>(plainText)).Build(); 653bc03f14fSopenharmony_ci pasteData->AddRecord(pasteDataRecord); 654bc03f14fSopenharmony_ci PasteData newPasteData; 655bc03f14fSopenharmony_ci PasteboardServiceTest::CommonTest(*pasteData, newPasteData); 656bc03f14fSopenharmony_ci auto firstRecord = newPasteData.GetRecordAt(0); 657bc03f14fSopenharmony_ci ASSERT_TRUE(firstRecord != nullptr); 658bc03f14fSopenharmony_ci ASSERT_TRUE(firstRecord->GetMimeType() == MIMETYPE_TEXT_WANT); 659bc03f14fSopenharmony_ci auto newWant = firstRecord->GetWant(); 660bc03f14fSopenharmony_ci ASSERT_TRUE(newWant != nullptr); 661bc03f14fSopenharmony_ci int32_t defaultValue = 333; 662bc03f14fSopenharmony_ci ASSERT_TRUE(newWant->GetIntParam(key, defaultValue) == id); 663bc03f14fSopenharmony_ci auto newPlainText = firstRecord->GetPlainText(); 664bc03f14fSopenharmony_ci ASSERT_TRUE(newPlainText != nullptr); 665bc03f14fSopenharmony_ci ASSERT_TRUE(*newPlainText == plainText); 666bc03f14fSopenharmony_ci} 667bc03f14fSopenharmony_ci 668bc03f14fSopenharmony_ci/** 669bc03f14fSopenharmony_ci* @tc.name: PasteDataTest007 670bc03f14fSopenharmony_ci* @tc.desc: PixelMap test. 671bc03f14fSopenharmony_ci* @tc.type: FUNC 672bc03f14fSopenharmony_ci* @tc.require: AR000H5GKU 673bc03f14fSopenharmony_ci*/ 674bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteDataTest007, TestSize.Level0) 675bc03f14fSopenharmony_ci{ 676bc03f14fSopenharmony_ci std::string htmlText = "<div class='disabled item tip user-programs'>"; 677bc03f14fSopenharmony_ci auto pasteData = PasteboardClient::GetInstance()->CreateHtmlData(htmlText); 678bc03f14fSopenharmony_ci ASSERT_TRUE(pasteData != nullptr); 679bc03f14fSopenharmony_ci OHOS::Uri uri("uri"); 680bc03f14fSopenharmony_ci uint32_t color[100] = { 3, 7, 9, 9, 7, 6 }; 681bc03f14fSopenharmony_ci InitializationOptions opts = { { 5, 7 }, PixelFormat::ARGB_8888, PixelFormat::ARGB_8888 }; 682bc03f14fSopenharmony_ci std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(color, sizeof(color) / sizeof(color[0]), opts); 683bc03f14fSopenharmony_ci std::shared_ptr<PixelMap> pixelMapIn = move(pixelMap); 684bc03f14fSopenharmony_ci PasteDataRecord::Builder builder(MIMETYPE_TEXT_URI); 685bc03f14fSopenharmony_ci std::shared_ptr<PasteDataRecord> pasteDataRecord = 686bc03f14fSopenharmony_ci builder.SetUri(std::make_shared<OHOS::Uri>(uri)).SetPixelMap(pixelMapIn).Build(); 687bc03f14fSopenharmony_ci pasteData->AddRecord(pasteDataRecord); 688bc03f14fSopenharmony_ci PasteData newPasteData; 689bc03f14fSopenharmony_ci PasteboardServiceTest::CommonTest(*pasteData, newPasteData); 690bc03f14fSopenharmony_ci auto firstRecord = newPasteData.GetRecordAt(0); 691bc03f14fSopenharmony_ci ASSERT_TRUE(firstRecord != nullptr); 692bc03f14fSopenharmony_ci ASSERT_TRUE(firstRecord->GetMimeType() == MIMETYPE_TEXT_URI); 693bc03f14fSopenharmony_ci auto newUri = firstRecord->GetUri(); 694bc03f14fSopenharmony_ci ASSERT_TRUE(newUri != nullptr); 695bc03f14fSopenharmony_ci ASSERT_TRUE(newUri->ToString() == uri.ToString()); 696bc03f14fSopenharmony_ci auto newPixelMap = firstRecord->GetPixelMap(); 697bc03f14fSopenharmony_ci ASSERT_TRUE(newPixelMap != nullptr); 698bc03f14fSopenharmony_ci ImageInfo imageInfo = {}; 699bc03f14fSopenharmony_ci newPixelMap->GetImageInfo(imageInfo); 700bc03f14fSopenharmony_ci ASSERT_TRUE(imageInfo.size.height == opts.size.height); 701bc03f14fSopenharmony_ci ASSERT_TRUE(imageInfo.size.width == opts.size.width); 702bc03f14fSopenharmony_ci ASSERT_TRUE(imageInfo.pixelFormat == opts.pixelFormat); 703bc03f14fSopenharmony_ci} 704bc03f14fSopenharmony_ci 705bc03f14fSopenharmony_ci/** 706bc03f14fSopenharmony_ci* @tc.name: PasteDataTest008 707bc03f14fSopenharmony_ci* @tc.desc: Create paste board data test. 708bc03f14fSopenharmony_ci* @tc.type: FUNC 709bc03f14fSopenharmony_ci* @tc.require: AR000H5GKU 710bc03f14fSopenharmony_ci*/ 711bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteDataTest008, TestSize.Level0) 712bc03f14fSopenharmony_ci{ 713bc03f14fSopenharmony_ci uint32_t color[100] = { 3, 7, 9, 9, 7, 6 }; 714bc03f14fSopenharmony_ci InitializationOptions opts = { { 5, 7 }, PixelFormat::ARGB_8888, PixelFormat::ARGB_8888 }; 715bc03f14fSopenharmony_ci std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(color, sizeof(color) / sizeof(color[0]), opts); 716bc03f14fSopenharmony_ci std::shared_ptr<PixelMap> pixelMapIn = move(pixelMap); 717bc03f14fSopenharmony_ci auto pasteData = PasteboardClient::GetInstance()->CreatePixelMapData(pixelMapIn); 718bc03f14fSopenharmony_ci ASSERT_TRUE(pasteData != nullptr); 719bc03f14fSopenharmony_ci PasteData newPasteData; 720bc03f14fSopenharmony_ci PasteboardServiceTest::CommonTest(*pasteData, newPasteData); 721bc03f14fSopenharmony_ci auto primaryPixelMap = newPasteData.GetPrimaryPixelMap(); 722bc03f14fSopenharmony_ci ASSERT_TRUE(primaryPixelMap != nullptr); 723bc03f14fSopenharmony_ci ImageInfo imageInfo = {}; 724bc03f14fSopenharmony_ci primaryPixelMap->GetImageInfo(imageInfo); 725bc03f14fSopenharmony_ci ASSERT_TRUE(imageInfo.size.height == opts.size.height); 726bc03f14fSopenharmony_ci ASSERT_TRUE(imageInfo.size.width == opts.size.width); 727bc03f14fSopenharmony_ci ASSERT_TRUE(imageInfo.pixelFormat == opts.pixelFormat); 728bc03f14fSopenharmony_ci} 729bc03f14fSopenharmony_ci 730bc03f14fSopenharmony_ci/** 731bc03f14fSopenharmony_ci* @tc.name: PasteDataTest009 732bc03f14fSopenharmony_ci* @tc.desc: Create paste board data test. 733bc03f14fSopenharmony_ci* @tc.type: FUNC 734bc03f14fSopenharmony_ci* @tc.require: AR000H5GKU 735bc03f14fSopenharmony_ci*/ 736bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteDataTest009, TestSize.Level0) 737bc03f14fSopenharmony_ci{ 738bc03f14fSopenharmony_ci std::string plainText = "plain text"; 739bc03f14fSopenharmony_ci auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText); 740bc03f14fSopenharmony_ci ASSERT_TRUE(pasteData != nullptr); 741bc03f14fSopenharmony_ci uint32_t color[100] = { 3, 7, 9, 9, 7, 6 }; 742bc03f14fSopenharmony_ci InitializationOptions opts = { { 5, 7 }, PixelFormat::ARGB_8888, PixelFormat::ARGB_8888 }; 743bc03f14fSopenharmony_ci std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(color, sizeof(color) / sizeof(color[0]), opts); 744bc03f14fSopenharmony_ci std::shared_ptr<PixelMap> pixelMapIn = move(pixelMap); 745bc03f14fSopenharmony_ci pasteData->AddPixelMapRecord(pixelMapIn); 746bc03f14fSopenharmony_ci PasteData newPasteData; 747bc03f14fSopenharmony_ci PasteboardServiceTest::CommonTest(*pasteData, newPasteData); 748bc03f14fSopenharmony_ci auto primaryPlainText = newPasteData.GetPrimaryText(); 749bc03f14fSopenharmony_ci ASSERT_TRUE(primaryPlainText != nullptr); 750bc03f14fSopenharmony_ci ASSERT_TRUE(*primaryPlainText == plainText); 751bc03f14fSopenharmony_ci auto primaryPixelMap = newPasteData.GetPrimaryPixelMap(); 752bc03f14fSopenharmony_ci ASSERT_TRUE(primaryPixelMap != nullptr); 753bc03f14fSopenharmony_ci ImageInfo imageInfo = {}; 754bc03f14fSopenharmony_ci primaryPixelMap->GetImageInfo(imageInfo); 755bc03f14fSopenharmony_ci ASSERT_TRUE(imageInfo.size.height == opts.size.height); 756bc03f14fSopenharmony_ci ASSERT_TRUE(imageInfo.size.width == opts.size.width); 757bc03f14fSopenharmony_ci ASSERT_TRUE(imageInfo.pixelFormat == opts.pixelFormat); 758bc03f14fSopenharmony_ci} 759bc03f14fSopenharmony_ci 760bc03f14fSopenharmony_ci/** 761bc03f14fSopenharmony_ci* @tc.name: PasteDataTest0010 762bc03f14fSopenharmony_ci* @tc.desc: Create paste board data test. 763bc03f14fSopenharmony_ci* @tc.type: FUNC 764bc03f14fSopenharmony_ci* @tc.require: AR000HEECD 765bc03f14fSopenharmony_ci*/ 766bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteDataTest0010, TestSize.Level0) 767bc03f14fSopenharmony_ci{ 768bc03f14fSopenharmony_ci std::vector<uint8_t> arrayBuffer(46); 769bc03f14fSopenharmony_ci arrayBuffer = { 2, 7, 6, 8, 9 }; 770bc03f14fSopenharmony_ci std::string mimeType = "image/jpg"; 771bc03f14fSopenharmony_ci auto pasteData = PasteboardClient::GetInstance()->CreateKvData(mimeType, arrayBuffer); 772bc03f14fSopenharmony_ci ASSERT_TRUE(pasteData != nullptr); 773bc03f14fSopenharmony_ci PasteData newPasteData; 774bc03f14fSopenharmony_ci PasteboardServiceTest::CommonTest(*pasteData, newPasteData); 775bc03f14fSopenharmony_ci auto firstRecord = newPasteData.GetRecordAt(0); 776bc03f14fSopenharmony_ci auto customData = firstRecord->GetCustomData(); 777bc03f14fSopenharmony_ci ASSERT_TRUE(customData != nullptr); 778bc03f14fSopenharmony_ci auto itemData = customData->GetItemData(); 779bc03f14fSopenharmony_ci ASSERT_TRUE(itemData.size() == 1); 780bc03f14fSopenharmony_ci auto item = itemData.find(mimeType); 781bc03f14fSopenharmony_ci ASSERT_TRUE(item != itemData.end()); 782bc03f14fSopenharmony_ci ASSERT_TRUE(item->second == arrayBuffer); 783bc03f14fSopenharmony_ci} 784bc03f14fSopenharmony_ci 785bc03f14fSopenharmony_ci/** 786bc03f14fSopenharmony_ci* @tc.name: PasteDataTest0011 787bc03f14fSopenharmony_ci* @tc.desc: Create paste board data test. 788bc03f14fSopenharmony_ci* @tc.type: FUNC 789bc03f14fSopenharmony_ci* @tc.require: AR000HEECD 790bc03f14fSopenharmony_ci*/ 791bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteDataTest0011, TestSize.Level0) 792bc03f14fSopenharmony_ci{ 793bc03f14fSopenharmony_ci std::string plainText = "plain text"; 794bc03f14fSopenharmony_ci auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText); 795bc03f14fSopenharmony_ci ASSERT_TRUE(pasteData != nullptr); 796bc03f14fSopenharmony_ci std::vector<uint8_t> arrayBuffer(46); 797bc03f14fSopenharmony_ci arrayBuffer = { 2, 7, 6, 8, 9 }; 798bc03f14fSopenharmony_ci std::string mimeType = "image/jpg"; 799bc03f14fSopenharmony_ci pasteData->AddKvRecord(mimeType, arrayBuffer); 800bc03f14fSopenharmony_ci PasteData newPasteData; 801bc03f14fSopenharmony_ci PasteboardServiceTest::CommonTest(*pasteData, newPasteData); 802bc03f14fSopenharmony_ci auto firstRecord = newPasteData.GetRecordAt(0); 803bc03f14fSopenharmony_ci auto customData = firstRecord->GetCustomData(); 804bc03f14fSopenharmony_ci ASSERT_TRUE(customData != nullptr); 805bc03f14fSopenharmony_ci auto itemData = customData->GetItemData(); 806bc03f14fSopenharmony_ci ASSERT_TRUE(itemData.size() == 1); 807bc03f14fSopenharmony_ci auto item = itemData.find(mimeType); 808bc03f14fSopenharmony_ci ASSERT_TRUE(item != itemData.end()); 809bc03f14fSopenharmony_ci ASSERT_TRUE(item->second == arrayBuffer); 810bc03f14fSopenharmony_ci auto primaryPlainText = newPasteData.GetPrimaryText(); 811bc03f14fSopenharmony_ci ASSERT_TRUE(primaryPlainText != nullptr); 812bc03f14fSopenharmony_ci ASSERT_TRUE(*primaryPlainText == plainText); 813bc03f14fSopenharmony_ci} 814bc03f14fSopenharmony_ci 815bc03f14fSopenharmony_ci/** 816bc03f14fSopenharmony_ci* @tc.name: PasteDataTest0012 817bc03f14fSopenharmony_ci* @tc.desc: Create paste board data test. 818bc03f14fSopenharmony_ci* @tc.type: FUNC 819bc03f14fSopenharmony_ci* @tc.require: AR000HEECD 820bc03f14fSopenharmony_ci*/ 821bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteDataTest0012, TestSize.Level0) 822bc03f14fSopenharmony_ci{ 823bc03f14fSopenharmony_ci std::string plainText = "plain text"; 824bc03f14fSopenharmony_ci auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText); 825bc03f14fSopenharmony_ci ASSERT_TRUE(pasteData != nullptr); 826bc03f14fSopenharmony_ci std::vector<uint8_t> arrayBuffer(46); 827bc03f14fSopenharmony_ci arrayBuffer = { 2, 7, 6, 8, 9 }; 828bc03f14fSopenharmony_ci std::string mimeType = "image/jpg"; 829bc03f14fSopenharmony_ci pasteData->AddKvRecord(mimeType, arrayBuffer); 830bc03f14fSopenharmony_ci auto record = pasteData->GetRecordAt(0); 831bc03f14fSopenharmony_ci ASSERT_TRUE(record != nullptr); 832bc03f14fSopenharmony_ci std::string mimeType1 = "img/png"; 833bc03f14fSopenharmony_ci std::vector<uint8_t> arrayBuffer1(54); 834bc03f14fSopenharmony_ci arrayBuffer1 = { 4, 7, 9, 8, 7 }; 835bc03f14fSopenharmony_ci auto customData = record->GetCustomData(); 836bc03f14fSopenharmony_ci ASSERT_TRUE(customData != nullptr); 837bc03f14fSopenharmony_ci customData->AddItemData(mimeType1, arrayBuffer1); 838bc03f14fSopenharmony_ci PasteData newPasteData; 839bc03f14fSopenharmony_ci PasteboardServiceTest::CommonTest(*pasteData, newPasteData); 840bc03f14fSopenharmony_ci auto firstRecord = newPasteData.GetRecordAt(0); 841bc03f14fSopenharmony_ci ASSERT_TRUE(firstRecord != nullptr); 842bc03f14fSopenharmony_ci customData = firstRecord->GetCustomData(); 843bc03f14fSopenharmony_ci ASSERT_TRUE(customData != nullptr); 844bc03f14fSopenharmony_ci auto itemData = customData->GetItemData(); 845bc03f14fSopenharmony_ci ASSERT_TRUE(itemData.size() == 2); 846bc03f14fSopenharmony_ci auto item = itemData.find(mimeType); 847bc03f14fSopenharmony_ci ASSERT_TRUE(item != itemData.end()); 848bc03f14fSopenharmony_ci ASSERT_TRUE(item->second == arrayBuffer); 849bc03f14fSopenharmony_ci item = itemData.find(mimeType1); 850bc03f14fSopenharmony_ci ASSERT_TRUE(item != itemData.end()); 851bc03f14fSopenharmony_ci ASSERT_TRUE(item->second == arrayBuffer1); 852bc03f14fSopenharmony_ci auto primaryPlainText = newPasteData.GetPrimaryText(); 853bc03f14fSopenharmony_ci ASSERT_TRUE(primaryPlainText != nullptr); 854bc03f14fSopenharmony_ci ASSERT_TRUE(*primaryPlainText == plainText); 855bc03f14fSopenharmony_ci auto secondRecord = newPasteData.GetRecordAt(1); 856bc03f14fSopenharmony_ci ASSERT_TRUE(secondRecord != nullptr); 857bc03f14fSopenharmony_ci auto secondRecordMimeType = secondRecord->GetMimeType(); 858bc03f14fSopenharmony_ci ASSERT_TRUE(secondRecordMimeType == MIMETYPE_TEXT_PLAIN); 859bc03f14fSopenharmony_ci} 860bc03f14fSopenharmony_ci 861bc03f14fSopenharmony_ci/** 862bc03f14fSopenharmony_ci* @tc.name: PasteDataTest0014 863bc03f14fSopenharmony_ci* @tc.desc: Create paste board data test. 864bc03f14fSopenharmony_ci* @tc.type: FUNC 865bc03f14fSopenharmony_ci* @tc.require: AROOOH5R5G 866bc03f14fSopenharmony_ci*/ 867bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteDataTest0014, TestSize.Level0) 868bc03f14fSopenharmony_ci{ 869bc03f14fSopenharmony_ci std::string plainText = "plain text"; 870bc03f14fSopenharmony_ci auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText); 871bc03f14fSopenharmony_ci ASSERT_TRUE(pasteData != nullptr); 872bc03f14fSopenharmony_ci auto shareOption = pasteData->GetShareOption(); 873bc03f14fSopenharmony_ci ASSERT_TRUE(shareOption == ShareOption::CrossDevice); 874bc03f14fSopenharmony_ci pasteData->SetShareOption(ShareOption::InApp); 875bc03f14fSopenharmony_ci auto tokenId = pasteData->GetTokenId(); 876bc03f14fSopenharmony_ci ASSERT_TRUE(tokenId == 0); 877bc03f14fSopenharmony_ci pasteData->SetTokenId(1); 878bc03f14fSopenharmony_ci PasteData newPasteData; 879bc03f14fSopenharmony_ci PasteboardServiceTest::CommonTest(*pasteData, newPasteData); 880bc03f14fSopenharmony_ci shareOption = newPasteData.GetShareOption(); 881bc03f14fSopenharmony_ci ASSERT_TRUE(shareOption == ShareOption::InApp); 882bc03f14fSopenharmony_ci tokenId = pasteData->GetTokenId(); 883bc03f14fSopenharmony_ci ASSERT_TRUE(tokenId != 0); 884bc03f14fSopenharmony_ci} 885bc03f14fSopenharmony_ci 886bc03f14fSopenharmony_ci/** 887bc03f14fSopenharmony_ci* @tc.name: PasteDataTest0015 888bc03f14fSopenharmony_ci* @tc.desc: isLocalPaste test. 889bc03f14fSopenharmony_ci* @tc.type: FUNC 890bc03f14fSopenharmony_ci* @tc.require: AROOOH5R5G 891bc03f14fSopenharmony_ci*/ 892bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteDataTest0015, TestSize.Level0) 893bc03f14fSopenharmony_ci{ 894bc03f14fSopenharmony_ci std::string plainText = "plain text"; 895bc03f14fSopenharmony_ci auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText); 896bc03f14fSopenharmony_ci ASSERT_TRUE(pasteData != nullptr); 897bc03f14fSopenharmony_ci auto isLocalPaste = pasteData->IsLocalPaste(); 898bc03f14fSopenharmony_ci ASSERT_FALSE(isLocalPaste); 899bc03f14fSopenharmony_ci pasteData->SetLocalPasteFlag(true); 900bc03f14fSopenharmony_ci isLocalPaste = pasteData->IsLocalPaste(); 901bc03f14fSopenharmony_ci ASSERT_TRUE(isLocalPaste); 902bc03f14fSopenharmony_ci pasteData->SetLocalPasteFlag(false); 903bc03f14fSopenharmony_ci isLocalPaste = pasteData->IsLocalPaste(); 904bc03f14fSopenharmony_ci ASSERT_FALSE(isLocalPaste); 905bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 906bc03f14fSopenharmony_ci auto hasPasteData = PasteboardClient::GetInstance()->HasPasteData(); 907bc03f14fSopenharmony_ci ASSERT_FALSE(hasPasteData); 908bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*pasteData); 909bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 910bc03f14fSopenharmony_ci hasPasteData = PasteboardClient::GetInstance()->HasPasteData(); 911bc03f14fSopenharmony_ci ASSERT_TRUE(hasPasteData); 912bc03f14fSopenharmony_ci PasteData newPasteData; 913bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->GetPasteData(newPasteData); 914bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 915bc03f14fSopenharmony_ci isLocalPaste = newPasteData.IsLocalPaste(); 916bc03f14fSopenharmony_ci ASSERT_TRUE(isLocalPaste); 917bc03f14fSopenharmony_ci} 918bc03f14fSopenharmony_ci 919bc03f14fSopenharmony_ci/** 920bc03f14fSopenharmony_ci* @tc.name: PasteDataTest0016 921bc03f14fSopenharmony_ci* @tc.desc: RemoveRecordAt HasMimeType test. 922bc03f14fSopenharmony_ci* @tc.type: FUNC 923bc03f14fSopenharmony_ci* @tc.require: AROOOH5R5G 924bc03f14fSopenharmony_ci*/ 925bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteDataTest0016, TestSize.Level0) 926bc03f14fSopenharmony_ci{ 927bc03f14fSopenharmony_ci std::string plainText = "plain text"; 928bc03f14fSopenharmony_ci auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText); 929bc03f14fSopenharmony_ci ASSERT_TRUE(pasteData != nullptr); 930bc03f14fSopenharmony_ci std::vector<uint8_t> arrayBuffer(46); 931bc03f14fSopenharmony_ci arrayBuffer = { 2, 7, 6, 8, 9 }; 932bc03f14fSopenharmony_ci std::string mimeType = "image/jpg"; 933bc03f14fSopenharmony_ci pasteData->AddKvRecord(mimeType, arrayBuffer); 934bc03f14fSopenharmony_ci pasteData->RemoveRecordAt(1); 935bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 936bc03f14fSopenharmony_ci auto hasPasteData = PasteboardClient::GetInstance()->HasPasteData(); 937bc03f14fSopenharmony_ci ASSERT_FALSE(hasPasteData); 938bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*pasteData); 939bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 940bc03f14fSopenharmony_ci hasPasteData = PasteboardClient::GetInstance()->HasPasteData(); 941bc03f14fSopenharmony_ci ASSERT_TRUE(hasPasteData); 942bc03f14fSopenharmony_ci PasteData newPasteData; 943bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->GetPasteData(newPasteData); 944bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 945bc03f14fSopenharmony_ci ASSERT_TRUE(newPasteData.HasMimeType(mimeType)); 946bc03f14fSopenharmony_ci ASSERT_TRUE(newPasteData.GetRecordCount() == 1); 947bc03f14fSopenharmony_ci auto record = newPasteData.GetRecordAt(0); 948bc03f14fSopenharmony_ci ASSERT_TRUE(record != nullptr); 949bc03f14fSopenharmony_ci auto customData = record->GetCustomData(); 950bc03f14fSopenharmony_ci ASSERT_TRUE(customData != nullptr); 951bc03f14fSopenharmony_ci auto itemData = customData->GetItemData(); 952bc03f14fSopenharmony_ci ASSERT_EQ(itemData.size(), 1); 953bc03f14fSopenharmony_ci auto item = itemData.find(mimeType); 954bc03f14fSopenharmony_ci ASSERT_TRUE(item != itemData.end()); 955bc03f14fSopenharmony_ci EXPECT_EQ(item->second, arrayBuffer); 956bc03f14fSopenharmony_ci} 957bc03f14fSopenharmony_ci 958bc03f14fSopenharmony_ci/** 959bc03f14fSopenharmony_ci* @tc.name: PasteDataTest0017 960bc03f14fSopenharmony_ci* @tc.desc: ReplaceRecordAt GetProperty GetTag test. 961bc03f14fSopenharmony_ci* @tc.type: FUNC 962bc03f14fSopenharmony_ci* @tc.require: AROOOH5R5G 963bc03f14fSopenharmony_ci*/ 964bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteDataTest0017, TestSize.Level0) 965bc03f14fSopenharmony_ci{ 966bc03f14fSopenharmony_ci uint32_t color[100] = { 3, 7, 9, 9, 7, 6 }; 967bc03f14fSopenharmony_ci InitializationOptions opts = { { 5, 7 }, PixelFormat::ARGB_8888, PixelFormat::ARGB_8888 }; 968bc03f14fSopenharmony_ci std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(color, sizeof(color) / sizeof(color[0]), opts); 969bc03f14fSopenharmony_ci std::shared_ptr<PixelMap> pixelMapIn = move(pixelMap); 970bc03f14fSopenharmony_ci auto pasteData = PasteboardClient::GetInstance()->CreatePixelMapData(pixelMapIn); 971bc03f14fSopenharmony_ci ASSERT_TRUE(pasteData != nullptr); 972bc03f14fSopenharmony_ci auto pixelMap1 = pasteData->GetPrimaryPixelMap(); 973bc03f14fSopenharmony_ci ASSERT_TRUE(pixelMap1 != nullptr); 974bc03f14fSopenharmony_ci ImageInfo imageInfo = {}; 975bc03f14fSopenharmony_ci pixelMap1->GetImageInfo(imageInfo); 976bc03f14fSopenharmony_ci ASSERT_EQ(imageInfo.size.height, opts.size.height); 977bc03f14fSopenharmony_ci ASSERT_EQ(imageInfo.size.width, opts.size.width); 978bc03f14fSopenharmony_ci ASSERT_EQ(imageInfo.pixelFormat, opts.pixelFormat); 979bc03f14fSopenharmony_ci std::string plainText = "plain text"; 980bc03f14fSopenharmony_ci auto record = PasteboardClient::GetInstance()->CreatePlainTextRecord(plainText); 981bc03f14fSopenharmony_ci ASSERT_TRUE(record != nullptr); 982bc03f14fSopenharmony_ci ASSERT_TRUE(pasteData->ReplaceRecordAt(0, record)); 983bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 984bc03f14fSopenharmony_ci auto hasPasteData = PasteboardClient::GetInstance()->HasPasteData(); 985bc03f14fSopenharmony_ci ASSERT_FALSE(hasPasteData); 986bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*pasteData); 987bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 988bc03f14fSopenharmony_ci hasPasteData = PasteboardClient::GetInstance()->HasPasteData(); 989bc03f14fSopenharmony_ci ASSERT_TRUE(hasPasteData); 990bc03f14fSopenharmony_ci PasteData newPasteData; 991bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->GetPasteData(newPasteData); 992bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 993bc03f14fSopenharmony_ci ASSERT_EQ(newPasteData.GetRecordCount(), 1); 994bc03f14fSopenharmony_ci auto record1 = newPasteData.GetRecordAt(0); 995bc03f14fSopenharmony_ci ASSERT_TRUE(record1 != nullptr); 996bc03f14fSopenharmony_ci auto plainText1 = record1->GetPlainText(); 997bc03f14fSopenharmony_ci ASSERT_TRUE(plainText1 != nullptr); 998bc03f14fSopenharmony_ci EXPECT_EQ(*plainText1, plainText); 999bc03f14fSopenharmony_ci auto property = newPasteData.GetProperty(); 1000bc03f14fSopenharmony_ci EXPECT_TRUE(property.additions.IsEmpty()); 1001bc03f14fSopenharmony_ci EXPECT_EQ(property.mimeTypes.size(), 1); 1002bc03f14fSopenharmony_ci EXPECT_EQ(property.mimeTypes[0], MIMETYPE_TEXT_PLAIN); 1003bc03f14fSopenharmony_ci EXPECT_TRUE(property.tag.empty()); 1004bc03f14fSopenharmony_ci EXPECT_EQ(property.shareOption, ShareOption::CrossDevice); 1005bc03f14fSopenharmony_ci EXPECT_TRUE(property.tokenId != 0); 1006bc03f14fSopenharmony_ci auto tag = newPasteData.GetTag(); 1007bc03f14fSopenharmony_ci EXPECT_TRUE(tag.empty()); 1008bc03f14fSopenharmony_ci} 1009bc03f14fSopenharmony_ci 1010bc03f14fSopenharmony_ci/** 1011bc03f14fSopenharmony_ci* @tc.name: PasteDataTest0018 1012bc03f14fSopenharmony_ci* @tc.desc: AddPasteboardChangedObserver RemovePasteboardChangedObserver OnRemoteDied OnRemoteSaDied test. 1013bc03f14fSopenharmony_ci* @tc.type: FUNC 1014bc03f14fSopenharmony_ci* @tc.require: AROOOH5R5G 1015bc03f14fSopenharmony_ci*/ 1016bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteDataTest0018, TestSize.Level0) 1017bc03f14fSopenharmony_ci{ 1018bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->RemovePasteboardChangedObserver(nullptr); 1019bc03f14fSopenharmony_ci if (PasteboardServiceTest::pasteboardObserver_ == nullptr) { 1020bc03f14fSopenharmony_ci PasteboardServiceTest::pasteboardObserver_ = new PasteboardObserverCallback(); 1021bc03f14fSopenharmony_ci } 1022bc03f14fSopenharmony_ci PasteboardServiceTest::pasteboardChangedFlag_ = false; 1023bc03f14fSopenharmony_ci ASSERT_TRUE(PasteboardServiceTest::pasteboardObserver_ != nullptr); 1024bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->AddPasteboardChangedObserver(PasteboardServiceTest::pasteboardObserver_); 1025bc03f14fSopenharmony_ci ASSERT_FALSE(PasteboardServiceTest::pasteboardChangedFlag_); 1026bc03f14fSopenharmony_ci const wptr<IRemoteObject> object; 1027bc03f14fSopenharmony_ci PasteboardSaDeathRecipient death; 1028bc03f14fSopenharmony_ci death.OnRemoteDied(object); 1029bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->OnRemoteSaDied(object); 1030bc03f14fSopenharmony_ci uint32_t color[100] = { 3, 7, 9, 9, 7, 6 }; 1031bc03f14fSopenharmony_ci InitializationOptions opts = { { 5, 7 }, PixelFormat::ARGB_8888, PixelFormat::ARGB_8888 }; 1032bc03f14fSopenharmony_ci std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(color, sizeof(color) / sizeof(color[0]), opts); 1033bc03f14fSopenharmony_ci std::shared_ptr<PixelMap> pixelMapIn = move(pixelMap); 1034bc03f14fSopenharmony_ci auto pasteData = PasteboardClient::GetInstance()->CreatePixelMapData(pixelMapIn); 1035bc03f14fSopenharmony_ci ASSERT_TRUE(pasteData != nullptr); 1036bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 1037bc03f14fSopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(5)); 1038bc03f14fSopenharmony_ci ASSERT_FALSE(PasteboardServiceTest::pasteboardChangedFlag_); 1039bc03f14fSopenharmony_ci auto hasPasteData = PasteboardClient::GetInstance()->HasPasteData(); 1040bc03f14fSopenharmony_ci ASSERT_FALSE(hasPasteData); 1041bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*pasteData); 1042bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 1043bc03f14fSopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(5)); 1044bc03f14fSopenharmony_ci ASSERT_TRUE(PasteboardServiceTest::pasteboardChangedFlag_); 1045bc03f14fSopenharmony_ci hasPasteData = PasteboardClient::GetInstance()->HasPasteData(); 1046bc03f14fSopenharmony_ci ASSERT_TRUE(hasPasteData); 1047bc03f14fSopenharmony_ci PasteData newPasteData; 1048bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->GetPasteData(newPasteData); 1049bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 1050bc03f14fSopenharmony_ci PasteboardServiceTest::pasteboardChangedFlag_ = false; 1051bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->RemovePasteboardChangedObserver(PasteboardServiceTest::pasteboardObserver_); 1052bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 1053bc03f14fSopenharmony_ci ASSERT_FALSE(PasteboardServiceTest::pasteboardChangedFlag_); 1054bc03f14fSopenharmony_ci hasPasteData = PasteboardClient::GetInstance()->HasPasteData(); 1055bc03f14fSopenharmony_ci ASSERT_FALSE(hasPasteData); 1056bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->SetPasteData(*pasteData); 1057bc03f14fSopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(5)); 1058bc03f14fSopenharmony_ci ASSERT_FALSE(PasteboardServiceTest::pasteboardChangedFlag_); 1059bc03f14fSopenharmony_ci hasPasteData = PasteboardClient::GetInstance()->HasPasteData(); 1060bc03f14fSopenharmony_ci ASSERT_TRUE(hasPasteData); 1061bc03f14fSopenharmony_ci} 1062bc03f14fSopenharmony_ci 1063bc03f14fSopenharmony_ci/** 1064bc03f14fSopenharmony_ci * @tc.name: PasteDataTest0019 1065bc03f14fSopenharmony_ci * @tc.desc: AddPasteboardEventObserver RemovePasteboardEventObserver test. 1066bc03f14fSopenharmony_ci * @tc.type: FUNC 1067bc03f14fSopenharmony_ci * @tc.require: AROOOH5R5G 1068bc03f14fSopenharmony_ci */ 1069bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteDataTest0019, TestSize.Level0) 1070bc03f14fSopenharmony_ci{ 1071bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->RemovePasteboardEventObserver(nullptr); 1072bc03f14fSopenharmony_ci if (PasteboardServiceTest::pasteboardEventObserver_ == nullptr) { 1073bc03f14fSopenharmony_ci PasteboardServiceTest::pasteboardEventObserver_ = new PasteboardEventObserverCallback(); 1074bc03f14fSopenharmony_ci } 1075bc03f14fSopenharmony_ci PasteboardServiceTest::pasteboardEventStatus_ = -1; 1076bc03f14fSopenharmony_ci ASSERT_TRUE(PasteboardServiceTest::pasteboardEventObserver_ != nullptr); 1077bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->AddPasteboardEventObserver(PasteboardServiceTest::pasteboardEventObserver_); 1078bc03f14fSopenharmony_ci ASSERT_EQ(PasteboardServiceTest::pasteboardEventStatus_, -1); 1079bc03f14fSopenharmony_ci auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData("hello"); 1080bc03f14fSopenharmony_ci ASSERT_TRUE(pasteData != nullptr); 1081bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 1082bc03f14fSopenharmony_ci ASSERT_EQ(PasteboardServiceTest::pasteboardEventStatus_, -1); 1083bc03f14fSopenharmony_ci auto hasPasteData = PasteboardClient::GetInstance()->HasPasteData(); 1084bc03f14fSopenharmony_ci ASSERT_FALSE(hasPasteData); 1085bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*pasteData); 1086bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 1087bc03f14fSopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(5)); 1088bc03f14fSopenharmony_ci ASSERT_EQ(PasteboardServiceTest::pasteboardEventStatus_, -1); 1089bc03f14fSopenharmony_ci hasPasteData = PasteboardClient::GetInstance()->HasPasteData(); 1090bc03f14fSopenharmony_ci ASSERT_TRUE(hasPasteData); 1091bc03f14fSopenharmony_ci PasteData newPasteData; 1092bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->GetPasteData(newPasteData); 1093bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 1094bc03f14fSopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(5)); 1095bc03f14fSopenharmony_ci ASSERT_EQ(PasteboardServiceTest::pasteboardEventStatus_, -1); 1096bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 1097bc03f14fSopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(5)); 1098bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 1099bc03f14fSopenharmony_ci ASSERT_EQ(PasteboardServiceTest::pasteboardEventStatus_, -1); 1100bc03f14fSopenharmony_ci PasteboardServiceTest::pasteboardEventStatus_ = -1; 1101bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->RemovePasteboardEventObserver(PasteboardServiceTest::pasteboardEventObserver_); 1102bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 1103bc03f14fSopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(5)); 1104bc03f14fSopenharmony_ci ASSERT_EQ(PasteboardServiceTest::pasteboardEventStatus_, -1); 1105bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->SetPasteData(*pasteData); 1106bc03f14fSopenharmony_ci ASSERT_EQ(PasteboardServiceTest::pasteboardEventStatus_, -1); 1107bc03f14fSopenharmony_ci} 1108bc03f14fSopenharmony_ci 1109bc03f14fSopenharmony_ci/** 1110bc03f14fSopenharmony_ci* @tc.name: PasteDataTest0020 1111bc03f14fSopenharmony_ci* @tc.desc: Create paste board test set bundleName and time. 1112bc03f14fSopenharmony_ci* @tc.type: FUNC 1113bc03f14fSopenharmony_ci*/ 1114bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteDataTest0020, TestSize.Level0) 1115bc03f14fSopenharmony_ci{ 1116bc03f14fSopenharmony_ci std::string text = "plain text"; 1117bc03f14fSopenharmony_ci auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(text); 1118bc03f14fSopenharmony_ci ASSERT_TRUE(pasteData != nullptr); 1119bc03f14fSopenharmony_ci std::string bundleName = "ohos.acts.distributeddatamgr.pasteboard"; 1120bc03f14fSopenharmony_ci pasteData->SetBundleName(bundleName); 1121bc03f14fSopenharmony_ci std::string time = GetTime(); 1122bc03f14fSopenharmony_ci pasteData->SetTime(time); 1123bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*pasteData); 1124bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 1125bc03f14fSopenharmony_ci auto has = PasteboardClient::GetInstance()->HasPasteData(); 1126bc03f14fSopenharmony_ci ASSERT_TRUE(has == true); 1127bc03f14fSopenharmony_ci} 1128bc03f14fSopenharmony_ci 1129bc03f14fSopenharmony_ci/** 1130bc03f14fSopenharmony_ci* @tc.name: PasteDataTest0021 1131bc03f14fSopenharmony_ci* @tc.desc: AddPasteboardEventObserver RemovePasteboardEventObserver test. 1132bc03f14fSopenharmony_ci* @tc.type: FUNC 1133bc03f14fSopenharmony_ci*/ 1134bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteDataTest0021, TestSize.Level0) 1135bc03f14fSopenharmony_ci{ 1136bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->AddPasteboardEventObserver(new PasteboardEventObserverCallback()); 1137bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->AddPasteboardEventObserver(new PasteboardEventObserverCallback()); 1138bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->AddPasteboardEventObserver(new PasteboardEventObserverCallback()); 1139bc03f14fSopenharmony_ci auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData("hello"); 1140bc03f14fSopenharmony_ci ASSERT_TRUE(pasteData != nullptr); 1141bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*pasteData); 1142bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 1143bc03f14fSopenharmony_ci auto hasData = PasteboardClient::GetInstance()->HasPasteData(); 1144bc03f14fSopenharmony_ci ASSERT_TRUE(hasData == true); 1145bc03f14fSopenharmony_ci PasteData newPasteData; 1146bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->GetPasteData(newPasteData); 1147bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 1148bc03f14fSopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(5)); 1149bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->RemovePasteboardEventObserver(nullptr); 1150bc03f14fSopenharmony_ci hasData = PasteboardClient::GetInstance()->HasPasteData(); 1151bc03f14fSopenharmony_ci ASSERT_TRUE(hasData == false); 1152bc03f14fSopenharmony_ci} 1153bc03f14fSopenharmony_ci 1154bc03f14fSopenharmony_ci/** 1155bc03f14fSopenharmony_ci* @tc.name: PasteDataTest0022 1156bc03f14fSopenharmony_ci* @tc.desc: isDraggedData test. 1157bc03f14fSopenharmony_ci* @tc.type: FUNC 1158bc03f14fSopenharmony_ci* @tc.require: AROOOH5R5G 1159bc03f14fSopenharmony_ci*/ 1160bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, PasteDataTest0022, TestSize.Level0) 1161bc03f14fSopenharmony_ci{ 1162bc03f14fSopenharmony_ci std::string plainText = "plain text"; 1163bc03f14fSopenharmony_ci auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText); 1164bc03f14fSopenharmony_ci ASSERT_TRUE(pasteData != nullptr); 1165bc03f14fSopenharmony_ci auto isDraggedData = pasteData->IsDraggedData(); 1166bc03f14fSopenharmony_ci ASSERT_FALSE(isDraggedData); 1167bc03f14fSopenharmony_ci pasteData->SetDraggedDataFlag(true); 1168bc03f14fSopenharmony_ci ASSERT_TRUE(pasteData->IsDraggedData()); 1169bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 1170bc03f14fSopenharmony_ci auto hasPasteData = PasteboardClient::GetInstance()->HasPasteData(); 1171bc03f14fSopenharmony_ci ASSERT_FALSE(hasPasteData); 1172bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*pasteData); 1173bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 1174bc03f14fSopenharmony_ci hasPasteData = PasteboardClient::GetInstance()->HasPasteData(); 1175bc03f14fSopenharmony_ci ASSERT_FALSE(hasPasteData); 1176bc03f14fSopenharmony_ci PasteData newPasteData; 1177bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->GetPasteData(newPasteData); 1178bc03f14fSopenharmony_ci ASSERT_FALSE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 1179bc03f14fSopenharmony_ci isDraggedData = newPasteData.IsDraggedData(); 1180bc03f14fSopenharmony_ci ASSERT_FALSE(isDraggedData); 1181bc03f14fSopenharmony_ci} 1182bc03f14fSopenharmony_ci 1183bc03f14fSopenharmony_ci/** 1184bc03f14fSopenharmony_ci* @tc.name: BigPixelMap001 1185bc03f14fSopenharmony_ci* @tc.desc: paste big pixel map image 1186bc03f14fSopenharmony_ci* @tc.type: FUNC 1187bc03f14fSopenharmony_ci* @tc.require:AR000H5I1D 1188bc03f14fSopenharmony_ci* @tc.author: baoyayong 1189bc03f14fSopenharmony_ci*/ 1190bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, BigPixelMap001, TestSize.Level1) 1191bc03f14fSopenharmony_ci{ 1192bc03f14fSopenharmony_ci constexpr uint32_t COLOR_SIZE = 1024 * 1960; 1193bc03f14fSopenharmony_ci auto color = std::make_unique<uint32_t[]>(COLOR_SIZE); 1194bc03f14fSopenharmony_ci InitializationOptions opts = { { 1024, 1960 }, PixelFormat::ARGB_8888, PixelFormat::ARGB_8888 }; 1195bc03f14fSopenharmony_ci std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(color.get(), COLOR_SIZE, opts); 1196bc03f14fSopenharmony_ci auto pasteData1 = PasteboardClient::GetInstance()->CreatePixelMapData(std::move(pixelMap)); 1197bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 1198bc03f14fSopenharmony_ci auto hasPasteData = PasteboardClient::GetInstance()->HasPasteData(); 1199bc03f14fSopenharmony_ci ASSERT_FALSE(hasPasteData); 1200bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*pasteData1); 1201bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 1202bc03f14fSopenharmony_ci hasPasteData = PasteboardClient::GetInstance()->HasPasteData(); 1203bc03f14fSopenharmony_ci ASSERT_TRUE(hasPasteData); 1204bc03f14fSopenharmony_ci PasteData pasteData2; 1205bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->GetPasteData(pasteData2); 1206bc03f14fSopenharmony_ci ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 1207bc03f14fSopenharmony_ci auto pixelMap2 = pasteData2.GetPrimaryPixelMap(); 1208bc03f14fSopenharmony_ci ASSERT_TRUE(pixelMap2 != nullptr); 1209bc03f14fSopenharmony_ci ImageInfo imageInfo{}; 1210bc03f14fSopenharmony_ci pixelMap2->GetImageInfo(imageInfo); 1211bc03f14fSopenharmony_ci EXPECT_TRUE(imageInfo.size.height == opts.size.height); 1212bc03f14fSopenharmony_ci EXPECT_TRUE(imageInfo.size.width == opts.size.width); 1213bc03f14fSopenharmony_ci EXPECT_TRUE(imageInfo.pixelFormat == opts.pixelFormat); 1214bc03f14fSopenharmony_ci} 1215bc03f14fSopenharmony_ci 1216bc03f14fSopenharmony_ci/** 1217bc03f14fSopenharmony_ci* @tc.name: GetPastedataFail001 1218bc03f14fSopenharmony_ci* @tc.desc: get paste data fail - SetValue() 1219bc03f14fSopenharmony_ci* @tc.type: FUNC 1220bc03f14fSopenharmony_ci* @tc.require: issuesI5WPTM 1221bc03f14fSopenharmony_ci* @tc.author: chenyu 1222bc03f14fSopenharmony_ci*/ 1223bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, GetPastedataFail001, TestSize.Level1) 1224bc03f14fSopenharmony_ci{ 1225bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 1226bc03f14fSopenharmony_ci PasteData data; 1227bc03f14fSopenharmony_ci auto ret = PasteboardClient::GetInstance()->GetPasteData(data); 1228bc03f14fSopenharmony_ci EXPECT_TRUE(ret == static_cast<int32_t>(PasteboardError::NO_DATA_ERROR)); 1229bc03f14fSopenharmony_ci} 1230bc03f14fSopenharmony_ci 1231bc03f14fSopenharmony_ci/** 1232bc03f14fSopenharmony_ci* @tc.name: DumpDataTest001 1233bc03f14fSopenharmony_ci* @tc.desc: DumpData()-remote, CrossDevice 1234bc03f14fSopenharmony_ci* @tc.type: FUNC 1235bc03f14fSopenharmony_ci* @tc.require: issueshI5YDEV 1236bc03f14fSopenharmony_ci* @tc.author: chenyu 1237bc03f14fSopenharmony_ci*/ 1238bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, DumpDataTest001, TestSize.Level1) 1239bc03f14fSopenharmony_ci{ 1240bc03f14fSopenharmony_ci std::string plainText = "plain text"; 1241bc03f14fSopenharmony_ci auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText); 1242bc03f14fSopenharmony_ci pasteData->SetRemote(true); 1243bc03f14fSopenharmony_ci pasteData->SetShareOption(ShareOption::CrossDevice); 1244bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 1245bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*pasteData); 1246bc03f14fSopenharmony_ci EXPECT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 1247bc03f14fSopenharmony_ci std::string result; 1248bc03f14fSopenharmony_ci ret = PasteboardServiceTest::ExecuteCmd(result); 1249bc03f14fSopenharmony_ci EXPECT_TRUE(ret); 1250bc03f14fSopenharmony_ci EXPECT_TRUE(result.find("CrossDevice") != std::string::npos); 1251bc03f14fSopenharmony_ci EXPECT_TRUE(result.find("remote") != std::string::npos); 1252bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 1253bc03f14fSopenharmony_ci} 1254bc03f14fSopenharmony_ci 1255bc03f14fSopenharmony_ci/** 1256bc03f14fSopenharmony_ci* @tc.name: DumpDataTest002 1257bc03f14fSopenharmony_ci* @tc.desc: DumpData()-local, LocalDevice 1258bc03f14fSopenharmony_ci* @tc.type: FUNC 1259bc03f14fSopenharmony_ci* @tc.require: issueshI5YDEV 1260bc03f14fSopenharmony_ci* @tc.author: chenyu 1261bc03f14fSopenharmony_ci*/ 1262bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, DumpDataTest002, TestSize.Level1) 1263bc03f14fSopenharmony_ci{ 1264bc03f14fSopenharmony_ci std::string plainText = "plain text"; 1265bc03f14fSopenharmony_ci auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText); 1266bc03f14fSopenharmony_ci pasteData->SetShareOption(ShareOption::LocalDevice); 1267bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 1268bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*pasteData); 1269bc03f14fSopenharmony_ci EXPECT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 1270bc03f14fSopenharmony_ci std::string result; 1271bc03f14fSopenharmony_ci ret = PasteboardServiceTest::ExecuteCmd(result); 1272bc03f14fSopenharmony_ci EXPECT_TRUE(ret); 1273bc03f14fSopenharmony_ci EXPECT_TRUE(result.find("LocalDevice") != std::string::npos); 1274bc03f14fSopenharmony_ci EXPECT_TRUE(result.find("local") != std::string::npos); 1275bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 1276bc03f14fSopenharmony_ci} 1277bc03f14fSopenharmony_ci 1278bc03f14fSopenharmony_ci/** 1279bc03f14fSopenharmony_ci* @tc.name: DumpDataTest003 1280bc03f14fSopenharmony_ci* @tc.desc: DumpData()-local, InApp 1281bc03f14fSopenharmony_ci* @tc.type: FUNC 1282bc03f14fSopenharmony_ci* @tc.require: issueshI5YDEV 1283bc03f14fSopenharmony_ci* @tc.author: chenyu 1284bc03f14fSopenharmony_ci*/ 1285bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, DumpDataTest003, TestSize.Level1) 1286bc03f14fSopenharmony_ci{ 1287bc03f14fSopenharmony_ci std::string plainText = "plain text"; 1288bc03f14fSopenharmony_ci auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText); 1289bc03f14fSopenharmony_ci pasteData->SetShareOption(ShareOption::InApp); 1290bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 1291bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*pasteData); 1292bc03f14fSopenharmony_ci EXPECT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 1293bc03f14fSopenharmony_ci std::string result; 1294bc03f14fSopenharmony_ci ret = PasteboardServiceTest::ExecuteCmd(result); 1295bc03f14fSopenharmony_ci EXPECT_TRUE(ret); 1296bc03f14fSopenharmony_ci EXPECT_TRUE(result.find("InAPP") != std::string::npos); 1297bc03f14fSopenharmony_ci EXPECT_TRUE(result.find("local") != std::string::npos); 1298bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 1299bc03f14fSopenharmony_ci} 1300bc03f14fSopenharmony_ci 1301bc03f14fSopenharmony_ci/** 1302bc03f14fSopenharmony_ci* @tc.name: DumpDataTest004 1303bc03f14fSopenharmony_ci* @tc.desc: DumpData()-no data 1304bc03f14fSopenharmony_ci* @tc.type: FUNC 1305bc03f14fSopenharmony_ci* @tc.require: issueshI5YDEV 1306bc03f14fSopenharmony_ci* @tc.author: chenyu 1307bc03f14fSopenharmony_ci*/ 1308bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, DumpDataTest004, TestSize.Level1) 1309bc03f14fSopenharmony_ci{ 1310bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 1311bc03f14fSopenharmony_ci 1312bc03f14fSopenharmony_ci std::string result; 1313bc03f14fSopenharmony_ci auto ret = PasteboardServiceTest::ExecuteCmd(result); 1314bc03f14fSopenharmony_ci EXPECT_TRUE(ret); 1315bc03f14fSopenharmony_ci EXPECT_EQ(result.find("Share"), std::string::npos); 1316bc03f14fSopenharmony_ci EXPECT_EQ(result.find("Option"), std::string::npos); 1317bc03f14fSopenharmony_ci} 1318bc03f14fSopenharmony_ci 1319bc03f14fSopenharmony_ci/** 1320bc03f14fSopenharmony_ci* @tc.name: HasPasteDataTest001 1321bc03f14fSopenharmony_ci* @tc.desc: if !pasteData->IsDraggedData() 1322bc03f14fSopenharmony_ci* @tc.type: FUNC 1323bc03f14fSopenharmony_ci* @tc.require: issueshI5YDEV 1324bc03f14fSopenharmony_ci* @tc.author: chenyu 1325bc03f14fSopenharmony_ci*/ 1326bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, HasPasteDataTest001, TestSize.Level0) 1327bc03f14fSopenharmony_ci{ 1328bc03f14fSopenharmony_ci std::vector<uint8_t> arrayBuffer(46); 1329bc03f14fSopenharmony_ci arrayBuffer = { 2, 7, 6, 8, 9 }; 1330bc03f14fSopenharmony_ci std::string mimeType = "image/jpg"; 1331bc03f14fSopenharmony_ci auto pasteData = PasteboardClient::GetInstance()->CreateKvData(mimeType, arrayBuffer); 1332bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 1333bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetPasteData(*pasteData); 1334bc03f14fSopenharmony_ci EXPECT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK)); 1335bc03f14fSopenharmony_ci auto hasPasteData = PasteboardClient::GetInstance()->HasPasteData(); 1336bc03f14fSopenharmony_ci // not DraggedData, not DefaultIME 1337bc03f14fSopenharmony_ci EXPECT_TRUE(hasPasteData); 1338bc03f14fSopenharmony_ci PasteboardClient::GetInstance()->Clear(); 1339bc03f14fSopenharmony_ci} 1340bc03f14fSopenharmony_ci 1341bc03f14fSopenharmony_ci/** 1342bc03f14fSopenharmony_ci* @tc.name: SetAppShareOptions 1343bc03f14fSopenharmony_ci* @tc.desc: set app share options 1344bc03f14fSopenharmony_ci* @tc.type: FUNC 1345bc03f14fSopenharmony_ci* @tc.require: issuesIA7V62 1346bc03f14fSopenharmony_ci* @tc.author: caozhijun 1347bc03f14fSopenharmony_ci*/ 1348bc03f14fSopenharmony_ciHWTEST_F(PasteboardServiceTest, SetAppShareOptions, TestSize.Level0) 1349bc03f14fSopenharmony_ci{ 1350bc03f14fSopenharmony_ci uint64_t tempTokenID = testTokenId_ | SYSTEM_APP_MASK; 1351bc03f14fSopenharmony_ci auto result = SetSelfTokenID(tempTokenID); 1352bc03f14fSopenharmony_ci PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "testTokenId= 0x%{public}x, ret= %{public}d!", testTokenId_, result); 1353bc03f14fSopenharmony_ci ShareOption setting = ShareOption::InApp; 1354bc03f14fSopenharmony_ci int32_t ret = PasteboardClient::GetInstance()->SetAppShareOptions(setting); 1355bc03f14fSopenharmony_ci EXPECT_TRUE(ret == 0); 1356bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->SetAppShareOptions(setting); 1357bc03f14fSopenharmony_ci EXPECT_TRUE(ret == static_cast<int32_t>(PasteboardError::INVALID_OPERATION_ERROR)); 1358bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->RemoveAppShareOptions(); 1359bc03f14fSopenharmony_ci EXPECT_TRUE(ret == 0); 1360bc03f14fSopenharmony_ci 1361bc03f14fSopenharmony_ci setting = ShareOption::LocalDevice; 1362bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->SetAppShareOptions(setting); 1363bc03f14fSopenharmony_ci EXPECT_TRUE(ret == 0); 1364bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->SetAppShareOptions(setting); 1365bc03f14fSopenharmony_ci EXPECT_TRUE(ret == static_cast<int32_t>(PasteboardError::INVALID_OPERATION_ERROR)); 1366bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->RemoveAppShareOptions(); 1367bc03f14fSopenharmony_ci EXPECT_TRUE(ret == 0); 1368bc03f14fSopenharmony_ci 1369bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->SetAppShareOptions(setting); 1370bc03f14fSopenharmony_ci EXPECT_TRUE(ret == 0); 1371bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->SetAppShareOptions(setting); 1372bc03f14fSopenharmony_ci EXPECT_TRUE(ret == static_cast<int32_t>(PasteboardError::INVALID_OPERATION_ERROR)); 1373bc03f14fSopenharmony_ci ret = PasteboardClient::GetInstance()->RemoveAppShareOptions(); 1374bc03f14fSopenharmony_ci EXPECT_TRUE(ret == 0); 1375bc03f14fSopenharmony_ci PasteboardServiceTest::RestoreSelfTokenId(); 1376bc03f14fSopenharmony_ci} 1377bc03f14fSopenharmony_ci} // namespace OHOS::MiscServices