1 /*
2 * Copyright (c) 2022 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 "sessioncallbackmock_fuzzer.h"
17 #include "session_callback_mock.h"
18 #include "softbus_error_code.h"
19 #include "session.h"
20 #include "session_mock.h"
21 #include <cstddef>
22 #include <cstdint>
23
24 #define SESSION_ID 1
25
26 namespace OHOS {
InnerOnSessionOpenedTest(const uint8_t * data,size_t size)27 void InnerOnSessionOpenedTest(const uint8_t* data, size_t size)
28 {
29 if ((data == nullptr) || (size == 0)) {
30 return;
31 }
32 int result = SOFTBUS_OK;
33
34 InnerOnSessionOpened(size, result);
35 }
36
InnerOnSessionClosedTest(const uint8_t * data,size_t size)37 void InnerOnSessionClosedTest(const uint8_t* data, size_t size)
38 {
39 if ((data == nullptr) || (size == 0)) {
40 return;
41 }
42
43 InnerOnSessionClosed(size);
44 }
45
InnerOnBytesReceivedTest(const uint8_t * data,size_t size)46 void InnerOnBytesReceivedTest(const uint8_t* data, size_t size)
47 {
48 if ((data == nullptr) || (size == 0)) {
49 return;
50 }
51 int sessionId = SESSION_ID;
52
53 InnerOnBytesReceived(sessionId, data, size);
54 }
55
InnerOnMessageReceivedTest(const uint8_t * data,size_t size)56 void InnerOnMessageReceivedTest(const uint8_t* data, size_t size)
57 {
58 if ((data == nullptr) || (size == 0)) {
59 return;
60 }
61 int sessionId = SESSION_ID;
62
63 InnerOnMessageReceived(sessionId, data, size);
64 }
65 } // namespace OHOS
66
67 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)68 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
69 {
70 /* Run your code on data */
71 OHOS::InnerOnSessionOpenedTest(data, size);
72 OHOS::InnerOnSessionClosedTest(data, size);
73 OHOS::InnerOnBytesReceivedTest(data, size);
74 OHOS::InnerOnMessageReceivedTest(data, size);
75 return 0;
76 }
77