• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <malloc.h>
17 #include <stdint.h>
18 #include <stdlib.h>
19 #include "functionalext.h"
20 
21 #define SIZE_ALIGN (4 * sizeof(size_t))
22 
23 const int32_t RELLOCTLEN = 100;
24 const int32_t INVALIDLEN = -100;
25 
26 /**
27  * @tc.name:      realloc_0100
28  * @tc.desc:      Verify realloc process success when first args is null second args is 50.
29  * @tc.level:     level 0.
30  */
realloc_0100(void)31 void realloc_0100(void)
32 {
33     void *ret = realloc(NULL, RELLOCTLEN);
34     EXPECT_PTRNE("realloc_0100", ret, NULL);
35 }
36 
37 /**
38  * @tc.name:      realloc_0200
39  * @tc.desc:      Verify realloc process success when first args is null second args is 0.
40  * @tc.level:     level 2
41  */
realloc_0200(void)42 void realloc_0200(void)
43 {
44     void *ret = realloc(NULL, 0);
45     EXPECT_PTRNE("realloc_0200", ret, NULL);
46 }
47 
48 /**
49  * @tc.name:      realloc_0300
50  * @tc.desc:      Verify realloc process fail when first args is null second args is -100.
51  * @tc.level:     level 2.
52  */
realloc_0300(void)53 void realloc_0300(void)
54 {
55     void *ret = realloc(NULL, INVALIDLEN);
56     EXPECT_PTREQ("realloc_0300", ret, NULL);
57 }
58 
59 /**
60  * @tc.name:      realloc_0400
61  * @tc.desc:      Verify realloc process success when first args is not null second args is 200
62  * @tc.level:     level 0.
63  */
realloc_0400(void)64 void realloc_0400(void)
65 {
66     char *cptr = (char *)malloc(RELLOCTLEN);
67     void *ret = realloc(cptr, RELLOCTLEN + RELLOCTLEN);
68     EXPECT_PTRNE("realloc_0400", ret, NULL);
69 }
70 
71 /**
72  * @tc.name:      realloc_0500
73  * @tc.desc:      Verify realloc process success when first args is not null second args is 100
74  * @tc.level:     level  1.
75  */
realloc_0500(void)76 void realloc_0500(void)
77 {
78     char *cptr = (char *)malloc(RELLOCTLEN);
79     void *ret = realloc(cptr, RELLOCTLEN);
80     EXPECT_PTRNE("realloc_0500", ret, NULL);
81 }
82 
83 /**
84  * @tc.name:      realloc_0600
85  * @tc.desc:      Verify realloc process success when first args is not null second args is 50
86  * @tc.level:     level 1.
87  */
realloc_0600(void)88 void realloc_0600(void)
89 {
90     char *cptr = (char *)malloc(RELLOCTLEN);
91     void *ret = realloc(cptr, RELLOCTLEN / 2);
92     EXPECT_PTRNE("realloc_0600", ret, NULL);
93 }
94 
main(void)95 int main(void)
96 {
97     realloc_0100();
98     realloc_0200();
99     realloc_0300();
100     realloc_0400();
101     realloc_0500();
102     realloc_0600();
103     return t_status;
104 }
105