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
16 #include <gtest/gtest.h>
17 #define private public
18 #define protected public
19 #include "vendor_bsuni_driver.h"
20 #undef private
21 #undef protected
22 #include "print_constant.h"
23 #include "print_log.h"
24 #include "mock/mock_bsuni_driver.h"
25 #include "mock/mock_vendor_manager.h"
26
27 using namespace testing;
28 using namespace testing::ext;
29
30 namespace {
31 const std::string PRINTER_TEST_IP = "192.168.2.222";
32 }
33
34 namespace OHOS {
35 namespace Print {
36 MockBsuniDriver *g_mockDriver = nullptr;
OnCreateTest(const Print_ServiceAbility * context)37 int32_t OnCreateTest(const Print_ServiceAbility *context)
38 {
39 if (g_mockDriver != nullptr) {
40 return g_mockDriver->OnCreate(context);
41 }
42 return 0;
43 }
OnDestroyTest()44 int32_t OnDestroyTest()
45 {
46 if (g_mockDriver != nullptr) {
47 return g_mockDriver->OnDestroy();
48 }
49 return 0;
50 }
OnStartDiscoveryTest()51 int32_t OnStartDiscoveryTest()
52 {
53 if (g_mockDriver != nullptr) {
54 return g_mockDriver->OnStartDiscovery();
55 }
56 return 0;
57 }
OnStopDiscoveryTest()58 int32_t OnStopDiscoveryTest()
59 {
60 if (g_mockDriver != nullptr) {
61 return g_mockDriver->OnStopDiscovery();
62 }
63 return 0;
64 }
OnConnectPrinterTest(const char * printerId)65 int32_t OnConnectPrinterTest(const char *printerId)
66 {
67 if (g_mockDriver != nullptr) {
68 return g_mockDriver->OnConnectPrinter(printerId);
69 }
70 return 0;
71 }
OnDisconnectPrinterTest(const char * printerId)72 int32_t OnDisconnectPrinterTest(const char *printerId)
73 {
74 if (g_mockDriver != nullptr) {
75 return g_mockDriver->OnDisconnectPrinter(printerId);
76 }
77 return 0;
78 }
OnQueryCapabilityTest(const char * printerId)79 int32_t OnQueryCapabilityTest(const char *printerId)
80 {
81 if (g_mockDriver != nullptr) {
82 return g_mockDriver->OnQueryCapability(printerId);
83 }
84 return 0;
85 }
OnQueryCapabilityByIpTest(const char * printerIp,const char * protocol)86 int32_t OnQueryCapabilityByIpTest(const char *printerIp, const char *protocol)
87 {
88 if (g_mockDriver != nullptr) {
89 return g_mockDriver->OnQueryCapabilityByIp(printerIp, protocol);
90 }
91 return 0;
92 }
OnQueryPropertiesTest(const char * printerId,const Print_StringList * propertyKeyList)93 int32_t OnQueryPropertiesTest(const char *printerId, const Print_StringList *propertyKeyList)
94 {
95 if (g_mockDriver != nullptr) {
96 return g_mockDriver->OnQueryProperties(printerId, propertyKeyList);
97 }
98 return 0;
99 }
100 using MockTestFunc =
101 std::function<void(VendorBsuniDriver &vendorDriver, MockBsuniDriver &mockDriver, MockVendorManager &mockManager)>;
102 class VendorBsuniDriverTest : public testing::Test {
103 public:
104 static void SetUpTestCase(void);
105 static void TearDownTestCase(void);
106 void SetUp();
107 void TearDown();
108 void DoMockTest(MockTestFunc func);
109 };
110
SetUpTestCase(void)111 void VendorBsuniDriverTest::SetUpTestCase(void) {}
112
TearDownTestCase(void)113 void VendorBsuniDriverTest::TearDownTestCase(void) {}
114
SetUp(void)115 void VendorBsuniDriverTest::SetUp(void)
116 {
117 static int32_t testNo = 0;
118 PRINT_HILOGI("VendorBsuniDriverTest_%{public}d", ++testNo);
119 }
120
TearDown(void)121 void VendorBsuniDriverTest::TearDown(void) {}
122
DoMockTest(MockTestFunc func)123 void VendorBsuniDriverTest::DoMockTest(MockTestFunc func)
124 {
125 if (func == nullptr) {
126 PRINT_HILOGE("test func is null");
127 return;
128 }
129 MockBsuniDriver mockDriver;
130 g_mockDriver = &mockDriver;
131 MockVendorManager mockManager;
132 VendorBsuniDriver vendorDriver;
133 Print_VendorExtension vendorExtension = { .onCreate = OnCreateTest,
134 .onDestroy = OnDestroyTest,
135 .onStartDiscovery = OnStartDiscoveryTest,
136 .onStopDiscovery = OnStopDiscoveryTest,
137 .onConnectPrinter = OnConnectPrinterTest,
138 .onDisconnectPrinter = OnDisconnectPrinterTest,
139 .onQueryCapability = OnQueryCapabilityTest,
140 .onQueryCapabilityByIp = OnQueryCapabilityByIpTest,
141 .onQueryProperties = OnQueryPropertiesTest };
142 vendorDriver.vendorExtension = &vendorExtension;
143 vendorDriver.vendorManager = &mockManager;
144 EXPECT_CALL(mockDriver, OnCreate(_)).Times(1).WillOnce(Return(0));
145 EXPECT_CALL(mockDriver, OnDestroy()).Times(1).WillOnce(Return(0));
146 vendorDriver.OnCreate();
147 func(vendorDriver, mockDriver, mockManager);
148 vendorDriver.OnDestroy();
149 vendorDriver.vendorExtension = nullptr;
150 g_mockDriver = nullptr;
151 }
152
153 HWTEST_F(VendorBsuniDriverTest, VendorBsuniDriverTest_0001, TestSize.Level1)
154 {
155 EXPECT_FALSE(VendorBsuniDriver::CheckVendorExtension(nullptr));
156 g_mockDriver = nullptr;
157 Print_VendorExtension vendorExtension = { .onCreate = OnCreateTest,
158 .onDestroy = OnDestroyTest,
159 .onStartDiscovery = OnStartDiscoveryTest,
160 .onStopDiscovery = OnStopDiscoveryTest,
161 .onConnectPrinter = OnConnectPrinterTest,
162 .onDisconnectPrinter = OnDisconnectPrinterTest,
163 .onQueryCapability = OnQueryCapabilityTest,
164 .onQueryCapabilityByIp = OnQueryCapabilityByIpTest,
165 .onQueryProperties = OnQueryPropertiesTest };
166 EXPECT_TRUE(VendorBsuniDriver::CheckVendorExtension(&vendorExtension));
167 vendorExtension.onQueryProperties = nullptr;
168 EXPECT_FALSE(VendorBsuniDriver::CheckVendorExtension(&vendorExtension));
169 vendorExtension.onQueryCapabilityByIp = nullptr;
170 EXPECT_FALSE(VendorBsuniDriver::CheckVendorExtension(&vendorExtension));
171 vendorExtension.onQueryCapability = nullptr;
172 EXPECT_FALSE(VendorBsuniDriver::CheckVendorExtension(&vendorExtension));
173 vendorExtension.onDisconnectPrinter = nullptr;
174 EXPECT_FALSE(VendorBsuniDriver::CheckVendorExtension(&vendorExtension));
175 vendorExtension.onConnectPrinter = nullptr;
176 EXPECT_FALSE(VendorBsuniDriver::CheckVendorExtension(&vendorExtension));
177 vendorExtension.onStopDiscovery = nullptr;
178 EXPECT_FALSE(VendorBsuniDriver::CheckVendorExtension(&vendorExtension));
179 vendorExtension.onStartDiscovery = nullptr;
180 EXPECT_FALSE(VendorBsuniDriver::CheckVendorExtension(&vendorExtension));
181 vendorExtension.onDestroy = nullptr;
182 EXPECT_FALSE(VendorBsuniDriver::CheckVendorExtension(&vendorExtension));
183 vendorExtension.onCreate = nullptr;
184 EXPECT_FALSE(VendorBsuniDriver::CheckVendorExtension(&vendorExtension));
185 }
186
187 HWTEST_F(VendorBsuniDriverTest, VendorBsuniDriverTest_0002, TestSize.Level2)
188 {
189 MockVendorManager mockManager;
190 VendorBsuniDriver vendorDriver;
191 EXPECT_EQ(vendorDriver.Init(&mockManager), false);
192 vendorDriver.UnInit();
193 }
194
195 HWTEST_F(VendorBsuniDriverTest, VendorBsuniDriverTest_0003, TestSize.Level2)
196 {
197 std::vector<std::string> propertyKeys;
198 propertyKeys.push_back(PRINTER_PROPERTY_KEY_DEVICE_STATE);
199 propertyKeys.push_back(PRINTER_PROPERTY_KEY_DEVICE_SUPPLIES);
200 VendorBsuniDriver vendorDriver;
201 vendorDriver.OnCreate();
202 vendorDriver.OnDestroy();
203 vendorDriver.OnStartDiscovery();
204 vendorDriver.OnStopDiscovery();
205 EXPECT_EQ(vendorDriver.OnQueryCapability("", 0), false);
206 EXPECT_EQ(vendorDriver.OnQueryCapabilityByIp(PRINTER_TEST_IP, "ipp"), false);
207 EXPECT_EQ(vendorDriver.OnQueryProperties(PRINTER_TEST_IP, propertyKeys), false);
208 Print_VendorExtension vendorExtension = { 0 };
209 vendorDriver.vendorExtension = &vendorExtension;
210 vendorDriver.OnCreate();
211 vendorDriver.OnDestroy();
212 vendorDriver.OnStartDiscovery();
213 vendorDriver.OnStopDiscovery();
214 EXPECT_EQ(vendorDriver.OnQueryCapability("", 0), false);
215 EXPECT_EQ(vendorDriver.OnQueryCapabilityByIp(PRINTER_TEST_IP, "ipp"), false);
216 EXPECT_EQ(vendorDriver.OnQueryProperties(PRINTER_TEST_IP, propertyKeys), false);
217 }
218
219 HWTEST_F(VendorBsuniDriverTest, VendorBsuniDriverTest_0004, TestSize.Level1)
220 {
221 std::vector<std::string> propertyKeys;
222 propertyKeys.push_back(PRINTER_PROPERTY_KEY_DEVICE_STATE);
223 propertyKeys.push_back(PRINTER_PROPERTY_KEY_DEVICE_SUPPLIES);
224 propertyKeys.push_back(PRINTER_PROPERTY_KEY_CUPS_PPD_FILE);
225 std::string printerId = PRINTER_TEST_IP;
226 VendorBsuniDriver vendorDriver;
227 EXPECT_EQ(vendorDriver.OnPrinterPropertiesQueried(printerId, nullptr), EXTENSION_ERROR_CALLBACK_NULL);
228 EXPECT_EQ(vendorDriver.OnPrinterCapabilityQueried(nullptr, nullptr, nullptr), EXTENSION_ERROR_CALLBACK_NULL);
229 MockVendorManager mockManager;
230 vendorDriver.vendorManager = &mockManager;
231 EXPECT_EQ(vendorDriver.OnPrinterPropertiesQueried(printerId, nullptr), EXTENSION_ERROR_NONE);
232 EXPECT_EQ(vendorDriver.OnPrinterCapabilityQueried(nullptr, nullptr, nullptr), EXTENSION_INVALID_PARAMETER);
233 Print_PropertyList propertyList = { 0 };
234 propertyList.count = static_cast<uint32_t>(propertyKeys.size());
235 propertyList.list = new (std::nothrow) Print_Property[propertyList.count];
236 ASSERT_NE(propertyList.list, nullptr);
237 for (uint32_t i = 0; i < propertyList.count; ++i) {
238 propertyList.list[i].key = const_cast<char *>(propertyKeys[i].c_str());
239 propertyList.list[i].value = "test data";
240 }
241 EXPECT_CALL(mockManager, OnPrinterPpdQueried(_, _, _)).WillOnce(Return(false)).WillRepeatedly(Return(true));
242 EXPECT_CALL(mockManager, OnPrinterStatusChanged(_, _, _)).WillOnce(Return(true)).WillRepeatedly(Return(false));
243 EXPECT_EQ(vendorDriver.OnPrinterPropertiesQueried(printerId, &propertyList), EXTENSION_ERROR_NONE);
244 propertyList.list[0].value = "{\"state\":\"0\"}";
245 EXPECT_EQ(vendorDriver.OnPrinterPropertiesQueried(printerId, &propertyList), EXTENSION_ERROR_NONE);
246 vendorDriver.MonitorPrinterStatus(printerId, true);
247 EXPECT_EQ(vendorDriver.OnPrinterPropertiesQueried(printerId, &propertyList), EXTENSION_ERROR_NONE);
248 EXPECT_EQ(vendorDriver.OnPrinterPropertiesQueried(printerId, &propertyList), EXTENSION_ERROR_NONE);
249 propertyList.list[0].value = "{\"state\":\"1\"}";
250 EXPECT_EQ(vendorDriver.OnPrinterPropertiesQueried(printerId, &propertyList), EXTENSION_ERROR_NONE);
251 Print_VendorExtension vendorExtension = { 0 };
252 vendorDriver.vendorExtension = &vendorExtension;
253 EXPECT_EQ(vendorDriver.OnPrinterPropertiesQueried(printerId, &propertyList), EXTENSION_ERROR_NONE);
254 vendorDriver.MonitorPrinterStatus(printerId, false);
255 delete[] propertyList.list;
256 propertyList.list = nullptr;
257 }
258
259 HWTEST_F(VendorBsuniDriverTest, VendorBsuniDriverTest_0005, TestSize.Level2)
260 {
261 VendorBsuniDriver::SetDriverWrapper(nullptr);
262 EXPECT_EQ(VendorBsuniDriver::AddPrinterToDiscovery(nullptr), EXTENSION_INVALID_PARAMETER);
263 EXPECT_EQ(VendorBsuniDriver::RemovePrinterFromDiscovery(nullptr), EXTENSION_INVALID_PARAMETER);
264 EXPECT_EQ(VendorBsuniDriver::AddPrinterToCups(nullptr, nullptr, nullptr, nullptr), EXTENSION_INVALID_PARAMETER);
265 EXPECT_EQ(VendorBsuniDriver::RemovePrinterFromCups(nullptr), EXTENSION_INVALID_PARAMETER);
266 EXPECT_EQ(VendorBsuniDriver::OnCapabilityQueried(nullptr, nullptr, nullptr), EXTENSION_ERROR_CALLBACK_NULL);
267 EXPECT_EQ(VendorBsuniDriver::OnPropertiesQueried(nullptr, nullptr), EXTENSION_INVALID_PARAMETER);
268 EXPECT_EQ(VendorBsuniDriver::OnPropertiesQueried(PRINTER_TEST_IP.c_str(), nullptr), EXTENSION_ERROR_CALLBACK_NULL);
269 EXPECT_EQ(VendorBsuniDriver::RemovePrinterFromDiscovery(PRINTER_TEST_IP.c_str()), EXTENSION_ERROR_CALLBACK_NULL);
270 EXPECT_EQ(VendorBsuniDriver::RemovePrinterFromCups(PRINTER_TEST_IP.c_str()), EXTENSION_ERROR_CALLBACK_NULL);
271 }
272
273 HWTEST_F(VendorBsuniDriverTest, VendorBsuniDriverTest_0006, TestSize.Level2)
274 {
275 VendorBsuniDriver vendorDriver;
276 vendorDriver.OnCreate();
277 vendorDriver.OnDestroy();
278 vendorDriver.OnStartDiscovery();
279 EXPECT_EQ(vendorDriver.OnQueryCapability(PRINTER_TEST_IP, 0), false);
280 vendorDriver.OnQueryCapabilityByIp(PRINTER_TEST_IP, "ipp");
281 std::vector<std::string> propertyKeys;
282 vendorDriver.OnQueryProperties(PRINTER_TEST_IP, propertyKeys);
283 }
284
285 HWTEST_F(VendorBsuniDriverTest, VendorBsuniDriverTest_0007, TestSize.Level2)
286 {
287 VendorBsuniDriver vendorDriver;
288 g_mockDriver = nullptr;
289 Print_VendorExtension vendorExtension = { .onCreate = OnCreateTest,
290 .onDestroy = OnDestroyTest,
291 .onStartDiscovery = OnStartDiscoveryTest,
292 .onStopDiscovery = OnStopDiscoveryTest,
293 .onConnectPrinter = OnConnectPrinterTest,
294 .onDisconnectPrinter = OnDisconnectPrinterTest,
295 .onQueryCapability = OnQueryCapabilityTest,
296 .onQueryCapabilityByIp = OnQueryCapabilityByIpTest,
297 .onQueryProperties = OnQueryPropertiesTest };
298 vendorDriver.vendorExtension = &vendorExtension;
299 vendorDriver.OnCreate();
300 vendorDriver.OnDestroy();
301 vendorDriver.OnStartDiscovery();
302 EXPECT_EQ(vendorDriver.OnQueryCapability(PRINTER_TEST_IP, 0), true);
303 vendorDriver.OnQueryCapabilityByIp(PRINTER_TEST_IP, "ipp");
304 std::vector<std::string> propertyKeys;
305 vendorDriver.OnQueryProperties(PRINTER_TEST_IP, propertyKeys);
306 }
307
308 HWTEST_F(VendorBsuniDriverTest, VendorBsuniDriverTest_0008, TestSize.Level2)
309 {
310 MockTestFunc testFunc = [this](VendorBsuniDriver &vendorDriver, MockBsuniDriver &mockDriver,
__anone21cdab60202(VendorBsuniDriver &vendorDriver, MockBsuniDriver &mockDriver, MockVendorManager &mockManager) 311 MockVendorManager &mockManager) {
312 EXPECT_CALL(mockDriver, OnStartDiscovery()).Times(1).WillOnce(Return(0));
313 EXPECT_CALL(mockDriver, OnStopDiscovery()).Times(1).WillOnce(Return(0));
314 vendorDriver.OnStartDiscovery();
315 vendorDriver.OnStopDiscovery();
316 };
317 DoMockTest(testFunc);
318 }
319
320 HWTEST_F(VendorBsuniDriverTest, VendorBsuniDriverTest_0009, TestSize.Level2)
321 {
322 MockTestFunc testFunc = [this](VendorBsuniDriver &vendorDriver, MockBsuniDriver &mockDriver,
__anone21cdab60302(VendorBsuniDriver &vendorDriver, MockBsuniDriver &mockDriver, MockVendorManager &mockManager) 323 MockVendorManager &mockManager) {
324 EXPECT_CALL(mockDriver, OnQueryCapability(_)).Times(2).WillOnce(Return(1)).WillRepeatedly(Return(0));
325 std::string printerId = PRINTER_TEST_IP;
326 EXPECT_EQ(vendorDriver.OnQueryCapability(printerId, 0), false);
327 EXPECT_EQ(vendorDriver.OnQueryCapability(printerId, 0), true);
328 };
329 DoMockTest(testFunc);
330 }
331
332 HWTEST_F(VendorBsuniDriverTest, VendorBsuniDriverTest_0010, TestSize.Level2)
333 {
334 MockTestFunc testFunc = [this](VendorBsuniDriver &vendorDriver, MockBsuniDriver &mockDriver,
__anone21cdab60402(VendorBsuniDriver &vendorDriver, MockBsuniDriver &mockDriver, MockVendorManager &mockManager) 335 MockVendorManager &mockManager) {
336 EXPECT_CALL(mockDriver, OnQueryCapabilityByIp(_, _)).Times(2).WillOnce(Return(1)).WillRepeatedly(Return(0));
337 std::string printerIp = PRINTER_TEST_IP;
338 vendorDriver.OnQueryCapabilityByIp(printerIp, "ipp");
339 vendorDriver.OnQueryCapabilityByIp(printerIp, "ipp");
340 };
341 DoMockTest(testFunc);
342 }
343
344 HWTEST_F(VendorBsuniDriverTest, VendorBsuniDriverTest_0011, TestSize.Level2)
345 {
346 MockTestFunc testFunc = [this](VendorBsuniDriver &vendorDriver, MockBsuniDriver &mockDriver,
__anone21cdab60502(VendorBsuniDriver &vendorDriver, MockBsuniDriver &mockDriver, MockVendorManager &mockManager) 347 MockVendorManager &mockManager) {
348 EXPECT_CALL(mockManager, RemovePrinterFromCups(_, _)).WillRepeatedly(Return(0));
349 EXPECT_CALL(mockManager, RemovePrinterFromDiscovery(_, _)).WillRepeatedly(Return(0));
350 std::string printerIp = PRINTER_TEST_IP;
351 EXPECT_EQ(VendorBsuniDriver::OnPropertiesQueried(nullptr, nullptr), EXTENSION_INVALID_PARAMETER);
352 EXPECT_EQ(VendorBsuniDriver::OnCapabilityQueried(nullptr, nullptr, nullptr), EXTENSION_INVALID_PARAMETER);
353 EXPECT_EQ(VendorBsuniDriver::RemovePrinterFromCups(nullptr), EXTENSION_INVALID_PARAMETER);
354 EXPECT_EQ(VendorBsuniDriver::OnPropertiesQueried(printerIp.c_str(), nullptr), EXTENSION_ERROR_NONE);
355 EXPECT_EQ(VendorBsuniDriver::RemovePrinterFromCups(printerIp.c_str()), EXTENSION_ERROR_NONE);
356 EXPECT_EQ(VendorBsuniDriver::RemovePrinterFromDiscovery(nullptr), EXTENSION_INVALID_PARAMETER);
357 EXPECT_EQ(VendorBsuniDriver::RemovePrinterFromDiscovery(printerIp.c_str()), EXTENSION_ERROR_NONE);
358 };
359 DoMockTest(testFunc);
360 }
361
BuildDefaultValue(Print_DefaultValue & defaultValue)362 static void BuildDefaultValue(Print_DefaultValue &defaultValue)
363 {
364 defaultValue.defaultColorMode = COLOR_MODE_MONOCHROME;
365 defaultValue.defaultDuplexMode = DUPLEX_MODE_ONE_SIDED;
366 defaultValue.defaultMediaType = "a";
367 defaultValue.defaultPageSizeId = "ISO_A4";
368 defaultValue.defaultMargin = {1, 1, 1, 1};
369 defaultValue.defaultPaperSource = "a";
370 defaultValue.defaultPrintQuality = Print_Quality::PRINT_QUALITY_HIGH;
371 defaultValue.defaultCopies = 1;
372 defaultValue.defaultResolution = {1, 1};
373 defaultValue.defaultOrientation = ORIENTATION_MODE_PORTRAIT;
374 defaultValue.otherDefaultValues = "default";
375 }
376
377 HWTEST_F(VendorBsuniDriverTest, VendorBsuniDriverTest_0012, TestSize.Level2)
378 {
379 MockTestFunc testFunc = [this](VendorBsuniDriver &vendorDriver, MockBsuniDriver &mockDriver,
__anone21cdab60602(VendorBsuniDriver &vendorDriver, MockBsuniDriver &mockDriver, MockVendorManager &mockManager) 380 MockVendorManager &mockManager) {
381 Print_DiscoveryItem printer = {0};
382 Print_PrinterCapability capability = {0};
383 Print_DefaultValue defaultValue;
384 BuildDefaultValue(defaultValue);
385 Print_PageSize pages[2];
386 std::string ppdData;
387 EXPECT_CALL(mockManager, AddPrinterToDiscovery(_, _)).WillRepeatedly(Return(0));
388 EXPECT_CALL(mockManager, UpdatePrinterToDiscovery(_, _)).WillOnce(Return(1)).WillRepeatedly(Return(0));
389 EXPECT_CALL(mockManager, AddPrinterToCupsWithPpd(_, _, _)).WillOnce(Return(1)).WillRepeatedly(Return(0));
390 EXPECT_CALL(mockManager, IsConnectingPrinter(_, _)).WillOnce(Return(false)).WillRepeatedly(Return(true));
391 EXPECT_CALL(mockManager, SetConnectingPrinter(_, _)).Times(1);
392 EXPECT_CALL(mockDriver, OnQueryProperties(_, _)).Times(1).WillRepeatedly(Return(0));
393 EXPECT_EQ(VendorBsuniDriver::AddPrinterToDiscovery(nullptr), EXTENSION_INVALID_PARAMETER);
394 EXPECT_EQ(VendorBsuniDriver::AddPrinterToDiscovery(&printer), EXTENSION_INVALID_PARAMETER);
395 EXPECT_EQ(VendorBsuniDriver::AddPrinterToCups(nullptr, nullptr, nullptr, nullptr),
396 EXTENSION_INVALID_PARAMETER);
397 EXPECT_NE(vendorDriver.OnPrinterCapabilityQueried(&printer, &capability, &defaultValue),
398 EXTENSION_ERROR_NONE);
399 printer.printerId = "printer";
400 EXPECT_EQ(VendorBsuniDriver::AddPrinterToDiscovery(&printer), EXTENSION_INVALID_PARAMETER);
401 printer.printerName = "name";
402 EXPECT_EQ(VendorBsuniDriver::AddPrinterToDiscovery(&printer), EXTENSION_ERROR_NONE);
403 EXPECT_EQ(VendorBsuniDriver::AddPrinterToCups(&printer, nullptr, nullptr, nullptr),
404 EXTENSION_INVALID_PARAMETER);
405 EXPECT_EQ(VendorBsuniDriver::AddPrinterToCups(&printer, &capability, &defaultValue, nullptr),
406 EXTENSION_INVALID_PARAMETER);
407 capability.supportedPageSizes = pages;
408 EXPECT_NE(VendorBsuniDriver::AddPrinterToCups(&printer, &capability, &defaultValue, nullptr),
409 EXTENSION_ERROR_NONE);
410 ppdData = "ppd";
411 EXPECT_NE(VendorBsuniDriver::AddPrinterToCups(&printer, &capability, &defaultValue, ppdData.c_str()),
412 EXTENSION_ERROR_NONE);
413 EXPECT_EQ(VendorBsuniDriver::AddPrinterToCups(&printer, &capability, &defaultValue, ppdData.c_str()),
414 EXTENSION_ERROR_NONE);
415 printer.printerUri = "test";
416 EXPECT_EQ(vendorDriver.OnPrinterCapabilityQueried(&printer, &capability, &defaultValue),
417 EXTENSION_ERROR_INVALID_PRINTER);
418 printer.printerUri = "test://test";
419 EXPECT_EQ(vendorDriver.OnPrinterCapabilityQueried(&printer, &capability, &defaultValue),
420 EXTENSION_ERROR_NONE);
421 EXPECT_EQ(vendorDriver.OnPrinterCapabilityQueried(&printer, &capability, &defaultValue),
422 EXTENSION_ERROR_NONE);
423 };
424 DoMockTest(testFunc);
425 }
426 } // namespace Print
427 } // namespace OHOS