* contrib/vmlog: Committed vmlog 0.0.5.
[cacao.git] / contrib / vmlog / t / string.c
1 #include "t/prolog.h"
2
3 static int destruct_counter = 0;
4 static int destruct_len = 0;
5
6 static void test_destuctor(vmlog_hash_entry *entry) {
7         if (entry->data) {
8                 destruct_counter++;
9                 destruct_len += entry->len;
10         }
11         else {
12                 IS(entry->len,0);
13                 IS(entry->index,0);
14         }
15 }
16
17 int main(int argc,char **argv) 
18 {
19         vmlog_log *vml;
20         int i;
21         int r;
22         int fd;
23         struct stat st;
24         int cumlen;
25
26         vml = vmlog_log_new(NULL,1);
27         NOTNULL(vml);
28
29         vmlog_file_open(&(vml->idxfile),"TESTIDX",vmlogTruncateAppend);
30         vmlog_file_open(&(vml->strfile),"TESTSTR",vmlogTruncateAppend);
31
32         cumlen = 0;
33         i = vmlog_get_string_index(vml,"foo",3);
34         IS(i,0);
35         IS(vml->stringhash.nentries,1);
36         cumlen += 3;
37
38         i = vmlog_get_string_index(vml,"foo",3);
39         IS(i,0);
40         IS(vml->stringhash.nentries,1);
41
42         i = vmlog_get_string_index(vml,"bar",3);
43         IS(i,1);
44         IS(vml->stringhash.nentries,2);
45         cumlen += 3;
46
47         i = vmlog_get_string_index(vml,"foo",3);
48         IS(i,0);
49         IS(vml->stringhash.nentries,2);
50
51         i = vmlog_get_string_index(vml,"",0);
52         IS(i,2);
53         IS(vml->stringhash.nentries,3);
54
55         i = vmlog_get_string_index(vml,"",0);
56         IS(i,2);
57         IS(vml->stringhash.nentries,3);
58
59         vmlog_hashtable_free(&(vml->stringhash),test_destuctor);
60         IS(destruct_counter,3);
61
62         vmlog_file_close(&(vml->idxfile));
63         vmlog_file_close(&(vml->strfile));
64
65         fd = open("TESTIDX",O_RDONLY);
66         TRUE(fd != -1);
67         r = fstat(fd,&st);
68         IS(st.st_size,3*sizeof(vmlog_string_entry));
69         close(fd);
70
71         fd = open("TESTSTR",O_RDONLY);
72         TRUE(fd != -1);
73         r = fstat(fd,&st);
74         IS(st.st_size,cumlen);
75         close(fd);
76
77         return 0;
78 }
79
80 /* vim: noet ts=8 sw=8
81  */
82
83