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 #include "print_security_guard_info.h"
18 #include "print_constant.h"
19 #include "print_log.h"
20
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace Print {
25 class PrintSecurityGuardInfoTest : public testing::Test {
26 public:
27 static void SetUpTestCase(void);
28 static void TearDownTestCase(void);
29 void SetUp();
30 void TearDown();
31 };
32
SetUpTestCase(void)33 void PrintSecurityGuardInfoTest::SetUpTestCase(void) {}
34
TearDownTestCase(void)35 void PrintSecurityGuardInfoTest::TearDownTestCase(void) {}
36
SetUp(void)37 void PrintSecurityGuardInfoTest::SetUp(void) {}
38
TearDown(void)39 void PrintSecurityGuardInfoTest::TearDown(void) {}
40
41 HWTEST_F(PrintSecurityGuardInfoTest, PrintSecurityGuardInfoTest_0001, TestSize.Level1)
42 {
43 std::vector<std::string> fileList;
44 PrintSecurityGuardInfo printSecurityGuardInfo("callPkg", fileList);
45 PrinterInfo printerInfo;
46 PrintJob printJob;
47 printSecurityGuardInfo.SetPrintTypeInfo(printerInfo, printJob);
48 EXPECT_NE("", printSecurityGuardInfo.ToJsonStr());
49 }
50
51 HWTEST_F(PrintSecurityGuardInfoTest, PrintSecurityGuardInfoTest_0002, TestSize.Level1)
52 {
53 std::vector<std::string> fileList;
54 PrintSecurityGuardInfo printSecurityGuardInfo("callPkg", fileList);
55 PrinterInfo printerInfo;
56 printerInfo.SetPrinterId("EPRINT_printer");
57 PrintJob printJob;
58 printSecurityGuardInfo.SetPrintTypeInfo(printerInfo, printJob);
59 EXPECT_NE("", printSecurityGuardInfo.ToJsonStr());
60 }
61
62 HWTEST_F(PrintSecurityGuardInfoTest, PrintSecurityGuardInfoTest_0003, TestSize.Level1)
63 {
64 std::vector<std::string> fileList;
65 PrintSecurityGuardInfo printSecurityGuardInfo("callPkg", fileList);
66 PrinterInfo printerInfo;
67 printerInfo.SetPrinterId("EPRINT_printer");
68 std::string option = R"({"ePrintUrl":"testUrl"})";
69 printerInfo.SetOption(option);
70 PrintJob printJob;
71 printJob.SetSubState(PRINT_JOB_COMPLETED_SUCCESS);
72 printSecurityGuardInfo.SetPrintTypeInfo(printerInfo, printJob);
73 EXPECT_NE("", printSecurityGuardInfo.ToJsonStr());
74 }
75
76 HWTEST_F(PrintSecurityGuardInfoTest, PrintSecurityGuardInfoTest_0004, TestSize.Level1)
77 {
78 std::vector<std::string> fileList;
79 PrintSecurityGuardInfo printSecurityGuardInfo("callPkg", fileList);
80 PrinterInfo printerInfo;
81 printerInfo.SetPrinterId("EPRINT_printer");
82 std::string option = R"({"ePrintUrl":0})";
83 printerInfo.SetOption(option);
84 PrintJob printJob;
85 printJob.SetSubState(PRINT_JOB_COMPLETED_CANCELLED);
86 printSecurityGuardInfo.SetPrintTypeInfo(printerInfo, printJob);
87 EXPECT_NE("", printSecurityGuardInfo.ToJsonStr());
88 }
89
90 HWTEST_F(PrintSecurityGuardInfoTest, PrintSecurityGuardInfoTest_0005, TestSize.Level1)
91 {
92 std::vector<std::string> fileList;
93 PrintSecurityGuardInfo printSecurityGuardInfo("callPkg", fileList);
94 PrinterInfo printerInfo;
95 printerInfo.SetPrinterId("EPRINT_printer");
96 std::string option = R"({"":"testUrl"})";
97 printerInfo.SetOption(option);
98 PrintJob printJob;
99 printJob.SetSubState(PRINT_JOB_COMPLETED_FAILED);
100 printSecurityGuardInfo.SetPrintTypeInfo(printerInfo, printJob);
101 EXPECT_NE("", printSecurityGuardInfo.ToJsonStr());
102 }
103
104 HWTEST_F(PrintSecurityGuardInfoTest, PrintSecurityGuardInfoTest_0006, TestSize.Level1)
105 {
106 std::vector<std::string> fileList;
107 PrintSecurityGuardInfo printSecurityGuardInfo("callPkg", fileList);
108 PrinterInfo printerInfo;
109 printerInfo.SetPrinterId("EPRINT_printer");
110 std::string option = R"({"":""})";
111 printerInfo.SetOption(option);
112 PrintJob printJob;
113 printJob.SetSubState(PRINT_JOB_COMPLETED_FILE_CORRUPT);
114 printSecurityGuardInfo.SetPrintTypeInfo(printerInfo, printJob);
115 EXPECT_NE("", printSecurityGuardInfo.ToJsonStr());
116 }
117 } // namespace Print
118 } // namespace OHOS