-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
45 lines (35 loc) · 1.25 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
// SPDX-License-Identifier: GPL-3.0-or-later
#include "array-list.h"
#include <assert.h>
#include <string.h>
struct symbol {
long location;
char *a_or_label_value;
};
void add_from_other_function(struct array_list *list) {
array_list_push(list, "does this work?");
struct symbol *please = malloc(sizeof(struct symbol));
please->location = 5;
please->a_or_label_value = strdup("cool cool col cool");
array_list_push(list, please);
}
int main() {
struct array_list list = array_list_create(1);
assert(list.capacity != 0);
assert(array_list_push(&list, "wow") == true);
assert(array_list_push(&list, 0) == true);
assert(array_list_push(&list, "uhh oh") == true);
add_from_other_function(&list);
assert(strcmp((char *)array_list_get(list, 3), "does this work?") == 0);
struct symbol *received = array_list_get(list, 4);
assert(strcmp(received->a_or_label_value, "cool cool col cool") == 0);
assert(received->location == 5);
free(received->a_or_label_value);
free(received);
assert(strcmp((char *)array_list_get(list, 0), "wow") == 0);
assert(array_list_remove(&list, 2) == true);
assert(array_list_push(&list, "okay") == true);
assert(array_list_remove(&list, 0) == true);
array_list_free(&list);
return EXIT_SUCCESS;
}