OSDN Git Service

code clean.
[putex/putex.git] / src / texsourc / libavl / libavl / unitTests / avl_test01.c
1 /*
2  *   Libavl is a library to manage AVL structure to store and organize
3  *   everykind of data. You just need to implement function to compare,
4  *   to desallocate and to print your structure.
5  *
6  *       DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 
7  *                   Version 2, December 2004 
8  *
9  *   Copyright (C) 2013 Adrien Oliva <adrien.oliva@yapbreak.fr>
10  *
11  *   Everyone is permitted to copy and distribute verbatim or modified 
12  *   copies of this license document, and changing it is allowed as long 
13  *   as the name is changed. 
14  *
15  *           DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 
16  *   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 
17  *
18  *   0. You just DO WHAT THE FUCK YOU WANT TO.
19  */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23
24 #include "../syslog.h"
25 #include "../avl.h"
26
27 int data_cmp(void *a, void *b)
28 {
29     return (int) ((char *) a - (char *) b);
30 }
31
32 void data_print(void *d)
33 {
34     printf("%p", d);
35 }
36
37 void data_delete(void *d)
38 {
39     (void) d;
40 }
41
42 char *alloc_tests()
43 {
44     tree *first = NULL;
45
46     // Try to allocate a new tree.
47     first = init_dictionnary(data_cmp, data_print, data_delete, NULL);
48     if (first == NULL) {
49         ELOG("Init dictionnary error");
50         return "Init dictionnary error";
51     }
52     if (sizeof(*first) != sizeof(tree)) {
53         ELOG("Wrong returned size");
54         return "Wrong returned size";
55     }
56
57     // Try to delete it
58     delete_tree(first);
59
60     // Try to delete a null tree
61     delete_tree(NULL);
62
63
64     return NULL;
65 }