Initial import to Tizen
[profile/ivi/sphinxbase.git] / test / unit / test_hash / deletehash.c
1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include <hash_table.h>
6 #include <err.h>
7
8 /* Explore a more complicated case for deletion */
9 int
10 main(int argc, char **argv)
11 {
12     hash_table_t *ht;
13     void *val;
14
15     if (argc != 2) {
16         printf("deletehash <key>\n");
17         exit(-1);
18     }
19
20     ht = hash_table_new(75, 0);
21
22     if (hash_table_enter(ht, "-hmmdump", (void *)1) != (void *)1) {
23         E_FATAL("Insertion of -hmmdump failed\n");
24     }
25
26     if (hash_table_enter(ht, "-svq4svq", (void *)2) != (void *)2) {
27         E_FATAL("Insertion of -svq4svq failed\n");
28     }
29
30     if (hash_table_enter(ht, "-outlatdir", (void *)3) != (void *)3) {
31         E_FATAL("Insertion of -svq4svq failed\n");
32     }
33
34     if (hash_table_enter(ht, "-lm", (void *)4) != (void *)4) {
35         E_FATAL("Insertion of -lm failed\n");
36     }
37
38     if (hash_table_enter(ht, "-beam", (void *)5) != (void *)5) {
39         E_FATAL("Insertion of -beam failed\n");
40     }
41
42     if (hash_table_enter(ht, "-lminmemory", (void *)6) != (void *)6) {
43         E_FATAL("Insertion of -lminmemory failed\n");
44     }
45
46     if (hash_table_enter(ht, "-subvq", (void *)7) != (void *)7) {
47         E_FATAL("Insertion of -outlatdir failed\n");
48     }
49
50     if (hash_table_enter(ht, "-bla", (void *)8) != (void *)8) {
51         E_FATAL("Insertion of -bla failed\n");
52     }
53
54     /*  hash_table_display(ht,1); */
55     if (hash_table_delete(ht, argv[1]) == NULL) {
56         E_INFOCONT("Failed as expected\n");
57         return 0;
58     }
59     else {
60         hash_table_display(ht, 1);
61     }
62
63     /* Test emptying */
64     hash_table_empty(ht);
65     if (hash_table_lookup(ht, "-beam", &val) == 0) {
66         E_FATAL("Emptying hash table failed\n");
67     }
68
69     hash_table_free(ht);
70     ht = NULL;
71     return 0;
72 }
73
74
75 #if 0
76 E_INFO("Hash table in the command line\n");
77 hash_table_display(ht, 1);
78
79 E_INFO("After deletion of -lm\n");
80 hash_table_delete(ht, "-lm");
81 hash_table_display(ht, 1);
82
83 E_INFO("After deletion of -lm\n");
84
85 hash_table_delete(ht, "-lm");
86 hash_table_display(ht, 1);
87
88 E_INFO("After deletion of -svq4svq\n");
89 hash_table_delete(ht, "-svq4svq");
90 hash_table_display(ht, 1);
91
92 E_INFO("After deletion of -beam\n");
93 hash_table_delete(ht, "-beam");
94 hash_table_display(ht, 1);
95 #endif