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 "save_button_test.h"
16
17 #include <string>
18 #include "sec_comp_log.h"
19 #include "sec_comp_err.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, "SaveButtonTest"};
29 }
30
SetUpTestCase()31 void SaveButtonTest::SetUpTestCase()
32 {}
33
TearDownTestCase()34 void SaveButtonTest::TearDownTestCase()
35 {}
36
SetUp()37 void SaveButtonTest::SetUp()
38 {
39 SC_LOG_INFO(LABEL, "setup");
40 }
41
TearDown()42 void SaveButtonTest::TearDown()
43 {}
44
45 /**
46 * @tc.name: IsParamValid001
47 * @tc.desc: Test save button from wrong value params json
48 * @tc.type: FUNC
49 * @tc.require: AR000HO9J7
50 */
51 HWTEST_F(SaveButtonTest, IsParamValid001, TestSize.Level1)
52 {
53 nlohmann::json jsonComponent;
54 TestCommon::BuildSaveComponentInfo(jsonComponent);
55 SaveButton button;
56
57 ASSERT_TRUE(button.FromJson(jsonComponent));
58
59 auto& stylesJson = jsonComponent[JsonTagConstants::JSON_STYLE_TAG];
60 stylesJson[JsonTagConstants::JSON_TEXT_TAG] = UNKNOWN_TEXT;
61 ASSERT_FALSE(button.FromJson(jsonComponent));
62
63 stylesJson[JsonTagConstants::JSON_TEXT_TAG] = SaveDesc::DOWNLOAD;
64 stylesJson[JsonTagConstants::JSON_ICON_TAG] = UNKNOWN_ICON;
65 ASSERT_FALSE(button.FromJson(jsonComponent));
66
67 stylesJson[JsonTagConstants::JSON_ICON_TAG] = SaveIcon::LINE_ICON;
68 stylesJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::UNKNOWN_BG;
69 ASSERT_FALSE(button.FromJson(jsonComponent));
70
71 stylesJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::CIRCLE;
72 stylesJson[JsonTagConstants::JSON_TEXT_TAG] = SaveDesc::MAX_LABEL_TYPE;
73 ASSERT_FALSE(button.FromJson(jsonComponent));
74
75 stylesJson[JsonTagConstants::JSON_TEXT_TAG] = SaveDesc::DOWNLOAD;
76 stylesJson[JsonTagConstants::JSON_ICON_TAG] = SaveIcon::MAX_ICON_TYPE;
77 ASSERT_FALSE(button.FromJson(jsonComponent));
78
79 stylesJson[JsonTagConstants::JSON_ICON_TAG] = SaveIcon::LINE_ICON;
80 stylesJson[JsonTagConstants::JSON_BG_TAG] = SecCompBackground::MAX_BG_TYPE;
81 ASSERT_FALSE(button.FromJson(jsonComponent));
82 }
83
84 /**
85 * @tc.name: CompareSaveButton001
86 * @tc.desc: Test compare save button
87 * @tc.type: FUNC
88 * @tc.require: AR000HO9J7
89 */
90 HWTEST_F(SaveButtonTest, CompareSaveButton001, TestSize.Level1)
91 {
92 SaveButton button1;
93 SaveButton button2;
94
95 nlohmann::json jsonComponent;
96 TestCommon::BuildSaveComponentInfo(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>(SaveDesc::DOWNLOAD);
105
106 button1.icon_ = UNKNOWN_ICON;
107 ASSERT_FALSE(button1.CompareComponentBasicInfo(&button2, true));
108 button1.icon_ = static_cast<int32_t>(SaveIcon::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: CompareSaveButton002
119 * @tc.desc: Test SaveButton compare
120 * @tc.type: FUNC
121 * @tc.require: AR000HO9J7
122 */
123 HWTEST_F(SaveButtonTest, CompareSaveButton002, TestSize.Level1)
124 {
125 nlohmann::json jsonComponent;
126 SaveButton comp1;
127 TestCommon::BuildSaveComponentInfo(jsonComponent);
128 ASSERT_TRUE(comp1.FromJson(jsonComponent));
129 SaveButton comp2 = comp1;
130
131 comp1.type_ = PASTE_COMPONENT;
132 ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true));
133 comp1.type_ = SAVE_COMPONENT;
134
135 comp1.icon_ = static_cast<int32_t>(SaveIcon::FILLED_ICON);
136 ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true));
137 comp1.icon_ = static_cast<int32_t>(SaveIcon::LINE_ICON);
138
139 comp1.text_ = static_cast<int32_t>(SaveDesc::DOWNLOAD_AND_SHARE);
140 ASSERT_FALSE(comp1.CompareComponentBasicInfo(&comp2, true));
141 comp1.text_ = static_cast<int32_t>(SaveDesc::DOWNLOAD);
142
143 comp1.bg_ = SecCompBackground::CAPSULE;
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: CompareSaveButton003
152 * @tc.desc: Test SaveButton compare
153 * @tc.type: FUNC
154 * @tc.require: AR000HO9J7
155 */
156 HWTEST_F(SaveButtonTest, CompareSaveButton003, TestSize.Level1)
157 {
158 SaveButton button1;
159 PasteButton button2;
160 nlohmann::json jsonComponent;
161 TestCommon::BuildSaveComponentInfo(jsonComponent);
162
163 ASSERT_TRUE(button1.FromJson(jsonComponent));
164 ASSERT_FALSE(button1.CompareComponentBasicInfo(&button2, true));
165 }
166