1bc03f14fSopenharmony_ci/* 2bc03f14fSopenharmony_ci * Copyright (c) 2024 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 16bc03f14fSopenharmony_ci#include <gtest/gtest.h> 17bc03f14fSopenharmony_ci 18bc03f14fSopenharmony_ci#include "application_defined_record.h" 19bc03f14fSopenharmony_ci#include "audio.h" 20bc03f14fSopenharmony_ci#include "folder.h" 21bc03f14fSopenharmony_ci#include "html.h" 22bc03f14fSopenharmony_ci#include "image.h" 23bc03f14fSopenharmony_ci#include "link.h" 24bc03f14fSopenharmony_ci#include "pasteboard_utils.h" 25bc03f14fSopenharmony_ci#include "plain_text.h" 26bc03f14fSopenharmony_ci#include "system_defined_appitem.h" 27bc03f14fSopenharmony_ci#include "system_defined_form.h" 28bc03f14fSopenharmony_ci#include "system_defined_pixelmap.h" 29bc03f14fSopenharmony_ci#include "video.h" 30bc03f14fSopenharmony_cinamespace OHOS::MiscServices { 31bc03f14fSopenharmony_ciusing namespace testing::ext; 32bc03f14fSopenharmony_ciusing namespace testing; 33bc03f14fSopenharmony_ciusing namespace OHOS::Media; 34bc03f14fSopenharmony_ciusing UnifiedDataProperties = UDMF::UnifiedDataProperties; 35bc03f14fSopenharmony_ciclass PasteboardUtilsTest : public testing::Test { 36bc03f14fSopenharmony_cipublic: 37bc03f14fSopenharmony_ci static void SetUpTestCase(void); 38bc03f14fSopenharmony_ci static void TearDownTestCase(void); 39bc03f14fSopenharmony_ci void SetUp(); 40bc03f14fSopenharmony_ci void TearDown(); 41bc03f14fSopenharmony_ci UDMF::UnifiedData InitTextData(); 42bc03f14fSopenharmony_ci UDMF::UnifiedData InitPlainData(); 43bc03f14fSopenharmony_ci UDMF::UnifiedData InitHtmlData(); 44bc03f14fSopenharmony_ci UDMF::UnifiedData InitWantData(); 45bc03f14fSopenharmony_ci UDMF::UnifiedData InitLinkData(); 46bc03f14fSopenharmony_ci UDMF::UnifiedData InitFileData(); 47bc03f14fSopenharmony_ci UDMF::UnifiedData InitImageData(); 48bc03f14fSopenharmony_ci UDMF::UnifiedData InitVideoData(); 49bc03f14fSopenharmony_ci UDMF::UnifiedData InitAudioData(); 50bc03f14fSopenharmony_ci UDMF::UnifiedData InitFolderData(); 51bc03f14fSopenharmony_ci UDMF::UnifiedData InitSystemRecordData(); 52bc03f14fSopenharmony_ci UDMF::UnifiedData InitSystemAppItemData(); 53bc03f14fSopenharmony_ci UDMF::UnifiedData InitSysteFormData(); 54bc03f14fSopenharmony_ci UDMF::UnifiedData InitSystemPixelMapData(); 55bc03f14fSopenharmony_ci UDMF::UnifiedData InitAppDefinedData(); 56bc03f14fSopenharmony_ci 57bc03f14fSopenharmony_ciprotected: 58bc03f14fSopenharmony_ci Details details_; 59bc03f14fSopenharmony_ci std::vector<uint8_t> rawData_; 60bc03f14fSopenharmony_ci std::string text_; 61bc03f14fSopenharmony_ci std::string extraText_; 62bc03f14fSopenharmony_ci std::string uri_; 63bc03f14fSopenharmony_ci}; 64bc03f14fSopenharmony_ci 65bc03f14fSopenharmony_civoid PasteboardUtilsTest::SetUpTestCase(void) {} 66bc03f14fSopenharmony_ci 67bc03f14fSopenharmony_civoid PasteboardUtilsTest::TearDownTestCase(void) {} 68bc03f14fSopenharmony_ci 69bc03f14fSopenharmony_civoid PasteboardUtilsTest::SetUp(void) 70bc03f14fSopenharmony_ci{ 71bc03f14fSopenharmony_ci rawData_ = { 1, 2, 3, 4, 5, 6, 7, 8 }; 72bc03f14fSopenharmony_ci details_.insert({ "keyString", "string_test" }); 73bc03f14fSopenharmony_ci details_.insert({ "keyInt32", 1 }); 74bc03f14fSopenharmony_ci details_.insert({ "keyBool", true }); 75bc03f14fSopenharmony_ci details_.insert({ "KeyU8Array", rawData_ }); 76bc03f14fSopenharmony_ci details_.insert({ "KeyDouble", 1.234 }); 77bc03f14fSopenharmony_ci} 78bc03f14fSopenharmony_ci 79bc03f14fSopenharmony_civoid PasteboardUtilsTest::TearDown(void) {} 80bc03f14fSopenharmony_ci 81bc03f14fSopenharmony_ciUDMF::UnifiedData PasteboardUtilsTest::InitTextData() 82bc03f14fSopenharmony_ci{ 83bc03f14fSopenharmony_ci UDMF::UnifiedData data; 84bc03f14fSopenharmony_ci std::shared_ptr<UDMF::Text> textRecord = std::make_shared<UDMF::Text>(); 85bc03f14fSopenharmony_ci textRecord->SetDetails(details_); 86bc03f14fSopenharmony_ci data.AddRecord(textRecord); 87bc03f14fSopenharmony_ci return data; 88bc03f14fSopenharmony_ci} 89bc03f14fSopenharmony_ci 90bc03f14fSopenharmony_ciUDMF::UnifiedData PasteboardUtilsTest::InitPlainData() 91bc03f14fSopenharmony_ci{ 92bc03f14fSopenharmony_ci text_ = "helloWorld_plainText"; 93bc03f14fSopenharmony_ci extraText_ = "helloWorld_plainabstract"; 94bc03f14fSopenharmony_ci UDMF::UnifiedData data; 95bc03f14fSopenharmony_ci std::shared_ptr<UDMF::PlainText> plainTextRecord = std::make_shared<UDMF::PlainText>(text_, extraText_); 96bc03f14fSopenharmony_ci plainTextRecord->SetDetails(details_); 97bc03f14fSopenharmony_ci data.AddRecord(plainTextRecord); 98bc03f14fSopenharmony_ci auto unifiedDataProperties = std::make_shared<UnifiedDataProperties>(); 99bc03f14fSopenharmony_ci unifiedDataProperties->isRemote = true; 100bc03f14fSopenharmony_ci data.SetProperties(unifiedDataProperties); 101bc03f14fSopenharmony_ci return data; 102bc03f14fSopenharmony_ci} 103bc03f14fSopenharmony_ci 104bc03f14fSopenharmony_ciUDMF::UnifiedData PasteboardUtilsTest::InitHtmlData() 105bc03f14fSopenharmony_ci{ 106bc03f14fSopenharmony_ci text_ = "<div class='disable'>helloWorld</div>"; 107bc03f14fSopenharmony_ci extraText_ = "helloWorld_plainabstract"; 108bc03f14fSopenharmony_ci UDMF::UnifiedData data; 109bc03f14fSopenharmony_ci std::shared_ptr<UDMF::Html> htmlRecord = std::make_shared<UDMF::Html>(text_, extraText_); 110bc03f14fSopenharmony_ci htmlRecord->SetDetails(details_); 111bc03f14fSopenharmony_ci data.AddRecord(htmlRecord); 112bc03f14fSopenharmony_ci return data; 113bc03f14fSopenharmony_ci} 114bc03f14fSopenharmony_ciUDMF::UnifiedData PasteboardUtilsTest::InitWantData() 115bc03f14fSopenharmony_ci{ 116bc03f14fSopenharmony_ci using namespace OHOS::AAFwk; 117bc03f14fSopenharmony_ci std::shared_ptr<Want> want = std::make_shared<Want>(); 118bc03f14fSopenharmony_ci std::string idKey = "id"; 119bc03f14fSopenharmony_ci int32_t idValue = 123; 120bc03f14fSopenharmony_ci std::string deviceKey = "deviceId_key"; 121bc03f14fSopenharmony_ci want->SetParam(idKey, idValue); 122bc03f14fSopenharmony_ci std::shared_ptr<UDMF::UnifiedRecord> wantRecord = 123bc03f14fSopenharmony_ci std::make_shared<UDMF::UnifiedRecord>(UDMF::OPENHARMONY_WANT, want); 124bc03f14fSopenharmony_ci UDMF::UnifiedData data; 125bc03f14fSopenharmony_ci data.AddRecord(wantRecord); 126bc03f14fSopenharmony_ci return data; 127bc03f14fSopenharmony_ci} 128bc03f14fSopenharmony_ci 129bc03f14fSopenharmony_ciUDMF::UnifiedData PasteboardUtilsTest::InitLinkData() 130bc03f14fSopenharmony_ci{ 131bc03f14fSopenharmony_ci text_ = "https://www.test.com"; 132bc03f14fSopenharmony_ci extraText_ = "https://www.test.com/content"; 133bc03f14fSopenharmony_ci UDMF::UnifiedData data; 134bc03f14fSopenharmony_ci std::shared_ptr<UDMF::Link> linkRecord = std::make_shared<UDMF::Link>(text_, extraText_); 135bc03f14fSopenharmony_ci linkRecord->SetDetails(details_); 136bc03f14fSopenharmony_ci data.AddRecord(linkRecord); 137bc03f14fSopenharmony_ci return data; 138bc03f14fSopenharmony_ci} 139bc03f14fSopenharmony_ciUDMF::UnifiedData PasteboardUtilsTest::InitFileData() 140bc03f14fSopenharmony_ci{ 141bc03f14fSopenharmony_ci UDMF::UnifiedData data; 142bc03f14fSopenharmony_ci auto typeStr = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::FILE); 143bc03f14fSopenharmony_ci uri_ = "file:/uri"; 144bc03f14fSopenharmony_ci std::shared_ptr<UDMF::File> fileRecord = std::make_shared<UDMF::File>(uri_); 145bc03f14fSopenharmony_ci fileRecord->SetDetails(details_); 146bc03f14fSopenharmony_ci data.AddRecord(fileRecord); 147bc03f14fSopenharmony_ci return data; 148bc03f14fSopenharmony_ci} 149bc03f14fSopenharmony_ciUDMF::UnifiedData PasteboardUtilsTest::InitImageData() 150bc03f14fSopenharmony_ci{ 151bc03f14fSopenharmony_ci UDMF::UnifiedData data; 152bc03f14fSopenharmony_ci auto typeStr = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::IMAGE); 153bc03f14fSopenharmony_ci uri_ = "file:/image"; 154bc03f14fSopenharmony_ci std::shared_ptr<UDMF::Image> imageRecord = std::make_shared<UDMF::Image>(uri_); 155bc03f14fSopenharmony_ci imageRecord->SetDetails(details_); 156bc03f14fSopenharmony_ci data.AddRecord(imageRecord); 157bc03f14fSopenharmony_ci return data; 158bc03f14fSopenharmony_ci} 159bc03f14fSopenharmony_ciUDMF::UnifiedData PasteboardUtilsTest::InitVideoData() 160bc03f14fSopenharmony_ci{ 161bc03f14fSopenharmony_ci UDMF::UnifiedData data; 162bc03f14fSopenharmony_ci auto typeStr = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::VIDEO); 163bc03f14fSopenharmony_ci uri_ = "file:/Video"; 164bc03f14fSopenharmony_ci std::shared_ptr<UDMF::Video> videoRecord = std::make_shared<UDMF::Video>(uri_); 165bc03f14fSopenharmony_ci videoRecord->SetDetails(details_); 166bc03f14fSopenharmony_ci data.AddRecord(videoRecord); 167bc03f14fSopenharmony_ci 168bc03f14fSopenharmony_ci return data; 169bc03f14fSopenharmony_ci} 170bc03f14fSopenharmony_ciUDMF::UnifiedData PasteboardUtilsTest::InitAudioData() 171bc03f14fSopenharmony_ci{ 172bc03f14fSopenharmony_ci UDMF::UnifiedData data; 173bc03f14fSopenharmony_ci auto typeStr = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::AUDIO); 174bc03f14fSopenharmony_ci uri_ = "file:/Audio"; 175bc03f14fSopenharmony_ci std::shared_ptr<UDMF::Audio> audioRecord = std::make_shared<UDMF::Audio>(uri_); 176bc03f14fSopenharmony_ci audioRecord->SetDetails(details_); 177bc03f14fSopenharmony_ci data.AddRecord(audioRecord); 178bc03f14fSopenharmony_ci return data; 179bc03f14fSopenharmony_ci} 180bc03f14fSopenharmony_ciUDMF::UnifiedData PasteboardUtilsTest::InitFolderData() 181bc03f14fSopenharmony_ci{ 182bc03f14fSopenharmony_ci UDMF::UnifiedData data; 183bc03f14fSopenharmony_ci auto typeStr = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::FOLDER); 184bc03f14fSopenharmony_ci uri_ = "file:/Folder"; 185bc03f14fSopenharmony_ci std::shared_ptr<UDMF::Folder> folderRecord = std::make_shared<UDMF::Folder>(uri_); 186bc03f14fSopenharmony_ci folderRecord->SetDetails(details_); 187bc03f14fSopenharmony_ci data.AddRecord(folderRecord); 188bc03f14fSopenharmony_ci return data; 189bc03f14fSopenharmony_ci} 190bc03f14fSopenharmony_ciUDMF::UnifiedData PasteboardUtilsTest::InitSystemRecordData() 191bc03f14fSopenharmony_ci{ 192bc03f14fSopenharmony_ci UDMF::UnifiedData data; 193bc03f14fSopenharmony_ci std::shared_ptr<UDMF::SystemDefinedRecord> systemRecord = std::make_shared<UDMF::SystemDefinedRecord>(); 194bc03f14fSopenharmony_ci systemRecord->SetDetails(details_); 195bc03f14fSopenharmony_ci data.AddRecord(systemRecord); 196bc03f14fSopenharmony_ci return data; 197bc03f14fSopenharmony_ci} 198bc03f14fSopenharmony_ciUDMF::UnifiedData PasteboardUtilsTest::InitSystemAppItemData() 199bc03f14fSopenharmony_ci{ 200bc03f14fSopenharmony_ci UDMF::UnifiedData data; 201bc03f14fSopenharmony_ci std::shared_ptr<UDMF::SystemDefinedAppItem> systemDefinedAppItem1 = std::make_shared<UDMF::SystemDefinedAppItem>(); 202bc03f14fSopenharmony_ci std::string appId = "appId"; 203bc03f14fSopenharmony_ci std::string appIconId = "appIconId"; 204bc03f14fSopenharmony_ci std::string appName = "appName"; 205bc03f14fSopenharmony_ci std::string appLabelId = "appLabelId"; 206bc03f14fSopenharmony_ci std::string bundleName = "bundleName"; 207bc03f14fSopenharmony_ci std::string abilityName = "abilityName"; 208bc03f14fSopenharmony_ci systemDefinedAppItem1->SetDetails(details_); 209bc03f14fSopenharmony_ci systemDefinedAppItem1->SetAppId(appId); 210bc03f14fSopenharmony_ci systemDefinedAppItem1->SetAppName(appName); 211bc03f14fSopenharmony_ci systemDefinedAppItem1->SetAppIconId(appIconId); 212bc03f14fSopenharmony_ci systemDefinedAppItem1->SetAppLabelId(appLabelId); 213bc03f14fSopenharmony_ci systemDefinedAppItem1->SetBundleName(bundleName); 214bc03f14fSopenharmony_ci systemDefinedAppItem1->SetAbilityName(abilityName); 215bc03f14fSopenharmony_ci systemDefinedAppItem1->SetType(UDMF::SYSTEM_DEFINED_APP_ITEM); 216bc03f14fSopenharmony_ci data.AddRecord(systemDefinedAppItem1); 217bc03f14fSopenharmony_ci return data; 218bc03f14fSopenharmony_ci} 219bc03f14fSopenharmony_ciUDMF::UnifiedData PasteboardUtilsTest::InitSysteFormData() 220bc03f14fSopenharmony_ci{ 221bc03f14fSopenharmony_ci UDMF::UnifiedData data; 222bc03f14fSopenharmony_ci std::shared_ptr<UDMF::SystemDefinedForm> form = std::make_shared<UDMF::SystemDefinedForm>(); 223bc03f14fSopenharmony_ci int32_t formId = 1; 224bc03f14fSopenharmony_ci std::string formName = "formName"; 225bc03f14fSopenharmony_ci std::string module = "module"; 226bc03f14fSopenharmony_ci std::string bundleName = "bundleName"; 227bc03f14fSopenharmony_ci std::string abilityName = "abilityName"; 228bc03f14fSopenharmony_ci form->SetDetails(details_); 229bc03f14fSopenharmony_ci form->SetFormId(formId); 230bc03f14fSopenharmony_ci form->SetFormName(formName); 231bc03f14fSopenharmony_ci form->SetAbilityName(abilityName); 232bc03f14fSopenharmony_ci form->SetBundleName(bundleName); 233bc03f14fSopenharmony_ci form->SetModule(module); 234bc03f14fSopenharmony_ci form->SetType(UDMF::SYSTEM_DEFINED_FORM); 235bc03f14fSopenharmony_ci data.AddRecord(form); 236bc03f14fSopenharmony_ci return data; 237bc03f14fSopenharmony_ci} 238bc03f14fSopenharmony_ciUDMF::UnifiedData PasteboardUtilsTest::InitSystemPixelMapData() 239bc03f14fSopenharmony_ci{ 240bc03f14fSopenharmony_ci uint32_t color[100] = { 3, 7, 9, 9, 7, 6 }; 241bc03f14fSopenharmony_ci InitializationOptions opts = { { 5, 7 }, PixelFormat::ARGB_8888, PixelFormat::ARGB_8888 }; 242bc03f14fSopenharmony_ci std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(color, sizeof(color) / sizeof(color[0]), opts); 243bc03f14fSopenharmony_ci std::shared_ptr<PixelMap> pixelMapIn = move(pixelMap); 244bc03f14fSopenharmony_ci std::shared_ptr<UDMF::UnifiedRecord> pixelMapRecord = 245bc03f14fSopenharmony_ci std::make_shared<UDMF::SystemDefinedPixelMap>(UDMF::SYSTEM_DEFINED_PIXEL_MAP, pixelMapIn); 246bc03f14fSopenharmony_ci UDMF::UnifiedData data; 247bc03f14fSopenharmony_ci data.AddRecord(pixelMapRecord); 248bc03f14fSopenharmony_ci return data; 249bc03f14fSopenharmony_ci} 250bc03f14fSopenharmony_ci 251bc03f14fSopenharmony_ciUDMF::UnifiedData PasteboardUtilsTest::InitAppDefinedData() 252bc03f14fSopenharmony_ci{ 253bc03f14fSopenharmony_ci UDMF::UnifiedData data; 254bc03f14fSopenharmony_ci std::shared_ptr<UDMF::ApplicationDefinedRecord> appRecord = std::make_shared<UDMF::ApplicationDefinedRecord>(); 255bc03f14fSopenharmony_ci std::map<std::string, std::vector<uint8_t>> customData; 256bc03f14fSopenharmony_ci customData[UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::APPLICATION_DEFINED_RECORD)] = rawData_; 257bc03f14fSopenharmony_ci appRecord->SetApplicationDefinedType(UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::APPLICATION_DEFINED_RECORD)); 258bc03f14fSopenharmony_ci appRecord->SetRawData(rawData_); 259bc03f14fSopenharmony_ci data.AddRecord(appRecord); 260bc03f14fSopenharmony_ci return data; 261bc03f14fSopenharmony_ci} 262bc03f14fSopenharmony_ci 263bc03f14fSopenharmony_ci/** 264bc03f14fSopenharmony_ci* @tc.name: Text2PasteRecord001 265bc03f14fSopenharmony_ci* @tc.desc: pasteData is local data. 266bc03f14fSopenharmony_ci* @tc.type: FUNC 267bc03f14fSopenharmony_ci* @tc.require: 268bc03f14fSopenharmony_ci* @tc.author: 269bc03f14fSopenharmony_ci*/ 270bc03f14fSopenharmony_ciHWTEST_F(PasteboardUtilsTest, Text2PasteRecord001, TestSize.Level0) 271bc03f14fSopenharmony_ci{ 272bc03f14fSopenharmony_ci auto data = InitTextData(); 273bc03f14fSopenharmony_ci auto pasteData = PasteboardUtils::GetInstance().Convert(data); 274bc03f14fSopenharmony_ci ASSERT_EQ(1, pasteData->GetRecordCount()); 275bc03f14fSopenharmony_ci auto record = pasteData->GetRecordAt(0); 276bc03f14fSopenharmony_ci auto type = record->GetMimeType(); 277bc03f14fSopenharmony_ci ASSERT_EQ(type, UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::TEXT)); 278bc03f14fSopenharmony_ci auto udType = record->GetUDType(); 279bc03f14fSopenharmony_ci ASSERT_EQ(udType, UDMF::UDType::TEXT); 280bc03f14fSopenharmony_ci auto details1 = record->GetDetails(); 281bc03f14fSopenharmony_ci ASSERT_EQ(*details1, details_); 282bc03f14fSopenharmony_ci 283bc03f14fSopenharmony_ci auto newData = PasteboardUtils::GetInstance().Convert(*pasteData); 284bc03f14fSopenharmony_ci ASSERT_EQ(1, newData->GetRecords().size()); 285bc03f14fSopenharmony_ci auto newRecord = newData->GetRecordAt(0); 286bc03f14fSopenharmony_ci auto newType = newRecord->GetType(); 287bc03f14fSopenharmony_ci ASSERT_EQ(newType, UDMF::TEXT); 288bc03f14fSopenharmony_ci auto newPlainRecord = static_cast<UDMF::Text *>(newRecord.get()); 289bc03f14fSopenharmony_ci auto newDetails = newPlainRecord->GetDetails(); 290bc03f14fSopenharmony_ci ASSERT_EQ(newDetails, details_); 291bc03f14fSopenharmony_ci} 292bc03f14fSopenharmony_ci 293bc03f14fSopenharmony_ci/** 294bc03f14fSopenharmony_ci* @tc.name: PlainText2PasteRecord001 295bc03f14fSopenharmony_ci* @tc.desc: pasteData is local data. 296bc03f14fSopenharmony_ci* @tc.type: FUNC 297bc03f14fSopenharmony_ci* @tc.require: 298bc03f14fSopenharmony_ci* @tc.author: 299bc03f14fSopenharmony_ci*/ 300bc03f14fSopenharmony_ciHWTEST_F(PasteboardUtilsTest, PlainText2PasteRecord001, TestSize.Level0) 301bc03f14fSopenharmony_ci{ 302bc03f14fSopenharmony_ci auto data = InitPlainData(); 303bc03f14fSopenharmony_ci auto pasteData = PasteboardUtils::GetInstance().Convert(data); 304bc03f14fSopenharmony_ci ASSERT_EQ(1, pasteData->GetRecordCount()); 305bc03f14fSopenharmony_ci auto record = pasteData->GetRecordAt(0); 306bc03f14fSopenharmony_ci auto type = record->GetMimeType(); 307bc03f14fSopenharmony_ci ASSERT_EQ(type, MIMETYPE_TEXT_PLAIN); 308bc03f14fSopenharmony_ci auto udType = record->GetUDType(); 309bc03f14fSopenharmony_ci ASSERT_EQ(udType, UDMF::UDType::PLAIN_TEXT); 310bc03f14fSopenharmony_ci auto udmfValue = record->GetUDMFValue(); 311bc03f14fSopenharmony_ci ASSERT_NE(udmfValue, nullptr); 312bc03f14fSopenharmony_ci auto link = std::make_shared<UDMF::PlainText>(UDMF::PLAIN_TEXT, *udmfValue); 313bc03f14fSopenharmony_ci ASSERT_EQ(link->GetContent(), text_); 314bc03f14fSopenharmony_ci ASSERT_EQ(link->GetAbstract(), extraText_); 315bc03f14fSopenharmony_ci 316bc03f14fSopenharmony_ci auto newData = PasteboardUtils::GetInstance().Convert(*pasteData); 317bc03f14fSopenharmony_ci ASSERT_EQ(1, newData->GetRecords().size()); 318bc03f14fSopenharmony_ci auto newRecord = newData->GetRecordAt(0); 319bc03f14fSopenharmony_ci auto newType = newRecord->GetType(); 320bc03f14fSopenharmony_ci ASSERT_EQ(newType, UDMF::PLAIN_TEXT); 321bc03f14fSopenharmony_ci auto newPlainRecord = static_cast<UDMF::PlainText *>(newRecord.get()); 322bc03f14fSopenharmony_ci auto newPlainText = newPlainRecord->GetContent(); 323bc03f14fSopenharmony_ci auto newAbstract = newPlainRecord->GetAbstract(); 324bc03f14fSopenharmony_ci auto newDetails = newPlainRecord->GetDetails(); 325bc03f14fSopenharmony_ci ASSERT_EQ(newPlainText, text_); 326bc03f14fSopenharmony_ci ASSERT_EQ(newAbstract, extraText_); 327bc03f14fSopenharmony_ci ASSERT_EQ(newDetails, details_); 328bc03f14fSopenharmony_ci auto unifiedProp = newData->GetProperties(); 329bc03f14fSopenharmony_ci ASSERT_EQ(unifiedProp->isRemote, true); 330bc03f14fSopenharmony_ci} 331bc03f14fSopenharmony_ci 332bc03f14fSopenharmony_ci/** 333bc03f14fSopenharmony_ci* @tc.name: Html2PasteRecord001 334bc03f14fSopenharmony_ci* @tc.desc: pasteData is local data. 335bc03f14fSopenharmony_ci* @tc.type: FUNC 336bc03f14fSopenharmony_ci* @tc.require: 337bc03f14fSopenharmony_ci* @tc.author: 338bc03f14fSopenharmony_ci*/ 339bc03f14fSopenharmony_ciHWTEST_F(PasteboardUtilsTest, Html2PasteRecord001, TestSize.Level0) 340bc03f14fSopenharmony_ci{ 341bc03f14fSopenharmony_ci auto data = InitHtmlData(); 342bc03f14fSopenharmony_ci auto pasteData = PasteboardUtils::GetInstance().Convert(data); 343bc03f14fSopenharmony_ci ASSERT_EQ(1, pasteData->GetRecordCount()); 344bc03f14fSopenharmony_ci auto record = pasteData->GetRecordAt(0); 345bc03f14fSopenharmony_ci auto type = record->GetMimeType(); 346bc03f14fSopenharmony_ci ASSERT_EQ(type, MIMETYPE_TEXT_HTML); 347bc03f14fSopenharmony_ci auto udType = record->GetUDType(); 348bc03f14fSopenharmony_ci ASSERT_EQ(udType, UDMF::UDType::HTML); 349bc03f14fSopenharmony_ci auto udmfValue = record->GetUDMFValue(); 350bc03f14fSopenharmony_ci ASSERT_NE(udmfValue, nullptr); 351bc03f14fSopenharmony_ci auto link = std::make_shared<UDMF::Html>(UDMF::HTML, *udmfValue); 352bc03f14fSopenharmony_ci ASSERT_EQ(link->GetHtmlContent(), text_); 353bc03f14fSopenharmony_ci ASSERT_EQ(link->GetPlainContent(), extraText_); 354bc03f14fSopenharmony_ci 355bc03f14fSopenharmony_ci auto newData = PasteboardUtils::GetInstance().Convert(*pasteData); 356bc03f14fSopenharmony_ci ASSERT_EQ(1, newData->GetRecords().size()); 357bc03f14fSopenharmony_ci auto newRecord = newData->GetRecordAt(0); 358bc03f14fSopenharmony_ci auto newType = newRecord->GetType(); 359bc03f14fSopenharmony_ci ASSERT_EQ(newType, UDMF::HTML); 360bc03f14fSopenharmony_ci auto newPlainRecord = static_cast<UDMF::Html *>(newRecord.get()); 361bc03f14fSopenharmony_ci auto newPlainText = newPlainRecord->GetHtmlContent(); 362bc03f14fSopenharmony_ci auto newAbstract = newPlainRecord->GetPlainContent(); 363bc03f14fSopenharmony_ci auto newDetails = newPlainRecord->GetDetails(); 364bc03f14fSopenharmony_ci ASSERT_EQ(newPlainText, text_); 365bc03f14fSopenharmony_ci ASSERT_EQ(newAbstract, extraText_); 366bc03f14fSopenharmony_ci ASSERT_EQ(newDetails, details_); 367bc03f14fSopenharmony_ci} 368bc03f14fSopenharmony_ci 369bc03f14fSopenharmony_ci/** 370bc03f14fSopenharmony_ci* @tc.name: Link2PasteRecord001 371bc03f14fSopenharmony_ci* @tc.desc: pasteData is local data. 372bc03f14fSopenharmony_ci* @tc.type: FUNC 373bc03f14fSopenharmony_ci* @tc.require: 374bc03f14fSopenharmony_ci* @tc.author: 375bc03f14fSopenharmony_ci*/ 376bc03f14fSopenharmony_ciHWTEST_F(PasteboardUtilsTest, Link2PasteRecord001, TestSize.Level0) 377bc03f14fSopenharmony_ci{ 378bc03f14fSopenharmony_ci auto data = InitLinkData(); 379bc03f14fSopenharmony_ci auto pasteData = PasteboardUtils::GetInstance().Convert(data); 380bc03f14fSopenharmony_ci ASSERT_EQ(1, pasteData->GetRecordCount()); 381bc03f14fSopenharmony_ci auto record = pasteData->GetRecordAt(0); 382bc03f14fSopenharmony_ci auto type = record->GetMimeType(); 383bc03f14fSopenharmony_ci ASSERT_EQ(type, MIMETYPE_TEXT_PLAIN); 384bc03f14fSopenharmony_ci auto udType = record->GetUDType(); 385bc03f14fSopenharmony_ci ASSERT_EQ(udType, UDMF::UDType::HYPERLINK); 386bc03f14fSopenharmony_ci auto udmfValue = record->GetUDMFValue(); 387bc03f14fSopenharmony_ci ASSERT_NE(udmfValue, nullptr); 388bc03f14fSopenharmony_ci auto link = std::make_shared<UDMF::Link>(UDMF::HYPERLINK, *udmfValue); 389bc03f14fSopenharmony_ci ASSERT_EQ(link->GetUrl(), text_); 390bc03f14fSopenharmony_ci ASSERT_EQ(link->GetDescription(), extraText_); 391bc03f14fSopenharmony_ci 392bc03f14fSopenharmony_ci auto newData = PasteboardUtils::GetInstance().Convert(*pasteData); 393bc03f14fSopenharmony_ci ASSERT_EQ(1, newData->GetRecords().size()); 394bc03f14fSopenharmony_ci auto newRecord = newData->GetRecordAt(0); 395bc03f14fSopenharmony_ci auto newType = newRecord->GetType(); 396bc03f14fSopenharmony_ci ASSERT_EQ(newType, UDMF::HYPERLINK); 397bc03f14fSopenharmony_ci auto newPlainRecord = static_cast<UDMF::Link *>(newRecord.get()); 398bc03f14fSopenharmony_ci auto newUrl = newPlainRecord->GetUrl(); 399bc03f14fSopenharmony_ci auto newDescription = newPlainRecord->GetDescription(); 400bc03f14fSopenharmony_ci auto newDetails = newPlainRecord->GetDetails(); 401bc03f14fSopenharmony_ci ASSERT_EQ(newUrl, text_); 402bc03f14fSopenharmony_ci ASSERT_EQ(newDescription, extraText_); 403bc03f14fSopenharmony_ci ASSERT_EQ(newDetails, details_); 404bc03f14fSopenharmony_ci} 405bc03f14fSopenharmony_ci 406bc03f14fSopenharmony_ci/** 407bc03f14fSopenharmony_ci* @tc.name: Want2PasteRecord001 408bc03f14fSopenharmony_ci* @tc.desc: pasteData is local data. 409bc03f14fSopenharmony_ci* @tc.type: FUNC 410bc03f14fSopenharmony_ci* @tc.require: 411bc03f14fSopenharmony_ci* @tc.author: 412bc03f14fSopenharmony_ci*/ 413bc03f14fSopenharmony_ciHWTEST_F(PasteboardUtilsTest, Want2PasteRecord001, TestSize.Level0) 414bc03f14fSopenharmony_ci{ 415bc03f14fSopenharmony_ci auto data = InitWantData(); 416bc03f14fSopenharmony_ci auto pasteData = PasteboardUtils::GetInstance().Convert(data); 417bc03f14fSopenharmony_ci ASSERT_EQ(1, pasteData->GetRecordCount()); 418bc03f14fSopenharmony_ci auto record = pasteData->GetRecordAt(0); 419bc03f14fSopenharmony_ci auto type = record->GetMimeType(); 420bc03f14fSopenharmony_ci ASSERT_EQ(type, MIMETYPE_TEXT_WANT); 421bc03f14fSopenharmony_ci auto udType = record->GetUDType(); 422bc03f14fSopenharmony_ci ASSERT_EQ(udType, int32_t(UDMF::UDType::OPENHARMONY_WANT)); 423bc03f14fSopenharmony_ci auto want1 = record->GetWant(); 424bc03f14fSopenharmony_ci int32_t idValue1 = want1->GetIntParam("id", 0); 425bc03f14fSopenharmony_ci ASSERT_EQ(idValue1, 123); 426bc03f14fSopenharmony_ci 427bc03f14fSopenharmony_ci auto newData = PasteboardUtils::GetInstance().Convert(*pasteData); 428bc03f14fSopenharmony_ci ASSERT_EQ(1, newData->GetRecords().size()); 429bc03f14fSopenharmony_ci auto newRecord = newData->GetRecordAt(0); 430bc03f14fSopenharmony_ci auto newType = newRecord->GetType(); 431bc03f14fSopenharmony_ci ASSERT_EQ(newType, UDMF::OPENHARMONY_WANT); 432bc03f14fSopenharmony_ci auto recordValue = newRecord->GetValue(); 433bc03f14fSopenharmony_ci auto wantValue = std::get_if<std::shared_ptr<OHOS::AAFwk::Want>>(&recordValue); 434bc03f14fSopenharmony_ci ASSERT_NE(wantValue, nullptr); 435bc03f14fSopenharmony_ci int32_t idValue2 = (*(wantValue))->GetIntParam("id", 0); 436bc03f14fSopenharmony_ci ASSERT_EQ(idValue2, 123); 437bc03f14fSopenharmony_ci} 438bc03f14fSopenharmony_ci 439bc03f14fSopenharmony_ci/** 440bc03f14fSopenharmony_ci* @tc.name: File2PasteRecord001 441bc03f14fSopenharmony_ci* @tc.desc: pasteData is local data. 442bc03f14fSopenharmony_ci* @tc.type: FUNC 443bc03f14fSopenharmony_ci* @tc.require: 444bc03f14fSopenharmony_ci* @tc.author: 445bc03f14fSopenharmony_ci*/ 446bc03f14fSopenharmony_ciHWTEST_F(PasteboardUtilsTest, File2PasteRecord001, TestSize.Level0) 447bc03f14fSopenharmony_ci{ 448bc03f14fSopenharmony_ci auto data = InitFileData(); 449bc03f14fSopenharmony_ci auto pasteData = PasteboardUtils::GetInstance().Convert(data); 450bc03f14fSopenharmony_ci ASSERT_EQ(1, pasteData->GetRecordCount()); 451bc03f14fSopenharmony_ci auto record = pasteData->GetRecordAt(0); 452bc03f14fSopenharmony_ci auto type = record->GetMimeType(); 453bc03f14fSopenharmony_ci ASSERT_EQ(type, MIMETYPE_TEXT_URI); 454bc03f14fSopenharmony_ci auto udType = record->GetUDType(); 455bc03f14fSopenharmony_ci ASSERT_EQ(udType, UDMF::UDType::FILE); 456bc03f14fSopenharmony_ci auto uri1 = record->GetUri()->ToString(); 457bc03f14fSopenharmony_ci ASSERT_EQ(uri1, uri_); 458bc03f14fSopenharmony_ci auto details1 = record->GetDetails(); 459bc03f14fSopenharmony_ci ASSERT_EQ(*details1, details_); 460bc03f14fSopenharmony_ci 461bc03f14fSopenharmony_ci auto newData = PasteboardUtils::GetInstance().Convert(*pasteData); 462bc03f14fSopenharmony_ci ASSERT_EQ(1, newData->GetRecords().size()); 463bc03f14fSopenharmony_ci auto newRecord = newData->GetRecordAt(0); 464bc03f14fSopenharmony_ci auto newType = newRecord->GetType(); 465bc03f14fSopenharmony_ci ASSERT_EQ(newType, UDMF::FILE); 466bc03f14fSopenharmony_ci auto newFileRecord = static_cast<UDMF::File *>(newRecord.get()); 467bc03f14fSopenharmony_ci auto newDetails = newFileRecord->GetDetails(); 468bc03f14fSopenharmony_ci ASSERT_EQ(newDetails, details_); 469bc03f14fSopenharmony_ci auto uri2 = newFileRecord->GetUri(); 470bc03f14fSopenharmony_ci ASSERT_EQ(uri2, uri_); 471bc03f14fSopenharmony_ci} 472bc03f14fSopenharmony_ci 473bc03f14fSopenharmony_ci/** 474bc03f14fSopenharmony_ci* @tc.name: Image2PasteRecord001 475bc03f14fSopenharmony_ci* @tc.desc: pasteData is local data. 476bc03f14fSopenharmony_ci* @tc.type: FUNC 477bc03f14fSopenharmony_ci* @tc.require: 478bc03f14fSopenharmony_ci* @tc.author: 479bc03f14fSopenharmony_ci*/ 480bc03f14fSopenharmony_ciHWTEST_F(PasteboardUtilsTest, Image2PasteRecord001, TestSize.Level0) 481bc03f14fSopenharmony_ci{ 482bc03f14fSopenharmony_ci auto data = InitImageData(); 483bc03f14fSopenharmony_ci auto pasteData = PasteboardUtils::GetInstance().Convert(data); 484bc03f14fSopenharmony_ci ASSERT_EQ(1, pasteData->GetRecordCount()); 485bc03f14fSopenharmony_ci auto record = pasteData->GetRecordAt(0); 486bc03f14fSopenharmony_ci auto type = record->GetMimeType(); 487bc03f14fSopenharmony_ci ASSERT_EQ(type, MIMETYPE_TEXT_URI); 488bc03f14fSopenharmony_ci auto udType = record->GetUDType(); 489bc03f14fSopenharmony_ci ASSERT_EQ(udType, UDMF::UDType::IMAGE); 490bc03f14fSopenharmony_ci auto uri1 = record->GetUri()->ToString(); 491bc03f14fSopenharmony_ci ASSERT_EQ(uri1, uri_); 492bc03f14fSopenharmony_ci auto details1 = record->GetDetails(); 493bc03f14fSopenharmony_ci ASSERT_EQ(*details1, details_); 494bc03f14fSopenharmony_ci 495bc03f14fSopenharmony_ci auto newData = PasteboardUtils::GetInstance().Convert(*pasteData); 496bc03f14fSopenharmony_ci ASSERT_EQ(1, newData->GetRecords().size()); 497bc03f14fSopenharmony_ci auto newRecord = newData->GetRecordAt(0); 498bc03f14fSopenharmony_ci auto newType = newRecord->GetType(); 499bc03f14fSopenharmony_ci ASSERT_EQ(newType, UDMF::IMAGE); 500bc03f14fSopenharmony_ci auto newImageRecord = static_cast<UDMF::Image *>(newRecord.get()); 501bc03f14fSopenharmony_ci auto newDetails = newImageRecord->GetDetails(); 502bc03f14fSopenharmony_ci ASSERT_EQ(newDetails, details_); 503bc03f14fSopenharmony_ci auto uri2 = newImageRecord->GetUri(); 504bc03f14fSopenharmony_ci ASSERT_EQ(uri2, uri_); 505bc03f14fSopenharmony_ci} 506bc03f14fSopenharmony_ci 507bc03f14fSopenharmony_ci/** 508bc03f14fSopenharmony_ci* @tc.name: Audio2PasteRecord001 509bc03f14fSopenharmony_ci* @tc.desc: pasteData is local data. 510bc03f14fSopenharmony_ci* @tc.type: FUNC 511bc03f14fSopenharmony_ci* @tc.require: 512bc03f14fSopenharmony_ci* @tc.author: 513bc03f14fSopenharmony_ci*/ 514bc03f14fSopenharmony_ciHWTEST_F(PasteboardUtilsTest, Audio2PasteRecord001, TestSize.Level0) 515bc03f14fSopenharmony_ci{ 516bc03f14fSopenharmony_ci auto data = InitAudioData(); 517bc03f14fSopenharmony_ci auto pasteData = PasteboardUtils::GetInstance().Convert(data); 518bc03f14fSopenharmony_ci ASSERT_EQ(1, pasteData->GetRecordCount()); 519bc03f14fSopenharmony_ci auto record = pasteData->GetRecordAt(0); 520bc03f14fSopenharmony_ci auto type = record->GetMimeType(); 521bc03f14fSopenharmony_ci ASSERT_EQ(type, MIMETYPE_TEXT_URI); 522bc03f14fSopenharmony_ci auto udType = record->GetUDType(); 523bc03f14fSopenharmony_ci ASSERT_EQ(udType, UDMF::UDType::AUDIO); 524bc03f14fSopenharmony_ci auto uri1 = record->GetUri()->ToString(); 525bc03f14fSopenharmony_ci ASSERT_EQ(uri1, uri_); 526bc03f14fSopenharmony_ci auto details1 = record->GetDetails(); 527bc03f14fSopenharmony_ci ASSERT_EQ(*details1, details_); 528bc03f14fSopenharmony_ci 529bc03f14fSopenharmony_ci auto newData = PasteboardUtils::GetInstance().Convert(*pasteData); 530bc03f14fSopenharmony_ci ASSERT_EQ(1, newData->GetRecords().size()); 531bc03f14fSopenharmony_ci auto newRecord = newData->GetRecordAt(0); 532bc03f14fSopenharmony_ci auto newType = newRecord->GetType(); 533bc03f14fSopenharmony_ci ASSERT_EQ(newType, UDMF::AUDIO); 534bc03f14fSopenharmony_ci auto newAudioRecord = static_cast<UDMF::Audio *>(newRecord.get()); 535bc03f14fSopenharmony_ci auto newDetails = newAudioRecord->GetDetails(); 536bc03f14fSopenharmony_ci ASSERT_EQ(newDetails, details_); 537bc03f14fSopenharmony_ci auto uri2 = newAudioRecord->GetUri(); 538bc03f14fSopenharmony_ci ASSERT_EQ(uri2, uri_); 539bc03f14fSopenharmony_ci} 540bc03f14fSopenharmony_ci 541bc03f14fSopenharmony_ci/** 542bc03f14fSopenharmony_ci* @tc.name: Video2PasteRecord001 543bc03f14fSopenharmony_ci* @tc.desc: pasteData is local data. 544bc03f14fSopenharmony_ci* @tc.type: FUNC 545bc03f14fSopenharmony_ci* @tc.require: 546bc03f14fSopenharmony_ci* @tc.author: 547bc03f14fSopenharmony_ci*/ 548bc03f14fSopenharmony_ciHWTEST_F(PasteboardUtilsTest, Video2PasteRecord001, TestSize.Level0) 549bc03f14fSopenharmony_ci{ 550bc03f14fSopenharmony_ci auto data = InitVideoData(); 551bc03f14fSopenharmony_ci auto pasteData = PasteboardUtils::GetInstance().Convert(data); 552bc03f14fSopenharmony_ci ASSERT_EQ(1, pasteData->GetRecordCount()); 553bc03f14fSopenharmony_ci auto record = pasteData->GetRecordAt(0); 554bc03f14fSopenharmony_ci auto type = record->GetMimeType(); 555bc03f14fSopenharmony_ci ASSERT_EQ(type, MIMETYPE_TEXT_URI); 556bc03f14fSopenharmony_ci auto udType = record->GetUDType(); 557bc03f14fSopenharmony_ci ASSERT_EQ(udType, UDMF::UDType::VIDEO); 558bc03f14fSopenharmony_ci auto uri1 = record->GetUri()->ToString(); 559bc03f14fSopenharmony_ci ASSERT_EQ(uri1, uri_); 560bc03f14fSopenharmony_ci auto details1 = record->GetDetails(); 561bc03f14fSopenharmony_ci ASSERT_EQ(*details1, details_); 562bc03f14fSopenharmony_ci 563bc03f14fSopenharmony_ci auto newData = PasteboardUtils::GetInstance().Convert(*pasteData); 564bc03f14fSopenharmony_ci ASSERT_EQ(1, newData->GetRecords().size()); 565bc03f14fSopenharmony_ci auto newRecord = newData->GetRecordAt(0); 566bc03f14fSopenharmony_ci auto newType = newRecord->GetType(); 567bc03f14fSopenharmony_ci ASSERT_EQ(newType, UDMF::VIDEO); 568bc03f14fSopenharmony_ci auto newVideoRecord = static_cast<UDMF::Video *>(newRecord.get()); 569bc03f14fSopenharmony_ci auto newDetails = newVideoRecord->GetDetails(); 570bc03f14fSopenharmony_ci ASSERT_EQ(newDetails, details_); 571bc03f14fSopenharmony_ci auto uri2 = newVideoRecord->GetUri(); 572bc03f14fSopenharmony_ci ASSERT_EQ(uri2, uri_); 573bc03f14fSopenharmony_ci} 574bc03f14fSopenharmony_ci 575bc03f14fSopenharmony_ci/** 576bc03f14fSopenharmony_ci* @tc.name: Folder2PasteRecord001 577bc03f14fSopenharmony_ci* @tc.desc: pasteData is local data. 578bc03f14fSopenharmony_ci* @tc.type: FUNC 579bc03f14fSopenharmony_ci* @tc.require: 580bc03f14fSopenharmony_ci* @tc.author: 581bc03f14fSopenharmony_ci*/ 582bc03f14fSopenharmony_ciHWTEST_F(PasteboardUtilsTest, Folder2PasteRecord001, TestSize.Level0) 583bc03f14fSopenharmony_ci{ 584bc03f14fSopenharmony_ci auto data = InitFolderData(); 585bc03f14fSopenharmony_ci auto pasteData = PasteboardUtils::GetInstance().Convert(data); 586bc03f14fSopenharmony_ci ASSERT_EQ(1, pasteData->GetRecordCount()); 587bc03f14fSopenharmony_ci auto record = pasteData->GetRecordAt(0); 588bc03f14fSopenharmony_ci auto type = record->GetMimeType(); 589bc03f14fSopenharmony_ci ASSERT_EQ(type, MIMETYPE_TEXT_URI); 590bc03f14fSopenharmony_ci auto udType = record->GetUDType(); 591bc03f14fSopenharmony_ci ASSERT_EQ(udType, UDMF::UDType::FOLDER); 592bc03f14fSopenharmony_ci auto uri1 = record->GetUri()->ToString(); 593bc03f14fSopenharmony_ci ASSERT_EQ(uri1, uri_); 594bc03f14fSopenharmony_ci auto details1 = record->GetDetails(); 595bc03f14fSopenharmony_ci ASSERT_EQ(*details1, details_); 596bc03f14fSopenharmony_ci 597bc03f14fSopenharmony_ci auto newData = PasteboardUtils::GetInstance().Convert(*pasteData); 598bc03f14fSopenharmony_ci ASSERT_EQ(1, newData->GetRecords().size()); 599bc03f14fSopenharmony_ci auto newRecord = newData->GetRecordAt(0); 600bc03f14fSopenharmony_ci auto newType = newRecord->GetType(); 601bc03f14fSopenharmony_ci ASSERT_EQ(newType, UDMF::FOLDER); 602bc03f14fSopenharmony_ci auto newFolderRecord = static_cast<UDMF::Folder *>(newRecord.get()); 603bc03f14fSopenharmony_ci auto newDetails = newFolderRecord->GetDetails(); 604bc03f14fSopenharmony_ci ASSERT_EQ(newDetails, details_); 605bc03f14fSopenharmony_ci auto uri2 = newFolderRecord->GetUri(); 606bc03f14fSopenharmony_ci ASSERT_EQ(uri2, uri_); 607bc03f14fSopenharmony_ci} 608bc03f14fSopenharmony_ci 609bc03f14fSopenharmony_ci/** 610bc03f14fSopenharmony_ci* @tc.name: SystemDefined2PasteRecord001 611bc03f14fSopenharmony_ci* @tc.desc: pasteData is local data. 612bc03f14fSopenharmony_ci* @tc.type: FUNC 613bc03f14fSopenharmony_ci* @tc.require: 614bc03f14fSopenharmony_ci* @tc.author: 615bc03f14fSopenharmony_ci*/ 616bc03f14fSopenharmony_ciHWTEST_F(PasteboardUtilsTest, SystemDefined2PasteRecord001, TestSize.Level0) 617bc03f14fSopenharmony_ci{ 618bc03f14fSopenharmony_ci auto data = InitSystemRecordData(); 619bc03f14fSopenharmony_ci auto pasteData = PasteboardUtils::GetInstance().Convert(data); 620bc03f14fSopenharmony_ci ASSERT_EQ(1, pasteData->GetRecordCount()); 621bc03f14fSopenharmony_ci auto record = pasteData->GetRecordAt(0); 622bc03f14fSopenharmony_ci auto type = record->GetMimeType(); 623bc03f14fSopenharmony_ci ASSERT_EQ(type, UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::SYSTEM_DEFINED_RECORD)); 624bc03f14fSopenharmony_ci auto udType = record->GetUDType(); 625bc03f14fSopenharmony_ci ASSERT_EQ(udType, UDMF::SYSTEM_DEFINED_RECORD); 626bc03f14fSopenharmony_ci auto details1 = record->GetDetails(); 627bc03f14fSopenharmony_ci ASSERT_EQ(*details1, details_); 628bc03f14fSopenharmony_ci 629bc03f14fSopenharmony_ci auto newData = PasteboardUtils::GetInstance().Convert(*pasteData); 630bc03f14fSopenharmony_ci ASSERT_EQ(1, newData->GetRecords().size()); 631bc03f14fSopenharmony_ci auto newRecord = newData->GetRecordAt(0); 632bc03f14fSopenharmony_ci auto newType = newRecord->GetType(); 633bc03f14fSopenharmony_ci ASSERT_EQ(newType, UDMF::SYSTEM_DEFINED_RECORD); 634bc03f14fSopenharmony_ci auto newSystemRecord = static_cast<UDMF::SystemDefinedRecord *>(newRecord.get()); 635bc03f14fSopenharmony_ci ASSERT_EQ(newSystemRecord->GetDetails(), details_); 636bc03f14fSopenharmony_ci} 637bc03f14fSopenharmony_ci 638bc03f14fSopenharmony_ci/** 639bc03f14fSopenharmony_ci* @tc.name: AppItem2PasteRecord001 640bc03f14fSopenharmony_ci* @tc.desc: pasteData is local data. 641bc03f14fSopenharmony_ci* @tc.type: FUNC 642bc03f14fSopenharmony_ci* @tc.require: 643bc03f14fSopenharmony_ci* @tc.author: 644bc03f14fSopenharmony_ci*/ 645bc03f14fSopenharmony_ciHWTEST_F(PasteboardUtilsTest, AppItem2PasteRecord001, TestSize.Level0) 646bc03f14fSopenharmony_ci{ 647bc03f14fSopenharmony_ci auto data = InitSystemAppItemData(); 648bc03f14fSopenharmony_ci auto pasteData = PasteboardUtils::GetInstance().Convert(data); 649bc03f14fSopenharmony_ci ASSERT_EQ(1, pasteData->GetRecordCount()); 650bc03f14fSopenharmony_ci auto record = pasteData->GetRecordAt(0); 651bc03f14fSopenharmony_ci auto type = record->GetMimeType(); 652bc03f14fSopenharmony_ci ASSERT_EQ(type, UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::SYSTEM_DEFINED_APP_ITEM)); 653bc03f14fSopenharmony_ci auto udType = record->GetUDType(); 654bc03f14fSopenharmony_ci ASSERT_EQ(udType, UDMF::SYSTEM_DEFINED_APP_ITEM); 655bc03f14fSopenharmony_ci auto details1 = record->GetDetails(); 656bc03f14fSopenharmony_ci ASSERT_NE(details1, nullptr); 657bc03f14fSopenharmony_ci ASSERT_EQ(*details1, details_); 658bc03f14fSopenharmony_ci auto udmfValue = record->GetUDMFValue(); 659bc03f14fSopenharmony_ci ASSERT_NE(udmfValue, nullptr); 660bc03f14fSopenharmony_ci auto newAppItem1 = std::make_shared<UDMF::SystemDefinedAppItem>(UDMF::SYSTEM_DEFINED_APP_ITEM, *udmfValue); 661bc03f14fSopenharmony_ci ASSERT_EQ(newAppItem1->GetAppId(), "appId"); 662bc03f14fSopenharmony_ci ASSERT_EQ(newAppItem1->GetAppIconId(), "appIconId"); 663bc03f14fSopenharmony_ci ASSERT_EQ(newAppItem1->GetAppName(), "appName"); 664bc03f14fSopenharmony_ci ASSERT_EQ(newAppItem1->GetAppLabelId(), "appLabelId"); 665bc03f14fSopenharmony_ci ASSERT_EQ(newAppItem1->GetBundleName(), "bundleName"); 666bc03f14fSopenharmony_ci ASSERT_EQ(newAppItem1->GetAbilityName(), "abilityName"); 667bc03f14fSopenharmony_ci 668bc03f14fSopenharmony_ci auto newData = PasteboardUtils::GetInstance().Convert(*pasteData); 669bc03f14fSopenharmony_ci ASSERT_EQ(1, newData->GetRecords().size()); 670bc03f14fSopenharmony_ci auto newRecord = newData->GetRecordAt(0); 671bc03f14fSopenharmony_ci auto newType = newRecord->GetType(); 672bc03f14fSopenharmony_ci ASSERT_EQ(newType, UDMF::SYSTEM_DEFINED_APP_ITEM); 673bc03f14fSopenharmony_ci auto newAppItem = static_cast<UDMF::SystemDefinedAppItem *>(newRecord.get()); 674bc03f14fSopenharmony_ci ASSERT_EQ(newAppItem->GetAppId(), "appId"); 675bc03f14fSopenharmony_ci ASSERT_EQ(newAppItem->GetAppIconId(), "appIconId"); 676bc03f14fSopenharmony_ci ASSERT_EQ(newAppItem->GetAppName(), "appName"); 677bc03f14fSopenharmony_ci ASSERT_EQ(newAppItem->GetAppLabelId(), "appLabelId"); 678bc03f14fSopenharmony_ci ASSERT_EQ(newAppItem->GetBundleName(), "bundleName"); 679bc03f14fSopenharmony_ci ASSERT_EQ(newAppItem->GetAbilityName(), "abilityName"); 680bc03f14fSopenharmony_ci ASSERT_EQ(newAppItem->GetDetails(), details_); 681bc03f14fSopenharmony_ci} 682bc03f14fSopenharmony_ci 683bc03f14fSopenharmony_ci/** 684bc03f14fSopenharmony_ci* @tc.name: Form2PasteRecord001 685bc03f14fSopenharmony_ci* @tc.desc: pasteData is local data. 686bc03f14fSopenharmony_ci* @tc.type: FUNC 687bc03f14fSopenharmony_ci* @tc.require: 688bc03f14fSopenharmony_ci* @tc.author: 689bc03f14fSopenharmony_ci*/ 690bc03f14fSopenharmony_ciHWTEST_F(PasteboardUtilsTest, Form2PasteRecord001, TestSize.Level0) 691bc03f14fSopenharmony_ci{ 692bc03f14fSopenharmony_ci auto data = InitSysteFormData(); 693bc03f14fSopenharmony_ci auto pasteData = PasteboardUtils::GetInstance().Convert(data); 694bc03f14fSopenharmony_ci ASSERT_EQ(1, pasteData->GetRecordCount()); 695bc03f14fSopenharmony_ci auto record = pasteData->GetRecordAt(0); 696bc03f14fSopenharmony_ci auto type = record->GetMimeType(); 697bc03f14fSopenharmony_ci ASSERT_EQ(type, UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::SYSTEM_DEFINED_FORM)); 698bc03f14fSopenharmony_ci auto udType = record->GetUDType(); 699bc03f14fSopenharmony_ci ASSERT_EQ(udType, UDMF::SYSTEM_DEFINED_FORM); 700bc03f14fSopenharmony_ci auto details1 = record->GetDetails(); 701bc03f14fSopenharmony_ci auto content = *(record->GetSystemDefinedContent()); 702bc03f14fSopenharmony_ci ASSERT_EQ(*details1, details_); 703bc03f14fSopenharmony_ci auto formId1 = std::get<std::int32_t>(content["formId"]); 704bc03f14fSopenharmony_ci auto formName1 = std::get<std::string>(content["formName"]); 705bc03f14fSopenharmony_ci auto module1 = std::get<std::string>(content["module"]); 706bc03f14fSopenharmony_ci auto bundleName1 = std::get<std::string>(content["bundleName"]); 707bc03f14fSopenharmony_ci auto abilityName1 = std::get<std::string>(content["abilityName"]); 708bc03f14fSopenharmony_ci ASSERT_EQ(1, formId1); 709bc03f14fSopenharmony_ci ASSERT_EQ("formName", formName1); 710bc03f14fSopenharmony_ci ASSERT_EQ("module", module1); 711bc03f14fSopenharmony_ci ASSERT_EQ("bundleName", bundleName1); 712bc03f14fSopenharmony_ci ASSERT_EQ("abilityName", abilityName1); 713bc03f14fSopenharmony_ci 714bc03f14fSopenharmony_ci auto newData = PasteboardUtils::GetInstance().Convert(*pasteData); 715bc03f14fSopenharmony_ci ASSERT_EQ(1, newData->GetRecords().size()); 716bc03f14fSopenharmony_ci auto newRecord = newData->GetRecordAt(0); 717bc03f14fSopenharmony_ci auto newType = newRecord->GetType(); 718bc03f14fSopenharmony_ci ASSERT_EQ(newType, UDMF::SYSTEM_DEFINED_FORM); 719bc03f14fSopenharmony_ci auto newForm = static_cast<UDMF::SystemDefinedForm *>(newRecord.get()); 720bc03f14fSopenharmony_ci ASSERT_EQ(newForm->GetFormId(), formId1); 721bc03f14fSopenharmony_ci ASSERT_EQ(newForm->GetFormName(), formName1); 722bc03f14fSopenharmony_ci ASSERT_EQ(newForm->GetModule(), module1); 723bc03f14fSopenharmony_ci ASSERT_EQ(newForm->GetBundleName(), bundleName1); 724bc03f14fSopenharmony_ci ASSERT_EQ(newForm->GetAbilityName(), abilityName1); 725bc03f14fSopenharmony_ci ASSERT_EQ(newForm->GetDetails(), details_); 726bc03f14fSopenharmony_ci} 727bc03f14fSopenharmony_ci 728bc03f14fSopenharmony_ci/** 729bc03f14fSopenharmony_ci* @tc.name: PixelMap2PasteRecord001 730bc03f14fSopenharmony_ci* @tc.desc: pasteData is local data. 731bc03f14fSopenharmony_ci* @tc.type: FUNC 732bc03f14fSopenharmony_ci* @tc.require: 733bc03f14fSopenharmony_ci* @tc.author: 734bc03f14fSopenharmony_ci*/ 735bc03f14fSopenharmony_ciHWTEST_F(PasteboardUtilsTest, PixelMap2PasteRecord001, TestSize.Level0) 736bc03f14fSopenharmony_ci{ 737bc03f14fSopenharmony_ci auto data = InitSystemPixelMapData(); 738bc03f14fSopenharmony_ci auto pasteData = PasteboardUtils::GetInstance().Convert(data); 739bc03f14fSopenharmony_ci ASSERT_EQ(1, pasteData->GetRecordCount()); 740bc03f14fSopenharmony_ci auto record = pasteData->GetRecordAt(0); 741bc03f14fSopenharmony_ci auto type = record->GetMimeType(); 742bc03f14fSopenharmony_ci ASSERT_EQ(type, MIMETYPE_PIXELMAP); 743bc03f14fSopenharmony_ci auto udType = record->GetUDType(); 744bc03f14fSopenharmony_ci ASSERT_EQ(udType, int32_t(UDMF::UDType::SYSTEM_DEFINED_PIXEL_MAP)); 745bc03f14fSopenharmony_ci auto newPixelMap = record->GetPixelMap(); 746bc03f14fSopenharmony_ci ASSERT_TRUE(newPixelMap != nullptr); 747bc03f14fSopenharmony_ci ImageInfo imageInfo = {}; 748bc03f14fSopenharmony_ci newPixelMap->GetImageInfo(imageInfo); 749bc03f14fSopenharmony_ci ASSERT_TRUE(imageInfo.size.height == 7); 750bc03f14fSopenharmony_ci ASSERT_TRUE(imageInfo.size.width == 5); 751bc03f14fSopenharmony_ci ASSERT_TRUE(imageInfo.pixelFormat == PixelFormat::ARGB_8888); 752bc03f14fSopenharmony_ci 753bc03f14fSopenharmony_ci auto newData = PasteboardUtils::GetInstance().Convert(*pasteData); 754bc03f14fSopenharmony_ci ASSERT_EQ(1, newData->GetRecords().size()); 755bc03f14fSopenharmony_ci auto newRecord = newData->GetRecordAt(0); 756bc03f14fSopenharmony_ci auto newType = newRecord->GetType(); 757bc03f14fSopenharmony_ci ASSERT_EQ(newType, UDMF::SYSTEM_DEFINED_PIXEL_MAP); 758bc03f14fSopenharmony_ci auto recordValue = newRecord->GetValue(); 759bc03f14fSopenharmony_ci auto newPixelMap1 = std::get_if<std::shared_ptr<OHOS::Media::PixelMap>>(&recordValue); 760bc03f14fSopenharmony_ci ASSERT_NE(newPixelMap1, nullptr); 761bc03f14fSopenharmony_ci ImageInfo imageInfo1 = {}; 762bc03f14fSopenharmony_ci (*newPixelMap1)->GetImageInfo(imageInfo1); 763bc03f14fSopenharmony_ci ASSERT_TRUE(imageInfo1.size.height == imageInfo.size.height); 764bc03f14fSopenharmony_ci ASSERT_TRUE(imageInfo1.size.width == imageInfo.size.width); 765bc03f14fSopenharmony_ci ASSERT_TRUE(imageInfo1.pixelFormat == imageInfo.pixelFormat); 766bc03f14fSopenharmony_ci} 767bc03f14fSopenharmony_ci 768bc03f14fSopenharmony_ci/** 769bc03f14fSopenharmony_ci* @tc.name: AppDefined2PasteRecord001 770bc03f14fSopenharmony_ci* @tc.desc: pasteData is local data. 771bc03f14fSopenharmony_ci* @tc.type: FUNC 772bc03f14fSopenharmony_ci* @tc.require: 773bc03f14fSopenharmony_ci* @tc.author: 774bc03f14fSopenharmony_ci*/ 775bc03f14fSopenharmony_ciHWTEST_F(PasteboardUtilsTest, AppDefined2PasteRecord001, TestSize.Level0) 776bc03f14fSopenharmony_ci{ 777bc03f14fSopenharmony_ci auto data = InitAppDefinedData(); 778bc03f14fSopenharmony_ci auto pasteData = PasteboardUtils::GetInstance().Convert(data); 779bc03f14fSopenharmony_ci ASSERT_EQ(1, pasteData->GetRecordCount()); 780bc03f14fSopenharmony_ci auto record = pasteData->GetRecordAt(0); 781bc03f14fSopenharmony_ci auto type = record->GetMimeType(); 782bc03f14fSopenharmony_ci ASSERT_EQ(type, UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::APPLICATION_DEFINED_RECORD)); 783bc03f14fSopenharmony_ci auto udType = record->GetUDType(); 784bc03f14fSopenharmony_ci ASSERT_EQ(udType, UDMF::APPLICATION_DEFINED_RECORD); 785bc03f14fSopenharmony_ci auto items = record->GetCustomData()->GetItemData(); 786bc03f14fSopenharmony_ci std::map<std::string, std::vector<uint8_t>> customData{ { type, rawData_ } }; 787bc03f14fSopenharmony_ci ASSERT_EQ(items, customData); 788bc03f14fSopenharmony_ci 789bc03f14fSopenharmony_ci auto newData = PasteboardUtils::GetInstance().Convert(*pasteData); 790bc03f14fSopenharmony_ci ASSERT_EQ(1, newData->GetRecords().size()); 791bc03f14fSopenharmony_ci auto newRecord = newData->GetRecordAt(0); 792bc03f14fSopenharmony_ci auto newType = newRecord->GetType(); 793bc03f14fSopenharmony_ci ASSERT_EQ(newType, UDMF::APPLICATION_DEFINED_RECORD); 794bc03f14fSopenharmony_ci auto newSystemRecord = static_cast<UDMF::ApplicationDefinedRecord *>(newRecord.get()); 795bc03f14fSopenharmony_ci ASSERT_EQ(newSystemRecord->GetRawData(), rawData_); 796bc03f14fSopenharmony_ci} 797bc03f14fSopenharmony_ci} // namespace OHOS::MiscServices