• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "vendor_ipp_everywhere.h"
19 #undef private
20 #include "print_constant.h"
21 #include "print_log.h"
22 #include "mock/mock_vendor_manager.h"
23 
24 namespace {
25 const int WAIT_TIME_MS = 100;
26 const std::string PRINTER_TEST_IP = "192.168.2.222";
27 }
28 using namespace testing;
29 using namespace testing::ext;
30 
31 namespace OHOS {
32 namespace Print {
33 class VendorDriverBaseTest : public VendorDriverBase {
34 public:
GetVendorName()35     std::string GetVendorName() override
36     {
37         return "driver.base.test";
38     }
39 };
40 class VendorIppEverywhereTest : public testing::Test {
41 public:
42     static void SetUpTestCase(void);
43     static void TearDownTestCase(void);
44     void SetUp();
45     void TearDown();
46 };
47 
SetUpTestCase(void)48 void VendorIppEverywhereTest::SetUpTestCase(void) {}
49 
TearDownTestCase(void)50 void VendorIppEverywhereTest::TearDownTestCase(void) {}
51 
SetUp(void)52 void VendorIppEverywhereTest::SetUp(void)
53 {
54     static int32_t testNo = 0;
55     PRINT_HILOGI("VendorIppEverywhereTest_%{public}d", ++testNo);
56 }
57 
TearDown(void)58 void VendorIppEverywhereTest::TearDown(void) {}
59 
60 HWTEST_F(VendorIppEverywhereTest, VendorIppEverywhereTest_0001, TestSize.Level1)
61 {
62     VendorIppEveryWhere vendorDriver;
63     EXPECT_EQ(vendorDriver.Init(nullptr), false);
64     vendorDriver.OnCreate();
65     ThreadSyncWait syncWait;
66     syncWait.Wait(WAIT_TIME_MS);
67     vendorDriver.OnStartDiscovery();
68     syncWait.Wait(WAIT_TIME_MS);
69     vendorDriver.OnStopDiscovery();
70     syncWait.Wait(WAIT_TIME_MS);
71     vendorDriver.OnDestroy();
72     syncWait.Wait(WAIT_TIME_MS);
73     vendorDriver.UnInit();
74 }
75 
76 HWTEST_F(VendorIppEverywhereTest, VendorIppEverywhereTest_0002, TestSize.Level2)
77 {
78     VendorIppEveryWhere vendorDriver;
79     EXPECT_EQ(vendorDriver.Init(nullptr), false);
80     EXPECT_FALSE(vendorDriver.OnQueryCapabilityByIp(PRINTER_TEST_IP, "protocol"));
81     EXPECT_FALSE(vendorDriver.OnQueryCapabilityByIp(PRINTER_TEST_IP, "auto"));
82     EXPECT_FALSE(vendorDriver.OnQueryCapabilityByIp(PRINTER_TEST_IP, "ipp"));
83     std::vector<std::string> propertyKeys;
84     EXPECT_FALSE(vendorDriver.OnQueryProperties(PRINTER_TEST_IP, propertyKeys));
85     propertyKeys.push_back(PRINTER_PROPERTY_KEY_DEVICE_STATE);
86     propertyKeys.push_back(PRINTER_PROPERTY_KEY_DEVICE_SUPPLIES);
87     EXPECT_FALSE(vendorDriver.OnQueryProperties(PRINTER_TEST_IP, propertyKeys));
88     vendorDriver.OnCreate();
89     ThreadSyncWait syncWait;
90     syncWait.Wait(WAIT_TIME_MS);
91     EXPECT_TRUE(vendorDriver.OnQueryCapabilityByIp(PRINTER_TEST_IP, "ipp"));
92     EXPECT_TRUE(vendorDriver.OnQueryProperties(PRINTER_TEST_IP, propertyKeys));
93     EXPECT_TRUE(vendorDriver.OnQueryCapability(PRINTER_TEST_IP, 0));
94     syncWait.Wait(WAIT_TIME_MS);
95     vendorDriver.OnDestroy();
96     vendorDriver.UnInit();
97 }
98 
99 HWTEST_F(VendorIppEverywhereTest, VendorIppEverywhereTest_0005, TestSize.Level2)
100 {
101     VendorIppEveryWhere vendorDriver;
102     PrinterCapability cap;
103     std::string uri;
104     EXPECT_EQ(vendorDriver.ConvertCapabilityToInfo(cap, uri), nullptr);
105     std::string option;
106     cap.SetOption(option);
107     EXPECT_EQ(vendorDriver.ConvertCapabilityToInfo(cap, uri), nullptr);
108     option = "{\"make\":\"maker\"}";
109     cap.SetOption(option);
110     EXPECT_EQ(vendorDriver.ConvertCapabilityToInfo(cap, uri), nullptr);
111     option = "{\"printerName\":\"name\"}";
112     cap.SetOption(option);
113     EXPECT_EQ(vendorDriver.ConvertCapabilityToInfo(cap, uri), nullptr);
114     option = "{\"printerName\":\"name\",\"make\":\"maker\"}";
115     cap.SetOption(option);
116     EXPECT_NE(vendorDriver.ConvertCapabilityToInfo(cap, uri), nullptr);
117 }
118 
119 HWTEST_F(VendorIppEverywhereTest, VendorIppEverywhereTest_0008, TestSize.Level2)
120 {
121     VendorDriverBaseTest vendorDriver;
122     std::string printerId = "test";
123     Print_PrinterState state = Print_PrinterState::PRINTER_UNAVAILABLE;
124     vendorDriver.OnPrinterStateQueried(printerId, state);
125     vendorDriver.UpdateAllPrinterStatus();
126     EXPECT_TRUE(vendorDriver.MonitorPrinterStatus(printerId, true));
127     vendorDriver.UpdateAllPrinterStatus();
128     EXPECT_FALSE(vendorDriver.OnQueryCapability(printerId, 0));
129     EXPECT_FALSE(vendorDriver.OnQueryCapabilityByIp(printerId, ""));
130     std::vector<std::string> propertyKeys;
131     EXPECT_FALSE(vendorDriver.OnQueryProperties(printerId, propertyKeys));
132 }
133 }  // namespace Print
134 }  // namespace OHOS