2017-12-24 19:06:58 +03:00
|
|
|
/*
|
|
|
|
author: Christian Bender
|
|
|
|
This is a simple test program for the dictionary.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
/* includes the dictionary */
|
|
|
|
#include "dict.h"
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2020-05-29 23:23:24 +03:00
|
|
|
Dictionary *testObj1;
|
|
|
|
Dictionary *testObj2;
|
2017-12-24 19:06:58 +03:00
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
int value = 28;
|
2017-12-24 19:06:58 +03:00
|
|
|
|
|
|
|
testObj1 = create_dict();
|
|
|
|
testObj2 = create_dict();
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
add_item_label(testObj1, "age", &value);
|
|
|
|
add_item_label(testObj2, "name", "Christian");
|
2017-12-24 19:06:58 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
test for function add_item_label
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
attention:
|
|
|
|
The void* pointer must be convert into an int* pointer.
|
2017-12-24 19:06:58 +03:00
|
|
|
After that you can dereference it.
|
|
|
|
*/
|
2020-05-29 23:23:24 +03:00
|
|
|
printf("My age is %d\n", *((int *)get_element_label(testObj1, "age")));
|
|
|
|
printf("My name is %s\n", get_element_label(testObj2, "name"));
|
2017-12-24 19:06:58 +03:00
|
|
|
|
|
|
|
/* test for function add_item_index */
|
2020-05-29 23:23:24 +03:00
|
|
|
if (!add_item_index(testObj1, 0, &value))
|
2017-12-24 19:06:58 +03:00
|
|
|
{
|
2020-05-29 23:23:24 +03:00
|
|
|
printf("My age at index %d is %d\n", 0,
|
|
|
|
*((int *)get_element_index(testObj1, 0)));
|
2017-12-24 19:06:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* error scenario */
|
|
|
|
/* get_element_label(testObj,"none"); */
|
|
|
|
|
|
|
|
/* tidy up */
|
|
|
|
destroy(testObj1);
|
|
|
|
destroy(testObj2);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|