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 
16 #include <gtest/gtest.h>
17 #define private public
18 #include "print_service_helper.h"
19 #undef private
20 #include "print_constant.h"
21 #include "ipc_skeleton.h"
22 #include "iservice_registry.h"
23 #include "system_ability_definition.h"
24 
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace Print {
29 
30 static const std::string SPOOLER_BUNDLE_NAME = "com.ohos.spooler";
31 static const std::string SPOOLER_PACKAGE_NAME = "com.ohos.spooler";
32 static const std::string SPOOLER_STATUS_BAR_ABILITY_NAME = "PluginPrintIconExtAbility";
33 static const std::string CALLER_PKG_NAME = "caller.pkgName";
34 
35 class PrintServiceHelperTest : public testing::Test {
36 public:
37     static void SetUpTestCase(void);
38     static void TearDownTestCase(void);
39     void SetUp();
40     void TearDown();
41 };
42 
SetUpTestCase(void)43 void PrintServiceHelperTest::SetUpTestCase(void) {}
44 
TearDownTestCase(void)45 void PrintServiceHelperTest::TearDownTestCase(void) {}
46 
SetUp(void)47 void PrintServiceHelperTest::SetUp(void)
48 {
49     static int32_t testNo = 0;
50     PRINT_HILOGI("PrintServiceHelperTest_%{public}d", ++testNo);
51 }
52 
TearDown(void)53 void PrintServiceHelperTest::TearDown(void) {}
54 
55 /**
56 * @tc.name: PrintServiceHelperTest_0002
57 * @tc.desc: faultPrint
58 * @tc.type: FUNC
59 * @tc.require:
60 */
61 HWTEST_F(PrintServiceHelperTest, PrintServiceHelperTest_0002, TestSize.Level1)
62 {
63     PrintServiceHelper helper;
64     EXPECT_EQ(helper.CheckPermission(""), false);
65 }
66 
67 /**
68 * @tc.name: PrintServiceHelperTest_0003
69 * @tc.desc: faultPrint
70 * @tc.type: FUNC
71 * @tc.require:
72 */
73 HWTEST_F(PrintServiceHelperTest, PrintServiceHelperTest_0003, TestSize.Level1)
74 {
75     PrintServiceHelper helper;
76     auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
77     EXPECT_EQ(helper.GetBundleMgr(), systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID));
78 }
79 
80 /**
81 * @tc.name: PrintServiceHelperTest_0004
82 * @tc.desc: faultPrint
83 * @tc.type: FUNC
84 * @tc.require:
85 */
86 HWTEST_F(PrintServiceHelperTest, PrintServiceHelperTest_0004, TestSize.Level1)
87 {
88     PrintServiceHelper helper;
89     std::vector<int> accountList;
90     EXPECT_EQ(helper.QueryAccounts(accountList), true);
91 }
92 
93 /**
94 * @tc.name: PrintServiceHelperTest_0005
95 * @tc.desc: faultPrint
96 * @tc.type: FUNC
97 * @tc.require:
98 */
99 HWTEST_F(PrintServiceHelperTest, PrintServiceHelperTest_0005, TestSize.Level1)
100 {
101     PrintServiceHelper helper;
102     std::vector<int> accountList = {};
103     EXPECT_EQ(helper.QueryAccounts(accountList), true);
104 }
105 
106 /**
107 * @tc.name: PrintServiceHelperTest_0006
108 * @tc.desc: faultPrint
109 * @tc.type: FUNC
110 * @tc.require:
111 */
112 HWTEST_F(PrintServiceHelperTest, PrintServiceHelperTest_0006, TestSize.Level1)
113 {
114     PrintServiceHelper helper;
115     sptr<AppExecFwk::IBundleMgr> mgr;
116     int userId = 0;
117     std::vector<AppExecFwk::ExtensionAbilityInfo> extensionInfos;
118     EXPECT_EQ(helper.QueryExtension(mgr, userId, extensionInfos), false);
119 }
120 
121 /**
122 * @tc.name: PrintServiceHelperTest_0007
123 * @tc.desc: faultPrint
124 * @tc.type: FUNC
125 * @tc.require:
126 */
127 HWTEST_F(PrintServiceHelperTest, PrintServiceHelperTest_0007, TestSize.Level1)
128 {
129     PrintServiceHelper helper;
130     sptr<AppExecFwk::IBundleMgr> mgr;
131     int userId = 0;
132     std::string userName;
133     EXPECT_EQ(helper.QueryNameForUid(mgr, userId, userName), false);
134 }
135 
136 /**
137 * @tc.name: PrintServiceHelperTest_0008
138 * @tc.desc: faultPrint
139 * @tc.type: FUNC
140 * @tc.require:
141 */
142 HWTEST_F(PrintServiceHelperTest, PrintServiceHelperTest_0008, TestSize.Level1)
143 {
144     PrintServiceHelper helper;
145     EXPECT_EQ(helper.IsSyncMode(), false);
146 }
147 
148 /**
149 * @tc.name: PrintServiceHelperTest_009
150 * @tc.desc: faultPrint
151 * @tc.type: FUNC
152 * @tc.require:
153 */
154 HWTEST_F(PrintServiceHelperTest, PrintServiceHelperTest_0009, TestSize.Level1) {
155     PrintServiceHelper helper;
156     AAFwk::Want want;
157     EXPECT_FALSE(helper.StartAbility(want));
158 }
159 
160 /**
161 * @tc.name: PrintServiceHelperTest_0010
162 * @tc.desc: faultPrint
163 * @tc.type: FUNC
164 * @tc.require:
165 */
166 HWTEST_F(PrintServiceHelperTest, PrintServiceHelperTest_0010, TestSize.Level1)
167 {
168     PrintServiceHelper helper;
169     helper.PrintSubscribeCommonEvent();
170     helper.PrintSubscribeCommonEvent();
171     EXPECT_EQ(helper.isSubscribeCommonEvent, true);
172 }
173 
174 /**
175 * @tc.name: PrintServiceHelperTest_0011
176 * @tc.desc: StartPluginPrintIconExtAbility
177 * @tc.type: FUNC
178 * @tc.require:
179 */
180 HWTEST_F(PrintServiceHelperTest, PrintServiceHelperTest_0011, TestSize.Level1) {
181     PrintServiceHelper helper;
182     AAFwk::Want want;
183     EXPECT_FALSE(helper.StartPluginPrintIconExtAbility(want));
184 }
185 } // namespace Print
186 } // namespace OHOS