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 
18 #include "netfirewall_common.h"
19 
20 namespace OHOS {
21 namespace NetManagerStandard {
22 namespace {
23 using namespace testing::ext;
24 }
25 
26 class NetFirewallPolicyTest : public testing::Test {
27 public:
SetUpTestCase()28     static void SetUpTestCase() {};
TearDownTestCase()29     static void TearDownTestCase() {};
SetUp()30     void SetUp() {};
TearDown()31     void TearDown() {};
32 };
33 
34 class RequestParamTest : public testing::Test {
35 public:
SetUpTestCase()36     static void SetUpTestCase() {};
TearDownTestCase()37     static void TearDownTestCase() {};
SetUp()38     void SetUp() {};
TearDown()39     void TearDown() {};
40 };
41 
42 class FirewallRulePageTest : public testing::Test {
43 public:
SetUpTestCase()44     static void SetUpTestCase() {};
TearDownTestCase()45     static void TearDownTestCase() {};
SetUp()46     void SetUp() {};
TearDown()47     void TearDown() {};
48 };
49 
50 class InterceptRecordPageTest : public testing::Test {
51 public:
SetUpTestCase()52     static void SetUpTestCase() {};
TearDownTestCase()53     static void TearDownTestCase() {};
SetUp()54     void SetUp() {};
TearDown()55     void TearDown() {};
56 };
57 
58 HWTEST_F(NetFirewallPolicyTest, Unmarshalling001, TestSize.Level0)
59 {
60     Parcel parcel;
61     sptr<NetFirewallPolicy> ptr = NetFirewallPolicy::Unmarshalling(parcel);
62     EXPECT_EQ(ptr, nullptr);
63 }
64 
65 HWTEST_F(NetFirewallPolicyTest, Unmarshalling002, TestSize.Level0)
66 {
67     Parcel parcel;
68     bool isOpen = true;
69     parcel.WriteBool(isOpen);
70     sptr<NetFirewallPolicy> ptr = NetFirewallPolicy::Unmarshalling(parcel);
71     EXPECT_EQ(ptr, nullptr);
72 }
73 
74 HWTEST_F(NetFirewallPolicyTest, Unmarshalling003, TestSize.Level0)
75 {
76     Parcel parcel;
77     bool isOpen = true;
78     parcel.WriteBool(isOpen);
79     int32_t inAction = 1;
80     parcel.WriteInt32(inAction);
81     sptr<NetFirewallPolicy> ptr = NetFirewallPolicy::Unmarshalling(parcel);
82     EXPECT_EQ(ptr, nullptr);
83 }
84 
85 HWTEST_F(RequestParamTest, Unmarshalling001, TestSize.Level0)
86 {
87     Parcel parcel;
88     sptr<RequestParam> ptr = RequestParam::Unmarshalling(parcel);
89     EXPECT_EQ(ptr, nullptr);
90 }
91 
92 HWTEST_F(RequestParamTest, Unmarshalling002, TestSize.Level0)
93 {
94     Parcel parcel;
95     int32_t page = 1;
96     parcel.WriteInt32(page);
97     sptr<RequestParam> ptr = RequestParam::Unmarshalling(parcel);
98     EXPECT_EQ(ptr, nullptr);
99 }
100 
101 HWTEST_F(RequestParamTest, Unmarshalling003, TestSize.Level0)
102 {
103     Parcel parcel;
104     int32_t page = 1;
105     parcel.WriteInt32(page);
106     int32_t pageSize = 2;
107     parcel.WriteInt32(pageSize);
108     sptr<RequestParam> ptr = RequestParam::Unmarshalling(parcel);
109     EXPECT_EQ(ptr, nullptr);
110 }
111 
112 HWTEST_F(RequestParamTest, Unmarshalling004, TestSize.Level0)
113 {
114     Parcel parcel;
115     int32_t page = 1;
116     parcel.WriteInt32(page);
117     int32_t pageSize = 2;
118     parcel.WriteInt32(pageSize);
119     int32_t orderField = 1;
120     parcel.WriteInt32(orderField);
121     sptr<RequestParam> ptr = RequestParam::Unmarshalling(parcel);
122     EXPECT_EQ(ptr, nullptr);
123 }
124 
125 HWTEST_F(FirewallRulePageTest, Unmarshalling001, TestSize.Level0)
126 {
127     Parcel parcel;
128     sptr<FirewallRulePage> ptr = FirewallRulePage::Unmarshalling(parcel);
129     EXPECT_EQ(ptr, nullptr);
130 }
131 
132 HWTEST_F(FirewallRulePageTest, Unmarshalling002, TestSize.Level0)
133 {
134     Parcel parcel;
135     int32_t page = 1;
136     parcel.WriteInt32(page);
137     sptr<FirewallRulePage> ptr = FirewallRulePage::Unmarshalling(parcel);
138     EXPECT_EQ(ptr, nullptr);
139 }
140 
141 HWTEST_F(FirewallRulePageTest, Unmarshalling003, TestSize.Level0)
142 {
143     Parcel parcel;
144     int32_t page = 1;
145     parcel.WriteInt32(page);
146     int32_t pageSize = 2;
147     parcel.WriteInt32(pageSize);
148     sptr<FirewallRulePage> ptr = FirewallRulePage::Unmarshalling(parcel);
149     EXPECT_EQ(ptr, nullptr);
150 }
151 
152 HWTEST_F(FirewallRulePageTest, Unmarshalling004, TestSize.Level0)
153 {
154     Parcel parcel;
155     int32_t page = 1;
156     parcel.WriteInt32(page);
157     int32_t pageSize = 2;
158     parcel.WriteInt32(pageSize);
159     int32_t totalPage = 50;
160     parcel.WriteInt32(totalPage);
161     sptr<FirewallRulePage> ptr = FirewallRulePage::Unmarshalling(parcel);
162     EXPECT_EQ(ptr, nullptr);
163 }
164 
165 HWTEST_F(FirewallRulePageTest, Unmarshalling005, TestSize.Level0)
166 {
167     Parcel parcel;
168     int32_t page = 1;
169     parcel.WriteInt32(page);
170     int32_t pageSize = 2;
171     parcel.WriteInt32(pageSize);
172     int32_t totalPage = 50;
173     parcel.WriteInt32(totalPage);
174     uint32_t size = 2;
175     parcel.WriteUint32(size);
176     sptr<FirewallRulePage> ptr = FirewallRulePage::Unmarshalling(parcel);
177     EXPECT_EQ(ptr, nullptr);
178 }
179 
180 HWTEST_F(InterceptRecordPageTest, Unmarshalling001, TestSize.Level0)
181 {
182     Parcel parcel;
183     sptr<InterceptRecordPage> ptr = InterceptRecordPage::Unmarshalling(parcel);
184     EXPECT_EQ(ptr, nullptr);
185 }
186 
187 HWTEST_F(InterceptRecordPageTest, Unmarshalling002, TestSize.Level0)
188 {
189     Parcel parcel;
190     int32_t page = 1;
191     parcel.WriteInt32(page);
192     sptr<InterceptRecordPage> ptr = InterceptRecordPage::Unmarshalling(parcel);
193     EXPECT_EQ(ptr, nullptr);
194 }
195 
196 HWTEST_F(InterceptRecordPageTest, Unmarshalling003, TestSize.Level0)
197 {
198     Parcel parcel;
199     int32_t page = 1;
200     parcel.WriteInt32(page);
201     int32_t pageSize = 2;
202     parcel.WriteInt32(pageSize);
203     sptr<InterceptRecordPage> ptr = InterceptRecordPage::Unmarshalling(parcel);
204     EXPECT_EQ(ptr, nullptr);
205 }
206 
207 HWTEST_F(InterceptRecordPageTest, Unmarshalling004, TestSize.Level0)
208 {
209     Parcel parcel;
210     int32_t page = 1;
211     parcel.WriteInt32(page);
212     int32_t pageSize = 2;
213     parcel.WriteInt32(pageSize);
214     int32_t totalPage = 50;
215     parcel.WriteInt32(totalPage);
216     sptr<InterceptRecordPage> ptr = InterceptRecordPage::Unmarshalling(parcel);
217     EXPECT_EQ(ptr, nullptr);
218 }
219 
220 HWTEST_F(InterceptRecordPageTest, Unmarshalling005, TestSize.Level0)
221 {
222     Parcel parcel;
223     int32_t page = 1;
224     parcel.WriteInt32(page);
225     int32_t pageSize = 2;
226     parcel.WriteInt32(pageSize);
227     int32_t totalPage = 50;
228     parcel.WriteInt32(totalPage);
229     uint32_t size = 2;
230     parcel.WriteUint32(size);
231     sptr<InterceptRecordPage> ptr = InterceptRecordPage::Unmarshalling(parcel);
232     EXPECT_EQ(ptr, nullptr);
233 }
234 }
235 }