• 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 "inner_api_collector_test.h"
17 
18 #include "gmock/gmock.h"
19 
20 #include "security_guard_define.h"
21 #include "security_guard_log.h"
22 #define private public
23 #define protected public
24 #include "acquire_data_manager_callback_service.h"
25 #include "acquire_data_manager_callback_stub.h"
26 #include "data_collect_manager_callback_service.h"
27 #include "data_collect_manager_callback_stub.h"
28 #include "data_collect_manager_proxy.h"
29 #include "data_collect_manager.h"
30 #include "risk_analysis_manager_callback_service.h"
31 #include "risk_analysis_manager_callback_stub.h"
32 #include "risk_analysis_manager_callback.h"
33 #include "risk_analysis_manager_proxy.h"
34 #include "collector_manager.h"
35 #include "security_collector_manager_callback_stub.h"
36 #include "security_collector_manager_proxy.h"
37 #include "security_collector_subscribe_info.h"
38 #include "security_event.h"
39 #include "security_event_ruler.h"
40 #include "security_event_query_callback_service.h"
41 #include "security_event_query_callback_stub.h"
42 #include "security_event_query_callback.h"
43 #undef private
44 #undef protected
45 
46 using namespace OHOS::Security::SecurityGuard;
47 using namespace OHOS::Security::SecurityCollector;
48 
49 namespace OHOS {
50 class MockCollectorSubscriber : public ICollectorSubscriber {
51 public:
MockCollectorSubscriber(const Event & event)52     explicit MockCollectorSubscriber(const Event &event) : ICollectorSubscriber(event) {};
OnNotify(const Event & event)53     int32_t OnNotify(const Event &event) override { return 0; };
54 };
55 
56 class MockRemoteObject final : public IRemoteObject {
57 public:
MockRemoteObject()58     MockRemoteObject() : IRemoteObject(u"")
59     {
60     }
GetObjectRefCount()61     int32_t GetObjectRefCount() { return 0; };
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)62     int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { return 0; };
AddDeathRecipient(const sptr<DeathRecipient> & recipient)63     bool AddDeathRecipient(const sptr<DeathRecipient> &recipient) { return true; };
RemoveDeathRecipient(const sptr<DeathRecipient> & recipient)64     bool RemoveDeathRecipient(const sptr<DeathRecipient> &recipient) { return true; };
Dump(int fd,const std::vector<std::u16string> & args)65     int Dump(int fd, const std::vector<std::u16string> &args) { return 0; };
66 };
67 
68 class MockAcquireDataManagerCallbackStub : public AcquireDataManagerCallbackStub {
69 public:
70     explicit MockAcquireDataManagerCallbackStub() = default;
71     ~MockAcquireDataManagerCallbackStub() override = default;
OnNotify(const std::vector<Security::SecurityCollector::Event> & events)72     int32_t OnNotify(const std::vector<Security::SecurityCollector::Event> &events) override { return 0; };
73 };
74 
75 class MockRiskAnalysisManagerCallbackStub : public RiskAnalysisManagerCallbackStub {
76 public:
77     MockRiskAnalysisManagerCallbackStub() = default;
78     ~MockRiskAnalysisManagerCallbackStub() override = default;
ResponseSecurityModelResult(const std::string & devId,uint32_t modelId,std::string & result)79     int32_t ResponseSecurityModelResult(const std::string &devId, uint32_t modelId, std::string &result) override
80     {
81         return 0;
82     };
83 };
84 
85 class MockSecurityCollectorManagerCallbackStub : public SecurityCollectorManagerCallbackStub {
86 public:
87     MockSecurityCollectorManagerCallbackStub() = default;
88     ~MockSecurityCollectorManagerCallbackStub() override = default;
89 
OnNotify(const Event & event)90     int32_t OnNotify(const Event &event) override { return 0; };
91 };
92 
93 class MockDataCollectManagerCallbackStub : public DataCollectManagerCallbackStub {
94 public:
95     MockDataCollectManagerCallbackStub() = default;
96     ~MockDataCollectManagerCallbackStub() override = default;
97 
ResponseRiskData(std::string & devId,std::string & riskData,uint32_t status,const std::string & errMsg="")98     int32_t ResponseRiskData(std::string &devId, std::string &riskData, uint32_t status,
99         const std::string& errMsg = "") override { return 0; };
100 };
101 
102 class MockSecurityEventQueryCallback : public SecurityEventQueryCallback {
103 public:
104     MockSecurityEventQueryCallback() = default;
105     ~MockSecurityEventQueryCallback() override = default;
OnQuery(const std::vector<SecurityEvent> & events)106     void OnQuery(const std::vector<SecurityEvent> &events) override {};
OnComplete()107     void OnComplete() override {};
OnError(const std::string & message)108     void OnError(const std::string &message) override {};
109 };
110 
111 class MockSecurityEventQueryCallbackStub : public SecurityEventQueryCallbackStub {
112 public:
113     MockSecurityEventQueryCallbackStub() = default;
114     ~MockSecurityEventQueryCallbackStub() override = default;
OnQuery(const std::vector<SecurityEvent> & events)115     void OnQuery(const std::vector<SecurityEvent> &events) override {};
OnComplete()116     void OnComplete() override {};
OnError(const std::string & message)117     void OnError(const std::string &message) override {};
118 };
119 
TestRequestRiskDataCallback(std::string &,std::string &,uint32_t,const std::string &)120 int32_t TestRequestRiskDataCallback(std::string &, std::string &, uint32_t, const std::string &)
121 {
122     return 0;
123 }
124 
TestResultCallback(const std::string & devId,uint32_t modelId,const std::string & result)125 int32_t TestResultCallback(const std::string &devId, uint32_t modelId, const std::string &result)
126 {
127     return 0;
128 }
129 }
130 
131 namespace OHOS::Security::SecurityGuardTest {
SetUpTestCase()132 void InnerApiCollectorTest::SetUpTestCase()
133 {
134 }
135 
TearDownTestCase()136 void InnerApiCollectorTest::TearDownTestCase()
137 {
138 }
139 
SetUp()140 void InnerApiCollectorTest::SetUp()
141 {
142 }
143 
TearDown()144 void InnerApiCollectorTest::TearDown()
145 {
146 }
147 
148 HWTEST_F(InnerApiCollectorTest, AcquireDataManagerTest001, testing::ext::TestSize.Level1)
149 {
150     Security::SecurityCollector::Event event;
151     auto subscriber = std::make_shared<MockCollectorSubscriber>(event);
152     int ret = DataCollectManager::GetInstance().Subscribe(subscriber);
153     EXPECT_FALSE(ret == SUCCESS);
154     ret = DataCollectManager::GetInstance().Unsubscribe(subscriber);
155     EXPECT_TRUE(ret == BAD_PARAM);
156     DataCollectManager::GetInstance().HandleDecipient();
157 
158     AcquireDataManagerCallbackService service;
159     ret = service.OnNotify({event});
160     EXPECT_TRUE(ret == FAILED);
161 
162     service.RegistCallBack(
__anonc046f6570102(const Security::SecurityCollector::Event &event) 163         [] (const Security::SecurityCollector::Event &event) {}
164     );
165     ret = service.OnNotify({event});
166     EXPECT_TRUE(ret == SUCCESS);
167 }
168 
169 HWTEST_F(InnerApiCollectorTest, AcquireDataManagerCallbackStubTest001, testing::ext::TestSize.Level1)
170 {
171     MockAcquireDataManagerCallbackStub stub;
172     MessageParcel datas;
173     MessageParcel reply;
174     MessageOption option;
175     int ret = stub.OnRemoteRequest(0, datas, reply, option);
176     EXPECT_TRUE(ret == NO_PERMISSION);
177     int64_t int64 = 0;
178     std::string string = "test";
179     datas.WriteInterfaceToken(AcquireDataManagerCallbackStub::GetDescriptor());
180     ret = stub.OnRemoteRequest(0, datas, reply, option);
181     EXPECT_FALSE(ret == SUCCESS);
182     datas.WriteInterfaceToken(AcquireDataManagerCallbackStub::GetDescriptor());
183     datas.WriteInt64(int64);
184     datas.WriteString(string);
185     datas.WriteString(string);
186     datas.WriteString(string);
187     ret = stub.OnRemoteRequest(AcquireDataManagerCallbackStub::CMD_DATA_SUBSCRIBE_CALLBACK, datas, reply, option);
188     EXPECT_TRUE(ret == SUCCESS);
189 }
190 
191 HWTEST_F(InnerApiCollectorTest, RiskAnalysisManagerCallbackServiceTest001, testing::ext::TestSize.Level1)
192 {
193     MockRiskAnalysisManagerCallbackStub stub;
194     MessageParcel datas;
195     MessageParcel reply;
196     MessageOption option;
197     uint32_t code = 0;
198     std::string string = "test";
199     int ret = stub.OnRemoteRequest(code, datas, reply, option);
200     EXPECT_TRUE(ret == NO_PERMISSION);
201     datas.WriteInterfaceToken(IRiskAnalysisManagerCallback::GetDescriptor());
202     ret = stub.OnRemoteRequest(code, datas, reply, option);
203     EXPECT_FALSE(ret == SUCCESS);
204     datas.WriteInterfaceToken(IRiskAnalysisManagerCallback::GetDescriptor());
205     datas.WriteUint32(0);
206     datas.WriteString(string);
207     ret = stub.OnRemoteRequest(RiskAnalysisManagerCallbackStub::CMD_SET_SECURITY_MODEL_RESULT,
208         datas, reply, option);
209     EXPECT_TRUE(ret == SUCCESS);
210     ResultCallback callback;
211     RiskAnalysisManagerCallbackService service(callback);
212     ret = service.ResponseSecurityModelResult(string, code, string);
213     EXPECT_TRUE(ret == SUCCESS);
214     service.callback_ = TestResultCallback;
215     ret = service.ResponseSecurityModelResult(string, code, string);
216     EXPECT_TRUE(ret == SUCCESS);
217 }
218 
219 HWTEST_F(InnerApiCollectorTest, RiskAnalysisManagerProxyTest001, testing::ext::TestSize.Level1)
220 {
221     sptr<IRemoteObject> obj(new (std::nothrow) MockRemoteObject());
__anonc046f6570202(const std::string &devId, uint32_t modelId, const std::string &result) 222     ResultCallback func = [] (const std::string &devId, uint32_t modelId, const std::string &result) -> int32_t {
223         return 0;
224     };
225     sptr<RiskAnalysisManagerCallbackService> callback = new (std::nothrow) RiskAnalysisManagerCallbackService(func);
226     uint32_t uint32 = 0;
227     std::string string = "test";
228     RiskAnalysisManagerProxy proxy{obj};
229     int ret = proxy.RequestSecurityModelResult(string, uint32, string, callback);
230     EXPECT_TRUE(ret == SUCCESS);
231     ret = proxy.SetModelState(uint32, true);
232     EXPECT_TRUE(ret == SUCCESS);
233 }
234 
235 HWTEST_F(InnerApiCollectorTest, CollectorManagerTest001, testing::ext::TestSize.Level1)
236 {
237     Security::SecurityCollector::Event event;
238     auto subscriber = std::make_shared<MockCollectorSubscriber>(event);
239     std::vector<SecurityEventRuler> rulers{};
240     std::vector<SecurityEvent> events{};
241     SecurityCollectorSubscribeInfo subscribeInfo{};
242     int ret = CollectorManager::GetInstance().Subscribe(subscriber);
243     EXPECT_FALSE(ret == SUCCESS);
244     ret = CollectorManager::GetInstance().Unsubscribe(subscriber);
245     EXPECT_TRUE(ret == BAD_PARAM);
246     ret = CollectorManager::GetInstance().QuerySecurityEvent(rulers, events);
247     EXPECT_FALSE(ret == SUCCESS);
248     ret = CollectorManager::GetInstance().CollectorStart(subscribeInfo);
249     EXPECT_FALSE(ret == SUCCESS);
250     ret = CollectorManager::GetInstance().CollectorStop(subscribeInfo);
251     EXPECT_FALSE(ret == SUCCESS);
252 
253     CollectorManager manager;
254     sptr<Security::SecurityCollector::SecurityCollectorManagerCallbackService> callback =
255         new (std::nothrow) Security::SecurityCollector::SecurityCollectorManagerCallbackService(nullptr);
256     manager.eventListeners_[subscriber] = callback;
257     ret = manager.Subscribe(nullptr);
258     EXPECT_TRUE(ret == BAD_PARAM);
259     ret = manager.Subscribe(subscriber);
260     EXPECT_FALSE(ret == SUCCESS);
261     ret = manager.Unsubscribe(nullptr);
262     EXPECT_TRUE(ret == BAD_PARAM);
263     ret = manager.Unsubscribe(subscriber);
264     EXPECT_FALSE(ret == SUCCESS);
265 }
266 
267 HWTEST_F(InnerApiCollectorTest, DataCollectManagerCallbackServiceTest001, testing::ext::TestSize.Level1)
268 {
269     MockDataCollectManagerCallbackStub stub;
270     MessageParcel datas;
271     MessageParcel reply;
272     MessageOption option;
273     uint32_t uint32 = 0;
274     std::string string = "test";
275     datas.WriteInterfaceToken(IDataCollectManagerCallback::GetDescriptor());
276     datas.WriteString(string);
277     datas.WriteUint32(uint32);
278     datas.WriteString(string);
279     int ret = stub.OnRemoteRequest(DataCollectManagerCallbackStub::CMD_SET_REQUEST_DATA, datas, reply, option);
280     EXPECT_TRUE(ret == SUCCESS);
281     ret = stub.OnRemoteRequest(0, datas, reply, option);
282     EXPECT_FALSE(ret == SUCCESS);
283     RequestRiskDataCallback callback;
284     DataCollectManagerCallbackService service(callback);
285     ret = service.ResponseRiskData(string, string, uint32, string);
286     EXPECT_TRUE(ret == NULL_OBJECT);
287     service.callback_ = TestRequestRiskDataCallback;
288     ret = service.ResponseRiskData(string, string, uint32, string);
289     EXPECT_TRUE(ret == SUCCESS);
290 }
291 
292 HWTEST_F(InnerApiCollectorTest, DataCollectManagerProxyTest001, testing::ext::TestSize.Level1)
293 {
294     RequestRiskDataCallback func = [] (std::string &devId, std::string &riskData, uint32_t status,
__anonc046f6570302(std::string &devId, std::string &riskData, uint32_t status, const std::string &errMsg) 295         const std::string &errMsg) -> int32_t {
296         return 0;
297     };
298     sptr<DataCollectManagerCallbackService> callback = new (std::nothrow) DataCollectManagerCallbackService(func);
299     int64_t int64 = 0;
300     std::string string = "test";
301     DataCollectManagerProxy proxy{callback};
302     int ret = proxy.RequestDataSubmit(int64, string, string, string);
303     EXPECT_EQ(ret, NO_PERMISSION);
304 }
305 
306 HWTEST_F(InnerApiCollectorTest, DataCollectManagerProxyTest002, testing::ext::TestSize.Level1)
307 {
308     RequestRiskDataCallback func = [] (std::string &devId, std::string &riskData, uint32_t status,
__anonc046f6570402(std::string &devId, std::string &riskData, uint32_t status, const std::string &errMsg) 309         const std::string &errMsg) -> int32_t {
310         return 0;
311     };
312     sptr<DataCollectManagerCallbackService> callback = new (std::nothrow) DataCollectManagerCallbackService(func);
313     std::string string = "test";
314     sptr<IRemoteObject> objReq(new (std::nothrow) DataCollectManagerCallbackService(func));
315     DataCollectManagerProxy proxy{callback};
316     int ret = proxy.RequestRiskData(string, string, objReq);
317     EXPECT_EQ(ret, NO_PERMISSION);
318 }
319 
320 HWTEST_F(InnerApiCollectorTest, DataCollectManagerProxyTest003, testing::ext::TestSize.Level1)
321 {
322     RequestRiskDataCallback func = [] (std::string &devId, std::string &riskData, uint32_t status,
__anonc046f6570502(std::string &devId, std::string &riskData, uint32_t status, const std::string &errMsg) 323         const std::string &errMsg) -> int32_t {
324         return 0;
325     };
326     sptr<DataCollectManagerCallbackService> callback = new (std::nothrow) DataCollectManagerCallbackService(func);
327     std::string string = "test";
328     sptr<IRemoteObject> objSub(new (std::nothrow) SecurityCollectorManagerCallbackService(nullptr));
329     SecurityCollectorSubscribeInfo subscribeInfo{};
330     DataCollectManagerProxy proxy{callback};
331     int ret = proxy.Subscribe(subscribeInfo, objSub);
332     EXPECT_EQ(ret, NO_PERMISSION);
333     ret = proxy.Unsubscribe(subscribeInfo, objSub);
334     EXPECT_EQ(ret, NO_PERMISSION);
335 }
336 
337 HWTEST_F(InnerApiCollectorTest, DataCollectManagerProxyTest004, testing::ext::TestSize.Level1)
338 {
339     RequestRiskDataCallback func = [] (std::string &devId, std::string &riskData, uint32_t status,
__anonc046f6570602(std::string &devId, std::string &riskData, uint32_t status, const std::string &errMsg) 340         const std::string &errMsg) -> int32_t {
341         return 0;
342     };
343     sptr<DataCollectManagerCallbackService> callback = new (std::nothrow) DataCollectManagerCallbackService(func);
344     std::string string = "test";
345     sptr<IRemoteObject> objQuery(new (std::nothrow) SecurityEventQueryCallbackService(nullptr));
346     std::vector<SecurityEventRuler> rulers{};
347     DataCollectManagerProxy proxy{callback};
348     int ret = proxy.QuerySecurityEvent(rulers, objQuery, "securityGroup");
349     EXPECT_EQ(ret, NO_PERMISSION);
350 }
351 
352 HWTEST_F(InnerApiCollectorTest, DataCollectManagerProxyTest005, testing::ext::TestSize.Level1)
353 {
354     RequestRiskDataCallback func = [] (std::string &devId, std::string &riskData, uint32_t status,
__anonc046f6570702(std::string &devId, std::string &riskData, uint32_t status, const std::string &errMsg) 355         const std::string &errMsg) -> int32_t {
356         return 0;
357     };
358     sptr<DataCollectManagerCallbackService> callback = new (std::nothrow) DataCollectManagerCallbackService(func);
359     std::string string = "test";
360     sptr<IRemoteObject> objCollect(new (std::nothrow) SecurityCollectorManagerCallbackService(nullptr));
361     SecurityCollectorSubscribeInfo subscribeInfo{};
362     DataCollectManagerProxy proxy{callback};
363     int ret = proxy.CollectorStart(subscribeInfo, objCollect);
364     EXPECT_EQ(ret, NO_PERMISSION);
365     ret = proxy.CollectorStop(subscribeInfo, objCollect);
366     EXPECT_EQ(ret, NO_PERMISSION);
367 }
368 
369 HWTEST_F(InnerApiCollectorTest, DataCollectManagerProxyTest006, testing::ext::TestSize.Level1)
370 {
371     RequestRiskDataCallback func = [] (std::string &devId, std::string &riskData, uint32_t status,
__anonc046f6570802(std::string &devId, std::string &riskData, uint32_t status, const std::string &errMsg) 372         const std::string &errMsg) -> int32_t {
373         return 0;
374     };
375     sptr<DataCollectManagerCallbackService> callback = new (std::nothrow) DataCollectManagerCallbackService(func);
376     std::string string = "test";
377     SecurityConfigUpdateInfo updateInfo{};
378     DataCollectManagerProxy proxy{callback};
379     int ret = proxy.ConfigUpdate(updateInfo);
380     EXPECT_EQ(ret, NO_PERMISSION);
381 }
382 
383 HWTEST_F(InnerApiCollectorTest, DataCollectManagerTest001, testing::ext::TestSize.Level1)
384 {
385     DataCollectManager manager;
386     std::vector<SecurityEventRuler> rulers;
387     std::shared_ptr<MockSecurityEventQueryCallback> callback = std::make_shared<MockSecurityEventQueryCallback>();
388     int ret = manager.QuerySecurityEvent(rulers, callback);
389     EXPECT_EQ(ret, NO_PERMISSION);
390 }
391 
392 HWTEST_F(InnerApiCollectorTest, SecurityCollectorManagerCallbackStubTest001, testing::ext::TestSize.Level1)
393 {
394     MockSecurityCollectorManagerCallbackStub stub;
395     MessageParcel datas;
396     MessageParcel reply;
397     MessageOption option;
398     uint32_t code = 0;
399     int64_t eventId = 0;
400     std::string string = "test";
401     std::vector<std::string> vec ={{"1111111111"}, "222222222"};
402     int ret = stub.OnRemoteRequest(code, datas, reply, option);
403     EXPECT_TRUE(ret == NO_PERMISSION);
404     datas.WriteInterfaceToken(ISecurityCollectorManagerCallback::GetDescriptor());
405     ret = stub.OnRemoteRequest(code, datas, reply, option);
406     EXPECT_FALSE(ret == SUCCESS);
407     datas.WriteInterfaceToken(ISecurityCollectorManagerCallback::GetDescriptor());
408     datas.WriteInt64(eventId);
409     datas.WriteString(string);
410     datas.WriteString(string);
411     datas.WriteString(string);
412     datas.WriteUint32(static_cast<uint32_t>(vec.size()));
413     for (auto iter : vec) {
414         datas.WriteString(iter);
415     }
416     ret = stub.OnRemoteRequest(SecurityCollectorManagerCallbackStub::CMD_COLLECTOR_NOTIFY, datas, reply, option);
417     EXPECT_TRUE(ret == SUCCESS);
418 }
419 
420 HWTEST_F(InnerApiCollectorTest, SecurityCollectorManagerProxyTest001, testing::ext::TestSize.Level1)
421 {
422     sptr<IRemoteObject> obj(new (std::nothrow) MockRemoteObject());
423     sptr<Security::SecurityCollector::SecurityCollectorManagerCallbackService> callback =
424         new (std::nothrow) Security::SecurityCollector::SecurityCollectorManagerCallbackService(nullptr);
425     SecurityCollectorSubscribeInfo subscribeInfo{};
426     SecurityCollectorManagerProxy proxy{obj};
427     std::vector<SecurityEventRuler> rulers{};
428     std::vector<SecurityEvent> events{};
429     int ret = proxy.Subscribe(subscribeInfo, callback);
430     EXPECT_TRUE(ret == SUCCESS);
431     ret = proxy.Unsubscribe(callback);
432     EXPECT_TRUE(ret == SUCCESS);
433     ret = proxy.CollectorStart(subscribeInfo, callback);
434     EXPECT_TRUE(ret == SUCCESS);
435     ret = proxy.CollectorStop(subscribeInfo, callback);
436     EXPECT_TRUE(ret == SUCCESS);
437     ret = proxy.QuerySecurityEvent(rulers, events);
438     EXPECT_FALSE(ret == SUCCESS);
439 }
440 
441 HWTEST_F(InnerApiCollectorTest, SecurityCollectorSubscribeInfoTest001, testing::ext::TestSize.Level1)
442 {
443     std::string string = "test";
444     int64_t int64 = 0;
445     SecurityCollectorSubscribeInfo info;
446     Parcel parcel;
447     bool ret = info.Marshalling(parcel);
448     EXPECT_TRUE(ret);
449     SecurityCollectorSubscribeInfo *retInfo = info.Unmarshalling(parcel);
450     EXPECT_FALSE(retInfo == nullptr);
451     ret = info.ReadFromParcel(parcel);
452     EXPECT_FALSE(ret);
453 
454     parcel.WriteInt64(int64);
455     ret = info.ReadFromParcel(parcel);
456     EXPECT_FALSE(ret);
457 
458     parcel.WriteInt64(int64);
459     parcel.WriteBool(true);
460     ret = info.ReadFromParcel(parcel);
461     EXPECT_FALSE(ret);
462 
463     parcel.WriteInt64(int64);
464     parcel.WriteBool(true);
465     parcel.WriteInt64(int64);
466     ret = info.ReadFromParcel(parcel);
467     EXPECT_FALSE(ret);
468 
469     parcel.WriteInt64(int64);
470     parcel.WriteBool(true);
471     parcel.WriteInt64(int64);
472     parcel.WriteString(string);
473     ret = info.ReadFromParcel(parcel);
474     EXPECT_FALSE(ret);
475 
476     parcel.WriteInt64(int64);
477     parcel.WriteBool(true);
478     parcel.WriteInt64(int64);
479     parcel.WriteString(string);
480     parcel.WriteString(string);
481     ret = info.ReadFromParcel(parcel);
482     EXPECT_FALSE(ret);
483 
484     parcel.WriteInt64(int64);
485     parcel.WriteBool(true);
486     parcel.WriteInt64(int64);
487     parcel.WriteString(string);
488     parcel.WriteString(string);
489     parcel.WriteString(string);
490     parcel.WriteString(string);
491     ret = info.ReadFromParcel(parcel);
492     EXPECT_TRUE(ret);
493 
494     retInfo = info.Unmarshalling(parcel);
495     EXPECT_TRUE(retInfo == nullptr);
496 }
497 
498 HWTEST_F(InnerApiCollectorTest, SecurityEventTest001, testing::ext::TestSize.Level1)
499 {
500     std::string string = "test";
501     int64_t int64 = 0;
502     SecurityEvent event;
503     Parcel parcel;
504     bool ret = event.Marshalling(parcel);
505     EXPECT_TRUE(ret);
506     SecurityEvent *retEvent = event.Unmarshalling(parcel);
507     EXPECT_FALSE(retEvent == nullptr);
508     ret = event.ReadFromParcel(parcel);
509     EXPECT_FALSE(ret);
510 
511     parcel.WriteInt64(int64);
512     ret = event.ReadFromParcel(parcel);
513     EXPECT_FALSE(ret);
514 
515     parcel.WriteInt64(int64);
516     parcel.WriteString(string);
517     ret = event.ReadFromParcel(parcel);
518     EXPECT_FALSE(ret);
519 
520     parcel.WriteInt64(int64);
521     parcel.WriteString(string);
522     parcel.WriteString(string);
523     ret = event.ReadFromParcel(parcel);
524     EXPECT_FALSE(ret);
525 
526     parcel.WriteInt64(int64);
527     parcel.WriteString(string);
528     parcel.WriteString(string);
529     parcel.WriteString(string);
530     ret = event.ReadFromParcel(parcel);
531     EXPECT_TRUE(ret);
532 
533     retEvent = event.Unmarshalling(parcel);
534     EXPECT_TRUE(retEvent == nullptr);
535 }
536 
537 HWTEST_F(InnerApiCollectorTest, SecurityEventRulerTest001, testing::ext::TestSize.Level1)
538 {
539     std::string string = "test";
540     int64_t int64 = 0;
541     SecurityEventRuler ruler;
542     Parcel parcel;
543     int ret = ruler.Marshalling(parcel);
544     EXPECT_TRUE(ret);
545     SecurityEventRuler *retRuler = ruler.Unmarshalling(parcel);
546     EXPECT_FALSE(retRuler == nullptr);
547     ret = ruler.ReadFromParcel(parcel);
548     EXPECT_FALSE(ret);
549 
550     parcel.WriteInt64(int64);
551     ret = ruler.ReadFromParcel(parcel);
552     EXPECT_FALSE(ret);
553 
554     parcel.WriteInt64(int64);
555     parcel.WriteString(string);
556     ret = ruler.ReadFromParcel(parcel);
557     EXPECT_FALSE(ret);
558 
559     parcel.WriteInt64(int64);
560     parcel.WriteString(string);
561     parcel.WriteString(string);
562     ret = ruler.ReadFromParcel(parcel);
563     EXPECT_FALSE(ret);
564 
565     parcel.WriteInt64(int64);
566     parcel.WriteString(string);
567     parcel.WriteString(string);
568     parcel.WriteString(string);
569     ret = ruler.ReadFromParcel(parcel);
570     EXPECT_TRUE(ret);
571 
572     retRuler = ruler.Unmarshalling(parcel);
573     EXPECT_TRUE(retRuler == nullptr);
574 }
575 
576 HWTEST_F(InnerApiCollectorTest, SecurityEventQueryCallbackServiceTest001, testing::ext::TestSize.Level1)
577 {
578     std::shared_ptr<MockSecurityEventQueryCallback> callback = std::make_shared<MockSecurityEventQueryCallback>();
579     SecurityEventQueryCallbackService service(nullptr);
580     std::string message = "message";
581     std::vector<SecurityEvent> events;
582     service.OnQuery(events);
583     EXPECT_EQ(events.size(), 0);
584     service.OnComplete();
585     service.OnError(message);
586     EXPECT_EQ(message, "message");
587     SecurityEventQueryCallbackService service2(callback);
588     service2.OnQuery(events);
589     EXPECT_EQ(events.size(), 0);
590     service2.OnComplete();
591     service2.OnError(message);
592     EXPECT_EQ(message, "message");
593 }
594 
595 HWTEST_F(InnerApiCollectorTest, SecurityEventQueryCallbackTest001, testing::ext::TestSize.Level1)
596 {
597     MockSecurityEventQueryCallbackStub stub;
598     MessageParcel data;
599     MessageParcel reply;
600     MessageOption option;
601     int32_t ret = stub.OnRemoteRequest(0, data, reply, option);
602     EXPECT_EQ(ret, SecurityGuard::NO_PERMISSION);
603     data.WriteInterfaceToken(SecurityEventQueryCallbackStub::GetDescriptor());
604     ret = stub.OnRemoteRequest(0, data, reply, option);
605     EXPECT_FALSE(ret == SecurityGuard::SUCCESS);
606 
607     data.WriteInterfaceToken(SecurityEventQueryCallbackStub::GetDescriptor());
608     ret = stub.OnRemoteRequest(SecurityEventQueryCallbackStub::CMD_ON_QUERY, data, reply, option);
609     EXPECT_EQ(ret, SecurityGuard::BAD_PARAM);
610 
611     data.WriteInterfaceToken(SecurityEventQueryCallbackStub::GetDescriptor());
612     data.WriteUint32(1);
613     ret = stub.OnRemoteRequest(SecurityEventQueryCallbackStub::CMD_ON_QUERY, data, reply, option);
614     EXPECT_EQ(ret, SecurityGuard::BAD_PARAM);
615 
616     data.WriteInterfaceToken(SecurityEventQueryCallbackStub::GetDescriptor());
617     data.WriteUint32(MAX_QUERY_EVENT_SIZE + 1);
618     ret = stub.OnRemoteRequest(SecurityEventQueryCallbackStub::CMD_ON_QUERY, data, reply, option);
619     EXPECT_EQ(ret, SecurityGuard::BAD_PARAM);
620 
621     data.WriteInterfaceToken(SecurityEventQueryCallbackStub::GetDescriptor());
622     ret = stub.OnRemoteRequest(SecurityEventQueryCallbackStub::CMD_ON_COMPLETE, data, reply, option);
623     EXPECT_EQ(ret, SecurityGuard::SUCCESS);
624 
625     data.WriteInterfaceToken(SecurityEventQueryCallbackStub::GetDescriptor());
626     stub.OnRemoteRequest(SecurityEventQueryCallbackStub::CMD_ON_ERROR, data, reply, option);
627     EXPECT_EQ(ret, SecurityGuard::SUCCESS);
628 }
629 
630 }