• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "pasteboard_client.h"
17 #include <gtest/gtest.h>
18 
19 namespace OHOS::MiscServices {
20 using namespace testing::ext;
21 using namespace testing;
22 using namespace OHOS::Media;
23 class PasteboardClientTest : public testing::Test {
24 public:
25     static void SetUpTestCase(void);
26     static void TearDownTestCase(void);
27     void SetUp();
28     void TearDown();
29 };
30 
SetUpTestCase(void)31 void PasteboardClientTest::SetUpTestCase(void)
32 {
33 }
34 
TearDownTestCase(void)35 void PasteboardClientTest::TearDownTestCase(void)
36 {
37 }
38 
SetUp(void)39 void PasteboardClientTest::SetUp(void)
40 {
41 }
42 
TearDown(void)43 void PasteboardClientTest::TearDown(void)
44 {
45 }
46 
47 /**
48 * @tc.name: IsRemoteData001
49 * @tc.desc: pasteData is local data.
50 * @tc.type: FUNC
51 * @tc.require:
52 * @tc.author:
53 */
54 HWTEST_F(PasteboardClientTest, IsRemoteData001, TestSize.Level0)
55 {
56     std::string plainText = "plain text";
57     auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
58     PasteboardClient::GetInstance()->SetPasteData(*pasteData);
59     bool ret = PasteboardClient::GetInstance()->IsRemoteData();
60     ASSERT_FALSE(ret);
61 }
62 
63 /**
64 * @tc.name: IsRemoteData002
65 * @tc.desc: pasteData is remote data.
66 * @tc.type: FUNC
67 * @tc.require:
68 * @tc.author:
69 */
70 HWTEST_F(PasteboardClientTest, IsRemoteData002, TestSize.Level0)
71 {
72     std::string plainText = "plain text";
73     auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
74     pasteData->SetRemote(true);
75     PasteboardClient::GetInstance()->SetPasteData(*pasteData);
76     bool ret = PasteboardClient::GetInstance()->IsRemoteData();
77     ASSERT_TRUE(ret);
78 }
79 
80 /**
81 * @tc.name: HasDataType001
82 * @tc.desc: data type is MIMETYPE_TEXT_PLAIN.
83 * @tc.type: FUNC
84 * @tc.require:
85 * @tc.author:
86 */
87 HWTEST_F(PasteboardClientTest, HasDataType001, TestSize.Level0)
88 {
89     std::string plainText = "helloWorld";
90     auto newData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
91     PasteboardClient::GetInstance()->SetPasteData(*newData);
92     auto ret = PasteboardClient::GetInstance()->HasDataType(MIMETYPE_TEXT_PLAIN);
93     ASSERT_TRUE(ret);
94     auto result = PasteboardClient::GetInstance()->HasDataType(MIMETYPE_TEXT_URI);
95     ASSERT_FALSE(result);
96 }
97 
98 /**
99 * @tc.name: HasDataType002
100 * @tc.desc: data type is MIMETYPE_TEXT_HTML.
101 * @tc.type: FUNC
102 * @tc.require:
103 * @tc.author:
104 */
105 HWTEST_F(PasteboardClientTest, HasDataType002, TestSize.Level0)
106 {
107     std::string htmlText = "<div class='disable'>helloWorld</div>";
108     auto newPasteData = PasteboardClient::GetInstance()->CreateHtmlData(htmlText);
109     PasteboardClient::GetInstance()->SetPasteData(*newPasteData);
110     auto ret = PasteboardClient::GetInstance()->HasDataType(MIMETYPE_TEXT_HTML);
111     ASSERT_TRUE(ret);
112     auto result = PasteboardClient::GetInstance()->HasDataType(MIMETYPE_TEXT_PLAIN);
113     ASSERT_FALSE(result);
114 }
115 
116 /**
117 * @tc.name: HasDataType003
118 * @tc.desc: data type is MIMETYPE_TEXT_URI
119 * @tc.type: FUNC
120 * @tc.require:
121 * @tc.author:
122 */
123 HWTEST_F(PasteboardClientTest, HasDataType003, TestSize.Level0)
124 {
125     OHOS::Uri uri("uri");
126     auto newPasteData = PasteboardClient::GetInstance()->CreateUriData(uri);
127     PasteboardClient::GetInstance()->SetPasteData(*newPasteData);
128     auto ret = PasteboardClient::GetInstance()->HasDataType(MIMETYPE_TEXT_URI);
129     ASSERT_TRUE(ret);
130     auto result = PasteboardClient::GetInstance()->HasDataType(MIMETYPE_TEXT_PLAIN);
131     ASSERT_FALSE(result);
132 }
133 
134 /**
135 * @tc.name: HasDataType004
136 * @tc.desc: data type is MIMETYPE_PIXELMAP
137 * @tc.type: FUNC
138 * @tc.require:
139 * @tc.author:
140 */
141 HWTEST_F(PasteboardClientTest, HasDataType004, TestSize.Level0)
142 {
143     uint32_t color[100] = { 3, 7, 9, 9, 7, 6 };
144     InitializationOptions opts = { { 5, 7 }, PixelFormat::ARGB_8888 };
145     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(color, sizeof(color) / sizeof(color[0]), opts);
146     std::shared_ptr<PixelMap> pixelMapIn = move(pixelMap);
147     auto newPasteData = PasteboardClient::GetInstance()->CreatePixelMapData(pixelMapIn);
148     PasteboardClient::GetInstance()->SetPasteData(*newPasteData);
149     auto ret = PasteboardClient::GetInstance()->HasDataType(MIMETYPE_PIXELMAP);
150     ASSERT_TRUE(ret);
151     auto result = PasteboardClient::GetInstance()->HasDataType(MIMETYPE_TEXT_URI);
152     ASSERT_FALSE(result);
153 }
154 
155 /**
156 * @tc.name: GetDataSource001
157 * @tc.desc: Get the source of the data.
158 * @tc.type: FUNC
159 * @tc.require:
160 * @tc.author:
161 */
162 HWTEST_F(PasteboardClientTest, GetDataSource001, TestSize.Level0)
163 {
164     std::string plainText = "helloWorld";
165     auto newData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
166     PasteboardClient::GetInstance()->SetPasteData(*newData);
167     std::string bundleName;
168     PasteboardClient::GetInstance()->GetDataSource(bundleName);
169     EXPECT_FALSE(bundleName.empty());
170 }
171 } // namespace OHOS::MiscServices