-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
test_program.c
49 lines (37 loc) · 1.07 KB
/
test_program.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
/*
author: Christian Bender
This is a simple test program for the dictionary.
*/
#include <stdio.h>
/* includes the dictionary */
#include "dict.h"
int main(void)
{
Dictionary *testObj1;
Dictionary *testObj2;
int value = 28;
testObj1 = create_dict();
testObj2 = create_dict();
add_item_label(testObj1, "age", &value);
add_item_label(testObj2, "name", "Christian");
/*
test for function add_item_label
attention:
The void* pointer must be convert into an int* pointer.
After that you can dereference it.
*/
printf("My age is %d\n", *((int *)get_element_label(testObj1, "age")));
printf("My name is %s\n", get_element_label(testObj2, "name"));
/* test for function add_item_index */
if (!add_item_index(testObj1, 0, &value))
{
printf("My age at index %d is %d\n", 0,
*((int *)get_element_index(testObj1, 0)));
}
/* error scenario */
/* get_element_label(testObj,"none"); */
/* tidy up */
destroy(testObj1);
destroy(testObj2);
return 0;
}