1 /*
2  * Copyright (c) 2024 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 #define LOG_TAG "HtmlTest"
16 
17 #include <unistd.h>
18 #include <gtest/gtest.h>
19 #include <string>
20 
21 #include "logger.h"
22 #include "udmf_capi_common.h"
23 #include "html.h"
24 
25 using namespace testing::ext;
26 using namespace OHOS::UDMF;
27 using namespace OHOS;
28 namespace OHOS::Test {
29 using namespace std;
30 
31 class HtmlTest : public testing::Test {
32 public:
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     void SetUp() override;
36     void TearDown() override;
37 };
38 
SetUpTestCase()39 void HtmlTest::SetUpTestCase()
40 {
41 }
42 
TearDownTestCase()43 void HtmlTest::TearDownTestCase()
44 {
45 }
46 
SetUp()47 void HtmlTest::SetUp()
48 {
49 }
50 
TearDown()51 void HtmlTest::TearDown()
52 {
53 }
54 
55 /**
56 * @tc.name: Html001
57 * @tc.desc: Abnormal testcase of Html, because htmlContent and plainContent are equal to MAX_TEXT_LEN
58 * @tc.type: FUNC
59 */
60 HWTEST_F(HtmlTest, Html001, TestSize.Level1)
61 {
62     LOG_INFO(UDMF_TEST, "Html001 begin.");
63     const std::string htmlContent(MAX_TEXT_LEN, 'a');
64     const std::string plainContent(MAX_TEXT_LEN, 'a');
65     Html html(htmlContent, plainContent);
66     EXPECT_NE(html.dataType_, HTML);
67     EXPECT_TRUE(html.htmlContent_.empty());
68     EXPECT_TRUE(html.plainContent_.empty());
69     LOG_INFO(UDMF_TEST, "Html001 end.");
70 }
71 
72 /**
73 * @tc.name: Html002
74 * @tc.desc: Abnormal testcase of Html, because plainContent and MAX_TEXT_LEN are equal
75 * @tc.type: FUNC
76 */
77 HWTEST_F(HtmlTest, Html002, TestSize.Level1)
78 {
79     LOG_INFO(UDMF_TEST, "Html002 begin.");
80     const std::string htmlContent(20, 'a');
81     const std::string plainContent(MAX_TEXT_LEN, 'a');
82     Html html(htmlContent, plainContent);
83     EXPECT_NE(html.dataType_, HTML);
84     EXPECT_TRUE(html.htmlContent_.empty());
85     EXPECT_TRUE(html.plainContent_.empty());
86     LOG_INFO(UDMF_TEST, "Html002 end.");
87 }
88 
89 /**
90 * @tc.name: Html003
91 * @tc.desc: Abnormal testcase of Html, because htmlContent and MAX_TEXT_LEN are equal
92 * @tc.type: FUNC
93 */
94 HWTEST_F(HtmlTest, Html003, TestSize.Level1)
95 {
96     LOG_INFO(UDMF_TEST, "Html003 begin.");
97     const std::string htmlContent(20, 'a');
98     const std::string plainContent(MAX_TEXT_LEN, 'a');
99     Html html(htmlContent, plainContent);
100     EXPECT_NE(html.dataType_, HTML);
101     EXPECT_TRUE(html.htmlContent_.empty());
102     EXPECT_TRUE(html.plainContent_.empty());
103     LOG_INFO(UDMF_TEST, "Html003 end.");
104 }
105 
106 /**
107 * @tc.name: Html004
108 * @tc.desc: Normal testcase of Html
109 * @tc.type: FUNC
110 */
111 HWTEST_F(HtmlTest, Html004, TestSize.Level1)
112 {
113     LOG_INFO(UDMF_TEST, "Html004 begin.");
114     const std::string htmlContent(20, 'a');
115     const std::string plainContent(20, 'a');
116     Html html(htmlContent, plainContent);
117     EXPECT_EQ(html.dataType_, HTML);
118     EXPECT_EQ(html.htmlContent_, htmlContent);
119     EXPECT_EQ(html.plainContent_, plainContent);
120     LOG_INFO(UDMF_TEST, "Html004 end.");
121 }
122 
123 /**
124 * @tc.name: Html005
125 * @tc.desc: Normal testcase of Html
126 * @tc.type: FUNC
127 */
128 HWTEST_F(HtmlTest, Html005, TestSize.Level1)
129 {
130     LOG_INFO(UDMF_TEST, "Html005 begin.");
131     UDType type = UDType::ENTITY;
132     ValueType value = "value";
133     Html html(type, value);
134     EXPECT_EQ(html.htmlContent_, std::get<std::string>(value));
135     LOG_INFO(UDMF_TEST, "Html005 end.");
136 }
137 
138 /**
139 * @tc.name: SetHtmlContent001
140 * @tc.desc: Abnormal testcase of SetHtmlContent, because htmlContent and MAX_TEXT_LEN are equal
141 * @tc.type: FUNC
142 */
143 HWTEST_F(HtmlTest, SetHtmlContent001, TestSize.Level1)
144 {
145     LOG_INFO(UDMF_TEST, "SetHtmlContent001 begin.");
146     const std::string htmlContent(20 * 1024 * 1024, 'a');
147     Html html;
148     html.SetHtmlContent(htmlContent);
149     EXPECT_NE(html.htmlContent_, htmlContent);
150     LOG_INFO(UDMF_TEST, "SetHtmlContent001 end.");
151 }
152 
153 /**
154 * @tc.name: SetPlainContent002
155 * @tc.desc: Abnormal testcase of SetPlainContent, because plainContent and MAX_TEXT_LEN are equal
156 * @tc.type: FUNC
157 */
158 HWTEST_F(HtmlTest, SetPlainContent002, TestSize.Level1)
159 {
160     LOG_INFO(UDMF_TEST, "SetPlainContent002 begin.");
161     const std::string plainContent(20 * 1024 * 1024, 'a');
162     Html html;
163     html.SetPlainContent(plainContent);
164     EXPECT_NE(html.plainContent_, plainContent);
165     LOG_INFO(UDMF_TEST, "SetPlainContent002 end.");
166 }
167 } // OHOS::Test