-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
84 lines (65 loc) · 1.39 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
#include <stdlib.h>
#include "mymalloc.h"
#include "mymalloc.c"
#include "GUIView.c"
int *array;
int* malloc_test(int *array, int size)
{
int *newArray = mymalloc(array, size);
if (newArray == (int *)0)
{
printf("mymalloc couldn't give array of size %d\n", size);
return (int *)0;
}
for (int i = 0; i < size; i++)
{
newArray[i] = 999;
}
return newArray;
}
int free_test(int *array, int *block, int size)
{
for (int i = 0; i < size; i++)
{
block[i] = 0;
}
return myfree(array, block);
}
void show_array()
{
for (int i = 0; i < 100; i++)
{
printf("%d: %d\n", i, array[i]);
}
}
void init(int size)
{
array = malloc(size * sizeof(int));
if (!myinit(array, size))
{
printf("!!! myinit() failed !!!\n");
}
if (!mydispose(array))
{
printf("!!! mydispose() failed after myinit() !!!\n");
}
//Test with another random array to make sure we don't have false
//positives
int *otherArray = malloc(sizeof(int));
if (mydispose(otherArray))
{
printf("!!! mydispose() returing false positive !!!\n");
}
free(otherArray);
}
int main()
{
init(50);
int *p = malloc_test(array, 5);
malloc_test(array, 10);
free_test(array, p, 5);
malloc_test(array, 4);
gui_show_array(array);
return 0;
}