* configure.ac: New switch for disabling -O2 (--disable-optimizations).
[cacao.git] / contrib / vmlog / t / threadhash.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         vmlog_thread_log *tlog;
21         vmlog_thread_log *tlog1;
22         int i;
23         vmlog_thread_log *tlogs[100];
24
25         vml = vmlog_log_new(NULL,1);
26         NOTNULL(vml);
27
28         tlog = vmlog_get_thread_log(vml,(void*)123);
29         tlog1 = tlog;
30         NOTNULL(tlog);
31         IS(vml->threadhash.nentries,1);
32         IS(tlog->threadid,(void*)123);
33
34         tlog = vmlog_get_thread_log(vml,(void*)0);
35         NOTNULL(tlog);
36         IS(vml->threadhash.nentries,2);
37         IS(tlog->threadid,(void*)0);
38
39         tlog = vmlog_get_thread_log(vml,(void*)123);
40         NOTNULL(tlog);
41         IS(vml->threadhash.nentries,2);
42         IS(tlog,tlog1);
43         IS(tlog->threadid,(void*)123);
44
45         vmlog_hashtable_free(&(vml->threadhash),test_destuctor);
46         IS(destruct_counter,2);
47
48         vmlog_hashtable_init(&(vml->threadhash),5);
49         for (i=0; i<10; ++i) {
50                 tlog = vmlog_get_thread_log(vml,(void*)(1000+i));
51                 NOTNULL(tlog);
52                 tlogs[i] = tlog;
53         }
54         for (i=0; i<10; ++i) {
55                 tlog = vmlog_get_thread_log(vml,(void*)(1000+i));
56                 IS(tlog,tlogs[i]);
57         }
58         destruct_counter = 0;
59         vmlog_hashtable_free(&(vml->threadhash),test_destuctor);
60         IS(destruct_counter,10);
61
62         return 0;
63 }
64
65 /* vim: noet ts=8 sw=8
66  */
67
68