114cf0368Sopenharmony_ci/* 214cf0368Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 314cf0368Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 414cf0368Sopenharmony_ci * you may not use this file except in compliance with the License. 514cf0368Sopenharmony_ci * You may obtain a copy of the License at 614cf0368Sopenharmony_ci * 714cf0368Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 814cf0368Sopenharmony_ci * 914cf0368Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1014cf0368Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1114cf0368Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1214cf0368Sopenharmony_ci * See the License for the specific language governing permissions and 1314cf0368Sopenharmony_ci * limitations under the License. 1414cf0368Sopenharmony_ci */ 1514cf0368Sopenharmony_ci#define LOG_TAG "HtmlTest" 1614cf0368Sopenharmony_ci 1714cf0368Sopenharmony_ci#include <unistd.h> 1814cf0368Sopenharmony_ci#include <gtest/gtest.h> 1914cf0368Sopenharmony_ci#include <string> 2014cf0368Sopenharmony_ci 2114cf0368Sopenharmony_ci#include "logger.h" 2214cf0368Sopenharmony_ci#include "udmf_capi_common.h" 2314cf0368Sopenharmony_ci#include "html.h" 2414cf0368Sopenharmony_ci 2514cf0368Sopenharmony_ciusing namespace testing::ext; 2614cf0368Sopenharmony_ciusing namespace OHOS::UDMF; 2714cf0368Sopenharmony_ciusing namespace OHOS; 2814cf0368Sopenharmony_cinamespace OHOS::Test { 2914cf0368Sopenharmony_ciusing namespace std; 3014cf0368Sopenharmony_ci 3114cf0368Sopenharmony_ciclass HtmlTest : public testing::Test { 3214cf0368Sopenharmony_cipublic: 3314cf0368Sopenharmony_ci static void SetUpTestCase(); 3414cf0368Sopenharmony_ci static void TearDownTestCase(); 3514cf0368Sopenharmony_ci void SetUp() override; 3614cf0368Sopenharmony_ci void TearDown() override; 3714cf0368Sopenharmony_ci}; 3814cf0368Sopenharmony_ci 3914cf0368Sopenharmony_civoid HtmlTest::SetUpTestCase() 4014cf0368Sopenharmony_ci{ 4114cf0368Sopenharmony_ci} 4214cf0368Sopenharmony_ci 4314cf0368Sopenharmony_civoid HtmlTest::TearDownTestCase() 4414cf0368Sopenharmony_ci{ 4514cf0368Sopenharmony_ci} 4614cf0368Sopenharmony_ci 4714cf0368Sopenharmony_civoid HtmlTest::SetUp() 4814cf0368Sopenharmony_ci{ 4914cf0368Sopenharmony_ci} 5014cf0368Sopenharmony_ci 5114cf0368Sopenharmony_civoid HtmlTest::TearDown() 5214cf0368Sopenharmony_ci{ 5314cf0368Sopenharmony_ci} 5414cf0368Sopenharmony_ci 5514cf0368Sopenharmony_ci/** 5614cf0368Sopenharmony_ci* @tc.name: Html001 5714cf0368Sopenharmony_ci* @tc.desc: Abnormal testcase of Html, because htmlContent and plainContent are equal to MAX_TEXT_LEN 5814cf0368Sopenharmony_ci* @tc.type: FUNC 5914cf0368Sopenharmony_ci*/ 6014cf0368Sopenharmony_ciHWTEST_F(HtmlTest, Html001, TestSize.Level1) 6114cf0368Sopenharmony_ci{ 6214cf0368Sopenharmony_ci LOG_INFO(UDMF_TEST, "Html001 begin."); 6314cf0368Sopenharmony_ci const std::string htmlContent(MAX_TEXT_LEN, 'a'); 6414cf0368Sopenharmony_ci const std::string plainContent(MAX_TEXT_LEN, 'a'); 6514cf0368Sopenharmony_ci Html html(htmlContent, plainContent); 6614cf0368Sopenharmony_ci EXPECT_NE(html.dataType_, HTML); 6714cf0368Sopenharmony_ci EXPECT_TRUE(html.htmlContent_.empty()); 6814cf0368Sopenharmony_ci EXPECT_TRUE(html.plainContent_.empty()); 6914cf0368Sopenharmony_ci LOG_INFO(UDMF_TEST, "Html001 end."); 7014cf0368Sopenharmony_ci} 7114cf0368Sopenharmony_ci 7214cf0368Sopenharmony_ci/** 7314cf0368Sopenharmony_ci* @tc.name: Html002 7414cf0368Sopenharmony_ci* @tc.desc: Abnormal testcase of Html, because plainContent and MAX_TEXT_LEN are equal 7514cf0368Sopenharmony_ci* @tc.type: FUNC 7614cf0368Sopenharmony_ci*/ 7714cf0368Sopenharmony_ciHWTEST_F(HtmlTest, Html002, TestSize.Level1) 7814cf0368Sopenharmony_ci{ 7914cf0368Sopenharmony_ci LOG_INFO(UDMF_TEST, "Html002 begin."); 8014cf0368Sopenharmony_ci const std::string htmlContent(20, 'a'); 8114cf0368Sopenharmony_ci const std::string plainContent(MAX_TEXT_LEN, 'a'); 8214cf0368Sopenharmony_ci Html html(htmlContent, plainContent); 8314cf0368Sopenharmony_ci EXPECT_NE(html.dataType_, HTML); 8414cf0368Sopenharmony_ci EXPECT_TRUE(html.htmlContent_.empty()); 8514cf0368Sopenharmony_ci EXPECT_TRUE(html.plainContent_.empty()); 8614cf0368Sopenharmony_ci LOG_INFO(UDMF_TEST, "Html002 end."); 8714cf0368Sopenharmony_ci} 8814cf0368Sopenharmony_ci 8914cf0368Sopenharmony_ci/** 9014cf0368Sopenharmony_ci* @tc.name: Html003 9114cf0368Sopenharmony_ci* @tc.desc: Abnormal testcase of Html, because htmlContent and MAX_TEXT_LEN are equal 9214cf0368Sopenharmony_ci* @tc.type: FUNC 9314cf0368Sopenharmony_ci*/ 9414cf0368Sopenharmony_ciHWTEST_F(HtmlTest, Html003, TestSize.Level1) 9514cf0368Sopenharmony_ci{ 9614cf0368Sopenharmony_ci LOG_INFO(UDMF_TEST, "Html003 begin."); 9714cf0368Sopenharmony_ci const std::string htmlContent(20, 'a'); 9814cf0368Sopenharmony_ci const std::string plainContent(MAX_TEXT_LEN, 'a'); 9914cf0368Sopenharmony_ci Html html(htmlContent, plainContent); 10014cf0368Sopenharmony_ci EXPECT_NE(html.dataType_, HTML); 10114cf0368Sopenharmony_ci EXPECT_TRUE(html.htmlContent_.empty()); 10214cf0368Sopenharmony_ci EXPECT_TRUE(html.plainContent_.empty()); 10314cf0368Sopenharmony_ci LOG_INFO(UDMF_TEST, "Html003 end."); 10414cf0368Sopenharmony_ci} 10514cf0368Sopenharmony_ci 10614cf0368Sopenharmony_ci/** 10714cf0368Sopenharmony_ci* @tc.name: Html004 10814cf0368Sopenharmony_ci* @tc.desc: Normal testcase of Html 10914cf0368Sopenharmony_ci* @tc.type: FUNC 11014cf0368Sopenharmony_ci*/ 11114cf0368Sopenharmony_ciHWTEST_F(HtmlTest, Html004, TestSize.Level1) 11214cf0368Sopenharmony_ci{ 11314cf0368Sopenharmony_ci LOG_INFO(UDMF_TEST, "Html004 begin."); 11414cf0368Sopenharmony_ci const std::string htmlContent(20, 'a'); 11514cf0368Sopenharmony_ci const std::string plainContent(20, 'a'); 11614cf0368Sopenharmony_ci Html html(htmlContent, plainContent); 11714cf0368Sopenharmony_ci EXPECT_EQ(html.dataType_, HTML); 11814cf0368Sopenharmony_ci EXPECT_EQ(html.htmlContent_, htmlContent); 11914cf0368Sopenharmony_ci EXPECT_EQ(html.plainContent_, plainContent); 12014cf0368Sopenharmony_ci LOG_INFO(UDMF_TEST, "Html004 end."); 12114cf0368Sopenharmony_ci} 12214cf0368Sopenharmony_ci 12314cf0368Sopenharmony_ci/** 12414cf0368Sopenharmony_ci* @tc.name: Html005 12514cf0368Sopenharmony_ci* @tc.desc: Normal testcase of Html 12614cf0368Sopenharmony_ci* @tc.type: FUNC 12714cf0368Sopenharmony_ci*/ 12814cf0368Sopenharmony_ciHWTEST_F(HtmlTest, Html005, TestSize.Level1) 12914cf0368Sopenharmony_ci{ 13014cf0368Sopenharmony_ci LOG_INFO(UDMF_TEST, "Html005 begin."); 13114cf0368Sopenharmony_ci UDType type = UDType::ENTITY; 13214cf0368Sopenharmony_ci ValueType value = "value"; 13314cf0368Sopenharmony_ci Html html(type, value); 13414cf0368Sopenharmony_ci EXPECT_EQ(html.htmlContent_, std::get<std::string>(value)); 13514cf0368Sopenharmony_ci LOG_INFO(UDMF_TEST, "Html005 end."); 13614cf0368Sopenharmony_ci} 13714cf0368Sopenharmony_ci 13814cf0368Sopenharmony_ci/** 13914cf0368Sopenharmony_ci* @tc.name: SetHtmlContent001 14014cf0368Sopenharmony_ci* @tc.desc: Abnormal testcase of SetHtmlContent, because htmlContent and MAX_TEXT_LEN are equal 14114cf0368Sopenharmony_ci* @tc.type: FUNC 14214cf0368Sopenharmony_ci*/ 14314cf0368Sopenharmony_ciHWTEST_F(HtmlTest, SetHtmlContent001, TestSize.Level1) 14414cf0368Sopenharmony_ci{ 14514cf0368Sopenharmony_ci LOG_INFO(UDMF_TEST, "SetHtmlContent001 begin."); 14614cf0368Sopenharmony_ci const std::string htmlContent(20 * 1024 * 1024, 'a'); 14714cf0368Sopenharmony_ci Html html; 14814cf0368Sopenharmony_ci html.SetHtmlContent(htmlContent); 14914cf0368Sopenharmony_ci EXPECT_NE(html.htmlContent_, htmlContent); 15014cf0368Sopenharmony_ci LOG_INFO(UDMF_TEST, "SetHtmlContent001 end."); 15114cf0368Sopenharmony_ci} 15214cf0368Sopenharmony_ci 15314cf0368Sopenharmony_ci/** 15414cf0368Sopenharmony_ci* @tc.name: SetPlainContent002 15514cf0368Sopenharmony_ci* @tc.desc: Abnormal testcase of SetPlainContent, because plainContent and MAX_TEXT_LEN are equal 15614cf0368Sopenharmony_ci* @tc.type: FUNC 15714cf0368Sopenharmony_ci*/ 15814cf0368Sopenharmony_ciHWTEST_F(HtmlTest, SetPlainContent002, TestSize.Level1) 15914cf0368Sopenharmony_ci{ 16014cf0368Sopenharmony_ci LOG_INFO(UDMF_TEST, "SetPlainContent002 begin."); 16114cf0368Sopenharmony_ci const std::string plainContent(20 * 1024 * 1024, 'a'); 16214cf0368Sopenharmony_ci Html html; 16314cf0368Sopenharmony_ci html.SetPlainContent(plainContent); 16414cf0368Sopenharmony_ci EXPECT_NE(html.plainContent_, plainContent); 16514cf0368Sopenharmony_ci LOG_INFO(UDMF_TEST, "SetPlainContent002 end."); 16614cf0368Sopenharmony_ci} 16714cf0368Sopenharmony_ci} // OHOS::Test