From 219ae387a710f569ba25eb97bd0df1b3c4895f85 Mon Sep 17 00:00:00 2001 From: zuotao Date: Thu, 17 Aug 2023 14:13:45 +0800 Subject: [PATCH] =?UTF-8?q?TDD=E7=94=A8=E4=BE=8B=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zuotao --- framework/test/src/clip_para_test.cpp | 4 +- framework/test/src/dm_adapter_test.cpp | 4 +- framework/test/src/paste_data_test.cpp | 60 ++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/framework/test/src/clip_para_test.cpp b/framework/test/src/clip_para_test.cpp index b2aa8b38..9cc6419d 100644 --- a/framework/test/src/clip_para_test.cpp +++ b/framework/test/src/clip_para_test.cpp @@ -60,8 +60,10 @@ HWTEST_F(ClipParaTest, InitMemberVariable_001, TestSize.Level0) ASSERT_TRUE(sendInformation == nullptr); auto remoteExpiration = ClipPara::GetInstance().GetRemoteExpiration(); ASSERT_TRUE(remoteExpiration == 0); + std::string deviceId = "EDAFD0A26B93FB13F2FB8894EDB8DF9158B0E5CB63FAB4C94AEFD64A82D2F487"; + ClipPara::GetInstance().SetLastSyncNetworkId(deviceId); auto lastSyncNetworkId = ClipPara::GetInstance().GetLastSyncNetworkId(); - ASSERT_TRUE(lastSyncNetworkId.empty()); + ASSERT_TRUE(lastSyncNetworkId == deviceId); auto isPullEvent = ClipPara::GetInstance().GetPullEvent(); ASSERT_FALSE(isPullEvent); auto isPullEventResult = ClipPara::GetInstance().GetPullEventResult(); diff --git a/framework/test/src/dm_adapter_test.cpp b/framework/test/src/dm_adapter_test.cpp index 61b8a394..2f632522 100644 --- a/framework/test/src/dm_adapter_test.cpp +++ b/framework/test/src/dm_adapter_test.cpp @@ -55,11 +55,11 @@ HWTEST_F(DMAdapterTest, GetLocalDeviceId, TestSize.Level0) std::string bundleName = "com.example.myapplication"; bool res = DMAdapter::GetInstance().Initialize(bundleName); ASSERT_FALSE(res); - auto &deviceId = DMAdapter::GetInstance().GetLocalDevice(); - ASSERT_FALSE(deviceId.empty()); std::string device = "deviceTestName"; auto fromDevice = DMAdapter::GetInstance().GetDeviceName(device); ASSERT_FALSE(fromDevice.empty()); + auto &deviceId = DMAdapter::GetInstance().GetLocalDevice(); + ASSERT_TRUE(deviceId.empty()); } /** diff --git a/framework/test/src/paste_data_test.cpp b/framework/test/src/paste_data_test.cpp index bec02c89..99cb7158 100644 --- a/framework/test/src/paste_data_test.cpp +++ b/framework/test/src/paste_data_test.cpp @@ -237,6 +237,47 @@ HWTEST_F(PasteDataTest, GetRealPathFailed002, TestSize.Level0) EXPECT_EQ(ret, INVALID_FD); } +/** +* @tc.name: MaxLength001 +* @tc.desc: PasteDataRecord: maxLength NewHtmlRecord +* @tc.type: FUNC +* @tc.require: +* @tc.author: +*/ +HWTEST_F(PasteDataTest, MaxLength001, TestSize.Level0) +{ + int maxLength = 20 * 1024 * 1024; + std::string res = "hello"; + std::string temp = "world"; + for (int i = 0; i < maxLength; i++) + { + res += temp; + } + std::string htmlText = "
" + res + "
"; + auto record = PasteboardClient::GetInstance()->CreateHtmlTextRecord(htmlText); + ASSERT_TRUE(record == nullptr); +} + +/** +* @tc.name: MaxLength002 +* @tc.desc: PasteDataRecord: maxLength NewPlaintTextRecord +* @tc.type: FUNC +* @tc.require: +* @tc.author: +*/ +HWTEST_F(PasteDataTest, MaxLength002, TestSize.Level0) +{ + int maxLength = 20 * 1024 * 1024; + std::string plainText = "hello"; + std::string temp = "world"; + for (int i = 0; i < maxLength; i++) + { + plainText += temp; + } + auto record = PasteboardClient::GetInstance()->CreatePlainTextRecord(plainText); + ASSERT_TRUE(record == nullptr); +} + /** * @tc.name: ConvertToText001 * @tc.desc: PasteDataRecord: ConvertToText htmlText @@ -521,6 +562,25 @@ HWTEST_F(PasteDataTest, GetConvertUri002, TestSize.Level0) ASSERT_TRUE(result2 == convertUri_); } +/** +* @tc.name: HasGrantUriPermission001 +* @tc.desc: PasteDataRecord: HasGrantUriPermission +* @tc.type: FUNC +* @tc.require: +* @tc.author: +*/ +HWTEST_F(PasteDataTest, HasGrantUriPermission001, TestSize.Level0) +{ + std::vector arrayBuffer(46); + arrayBuffer = { 1, 2, 6, 8, 9 }; + std::string mimeType = "image/jpg"; + auto pasteDataRecord = PasteboardClient::GetInstance()->CreateKvRecord(mimeType, arrayBuffer); + ASSERT_TRUE(pasteDataRecord != nullptr); + pasteDataRecord->SetGrantUriPermission(true); + auto hasGrantUriPermission_ = pasteDataRecord->HasGrantUriPermission(); + ASSERT_TRUE(hasGrantUriPermission_); +} + /** * @tc.name: LoadSystemAbilityFail001 * @tc.desc: PasteDataRecord: LoadSystemAbilityFail -- Gitee