1 /*
2 * Copyright (c) 2023 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 #include "paste_button_test.h"
16
17 #include <string>
18 #include "sec_comp_err.h"
19 #include "sec_comp_log.h"
20 #include "test_common.h"
21
22 using namespace testing::ext;
23 using namespace OHOS;
24 using namespace OHOS::Security::SecurityComponent;
25
26 namespace {
27 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
28 LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "PasteButtonTest"};
29 }
30
SetUpTestCase()31 void PasteButtonTest::SetUpTestCase()
32 {}
33
TearDownTestCase()34 void PasteButtonTest::TearDownTestCase()
35 {}
36
SetUp()37 void PasteButtonTest::SetUp()
38 {
39 SC_LOG_INFO(LABEL, "setup");
40 }
41
TearDown()42 void PasteButtonTest::TearDown()
43 {}
44
45 /**
46 * @tc.name: IsParamValid001
47 * @tc.desc: Test paste button from wrong value params json
48 * @tc.type: FUNC
49 * @tc.require: AR000HO9JB
50 */
51 HWTEST_F(PasteButtonTest, IsParamValid001, TestSize.Level1)
52 {
53 nlohmann::json jsonComponent;
54 TestCommon::BuildPasteComponentInfo(jsonComponent);
55 PasteButton button;
56
57 ASSERT_TRUE(button.FromJson(jsonComponent));
58
59 auto& styleJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG];
60 styleJson[JsonTagConstants::JSON_TEXT_TAG] = UNKNOWN_TEXT;
61 ASSERT_FALSE(button.FromJson(jsonComponent));
62
63 styleJson[JsonTagConstants::JSON_TEXT_TAG] = PasteDesc::PASTE;
64 styleJson[JsonTagConstants::JSON_ICON_TAG] = UNKNOWN_ICON;
65 ASSERT_FALSE(button.FromJson(jsonComponent));
66
67 styleJson[JsonTagConstants::JSON_ICON_TAG] = PasteIcon::LINE_ICON;
68 styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::UNKNOWN_BG;
69 ASSERT_FALSE(button.FromJson(jsonComponent));
70
71 styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::CIRCLE;
72 styleJson[JsonTagConstants::JSON_TEXT_TAG] = PasteDesc::MAX_LABEL_TYPE;
73 ASSERT_FALSE(button.FromJson(jsonComponent));
74
75 styleJson[JsonTagConstants::JSON_TEXT_TAG] = PasteDesc::PASTE;
76 styleJson[JsonTagConstants::JSON_ICON_TAG] = PasteIcon::MAX_ICON_TYPE;
77 ASSERT_FALSE(button.FromJson(jsonComponent));
78
79 styleJson[JsonTagConstants::JSON_ICON_TAG] = PasteIcon::LINE_ICON;
80 styleJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::MAX_BG_TYPE;
81 ASSERT_FALSE(button.FromJson(jsonComponent));
82 }
83
84 /**
85 * @tc.name: ComparePasteButton001
86 * @tc.desc: Test compare paste button
87 * @tc.type: FUNC
88 * @tc.require: AR000HO9JB
89 */
90 HWTEST_F(PasteButtonTest, ComparePasteButton001, TestSize.Level1)
91 {
92 PasteButton button1;
93 PasteButton button2;
94
95 nlohmann::json jsonComponent;
96 TestCommon::BuildPasteComponentInfo(jsonComponent);
97
98 ASSERT_TRUE(button1.FromJson(jsonComponent));
99 ASSERT_TRUE(button2.FromJson(jsonComponent));
100 ASSERT_TRUE(button1.CompareComponentBasicInfo(&button2, true));
101
102 button1.text_ = UNKNOWN_TEXT;
103 ASSERT_FALSE(button1.CompareComponentBasicInfo(&button2, true));
104 button1.text_ = static_cast<int32_t>(PasteDesc::PASTE);
105
106 button1.icon_ = UNKNOWN_ICON;
107 ASSERT_FALSE(button1.CompareComponentBasicInfo(&button2, true));
108 button1.icon_ = static_cast<int32_t>(PasteIcon::LINE_ICON);
109
110 button1.bg_ = SecCompBackground::UNKNOWN_BG;
111 ASSERT_FALSE(button1.CompareComponentBasicInfo(&button2, true));
112 button1.bg_ = SecCompBackground::CIRCLE;
113
114 ASSERT_TRUE(button1.CompareComponentBasicInfo(&button2, true));
115 }
116
117 /**
118 * @tc.name: ComparePasteButton002
119 * @tc.desc: Test PasteButton compare
120 * @tc.type: FUNC
121 * @tc.require: AR000HO9JB
122 */
123 HWTEST_F(PasteButtonTest, ComparePasteButton002, TestSize.Level1)
124 {
125 nlohmann::json jsonComponent;
126 PasteButton comp1;
127 TestCommon::BuildPasteComponentInfo(jsonComponent);
128 ASSERT_TRUE(comp1.FromJson(jsonComponent));
129 PasteButton comp2 = comp1;
130
131 comp1.type_ = SAVE_COMPONENT;
132 ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true));
133 comp1.type_ = PASTE_COMPONENT;
134
135 comp1.icon_ = static_cast<int32_t>(PasteIcon::FILLED_ICON);
136 ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true));
137 comp1.icon_ = static_cast<int32_t>(PasteIcon::LINE_ICON);
138
139 comp1.text_ = static_cast<int32_t>(PasteDesc::MAX_LABEL_TYPE);
140 ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true));
141 comp1.text_ = static_cast<int32_t>(PasteDesc::PASTE);
142
143 comp1.bg_ = SecCompBackground::NORMAL;
144 ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true));
145 comp1.bg_ = SecCompBackground::CIRCLE;
146
147 ASSERT_TRUE(comp1.CompareComponentBasicInfo(&comp2, true));
148 }
149
150 /**
151 * @tc.name: ComparePasteButton003
152 * @tc.desc: Test PasteButton compare
153 * @tc.type: FUNC
154 * @tc.require: AR000HO9JB
155 */
156 HWTEST_F(PasteButtonTest, ComparePasteButton003, TestSize.Level1)
157 {
158 PasteButton button1;
159 SaveButton button2;
160 nlohmann::json jsonComponent;
161 TestCommon::BuildPasteComponentInfo(jsonComponent);
162
163 ASSERT_TRUE(button1.FromJson(jsonComponent));
164 ASSERT_FALSE(button1.CompareComponentBasicInfo(&button2, true));
165 }
166