1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 #include "oic_malloc.h"
26 #include "gtest/gtest.h"
27 #include <sys/types.h>
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
48 static uint8_t *pBuffer;
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
54 TEST(OICMalloc, MallocPass1)
56 // Try to allocate a small buffer
57 pBuffer = (uint8_t *)OICMalloc(1);
62 TEST(OICMalloc, MallocPass2)
64 // Try to allocate a small buffer
65 pBuffer = (uint8_t *)OICMalloc(128);
70 TEST(OICMalloc, MallocFail1)
72 // Try to allocate a buffer of size 0
73 pBuffer = (uint8_t *)OICMalloc(0);
74 EXPECT_TRUE(NULL == pBuffer);
78 TEST(OICMalloc, MallocFail2)
80 // Try to allocate a ridiculous amount of RAM
81 pBuffer = (uint8_t *)OICMalloc((size_t)0x7FFFFFFFFFFFFFFF);
82 EXPECT_TRUE(NULL == pBuffer);
86 TEST(OICCalloc, CallocPass1)
88 // Try to allocate a small buffer
89 pBuffer = (uint8_t *)OICCalloc(1, 1);
94 TEST(OICCalloc, CallocPass2)
96 // Try to allocate a small buffer
97 pBuffer = (uint8_t *)OICCalloc(1, 128);
102 TEST(OICCalloc, CallocPass3)
104 // Try to allocate a buffer for an array
105 pBuffer = (uint8_t *)OICCalloc(5, 128);
106 EXPECT_TRUE(pBuffer);
110 TEST(OICCalloc, CallocFail1)
112 // Try to allocate a buffer of size 0
113 pBuffer = (uint8_t *)OICCalloc(1, 0);
114 EXPECT_TRUE(NULL == pBuffer);
118 TEST(OICCalloc, CallocFail2)
120 // Try to allocate a buffer with num of 0
121 pBuffer = (uint8_t *)OICCalloc(0, 5);
122 EXPECT_TRUE(NULL == pBuffer);
126 TEST(OICCalloc, CallocFail3)
128 // Try to allocate a buffer with size and num 0
129 pBuffer = (uint8_t *)OICCalloc(0, 0);
130 EXPECT_TRUE(NULL == pBuffer);
134 TEST(OICCalloc, CallocFail4)
136 // Try to allocate a ridiculous amount of RAM
137 pBuffer = (uint8_t *)OICCalloc(1, (size_t)0x7FFFFFFFFFFFFFFF);
138 EXPECT_TRUE(NULL == pBuffer);