1bc03f14fSopenharmony_ci/*
2bc03f14fSopenharmony_ci * Copyright (c) 2023-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
16bc03f14fSopenharmony_ci#include <gtest/gtest.h>
17bc03f14fSopenharmony_ci
18bc03f14fSopenharmony_ci#include "pasteboard_client.h"
19bc03f14fSopenharmony_ci#include "unistd.h"
20bc03f14fSopenharmony_ci
21bc03f14fSopenharmony_cinamespace OHOS::MiscServices {
22bc03f14fSopenharmony_ciusing namespace testing::ext;
23bc03f14fSopenharmony_ciusing namespace testing;
24bc03f14fSopenharmony_ciusing namespace OHOS::Media;
25bc03f14fSopenharmony_ciconstexpr const uid_t EDM_UID = 3057;
26bc03f14fSopenharmony_ciusing Patterns = std::set<Pattern>;
27bc03f14fSopenharmony_ciclass PasteboardClientTest : public testing::Test {
28bc03f14fSopenharmony_cipublic:
29bc03f14fSopenharmony_ci    static void SetUpTestCase(void);
30bc03f14fSopenharmony_ci    static void TearDownTestCase(void);
31bc03f14fSopenharmony_ci    void SetUp() override;
32bc03f14fSopenharmony_ci    void TearDown() override;
33bc03f14fSopenharmony_ci};
34bc03f14fSopenharmony_ci
35bc03f14fSopenharmony_civoid PasteboardClientTest::SetUpTestCase(void)
36bc03f14fSopenharmony_ci{
37bc03f14fSopenharmony_ci    setuid(EDM_UID);
38bc03f14fSopenharmony_ci}
39bc03f14fSopenharmony_ci
40bc03f14fSopenharmony_civoid PasteboardClientTest::TearDownTestCase(void)
41bc03f14fSopenharmony_ci{
42bc03f14fSopenharmony_ci    setuid(0);
43bc03f14fSopenharmony_ci}
44bc03f14fSopenharmony_ci
45bc03f14fSopenharmony_civoid PasteboardClientTest::SetUp(void) {}
46bc03f14fSopenharmony_ci
47bc03f14fSopenharmony_civoid PasteboardClientTest::TearDown(void) {}
48bc03f14fSopenharmony_ci
49bc03f14fSopenharmony_ci/**
50bc03f14fSopenharmony_ci* @tc.name: IsRemoteData001
51bc03f14fSopenharmony_ci* @tc.desc: pasteData is local data.
52bc03f14fSopenharmony_ci* @tc.type: FUNC
53bc03f14fSopenharmony_ci* @tc.require:
54bc03f14fSopenharmony_ci* @tc.author:
55bc03f14fSopenharmony_ci*/
56bc03f14fSopenharmony_ciHWTEST_F(PasteboardClientTest, IsRemoteData001, TestSize.Level0)
57bc03f14fSopenharmony_ci{
58bc03f14fSopenharmony_ci    std::string plainText = "plain text";
59bc03f14fSopenharmony_ci    auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
60bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetPasteData(*pasteData);
61bc03f14fSopenharmony_ci    bool ret = PasteboardClient::GetInstance()->IsRemoteData();
62bc03f14fSopenharmony_ci    ASSERT_FALSE(ret);
63bc03f14fSopenharmony_ci}
64bc03f14fSopenharmony_ci
65bc03f14fSopenharmony_ci/**
66bc03f14fSopenharmony_ci* @tc.name: IsRemoteData002
67bc03f14fSopenharmony_ci* @tc.desc: pasteData is remote data.
68bc03f14fSopenharmony_ci* @tc.type: FUNC
69bc03f14fSopenharmony_ci* @tc.require:
70bc03f14fSopenharmony_ci* @tc.author:
71bc03f14fSopenharmony_ci*/
72bc03f14fSopenharmony_ciHWTEST_F(PasteboardClientTest, IsRemoteData002, TestSize.Level0)
73bc03f14fSopenharmony_ci{
74bc03f14fSopenharmony_ci    std::string plainText = "plain text";
75bc03f14fSopenharmony_ci    auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
76bc03f14fSopenharmony_ci    pasteData->SetRemote(true);
77bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetPasteData(*pasteData);
78bc03f14fSopenharmony_ci    bool ret = PasteboardClient::GetInstance()->IsRemoteData();
79bc03f14fSopenharmony_ci    ASSERT_TRUE(ret);
80bc03f14fSopenharmony_ci}
81bc03f14fSopenharmony_ci
82bc03f14fSopenharmony_ci/**
83bc03f14fSopenharmony_ci* @tc.name: HasDataType001
84bc03f14fSopenharmony_ci* @tc.desc: data type is MIMETYPE_TEXT_PLAIN.
85bc03f14fSopenharmony_ci* @tc.type: FUNC
86bc03f14fSopenharmony_ci* @tc.require:
87bc03f14fSopenharmony_ci* @tc.author:
88bc03f14fSopenharmony_ci*/
89bc03f14fSopenharmony_ciHWTEST_F(PasteboardClientTest, HasDataType001, TestSize.Level0)
90bc03f14fSopenharmony_ci{
91bc03f14fSopenharmony_ci    std::string plainText = "helloWorld";
92bc03f14fSopenharmony_ci    auto newData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
93bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetPasteData(*newData);
94bc03f14fSopenharmony_ci    auto ret = PasteboardClient::GetInstance()->HasDataType(MIMETYPE_TEXT_PLAIN);
95bc03f14fSopenharmony_ci    ASSERT_TRUE(ret);
96bc03f14fSopenharmony_ci    auto result = PasteboardClient::GetInstance()->HasDataType(MIMETYPE_TEXT_URI);
97bc03f14fSopenharmony_ci    ASSERT_FALSE(result);
98bc03f14fSopenharmony_ci}
99bc03f14fSopenharmony_ci
100bc03f14fSopenharmony_ci/**
101bc03f14fSopenharmony_ci* @tc.name: HasDataType002
102bc03f14fSopenharmony_ci* @tc.desc: data type is MIMETYPE_TEXT_HTML.
103bc03f14fSopenharmony_ci* @tc.type: FUNC
104bc03f14fSopenharmony_ci* @tc.require:
105bc03f14fSopenharmony_ci* @tc.author:
106bc03f14fSopenharmony_ci*/
107bc03f14fSopenharmony_ciHWTEST_F(PasteboardClientTest, HasDataType002, TestSize.Level0)
108bc03f14fSopenharmony_ci{
109bc03f14fSopenharmony_ci    std::string htmlText = "<div class='disable'>helloWorld</div>";
110bc03f14fSopenharmony_ci    auto newPasteData = PasteboardClient::GetInstance()->CreateHtmlData(htmlText);
111bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetPasteData(*newPasteData);
112bc03f14fSopenharmony_ci    auto ret = PasteboardClient::GetInstance()->HasDataType(MIMETYPE_TEXT_HTML);
113bc03f14fSopenharmony_ci    ASSERT_TRUE(ret);
114bc03f14fSopenharmony_ci    auto result = PasteboardClient::GetInstance()->HasDataType(MIMETYPE_TEXT_PLAIN);
115bc03f14fSopenharmony_ci    ASSERT_FALSE(result);
116bc03f14fSopenharmony_ci}
117bc03f14fSopenharmony_ci
118bc03f14fSopenharmony_ci/**
119bc03f14fSopenharmony_ci* @tc.name: HasDataType003
120bc03f14fSopenharmony_ci* @tc.desc: data type is MIMETYPE_TEXT_URI
121bc03f14fSopenharmony_ci* @tc.type: FUNC
122bc03f14fSopenharmony_ci* @tc.require:
123bc03f14fSopenharmony_ci* @tc.author:
124bc03f14fSopenharmony_ci*/
125bc03f14fSopenharmony_ciHWTEST_F(PasteboardClientTest, HasDataType003, TestSize.Level0)
126bc03f14fSopenharmony_ci{
127bc03f14fSopenharmony_ci    OHOS::Uri uri("uri");
128bc03f14fSopenharmony_ci    auto newPasteData = PasteboardClient::GetInstance()->CreateUriData(uri);
129bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetPasteData(*newPasteData);
130bc03f14fSopenharmony_ci    auto ret = PasteboardClient::GetInstance()->HasDataType(MIMETYPE_TEXT_URI);
131bc03f14fSopenharmony_ci    ASSERT_TRUE(ret);
132bc03f14fSopenharmony_ci    auto result = PasteboardClient::GetInstance()->HasDataType(MIMETYPE_TEXT_PLAIN);
133bc03f14fSopenharmony_ci    ASSERT_FALSE(result);
134bc03f14fSopenharmony_ci}
135bc03f14fSopenharmony_ci
136bc03f14fSopenharmony_ci/**
137bc03f14fSopenharmony_ci* @tc.name: HasDataType004
138bc03f14fSopenharmony_ci* @tc.desc: data type is MIMETYPE_PIXELMAP
139bc03f14fSopenharmony_ci* @tc.type: FUNC
140bc03f14fSopenharmony_ci* @tc.require:
141bc03f14fSopenharmony_ci* @tc.author:
142bc03f14fSopenharmony_ci*/
143bc03f14fSopenharmony_ciHWTEST_F(PasteboardClientTest, HasDataType004, TestSize.Level0)
144bc03f14fSopenharmony_ci{
145bc03f14fSopenharmony_ci    uint32_t color[100] = { 3, 7, 9, 9, 7, 6 };
146bc03f14fSopenharmony_ci    InitializationOptions opts = { { 5, 7 }, 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    auto newPasteData = PasteboardClient::GetInstance()->CreatePixelMapData(pixelMapIn);
150bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetPasteData(*newPasteData);
151bc03f14fSopenharmony_ci    auto ret = PasteboardClient::GetInstance()->HasDataType(MIMETYPE_PIXELMAP);
152bc03f14fSopenharmony_ci    ASSERT_TRUE(ret);
153bc03f14fSopenharmony_ci    auto result = PasteboardClient::GetInstance()->HasDataType(MIMETYPE_TEXT_URI);
154bc03f14fSopenharmony_ci    ASSERT_FALSE(result);
155bc03f14fSopenharmony_ci}
156bc03f14fSopenharmony_ci
157bc03f14fSopenharmony_ci/**
158bc03f14fSopenharmony_ci* @tc.name: GetDataSource001
159bc03f14fSopenharmony_ci* @tc.desc: Get the source of the data.
160bc03f14fSopenharmony_ci* @tc.type: FUNC
161bc03f14fSopenharmony_ci* @tc.require:
162bc03f14fSopenharmony_ci* @tc.author:
163bc03f14fSopenharmony_ci*/
164bc03f14fSopenharmony_ciHWTEST_F(PasteboardClientTest, GetDataSource001, TestSize.Level0)
165bc03f14fSopenharmony_ci{
166bc03f14fSopenharmony_ci    std::string plainText = "helloWorld";
167bc03f14fSopenharmony_ci    auto newData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
168bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetPasteData(*newData);
169bc03f14fSopenharmony_ci    std::string bundleName;
170bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->GetDataSource(bundleName);
171bc03f14fSopenharmony_ci    EXPECT_FALSE(bundleName.empty());
172bc03f14fSopenharmony_ci}
173bc03f14fSopenharmony_ci
174bc03f14fSopenharmony_ci/**
175bc03f14fSopenharmony_ci* @tc.name: SetGlobalShareOption
176bc03f14fSopenharmony_ci* @tc.desc: Set global shareOption
177bc03f14fSopenharmony_ci* @tc.type: FUNC
178bc03f14fSopenharmony_ci* @tc.require:
179bc03f14fSopenharmony_ci* @tc.author:
180bc03f14fSopenharmony_ci*/
181bc03f14fSopenharmony_ciHWTEST_F(PasteboardClientTest, SetGlobalShareOption, TestSize.Level0)
182bc03f14fSopenharmony_ci{
183bc03f14fSopenharmony_ci    std::map<uint32_t, ShareOption> settings = { { 100, ShareOption::InApp }, { 200, ShareOption::LocalDevice },
184bc03f14fSopenharmony_ci        { 300, ShareOption::CrossDevice } };
185bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetGlobalShareOption(settings);
186bc03f14fSopenharmony_ci    auto result = PasteboardClient::GetInstance()->GetGlobalShareOption({});
187bc03f14fSopenharmony_ci    EXPECT_TRUE(result.size() == 3);
188bc03f14fSopenharmony_ci    EXPECT_EQ(result[100], ShareOption::InApp);
189bc03f14fSopenharmony_ci    EXPECT_EQ(result[200], ShareOption::LocalDevice);
190bc03f14fSopenharmony_ci    EXPECT_EQ(result[300], ShareOption::CrossDevice);
191bc03f14fSopenharmony_ci    std::map<uint32_t, ShareOption> modify = { { 100, ShareOption::CrossDevice }, { 400, ShareOption::InApp } };
192bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetGlobalShareOption(modify);
193bc03f14fSopenharmony_ci    result = PasteboardClient::GetInstance()->GetGlobalShareOption({});
194bc03f14fSopenharmony_ci    EXPECT_TRUE(result.size() == 4);
195bc03f14fSopenharmony_ci    EXPECT_EQ(result[100], ShareOption::CrossDevice);
196bc03f14fSopenharmony_ci    EXPECT_EQ(result[400], ShareOption::InApp);
197bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->RemoveGlobalShareOption({ 100, 200, 300, 400 });
198bc03f14fSopenharmony_ci}
199bc03f14fSopenharmony_ci
200bc03f14fSopenharmony_ci/**
201bc03f14fSopenharmony_ci* @tc.name: GetGlobalShareOption
202bc03f14fSopenharmony_ci* @tc.desc: Get global shareOption
203bc03f14fSopenharmony_ci* @tc.type: FUNC
204bc03f14fSopenharmony_ci* @tc.require:
205bc03f14fSopenharmony_ci* @tc.author:
206bc03f14fSopenharmony_ci*/
207bc03f14fSopenharmony_ciHWTEST_F(PasteboardClientTest, GetGlobalShareOption, TestSize.Level0)
208bc03f14fSopenharmony_ci{
209bc03f14fSopenharmony_ci    std::map<uint32_t, ShareOption> settings = { { 100, ShareOption::InApp }, { 200, ShareOption::LocalDevice },
210bc03f14fSopenharmony_ci        { 300, ShareOption::CrossDevice } };
211bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetGlobalShareOption(settings);
212bc03f14fSopenharmony_ci    auto result = PasteboardClient::GetInstance()->GetGlobalShareOption({});
213bc03f14fSopenharmony_ci    EXPECT_TRUE(result.size() == 3);
214bc03f14fSopenharmony_ci    EXPECT_EQ(result[100], ShareOption::InApp);
215bc03f14fSopenharmony_ci    EXPECT_EQ(result[200], ShareOption::LocalDevice);
216bc03f14fSopenharmony_ci    EXPECT_EQ(result[300], ShareOption::CrossDevice);
217bc03f14fSopenharmony_ci    result = PasteboardClient::GetInstance()->GetGlobalShareOption({ 100, 400 });
218bc03f14fSopenharmony_ci    EXPECT_TRUE(result.size() == 1);
219bc03f14fSopenharmony_ci    EXPECT_EQ(result[100], ShareOption::InApp);
220bc03f14fSopenharmony_ci    EXPECT_TRUE(result.find(400) == result.end());
221bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->RemoveGlobalShareOption({ 100, 200, 300 });
222bc03f14fSopenharmony_ci}
223bc03f14fSopenharmony_ci
224bc03f14fSopenharmony_ci/**
225bc03f14fSopenharmony_ci* @tc.name: RemoveGlobalShareOption
226bc03f14fSopenharmony_ci* @tc.desc: Remove global shareOption
227bc03f14fSopenharmony_ci* @tc.type: FUNC
228bc03f14fSopenharmony_ci* @tc.require:
229bc03f14fSopenharmony_ci* @tc.author:
230bc03f14fSopenharmony_ci*/
231bc03f14fSopenharmony_ciHWTEST_F(PasteboardClientTest, RemoveGlobalShareOption, TestSize.Level0)
232bc03f14fSopenharmony_ci{
233bc03f14fSopenharmony_ci    std::map<uint32_t, ShareOption> settings = { { 100, ShareOption::InApp }, { 200, ShareOption::LocalDevice },
234bc03f14fSopenharmony_ci        { 300, ShareOption::CrossDevice } };
235bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetGlobalShareOption(settings);
236bc03f14fSopenharmony_ci    auto result = PasteboardClient::GetInstance()->GetGlobalShareOption({});
237bc03f14fSopenharmony_ci    EXPECT_TRUE(result.size() == 3);
238bc03f14fSopenharmony_ci    EXPECT_EQ(result[100], ShareOption::InApp);
239bc03f14fSopenharmony_ci    EXPECT_EQ(result[200], ShareOption::LocalDevice);
240bc03f14fSopenharmony_ci    EXPECT_EQ(result[300], ShareOption::CrossDevice);
241bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->RemoveGlobalShareOption({});
242bc03f14fSopenharmony_ci    result = PasteboardClient::GetInstance()->GetGlobalShareOption({});
243bc03f14fSopenharmony_ci    EXPECT_TRUE(result.size() == 3);
244bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->RemoveGlobalShareOption({ 100, 400 });
245bc03f14fSopenharmony_ci    result = PasteboardClient::GetInstance()->GetGlobalShareOption({});
246bc03f14fSopenharmony_ci    EXPECT_TRUE(result.size() == 2);
247bc03f14fSopenharmony_ci    EXPECT_TRUE(result.find(100) == result.end());
248bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->RemoveGlobalShareOption({ 200, 300 });
249bc03f14fSopenharmony_ci}
250bc03f14fSopenharmony_ci
251bc03f14fSopenharmony_ci/**
252bc03f14fSopenharmony_ci* @tc.name: DetectPatterns001
253bc03f14fSopenharmony_ci* @tc.desc: Cover Permutation
254bc03f14fSopenharmony_ci* @tc.type: FUNC
255bc03f14fSopenharmony_ci* @tc.require:
256bc03f14fSopenharmony_ci* @tc.author:
257bc03f14fSopenharmony_ci*/
258bc03f14fSopenharmony_ciHWTEST_F(PasteboardClientTest, DetectPatterns001, TestSize.Level0)
259bc03f14fSopenharmony_ci{
260bc03f14fSopenharmony_ci    std::string plainText("r法塔赫已经,速tdghf!】qd rqdswww.comsski,.sjopwe"
261bc03f14fSopenharmony_ci                          "ihhtpsdhttp我也带过去给他№のjioijhhu");
262bc03f14fSopenharmony_ci    std::string plainText0("https://giedqwrtheeeeeefub.cerm/meeeelkove/obaklo_tjokl"
263bc03f14fSopenharmony_ci                           "psetkjdttk/bkkjob/mwjweww.md)");
264bc03f14fSopenharmony_ci    std::string plainText1("2我就破888芙蓉王82h7");
265bc03f14fSopenharmony_ci    std::string plainText2("uhiyqydueuw@kahqw.oisko.sji");
266bc03f14fSopenharmony_ci
267bc03f14fSopenharmony_ci    std::vector<std::string> plainTextVec{ plainText, plainText + plainText0, plainText + plainText1,
268bc03f14fSopenharmony_ci        plainText + plainText2, plainText + plainText0 + plainText1, plainText0 + plainText2 + plainText,
269bc03f14fSopenharmony_ci        plainText1 + plainText + plainText2, plainText0 + plainText1 + plainText + plainText2 };
270bc03f14fSopenharmony_ci    std::vector<Patterns> patternsVec{ {}, { Pattern::URL }, { Pattern::Number }, { Pattern::EmailAddress },
271bc03f14fSopenharmony_ci        { Pattern::URL, Pattern::Number }, { Pattern::URL, Pattern::EmailAddress },
272bc03f14fSopenharmony_ci        { Pattern::Number, Pattern::EmailAddress }, { Pattern::URL, Pattern::Number, Pattern::EmailAddress } };
273bc03f14fSopenharmony_ci    std::vector<std::vector<int>> patternsRightIndexVec{ { 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 1, 0, 0, 1, 1, 0, 1 },
274bc03f14fSopenharmony_ci        { 0, 0, 2, 0, 2, 0, 2, 2 }, { 0, 0, 0, 3, 0, 3, 3, 3 }, { 0, 1, 2, 0, 4, 1, 2, 4 }, { 0, 1, 0, 3, 1, 5, 3, 5 },
275bc03f14fSopenharmony_ci        { 0, 0, 2, 3, 2, 3, 6, 6 }, { 0, 1, 2, 3, 4, 5, 6, 7 } };
276bc03f14fSopenharmony_ci    for (int i = 0; i != 8; ++i) {
277bc03f14fSopenharmony_ci        for (int j = 0; j != 8; ++j) {
278bc03f14fSopenharmony_ci            auto newData = PasteboardClient::GetInstance()->CreatePlainTextData(plainTextVec[i]);
279bc03f14fSopenharmony_ci            PasteboardClient::GetInstance()->SetPasteData(*newData);
280bc03f14fSopenharmony_ci            auto ret = PasteboardClient::GetInstance()->DetectPatterns(patternsVec[j]);
281bc03f14fSopenharmony_ci            int rightIndex = patternsRightIndexVec[i][j];
282bc03f14fSopenharmony_ci            ASSERT_EQ(ret, patternsVec[rightIndex]);
283bc03f14fSopenharmony_ci        }
284bc03f14fSopenharmony_ci    }
285bc03f14fSopenharmony_ci}
286bc03f14fSopenharmony_ci
287bc03f14fSopenharmony_ci/**
288bc03f14fSopenharmony_ci* @tc.name: DetectPatterns002
289bc03f14fSopenharmony_ci* @tc.desc: check HTML
290bc03f14fSopenharmony_ci* @tc.type: FUNC
291bc03f14fSopenharmony_ci* @tc.require:
292bc03f14fSopenharmony_ci* @tc.author:
293bc03f14fSopenharmony_ci*/
294bc03f14fSopenharmony_ciHWTEST_F(PasteboardClientTest, DetectPatterns002, TestSize.Level0)
295bc03f14fSopenharmony_ci{
296bc03f14fSopenharmony_ci    std::string htmlText1 = "<!DOCTYPE html><html><head><title>"
297bc03f14fSopenharmony_ci                            "超链案头研究。,封为啊啊</title></head><body><h2>发高热</h2>"
298bc03f14fSopenharmony_ci                            "<p>隔热隔热的氛围<a href=\"https://exq23amwerwqple.com\">"
299bc03f14fSopenharmony_ci                            "个人网站https://ex24t33tamp65hhle.com</a>。</p></body></html>";
300bc03f14fSopenharmony_ci    auto newData1 = PasteboardClient::GetInstance()->CreateHtmlData(htmlText1);
301bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetPasteData(*newData1);
302bc03f14fSopenharmony_ci    Patterns patternsToCheck1{ Pattern::URL, Pattern::EmailAddress };
303bc03f14fSopenharmony_ci    auto ret1 = PasteboardClient::GetInstance()->DetectPatterns(patternsToCheck1);
304bc03f14fSopenharmony_ci    Patterns expected1{ Pattern::URL };
305bc03f14fSopenharmony_ci    ASSERT_EQ(ret1, expected1);
306bc03f14fSopenharmony_ci
307bc03f14fSopenharmony_ci    std::string htmlText2 = "<!DOCTYPE html><html><head><title>"
308bc03f14fSopenharmony_ci                            "各个环节</title></head><body><h2>妈妈那边的</h2>"
309bc03f14fSopenharmony_ci                            "<p>啊啊分,凤凰方法,环境https://examjjuyewple.com问我的<a "
310bc03f14fSopenharmony_ci                            "href=\"https://ehhgxametgeple.com\">"
311bc03f14fSopenharmony_ci                            "阿婆吗weqkqo@exaetmple.com</a>。????打法</p></body></html>";
312bc03f14fSopenharmony_ci    auto newData2 = PasteboardClient::GetInstance()->CreateHtmlData(htmlText2);
313bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetPasteData(*newData2);
314bc03f14fSopenharmony_ci    Patterns patternsToCheck2{ Pattern::URL, Pattern::EmailAddress, Pattern::Number };
315bc03f14fSopenharmony_ci    auto ret2 = PasteboardClient::GetInstance()->DetectPatterns(patternsToCheck2);
316bc03f14fSopenharmony_ci    Patterns expected2{ Pattern::URL, Pattern::EmailAddress };
317bc03f14fSopenharmony_ci    ASSERT_EQ(ret2, expected2);
318bc03f14fSopenharmony_ci}
319bc03f14fSopenharmony_ci
320bc03f14fSopenharmony_ci/**
321bc03f14fSopenharmony_ci* @tc.name: DetectPatterns003
322bc03f14fSopenharmony_ci* @tc.desc: Outlier force cast uint32_t to unsurportted Pattern
323bc03f14fSopenharmony_ci* @tc.type: FUNC
324bc03f14fSopenharmony_ci* @tc.require:
325bc03f14fSopenharmony_ci* @tc.author:
326bc03f14fSopenharmony_ci*/
327bc03f14fSopenharmony_ciHWTEST_F(PasteboardClientTest, DetectPatterns003, TestSize.Level0)
328bc03f14fSopenharmony_ci{
329bc03f14fSopenharmony_ci    std::string plainText1 = "部分人的十点半:\n"
330bc03f14fSopenharmony_ci                             "「而飞过海」\n"
331bc03f14fSopenharmony_ci                             "方法:\n"
332bc03f14fSopenharmony_ci                             "https://pr5yyye-drseyive.u54yk.cwerfe/s/42e1ewed77f3dab4"
333bc03f14fSopenharmony_ci                             "网gest加尔文iqru发的我ui哦计划任务i文化人:\n"
334bc03f14fSopenharmony_ci                             "~b0043fg3423tddj~";
335bc03f14fSopenharmony_ci    auto newData1 = PasteboardClient::GetInstance()->CreatePlainTextData(plainText1);
336bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetPasteData(*newData1);
337bc03f14fSopenharmony_ci    Patterns patternsToCheck{ Pattern::Number, Pattern::URL, Pattern::EmailAddress, static_cast<Pattern>(1023) };
338bc03f14fSopenharmony_ci    auto ret1 = PasteboardClient::GetInstance()->DetectPatterns(patternsToCheck);
339bc03f14fSopenharmony_ci    Patterns expected1{};
340bc03f14fSopenharmony_ci    ASSERT_EQ(ret1, expected1);
341bc03f14fSopenharmony_ci    std::string plainText2 = "【撒迪化,等我i却很难,无穷花的!】"
342bc03f14fSopenharmony_ci                             "额外i卡号!念佛为?,为单位打开陪我。而奋斗,我去二队去,威威:trfwrtg"
343bc03f14fSopenharmony_ci                             "(¥¥软骨素用人员为bdfdgse https://tgrthwerrwt.com/marrkerrerlorrve/ "
344bc03f14fSopenharmony_ci                             "usrdq12_22swe@16rtgre3.com)";
345bc03f14fSopenharmony_ci    auto newData2 = PasteboardClient::GetInstance()->CreatePlainTextData(plainText2);
346bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetPasteData(*newData2);
347bc03f14fSopenharmony_ci    auto ret2 = PasteboardClient::GetInstance()->DetectPatterns(patternsToCheck);
348bc03f14fSopenharmony_ci    Patterns expected2{};
349bc03f14fSopenharmony_ci    ASSERT_EQ(ret2, expected2);
350bc03f14fSopenharmony_ci    std::string plainText3 = "【撒迪化,等我i却很难,无穷花的!】"
351bc03f14fSopenharmony_ci                             "额外i卡号!念佛为?,为单位打开陪我。而奋斗,我去二队去,威威:trfwrtg";
352bc03f14fSopenharmony_ci    auto newData3 = PasteboardClient::GetInstance()->CreatePlainTextData(plainText3);
353bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetPasteData(*newData3);
354bc03f14fSopenharmony_ci    auto ret3 = PasteboardClient::GetInstance()->DetectPatterns(patternsToCheck);
355bc03f14fSopenharmony_ci    ASSERT_EQ(ret3, Patterns{});
356bc03f14fSopenharmony_ci}
357bc03f14fSopenharmony_ci
358bc03f14fSopenharmony_ci/**
359bc03f14fSopenharmony_ci* @tc.name: DetectPatterns004
360bc03f14fSopenharmony_ci* @tc.desc: Outlier force cast uint32_t 0xffffffff to unsurportted Pattern
361bc03f14fSopenharmony_ci* @tc.type: FUNC
362bc03f14fSopenharmony_ci* @tc.require:
363bc03f14fSopenharmony_ci* @tc.author:
364bc03f14fSopenharmony_ci*/
365bc03f14fSopenharmony_ciHWTEST_F(PasteboardClientTest, DetectPatterns004, TestSize.Level0)
366bc03f14fSopenharmony_ci{
367bc03f14fSopenharmony_ci    std::string plainText1 = "部分人的十点半:\n"
368bc03f14fSopenharmony_ci                             "「而飞过海」\n"
369bc03f14fSopenharmony_ci                             "方法:\n"
370bc03f14fSopenharmony_ci                             "https://pr5yyye-drseyive.u54yk.cwerfe/s/42e1ewed77f3dab4"
371bc03f14fSopenharmony_ci                             "网gest加尔文iqru发的我ui哦计划任务i文化人:\n"
372bc03f14fSopenharmony_ci                             "~b0043fg3423tddj~";
373bc03f14fSopenharmony_ci    auto newData1 = PasteboardClient::GetInstance()->CreatePlainTextData(plainText1);
374bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetPasteData(*newData1);
375bc03f14fSopenharmony_ci    std::set<Pattern> patternsToCheck{ Pattern::Number, Pattern::URL, Pattern::EmailAddress,
376bc03f14fSopenharmony_ci        static_cast<Pattern>(0xffffffff), static_cast<Pattern>(0xffffff1a) };
377bc03f14fSopenharmony_ci    auto ret1 = PasteboardClient::GetInstance()->DetectPatterns(patternsToCheck);
378bc03f14fSopenharmony_ci    std::set<Pattern> expected1{};
379bc03f14fSopenharmony_ci    ASSERT_EQ(ret1, expected1);
380bc03f14fSopenharmony_ci    std::string plainText2 = "【撒迪化,等我i却很难,无穷花的!】"
381bc03f14fSopenharmony_ci                             "额外i卡号!念佛为?,为单位打开陪我。而奋斗,我去二队去,威威:trfwrtg"
382bc03f14fSopenharmony_ci                             "(¥¥软骨素用人员为bdfdgse https://tgrthwerrwt.com/marrkerrerlorrve/ "
383bc03f14fSopenharmony_ci                             "usrdq12_22swe@16rtgre3.com)";
384bc03f14fSopenharmony_ci    auto newData2 = PasteboardClient::GetInstance()->CreatePlainTextData(plainText2);
385bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetPasteData(*newData2);
386bc03f14fSopenharmony_ci    auto ret2 = PasteboardClient::GetInstance()->DetectPatterns(patternsToCheck);
387bc03f14fSopenharmony_ci    std::set<Pattern> expected2{};
388bc03f14fSopenharmony_ci    ASSERT_EQ(ret2, expected2);
389bc03f14fSopenharmony_ci    std::string plainText3 = "【撒迪化,等我i却很难,无穷花的!】"
390bc03f14fSopenharmony_ci                             "额外i卡号!念佛为?,为单位打开陪我。而奋斗,我去二队去,威威:trfwrtg";
391bc03f14fSopenharmony_ci    auto newData3 = PasteboardClient::GetInstance()->CreatePlainTextData(plainText3);
392bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetPasteData(*newData3);
393bc03f14fSopenharmony_ci    auto ret3 = PasteboardClient::GetInstance()->DetectPatterns(patternsToCheck);
394bc03f14fSopenharmony_ci    ASSERT_EQ(ret3, std::set<Pattern>{});
395bc03f14fSopenharmony_ci}
396bc03f14fSopenharmony_ci
397bc03f14fSopenharmony_ci} // namespace OHOS::MiscServices