1 
2 /*
3  * Copyright (c) 2022 Huawei Device Co., Ltd.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "dslm_memory_mock.h"
18 
19 #include <malloc.h>
20 
21 namespace OHOS {
22 namespace Security {
23 namespace DslmUnitTest {
24 
Malloc(size_t size)25 void *MockMalloc::Malloc(size_t size)
26 {
27     return malloc(size);
28 }
29 
Free(void * memory)30 void MockFree::Free(void *memory)
31 {
32     return free(memory);
33 }
34 } // namespace DslmUnitTest
35 } // namespace Security
36 } // namespace OHOS
37 
38 extern "C" {
39 using namespace OHOS::Security::DslmUnitTest;
40 
41 // mock the UtilsMalloc, and routing to MockMalloc::Malloc
42 IMPLEMENT_FUNCTION_WITH_INVOKER(MockMalloc, void *, UtilsMalloc, (size_t size), MockMalloc::Malloc);
43 
44 // mock the UtilsFree, and routing to MockFree::Free
45 IMPLEMENT_FUNCTION_WITH_INVOKER(MockFree, void, UtilsFree, (void *memory), MockFree::Free);
46 
47 // mock the strcpy_s, and routing to the real strcpy_s function
48 IMPLEMENT_FUNCTION(MockStrcpy, errno_t, strcpy_s, (char *strDest, size_t destMax, const char *strSrc));
49 }