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 "ApplicationUtdJsonParserTest"
16
17 #include <unistd.h>
18 #include <gtest/gtest.h>
19 #include <string>
20
21 #include "logger.h"
22 #include "unified_record.h"
23 #include "link.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 LinkTest : 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 LinkTest::SetUpTestCase()
40 {
41 }
42
TearDownTestCase()43 void LinkTest::TearDownTestCase()
44 {
45 }
46
SetUp()47 void LinkTest::SetUp()
48 {
49 }
50
TearDown()51 void LinkTest::TearDown()
52 {
53 }
54
55 /**
56 * @tc.name: LinkTest001
57 * @tc.desc: Normal testcase of Link
58 * @tc.type: FUNC
59 */
60 HWTEST_F(LinkTest, LinkTest001, TestSize.Level1)
61 {
62 LOG_INFO(UDMF_TEST, "LinkTest001 begin.");
63 UDType type = UDType::ENTITY;
64 ValueType value = "value";
65 Link link(type, value);
66 EXPECT_EQ(link.url_, std::get<std::string>(value));
67 LOG_INFO(UDMF_TEST, "LinkTest001 end.");
68 }
69
70 /**
71 * @tc.name: LinkTest002
72 * @tc.desc: Abnormal testcase of Link,because url and description are equal to MAX_TEXT_LEN
73 * @tc.type: FUNC
74 */
75 HWTEST_F(LinkTest, LinkTest002, TestSize.Level1)
76 {
77 LOG_INFO(UDMF_TEST, "LinkTest002 begin.");
78 const std::string url(MAX_TEXT_LEN, 'a');
79 const std::string description(MAX_TEXT_LEN, 'a');
80 Link link(url, description);
81 EXPECT_NE(link.dataType_, HYPERLINK);
82 EXPECT_NE(link.url_, url);
83 EXPECT_NE(link.description_, description);
84 LOG_INFO(UDMF_TEST, "LinkTest002 end.");
85 }
86
87 /**
88 * @tc.name: LinkTest003
89 * @tc.desc: Abnormal testcase of Link,because url and MAX_TEXT_LEN are equal
90 * @tc.type: FUNC
91 */
92 HWTEST_F(LinkTest, LinkTest003, TestSize.Level1)
93 {
94 LOG_INFO(UDMF_TEST, "LinkTest003 begin.");
95 const std::string url(MAX_TEXT_LEN, 'a');
96 const std::string description(20, 'a');
97 Link link(url, description);
98 EXPECT_NE(link.dataType_, HYPERLINK);
99 EXPECT_NE(link.url_, url);
100 EXPECT_NE(link.description_, description);
101 LOG_INFO(UDMF_TEST, "LinkTest003 end.");
102 }
103
104 /**
105 * @tc.name: LinkTest004
106 * @tc.desc: Abnormal testcase of Link,because description and MAX_TEXT_LEN are equal
107 * @tc.type: FUNC
108 */
109 HWTEST_F(LinkTest, LinkTest004, TestSize.Level1)
110 {
111 LOG_INFO(UDMF_TEST, "LinkTest004 begin.");
112 const std::string url(20, 'a');
113 const std::string description(MAX_TEXT_LEN, 'a');
114 Link link(url, description);
115 EXPECT_NE(link.dataType_, HYPERLINK);
116 EXPECT_NE(link.url_, url);
117 EXPECT_NE(link.description_, description);
118 LOG_INFO(UDMF_TEST, "LinkTest004 end.");
119 }
120
121 /**
122 * @tc.name: SetUrlTest001
123 * @tc.desc: Abnormal testcase of SetUrl,because url and MAX_TEXT_LEN are equal
124 * @tc.type: FUNC
125 */
126 HWTEST_F(LinkTest, SetUrlTest001, TestSize.Level1)
127 {
128 LOG_INFO(UDMF_TEST, "SetUrlTest001 begin.");
129 const std::string url(MAX_TEXT_LEN, 'a');
130 Link link;
131 link.SetUrl(url);
132 EXPECT_NE(link.url_, url);
133 LOG_INFO(UDMF_TEST, "SetUrlTest001 end.");
134 }
135
136 /**
137 * @tc.name: SetDescription001
138 * @tc.desc: Abnormal testcase of SetDescription,because url and MAX_TEXT_LEN are equal
139 * @tc.type: FUNC
140 */
141 HWTEST_F(LinkTest, SetDescription001, TestSize.Level1)
142 {
143 LOG_INFO(UDMF_TEST, "SetDescription001 begin.");
144 const std::string description(MAX_TEXT_LEN, 'a');
145 Link link;
146 link.SetDescription(description);
147 EXPECT_NE(link.description_, description);
148 LOG_INFO(UDMF_TEST, "SetDescription001 end.");
149 }
150
151 /**
152 * @tc.name: SetDescription002
153 * @tc.desc: Abnormal testcase of SetDescription,because description and MAX_TEXT_LEN are equal
154 * @tc.type: FUNC
155 */
156 HWTEST_F(LinkTest, SetDescription002, TestSize.Level1)
157 {
158 LOG_INFO(UDMF_TEST, "SetDescription002 begin.");
159 const std::string description(MAX_TEXT_LEN, 'a');
160 Link link;
161 link.SetDescription(description);
162 EXPECT_NE(link.description_, description);
163 LOG_INFO(UDMF_TEST, "SetDescription002 end.");
164 }
165 } // OHOS::Test