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 "PlainTextTest"
16
17 #include <unistd.h>
18 #include <gtest/gtest.h>
19 #include <string>
20
21 #include "logger.h"
22 #include "plain_text.h"
23 #include "udmf_capi_common.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 PlainTextTest : 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 PlainTextTest::SetUpTestCase()
40 {
41 }
42
TearDownTestCase()43 void PlainTextTest::TearDownTestCase()
44 {
45 }
46
SetUp()47 void PlainTextTest::SetUp()
48 {
49 }
50
TearDown()51 void PlainTextTest::TearDown()
52 {
53 }
54
55 /**
56 * @tc.name: PlainText001
57 * @tc.desc: Abnormal testcase of PlainText, because content is equal to MAX_TEXT_LEN
58 * @tc.type: FUNC
59 */
60 HWTEST_F(PlainTextTest, PlainText001, TestSize.Level1)
61 {
62 LOG_INFO(UDMF_TEST, "PlainText001 begin.");
63 const std::string content(MAX_TEXT_LEN, 'a');
64 const std::string abstract = "abstract";
65 PlainText plainText(content, abstract);
66 EXPECT_NE(plainText.dataType_, PLAIN_TEXT);
67 EXPECT_NE(plainText.content_, content);
68 EXPECT_NE(plainText.abstract_, abstract);
69 LOG_INFO(UDMF_TEST, "PlainText001 end.");
70 }
71
72 /**
73 * @tc.name: SetContent002
74 * @tc.desc: Abnormal testcase of SetContent, because text is equal to MAX_TEXT_LEN
75 * @tc.type: FUNC
76 */
77 HWTEST_F(PlainTextTest, SetContent002, TestSize.Level1)
78 {
79 LOG_INFO(UDMF_TEST, "SetContent002 begin.");
80 const std::string text(MAX_TEXT_LEN, 'a');
81 PlainText plainText;
82 plainText.SetContent(text);
83 EXPECT_NE(plainText.content_, text);
84 LOG_INFO(UDMF_TEST, "SetContent002 end.");
85 }
86
87 /**
88 * @tc.name: SetAbstract003
89 * @tc.desc: Abnormal testcase of SetAbstract, because abstract is equal to MAX_TEXT_LEN
90 * @tc.type: FUNC
91 */
92 HWTEST_F(PlainTextTest, SetAbstract003, TestSize.Level1)
93 {
94 LOG_INFO(UDMF_TEST, "SetAbstract003 begin.");
95 const std::string abstract(MAX_TEXT_LEN, 'a');
96 PlainText plainText;
97 plainText.SetAbstract(abstract);
98 EXPECT_NE(plainText.abstract_, abstract);
99 LOG_INFO(UDMF_TEST, "SetAbstract003 end.");
100 }
101 } // OHOS::Test