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#include <paste_data.h>
18bc03f14fSopenharmony_ci#include <unified_data.h>
19bc03f14fSopenharmony_ci
20bc03f14fSopenharmony_ci#include "convert_utils.h"
21bc03f14fSopenharmony_ci#include "paste_data_entry.h"
22bc03f14fSopenharmony_ci#include "tlv_object.h"
23bc03f14fSopenharmony_ci#include "unified_meta.h"
24bc03f14fSopenharmony_ci
25bc03f14fSopenharmony_cinamespace OHOS::MiscServices {
26bc03f14fSopenharmony_ciusing namespace testing::ext;
27bc03f14fSopenharmony_ciusing namespace testing;
28bc03f14fSopenharmony_ciusing namespace OHOS::Media;
29bc03f14fSopenharmony_ciclass ConvertUtilsTest : public testing::Test {
30bc03f14fSopenharmony_cipublic:
31bc03f14fSopenharmony_ci    static void SetUpTestCase(void);
32bc03f14fSopenharmony_ci    static void TearDownTestCase(void);
33bc03f14fSopenharmony_ci    void SetUp();
34bc03f14fSopenharmony_ci    void TearDown();
35bc03f14fSopenharmony_ci
36bc03f14fSopenharmony_ciprotected:
37bc03f14fSopenharmony_ci    std::string text_ = "test";
38bc03f14fSopenharmony_ci    std::string extraText_ = "extr";
39bc03f14fSopenharmony_ci    std::string uri_ = "";
40bc03f14fSopenharmony_ci    std::string html_ = "<div class='disable'>helloWorld</div>";
41bc03f14fSopenharmony_ci    std::string link_ = "http://abc.com";
42bc03f14fSopenharmony_ci    std::string appUtdId1_ = "appdefined-mytype1";
43bc03f14fSopenharmony_ci    std::string appUtdId2_ = "appdefined-mytype2";
44bc03f14fSopenharmony_ci    std::vector<uint8_t> rawData1_ = { 1, 2, 3, 4, 5, 6, 7, 8 };
45bc03f14fSopenharmony_ci    std::vector<uint8_t> rawData2_ = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
46bc03f14fSopenharmony_ci
47bc03f14fSopenharmony_ci    void CheckEntries(const std::vector<std::shared_ptr<PasteDataEntry>> &entries);
48bc03f14fSopenharmony_ci    void CheckPlainUds(const std::shared_ptr<PasteDataEntry> entry);
49bc03f14fSopenharmony_ci    void CheckFileUriUds(const std::shared_ptr<PasteDataEntry> entry);
50bc03f14fSopenharmony_ci    void CheckPixelMapUds(const std::shared_ptr<PasteDataEntry> entry);
51bc03f14fSopenharmony_ci    void CheckHtmlUds(const std::shared_ptr<PasteDataEntry> entry);
52bc03f14fSopenharmony_ci    void CheckLinkUds(const std::shared_ptr<PasteDataEntry> entry);
53bc03f14fSopenharmony_ci    void CheckCustomEntry(const std::shared_ptr<PasteDataEntry> entry);
54bc03f14fSopenharmony_ci
55bc03f14fSopenharmony_ci    void InitDataWithEntries(UDMF::UnifiedData &data);
56bc03f14fSopenharmony_ci    void InitDataWithPlainEntry(UDMF::UnifiedData &data);
57bc03f14fSopenharmony_ci    void InitDataWithHtmlEntry(UDMF::UnifiedData &data);
58bc03f14fSopenharmony_ci    void InitDataWithFileUriEntry(UDMF::UnifiedData &data);
59bc03f14fSopenharmony_ci    void InitDataWithPixelMapEntry(UDMF::UnifiedData &data);
60bc03f14fSopenharmony_ci    void InitDataWitCustomEntry(UDMF::UnifiedData &data);
61bc03f14fSopenharmony_ci    void InitDataWitSameCustomEntry(UDMF::UnifiedData &data);
62bc03f14fSopenharmony_ci
63bc03f14fSopenharmony_ci    void AddPlainUdsEntry(UDMF::UnifiedRecord &record);
64bc03f14fSopenharmony_ci    void AddFileUriUdsEntry(UDMF::UnifiedRecord &record);
65bc03f14fSopenharmony_ci    void AddHtmlUdsEntry(UDMF::UnifiedRecord &record);
66bc03f14fSopenharmony_ci    void AddPixelMapUdsEntry(UDMF::UnifiedRecord &record);
67bc03f14fSopenharmony_ci    void AddLinkUdsEntry(UDMF::UnifiedRecord &record);
68bc03f14fSopenharmony_ci    void AddCustomEntry(UDMF::UnifiedRecord &record);
69bc03f14fSopenharmony_ci    void AddCustomEntries(UDMF::UnifiedRecord &record);
70bc03f14fSopenharmony_ci
71bc03f14fSopenharmony_ci    static PasteData TlvData(const std::shared_ptr<PasteData> &data);
72bc03f14fSopenharmony_ci};
73bc03f14fSopenharmony_ci
74bc03f14fSopenharmony_civoid ConvertUtilsTest::SetUpTestCase(void) {}
75bc03f14fSopenharmony_ci
76bc03f14fSopenharmony_civoid ConvertUtilsTest::TearDownTestCase(void) {}
77bc03f14fSopenharmony_ci
78bc03f14fSopenharmony_civoid ConvertUtilsTest::SetUp(void) {}
79bc03f14fSopenharmony_ci
80bc03f14fSopenharmony_civoid ConvertUtilsTest::TearDown(void) {}
81bc03f14fSopenharmony_ci
82bc03f14fSopenharmony_ciPasteData ConvertUtilsTest::TlvData(const std::shared_ptr<PasteData> &data)
83bc03f14fSopenharmony_ci{
84bc03f14fSopenharmony_ci    std::vector<std::uint8_t> buffer;
85bc03f14fSopenharmony_ci    data->Init(buffer);
86bc03f14fSopenharmony_ci    data->Encode(buffer);
87bc03f14fSopenharmony_ci    PasteData decodePasteData;
88bc03f14fSopenharmony_ci    decodePasteData.Decode(buffer);
89bc03f14fSopenharmony_ci    return decodePasteData;
90bc03f14fSopenharmony_ci}
91bc03f14fSopenharmony_ci
92bc03f14fSopenharmony_civoid ConvertUtilsTest::AddPlainUdsEntry(UDMF::UnifiedRecord &record)
93bc03f14fSopenharmony_ci{
94bc03f14fSopenharmony_ci    Object plainUds;
95bc03f14fSopenharmony_ci    auto utdId = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::PLAIN_TEXT);
96bc03f14fSopenharmony_ci    plainUds.value_[UDMF::UNIFORM_DATA_TYPE] = utdId;
97bc03f14fSopenharmony_ci    plainUds.value_[UDMF::CONTENT] = text_;
98bc03f14fSopenharmony_ci    record.AddEntry(utdId, std::make_shared<Object>(plainUds));
99bc03f14fSopenharmony_ci}
100bc03f14fSopenharmony_ci
101bc03f14fSopenharmony_civoid ConvertUtilsTest::AddFileUriUdsEntry(UDMF::UnifiedRecord &record)
102bc03f14fSopenharmony_ci{
103bc03f14fSopenharmony_ci    Object fileUriobject;
104bc03f14fSopenharmony_ci    auto utdId = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::FILE_URI);
105bc03f14fSopenharmony_ci    fileUriobject.value_[UDMF::UNIFORM_DATA_TYPE] = utdId;
106bc03f14fSopenharmony_ci    fileUriobject.value_[UDMF::FILE_URI_PARAM] = uri_;
107bc03f14fSopenharmony_ci    fileUriobject.value_[UDMF::FILE_TYPE] = "";
108bc03f14fSopenharmony_ci    record.AddEntry(utdId, std::make_shared<Object>(fileUriobject));
109bc03f14fSopenharmony_ci}
110bc03f14fSopenharmony_ci
111bc03f14fSopenharmony_civoid ConvertUtilsTest::AddHtmlUdsEntry(UDMF::UnifiedRecord &record)
112bc03f14fSopenharmony_ci{
113bc03f14fSopenharmony_ci    auto utdId = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::HTML);
114bc03f14fSopenharmony_ci    Object htmlobject;
115bc03f14fSopenharmony_ci    htmlobject.value_[UDMF::UNIFORM_DATA_TYPE] = utdId;
116bc03f14fSopenharmony_ci    htmlobject.value_[UDMF::HTML_CONTENT] = html_;
117bc03f14fSopenharmony_ci    record.AddEntry(utdId, std::make_shared<Object>(htmlobject));
118bc03f14fSopenharmony_ci}
119bc03f14fSopenharmony_ci
120bc03f14fSopenharmony_civoid ConvertUtilsTest::AddLinkUdsEntry(UDMF::UnifiedRecord &record)
121bc03f14fSopenharmony_ci{
122bc03f14fSopenharmony_ci    auto utdId = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::HYPERLINK);
123bc03f14fSopenharmony_ci    Object linkObject;
124bc03f14fSopenharmony_ci    linkObject.value_[UDMF::UNIFORM_DATA_TYPE] = utdId;
125bc03f14fSopenharmony_ci    linkObject.value_[UDMF::URL] = link_;
126bc03f14fSopenharmony_ci    record.AddEntry(utdId, std::make_shared<Object>(linkObject));
127bc03f14fSopenharmony_ci}
128bc03f14fSopenharmony_ci
129bc03f14fSopenharmony_civoid ConvertUtilsTest::AddCustomEntry(UDMF::UnifiedRecord &record)
130bc03f14fSopenharmony_ci{
131bc03f14fSopenharmony_ci    record.AddEntry(appUtdId1_, rawData1_);
132bc03f14fSopenharmony_ci}
133bc03f14fSopenharmony_ci
134bc03f14fSopenharmony_civoid ConvertUtilsTest::AddCustomEntries(UDMF::UnifiedRecord &record)
135bc03f14fSopenharmony_ci{
136bc03f14fSopenharmony_ci    record.AddEntry(appUtdId1_, rawData1_);
137bc03f14fSopenharmony_ci    record.AddEntry(appUtdId2_, rawData2_);
138bc03f14fSopenharmony_ci}
139bc03f14fSopenharmony_ci
140bc03f14fSopenharmony_civoid ConvertUtilsTest::AddPixelMapUdsEntry(UDMF::UnifiedRecord &record)
141bc03f14fSopenharmony_ci{
142bc03f14fSopenharmony_ci    auto utdId = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::SYSTEM_DEFINED_PIXEL_MAP);
143bc03f14fSopenharmony_ci    Object object;
144bc03f14fSopenharmony_ci    object.value_[UDMF::UNIFORM_DATA_TYPE] = utdId;
145bc03f14fSopenharmony_ci    uint32_t color[100] = { 3, 7, 9, 9, 7, 6 };
146bc03f14fSopenharmony_ci    InitializationOptions opts = { { 5, 7 }, PixelFormat::ARGB_8888, PixelFormat::ARGB_8888 };
147bc03f14fSopenharmony_ci    std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(color, sizeof(color) / sizeof(color[0]), opts);
148bc03f14fSopenharmony_ci    std::shared_ptr<PixelMap> pixelMapIn = move(pixelMap);
149bc03f14fSopenharmony_ci    object.value_[UDMF::PIXEL_MAP] = pixelMapIn;
150bc03f14fSopenharmony_ci    record.AddEntry(utdId, std::make_shared<Object>(object));
151bc03f14fSopenharmony_ci}
152bc03f14fSopenharmony_ci
153bc03f14fSopenharmony_civoid ConvertUtilsTest::InitDataWithPlainEntry(UDMF::UnifiedData &data)
154bc03f14fSopenharmony_ci{
155bc03f14fSopenharmony_ci    std::shared_ptr<UDMF::UnifiedRecord> record = std::make_shared<UDMF::UnifiedRecord>();
156bc03f14fSopenharmony_ci    AddPlainUdsEntry(*record);
157bc03f14fSopenharmony_ci    data.AddRecord(record);
158bc03f14fSopenharmony_ci    auto size = data.GetRecords().size();
159bc03f14fSopenharmony_ci    ASSERT_EQ(1, size);
160bc03f14fSopenharmony_ci    auto entriesSize = data.GetRecordAt(0)->GetEntries()->size();
161bc03f14fSopenharmony_ci    ASSERT_EQ(1, entriesSize);
162bc03f14fSopenharmony_ci}
163bc03f14fSopenharmony_ci
164bc03f14fSopenharmony_civoid ConvertUtilsTest::InitDataWithHtmlEntry(UDMF::UnifiedData &data)
165bc03f14fSopenharmony_ci{
166bc03f14fSopenharmony_ci    std::shared_ptr<UDMF::UnifiedRecord> record = std::make_shared<UDMF::UnifiedRecord>();
167bc03f14fSopenharmony_ci    AddHtmlUdsEntry(*record);
168bc03f14fSopenharmony_ci    data.AddRecord(record);
169bc03f14fSopenharmony_ci    auto size = data.GetRecords().size();
170bc03f14fSopenharmony_ci    ASSERT_EQ(1, size);
171bc03f14fSopenharmony_ci    auto entriesSize = data.GetRecordAt(0)->GetEntries()->size();
172bc03f14fSopenharmony_ci    ASSERT_EQ(1, entriesSize);
173bc03f14fSopenharmony_ci}
174bc03f14fSopenharmony_ci
175bc03f14fSopenharmony_civoid ConvertUtilsTest::InitDataWithFileUriEntry(UDMF::UnifiedData &data)
176bc03f14fSopenharmony_ci{
177bc03f14fSopenharmony_ci    std::shared_ptr<UDMF::UnifiedRecord> record = std::make_shared<UDMF::UnifiedRecord>();
178bc03f14fSopenharmony_ci    AddFileUriUdsEntry(*record);
179bc03f14fSopenharmony_ci    data.AddRecord(record);
180bc03f14fSopenharmony_ci    auto size = data.GetRecords().size();
181bc03f14fSopenharmony_ci    ASSERT_EQ(1, size);
182bc03f14fSopenharmony_ci    auto entriesSize = data.GetRecordAt(0)->GetEntries()->size();
183bc03f14fSopenharmony_ci    ASSERT_EQ(1, entriesSize);
184bc03f14fSopenharmony_ci}
185bc03f14fSopenharmony_ci
186bc03f14fSopenharmony_civoid ConvertUtilsTest::InitDataWithPixelMapEntry(UDMF::UnifiedData &data)
187bc03f14fSopenharmony_ci{
188bc03f14fSopenharmony_ci    std::shared_ptr<UDMF::UnifiedRecord> record = std::make_shared<UDMF::UnifiedRecord>();
189bc03f14fSopenharmony_ci    AddPixelMapUdsEntry(*record);
190bc03f14fSopenharmony_ci    data.AddRecord(record);
191bc03f14fSopenharmony_ci    auto size = data.GetRecords().size();
192bc03f14fSopenharmony_ci    ASSERT_EQ(1, size);
193bc03f14fSopenharmony_ci    auto entriesSize = data.GetRecordAt(0)->GetEntries()->size();
194bc03f14fSopenharmony_ci    ASSERT_EQ(1, entriesSize);
195bc03f14fSopenharmony_ci}
196bc03f14fSopenharmony_ci
197bc03f14fSopenharmony_civoid ConvertUtilsTest::InitDataWitCustomEntry(UDMF::UnifiedData &data)
198bc03f14fSopenharmony_ci{
199bc03f14fSopenharmony_ci    std::shared_ptr<UDMF::UnifiedRecord> record = std::make_shared<UDMF::UnifiedRecord>();
200bc03f14fSopenharmony_ci    AddCustomEntry(*record);
201bc03f14fSopenharmony_ci    data.AddRecord(record);
202bc03f14fSopenharmony_ci    auto size = data.GetRecords().size();
203bc03f14fSopenharmony_ci    ASSERT_EQ(1, size);
204bc03f14fSopenharmony_ci    auto entriesSize = data.GetRecordAt(0)->GetEntries()->size();
205bc03f14fSopenharmony_ci    ASSERT_EQ(1, entriesSize);
206bc03f14fSopenharmony_ci}
207bc03f14fSopenharmony_ci
208bc03f14fSopenharmony_civoid ConvertUtilsTest::InitDataWitSameCustomEntry(UDMF::UnifiedData &data)
209bc03f14fSopenharmony_ci{
210bc03f14fSopenharmony_ci    std::shared_ptr<UDMF::UnifiedRecord> record = std::make_shared<UDMF::UnifiedRecord>();
211bc03f14fSopenharmony_ci    AddCustomEntry(*record);
212bc03f14fSopenharmony_ci    record->AddEntry(appUtdId1_, rawData2_);
213bc03f14fSopenharmony_ci    data.AddRecord(record);
214bc03f14fSopenharmony_ci    auto size = data.GetRecords().size();
215bc03f14fSopenharmony_ci    ASSERT_EQ(1, size);
216bc03f14fSopenharmony_ci    auto entriesSize = data.GetRecordAt(0)->GetEntries()->size();
217bc03f14fSopenharmony_ci    ASSERT_EQ(1, entriesSize);
218bc03f14fSopenharmony_ci}
219bc03f14fSopenharmony_ci
220bc03f14fSopenharmony_civoid ConvertUtilsTest::InitDataWithEntries(UDMF::UnifiedData &data)
221bc03f14fSopenharmony_ci{
222bc03f14fSopenharmony_ci    std::shared_ptr<UDMF::UnifiedRecord> record = std::make_shared<UDMF::UnifiedRecord>();
223bc03f14fSopenharmony_ci    AddPlainUdsEntry(*record);
224bc03f14fSopenharmony_ci    AddHtmlUdsEntry(*record);
225bc03f14fSopenharmony_ci    AddFileUriUdsEntry(*record);
226bc03f14fSopenharmony_ci    AddLinkUdsEntry(*record);
227bc03f14fSopenharmony_ci    AddCustomEntries(*record);
228bc03f14fSopenharmony_ci    auto entriesSize = record->GetEntries()->size();
229bc03f14fSopenharmony_ci    ASSERT_EQ(6, entriesSize);
230bc03f14fSopenharmony_ci    data.AddRecord(record);
231bc03f14fSopenharmony_ci    auto size = data.GetRecords().size();
232bc03f14fSopenharmony_ci    ASSERT_EQ(1, size);
233bc03f14fSopenharmony_ci}
234bc03f14fSopenharmony_ci
235bc03f14fSopenharmony_civoid ConvertUtilsTest::CheckEntries(const std::vector<std::shared_ptr<PasteDataEntry>> &entries)
236bc03f14fSopenharmony_ci{
237bc03f14fSopenharmony_ci    for (auto const &entry : entries) {
238bc03f14fSopenharmony_ci        if (entry->GetUtdId() == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::PLAIN_TEXT)) {
239bc03f14fSopenharmony_ci            CheckPlainUds(entry);
240bc03f14fSopenharmony_ci        } else if (entry->GetUtdId() == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::FILE_URI)) {
241bc03f14fSopenharmony_ci            CheckFileUriUds(entry);
242bc03f14fSopenharmony_ci        } else if (entry->GetUtdId() == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::SYSTEM_DEFINED_PIXEL_MAP)) {
243bc03f14fSopenharmony_ci            CheckPixelMapUds(entry);
244bc03f14fSopenharmony_ci        } else if (entry->GetUtdId() == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::HYPERLINK)) {
245bc03f14fSopenharmony_ci            CheckLinkUds(entry);
246bc03f14fSopenharmony_ci        } else if (entry->GetUtdId() == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::HTML)) {
247bc03f14fSopenharmony_ci            CheckHtmlUds(entry);
248bc03f14fSopenharmony_ci        } else {
249bc03f14fSopenharmony_ci            CheckCustomEntry(entry);
250bc03f14fSopenharmony_ci        }
251bc03f14fSopenharmony_ci    }
252bc03f14fSopenharmony_ci}
253bc03f14fSopenharmony_ci
254bc03f14fSopenharmony_civoid ConvertUtilsTest::CheckPlainUds(const std::shared_ptr<PasteDataEntry> entry)
255bc03f14fSopenharmony_ci{
256bc03f14fSopenharmony_ci    ASSERT_NE(entry, nullptr);
257bc03f14fSopenharmony_ci    ASSERT_EQ(MIMETYPE_TEXT_PLAIN, entry->GetMimeType());
258bc03f14fSopenharmony_ci    auto decodeValue = entry->GetValue();
259bc03f14fSopenharmony_ci    auto object = std::get_if<std::shared_ptr<Object>>(&decodeValue);
260bc03f14fSopenharmony_ci    ASSERT_NE(object, nullptr);
261bc03f14fSopenharmony_ci    auto objectValue = (*object)->value_;
262bc03f14fSopenharmony_ci    auto typeValue = std::get_if<std::string>(&objectValue[UDMF::UNIFORM_DATA_TYPE]);
263bc03f14fSopenharmony_ci    ASSERT_NE(typeValue, nullptr);
264bc03f14fSopenharmony_ci    ASSERT_EQ(*typeValue, UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::PLAIN_TEXT));
265bc03f14fSopenharmony_ci    auto value = std::get_if<std::string>(&objectValue[UDMF::CONTENT]);
266bc03f14fSopenharmony_ci    ASSERT_NE(value, nullptr);
267bc03f14fSopenharmony_ci    ASSERT_EQ(*value, text_);
268bc03f14fSopenharmony_ci}
269bc03f14fSopenharmony_ci
270bc03f14fSopenharmony_civoid ConvertUtilsTest::CheckFileUriUds(const std::shared_ptr<PasteDataEntry> entry)
271bc03f14fSopenharmony_ci{
272bc03f14fSopenharmony_ci    ASSERT_NE(entry, nullptr);
273bc03f14fSopenharmony_ci    ASSERT_EQ(MIMETYPE_TEXT_URI, entry->GetMimeType());
274bc03f14fSopenharmony_ci    auto decodeValue = entry->GetValue();
275bc03f14fSopenharmony_ci    auto object = std::get_if<std::shared_ptr<Object>>(&decodeValue);
276bc03f14fSopenharmony_ci    ASSERT_NE(object, nullptr);
277bc03f14fSopenharmony_ci    auto objectValue = (*object)->value_;
278bc03f14fSopenharmony_ci    auto typeValue = std::get_if<std::string>(&objectValue[UDMF::UNIFORM_DATA_TYPE]);
279bc03f14fSopenharmony_ci    ASSERT_NE(typeValue, nullptr);
280bc03f14fSopenharmony_ci    ASSERT_EQ(*typeValue, UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::FILE_URI));
281bc03f14fSopenharmony_ci    auto value = std::get_if<std::string>(&objectValue[UDMF::FILE_URI_PARAM]);
282bc03f14fSopenharmony_ci    ASSERT_NE(value, nullptr);
283bc03f14fSopenharmony_ci    ASSERT_EQ(*value, uri_);
284bc03f14fSopenharmony_ci}
285bc03f14fSopenharmony_ci
286bc03f14fSopenharmony_civoid ConvertUtilsTest::CheckHtmlUds(const std::shared_ptr<PasteDataEntry> entry)
287bc03f14fSopenharmony_ci{
288bc03f14fSopenharmony_ci    ASSERT_NE(entry, nullptr);
289bc03f14fSopenharmony_ci    ASSERT_EQ(MIMETYPE_TEXT_HTML, entry->GetMimeType());
290bc03f14fSopenharmony_ci    auto decodeValue = entry->GetValue();
291bc03f14fSopenharmony_ci    auto object = std::get_if<std::shared_ptr<Object>>(&decodeValue);
292bc03f14fSopenharmony_ci    ASSERT_NE(object, nullptr);
293bc03f14fSopenharmony_ci    auto objectValue = (*object)->value_;
294bc03f14fSopenharmony_ci    auto typeValue = std::get_if<std::string>(&objectValue[UDMF::UNIFORM_DATA_TYPE]);
295bc03f14fSopenharmony_ci    ASSERT_NE(typeValue, nullptr);
296bc03f14fSopenharmony_ci    ASSERT_EQ(*typeValue, UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::HTML));
297bc03f14fSopenharmony_ci    auto value = std::get_if<std::string>(&objectValue[UDMF::HTML_CONTENT]);
298bc03f14fSopenharmony_ci    ASSERT_NE(value, nullptr);
299bc03f14fSopenharmony_ci    ASSERT_EQ(*value, html_);
300bc03f14fSopenharmony_ci}
301bc03f14fSopenharmony_ci
302bc03f14fSopenharmony_civoid ConvertUtilsTest::CheckPixelMapUds(const std::shared_ptr<PasteDataEntry> entry)
303bc03f14fSopenharmony_ci{
304bc03f14fSopenharmony_ci    ASSERT_NE(entry, nullptr);
305bc03f14fSopenharmony_ci    ASSERT_EQ(MIMETYPE_PIXELMAP, entry->GetMimeType());
306bc03f14fSopenharmony_ci    auto decodeValue = entry->GetValue();
307bc03f14fSopenharmony_ci    auto object = std::get_if<std::shared_ptr<Object>>(&decodeValue);
308bc03f14fSopenharmony_ci    ASSERT_NE(object, nullptr);
309bc03f14fSopenharmony_ci    auto objectValue = (*object)->value_;
310bc03f14fSopenharmony_ci    auto typeValue = std::get_if<std::string>(&objectValue[UDMF::UNIFORM_DATA_TYPE]);
311bc03f14fSopenharmony_ci    ASSERT_NE(typeValue, nullptr);
312bc03f14fSopenharmony_ci    ASSERT_EQ(*typeValue, UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::SYSTEM_DEFINED_PIXEL_MAP));
313bc03f14fSopenharmony_ci    auto value = std::get_if<std::shared_ptr<PixelMap>>(&objectValue[UDMF::PIXEL_MAP]);
314bc03f14fSopenharmony_ci    ASSERT_NE(value, nullptr);
315bc03f14fSopenharmony_ci    ImageInfo imageInfo = {};
316bc03f14fSopenharmony_ci    (*value)->GetImageInfo(imageInfo);
317bc03f14fSopenharmony_ci    ASSERT_TRUE(imageInfo.size.height == 7);
318bc03f14fSopenharmony_ci    ASSERT_TRUE(imageInfo.size.width == 5);
319bc03f14fSopenharmony_ci    ASSERT_TRUE(imageInfo.pixelFormat == PixelFormat::ARGB_8888);
320bc03f14fSopenharmony_ci}
321bc03f14fSopenharmony_ci
322bc03f14fSopenharmony_civoid ConvertUtilsTest::CheckLinkUds(const std::shared_ptr<PasteDataEntry> entry)
323bc03f14fSopenharmony_ci{
324bc03f14fSopenharmony_ci    ASSERT_NE(entry, nullptr);
325bc03f14fSopenharmony_ci    ASSERT_EQ(MIMETYPE_TEXT_PLAIN, entry->GetMimeType());
326bc03f14fSopenharmony_ci    auto decodeValue = entry->GetValue();
327bc03f14fSopenharmony_ci    auto object = std::get_if<std::shared_ptr<Object>>(&decodeValue);
328bc03f14fSopenharmony_ci    ASSERT_NE(object, nullptr);
329bc03f14fSopenharmony_ci    auto objectValue = (*object)->value_;
330bc03f14fSopenharmony_ci    auto typeValue = std::get_if<std::string>(&objectValue[UDMF::UNIFORM_DATA_TYPE]);
331bc03f14fSopenharmony_ci    ASSERT_NE(typeValue, nullptr);
332bc03f14fSopenharmony_ci    ASSERT_EQ(*typeValue, UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::HYPERLINK));
333bc03f14fSopenharmony_ci    auto value = std::get_if<std::string>(&objectValue[UDMF::URL]);
334bc03f14fSopenharmony_ci    ASSERT_NE(value, nullptr);
335bc03f14fSopenharmony_ci    ASSERT_EQ(*value, link_);
336bc03f14fSopenharmony_ci}
337bc03f14fSopenharmony_ci
338bc03f14fSopenharmony_civoid ConvertUtilsTest::CheckCustomEntry(const std::shared_ptr<PasteDataEntry> entry)
339bc03f14fSopenharmony_ci{
340bc03f14fSopenharmony_ci    ASSERT_NE(entry, nullptr);
341bc03f14fSopenharmony_ci    ASSERT_EQ(entry->GetUtdId(), entry->GetMimeType());
342bc03f14fSopenharmony_ci    auto decodeValue = entry->GetValue();
343bc03f14fSopenharmony_ci    auto object = std::get_if<std::vector<uint8_t>>(&decodeValue);
344bc03f14fSopenharmony_ci    ASSERT_NE(object, nullptr);
345bc03f14fSopenharmony_ci    if (entry->GetUtdId() == appUtdId1_) {
346bc03f14fSopenharmony_ci        ASSERT_EQ(*object, rawData1_);
347bc03f14fSopenharmony_ci    } else {
348bc03f14fSopenharmony_ci        ASSERT_EQ(*object, rawData2_);
349bc03f14fSopenharmony_ci    }
350bc03f14fSopenharmony_ci}
351bc03f14fSopenharmony_ci
352bc03f14fSopenharmony_ci/**
353bc03f14fSopenharmony_ci* @tc.name: PlainEntryTest001
354bc03f14fSopenharmony_ci* @tc.desc:
355bc03f14fSopenharmony_ci* @tc.type: FUNC
356bc03f14fSopenharmony_ci* @tc.require:
357bc03f14fSopenharmony_ci* @tc.author:tarowang
358bc03f14fSopenharmony_ci*/
359bc03f14fSopenharmony_ciHWTEST_F(ConvertUtilsTest, PlainEntryTest001, TestSize.Level0)
360bc03f14fSopenharmony_ci{
361bc03f14fSopenharmony_ci    UDMF::UnifiedData data;
362bc03f14fSopenharmony_ci    InitDataWithPlainEntry(data);
363bc03f14fSopenharmony_ci    auto entriesSize = data.GetRecordAt(0)->GetEntries()->size();
364bc03f14fSopenharmony_ci    auto pasteData = ConvertUtils::Convert(data);
365bc03f14fSopenharmony_ci    auto decodePasteData = TlvData(pasteData);
366bc03f14fSopenharmony_ci    ASSERT_EQ(1, decodePasteData.GetRecordCount());
367bc03f14fSopenharmony_ci    auto record = decodePasteData.GetRecordAt(0);
368bc03f14fSopenharmony_ci    auto type = record->GetMimeType();
369bc03f14fSopenharmony_ci    ASSERT_EQ(type, MIMETYPE_TEXT_PLAIN);
370bc03f14fSopenharmony_ci    auto udType = record->GetUDType();
371bc03f14fSopenharmony_ci    ASSERT_EQ(udType, UDMF::UDType::PLAIN_TEXT);
372bc03f14fSopenharmony_ci    auto plain = record->GetPlainText();
373bc03f14fSopenharmony_ci    ASSERT_EQ(*plain, text_);
374bc03f14fSopenharmony_ci    auto entries = record->GetEntries();
375bc03f14fSopenharmony_ci    ASSERT_EQ(entries.size(), entriesSize);
376bc03f14fSopenharmony_ci    CheckEntries(entries);
377bc03f14fSopenharmony_ci}
378bc03f14fSopenharmony_ci
379bc03f14fSopenharmony_ci/**
380bc03f14fSopenharmony_ci* @tc.name: HtmlEntryTest001
381bc03f14fSopenharmony_ci* @tc.desc:
382bc03f14fSopenharmony_ci* @tc.type: FUNC
383bc03f14fSopenharmony_ci* @tc.require:
384bc03f14fSopenharmony_ci* @tc.author:tarowang
385bc03f14fSopenharmony_ci*/
386bc03f14fSopenharmony_ciHWTEST_F(ConvertUtilsTest, HtmlEntryTest001, TestSize.Level0)
387bc03f14fSopenharmony_ci{
388bc03f14fSopenharmony_ci    UDMF::UnifiedData data;
389bc03f14fSopenharmony_ci    InitDataWithHtmlEntry(data);
390bc03f14fSopenharmony_ci    auto entriesSize = data.GetRecordAt(0)->GetEntries()->size();
391bc03f14fSopenharmony_ci    auto pasteData = ConvertUtils::Convert(data);
392bc03f14fSopenharmony_ci    auto decodePasteData = TlvData(pasteData);
393bc03f14fSopenharmony_ci    ASSERT_EQ(1, decodePasteData.GetRecordCount());
394bc03f14fSopenharmony_ci    auto record = decodePasteData.GetRecordAt(0);
395bc03f14fSopenharmony_ci    auto type = record->GetMimeType();
396bc03f14fSopenharmony_ci    ASSERT_EQ(type, MIMETYPE_TEXT_HTML);
397bc03f14fSopenharmony_ci    auto udType = record->GetUDType();
398bc03f14fSopenharmony_ci    ASSERT_EQ(udType, UDMF::UDType::HTML);
399bc03f14fSopenharmony_ci    auto plain = record->GetHtmlText();
400bc03f14fSopenharmony_ci    ASSERT_EQ(*plain, html_);
401bc03f14fSopenharmony_ci    auto entries = record->GetEntries();
402bc03f14fSopenharmony_ci    ASSERT_EQ(entries.size(), entriesSize);
403bc03f14fSopenharmony_ci    CheckEntries(entries);
404bc03f14fSopenharmony_ci}
405bc03f14fSopenharmony_ci
406bc03f14fSopenharmony_ci/**
407bc03f14fSopenharmony_ci* @tc.name: PixelMapEntryTest001
408bc03f14fSopenharmony_ci* @tc.desc:
409bc03f14fSopenharmony_ci* @tc.type: FUNC
410bc03f14fSopenharmony_ci* @tc.require:
411bc03f14fSopenharmony_ci* @tc.author:tarowang
412bc03f14fSopenharmony_ci*/
413bc03f14fSopenharmony_ciHWTEST_F(ConvertUtilsTest, PixelMapEntryTest001, TestSize.Level0)
414bc03f14fSopenharmony_ci{
415bc03f14fSopenharmony_ci    UDMF::UnifiedData data;
416bc03f14fSopenharmony_ci    InitDataWithPixelMapEntry(data);
417bc03f14fSopenharmony_ci    auto entriesSize = data.GetRecordAt(0)->GetEntries()->size();
418bc03f14fSopenharmony_ci    auto pasteData = ConvertUtils::Convert(data);
419bc03f14fSopenharmony_ci    auto decodePasteData = TlvData(pasteData);
420bc03f14fSopenharmony_ci    ASSERT_EQ(1, decodePasteData.GetRecordCount());
421bc03f14fSopenharmony_ci    auto record = decodePasteData.GetRecordAt(0);
422bc03f14fSopenharmony_ci    auto type = record->GetMimeType();
423bc03f14fSopenharmony_ci    ASSERT_EQ(type, MIMETYPE_PIXELMAP);
424bc03f14fSopenharmony_ci    auto udType = record->GetUDType();
425bc03f14fSopenharmony_ci    ASSERT_EQ(udType, UDMF::UDType::SYSTEM_DEFINED_PIXEL_MAP);
426bc03f14fSopenharmony_ci    auto pixelMap = record->GetPixelMap();
427bc03f14fSopenharmony_ci    ASSERT_NE(pixelMap, nullptr);
428bc03f14fSopenharmony_ci    ImageInfo imageInfo = {};
429bc03f14fSopenharmony_ci    pixelMap->GetImageInfo(imageInfo);
430bc03f14fSopenharmony_ci    ASSERT_TRUE(imageInfo.size.height == 7);
431bc03f14fSopenharmony_ci    ASSERT_TRUE(imageInfo.size.width == 5);
432bc03f14fSopenharmony_ci    ASSERT_TRUE(imageInfo.pixelFormat == PixelFormat::ARGB_8888);
433bc03f14fSopenharmony_ci    auto entries = record->GetEntries();
434bc03f14fSopenharmony_ci    ASSERT_EQ(entries.size(), entriesSize);
435bc03f14fSopenharmony_ci    CheckEntries(entries);
436bc03f14fSopenharmony_ci}
437bc03f14fSopenharmony_ci
438bc03f14fSopenharmony_ci/**
439bc03f14fSopenharmony_ci* @tc.name: EntriesTest001
440bc03f14fSopenharmony_ci* @tc.desc:
441bc03f14fSopenharmony_ci* @tc.type: FUNC
442bc03f14fSopenharmony_ci* @tc.require:
443bc03f14fSopenharmony_ci* @tc.author:tarowang
444bc03f14fSopenharmony_ci*/
445bc03f14fSopenharmony_ciHWTEST_F(ConvertUtilsTest, EntriesTest001, TestSize.Level0)
446bc03f14fSopenharmony_ci{
447bc03f14fSopenharmony_ci    UDMF::UnifiedData data;
448bc03f14fSopenharmony_ci    InitDataWithEntries(data);
449bc03f14fSopenharmony_ci    auto entriesSize = data.GetRecordAt(0)->GetEntries()->size();
450bc03f14fSopenharmony_ci    auto pasteData = ConvertUtils::Convert(data);
451bc03f14fSopenharmony_ci    auto decodePasteData = TlvData(pasteData);
452bc03f14fSopenharmony_ci    ASSERT_EQ(1, decodePasteData.GetRecordCount());
453bc03f14fSopenharmony_ci    auto record = decodePasteData.GetRecordAt(0);
454bc03f14fSopenharmony_ci    auto type = record->GetMimeType();
455bc03f14fSopenharmony_ci    ASSERT_EQ(type, MIMETYPE_TEXT_PLAIN);
456bc03f14fSopenharmony_ci    auto udType = record->GetUDType();
457bc03f14fSopenharmony_ci    ASSERT_EQ(udType, UDMF::UDType::PLAIN_TEXT);
458bc03f14fSopenharmony_ci    auto plain = record->GetPlainText();
459bc03f14fSopenharmony_ci    ASSERT_NE(plain, nullptr);
460bc03f14fSopenharmony_ci    ASSERT_EQ(*plain, text_);
461bc03f14fSopenharmony_ci
462bc03f14fSopenharmony_ci    auto entries = record->GetEntries();
463bc03f14fSopenharmony_ci    ASSERT_EQ(entries.size(), entriesSize);
464bc03f14fSopenharmony_ci    CheckEntries(entries);
465bc03f14fSopenharmony_ci}
466bc03f14fSopenharmony_ci
467bc03f14fSopenharmony_ci/**
468bc03f14fSopenharmony_ci* @tc.name: SameTypeEntryTest001
469bc03f14fSopenharmony_ci* @tc.desc:
470bc03f14fSopenharmony_ci* @tc.type: FUNC
471bc03f14fSopenharmony_ci* @tc.require:
472bc03f14fSopenharmony_ci* @tc.author:tarowang
473bc03f14fSopenharmony_ci*/
474bc03f14fSopenharmony_ciHWTEST_F(ConvertUtilsTest, SameTypeEntryTest001, TestSize.Level0)
475bc03f14fSopenharmony_ci{
476bc03f14fSopenharmony_ci    UDMF::UnifiedData data;
477bc03f14fSopenharmony_ci    InitDataWitSameCustomEntry(data);
478bc03f14fSopenharmony_ci    auto pasteData = ConvertUtils::Convert(data);
479bc03f14fSopenharmony_ci    auto decodePasteData = TlvData(pasteData);
480bc03f14fSopenharmony_ci    ASSERT_EQ(1, decodePasteData.GetRecordCount());
481bc03f14fSopenharmony_ci    auto record = decodePasteData.GetRecordAt(0);
482bc03f14fSopenharmony_ci    auto type = record->GetMimeType();
483bc03f14fSopenharmony_ci    ASSERT_EQ(type, appUtdId1_);
484bc03f14fSopenharmony_ci    auto udType = record->GetUDType();
485bc03f14fSopenharmony_ci    ASSERT_EQ(udType, UDMF::UDType::APPLICATION_DEFINED_RECORD);
486bc03f14fSopenharmony_ci    auto customData = record->GetCustomData();
487bc03f14fSopenharmony_ci    ASSERT_NE(customData, nullptr);
488bc03f14fSopenharmony_ci    auto rawData = customData->GetItemData();
489bc03f14fSopenharmony_ci    ASSERT_EQ(rawData.size(), 1);
490bc03f14fSopenharmony_ci    ASSERT_EQ(rawData[appUtdId1_], rawData2_);
491bc03f14fSopenharmony_ci}
492bc03f14fSopenharmony_ci} // namespace OHOS::MiscServices