1 /***************************************************************************
2 * Copyright 1995 Michael Veksler. mveksler@vnet.ibm.com
3 ***************************************************************************
5 * Purpose : test generic_hash correctness.
7 * This code covers only about 80% of generic_hash code.
8 * There might be bugs in the remaining 20% - although most
9 * of the functionality is tested with wine linckage.
10 * For complete testing a little more work should be done.
11 ***************************************************************************
17 #include "generic_hash.h"
20 typedef struct { int a
,b
;} DATA
;
25 HASH_CONTAINER
*hash1
;
26 HASH_CONTAINER
*hash2
; /* actual data is shared with hash1 */
28 /* test insertion using keys[] and data[] inserting using hash1 and */
29 /* hash2 periodically, test hash after every 2 insertions */
35 printf("testing insertion \n");
36 for (i
=0 ; i
< SIZE
-1 ; i
+=2) {
37 assert(hash_add_item(hash1
, keys
[i
], (HASH_VAL
*)&data
[i
]));
38 assert(hash_add_item(hash2
, keys
[i
+1], (HASH_VAL
*)&data
[i
+1]));
39 for (j
=0 ; j
<= i
+1 ; j
++) {
40 item
= hash_locate_item(hash1
, keys
[j
], (HASH_VAL
*)&data
[j
]);
42 printf("NULL item: i=%d,j=%d\n",i
,j
);
46 if (memcmp(item
,&data
[j
],sizeof(DATA
))!=0) {
47 printf("i=%d,j=%d\n",i
,j
);
48 printf("saved=(%d,%d), orig=(%d,%d)\n",
49 ((DATA
*)item
)->a
, ((DATA
*)item
)->b
,
50 data
[j
].a
, data
[j
].b
);
56 /* test deletion using keys[] and data[] deleting using hash1 and */
57 /* hash2 periodicly, test hash after every 2 deletions */
63 printf("testing deletion\n");
64 for (i
=0 ; i
< SIZE
-1 ; i
+=2) {
65 assert(hash_delete_item(hash2
, keys
[i
], NULL
));
66 assert(hash_delete_item(hash1
, keys
[i
+1], NULL
));
67 for (j
=0 ; j
< SIZE
; j
++) {
68 item
= hash_locate_item(hash2
, keys
[j
], (HASH_VAL
*)&data
[j
]);
71 printf("NULL item: i=%d,j=%d\n",i
,j
);
74 if (item
!= NULL
&& j
<= i
+1) {
75 printf("Non NULL item: i=%d,j=%d\n",i
,j
);
78 if (memcmp(item
,&data
[j
],sizeof(DATA
))!=0) {
79 printf("i=%d,j=%d\n",i
,j
);
80 printf("saved=(%d,%d), orig=(%d,%d)\n",
81 ((DATA
*)item
)->a
, ((DATA
*)item
)->b
,
82 data
[j
].a
, data
[j
].b
);
94 hash1
= create_hash(sizeof(DATA
), 1);
96 hash2
= attach_remote_hash(hash1
->shared
, sizeof(DATA
), HASH_MEM_ACCESS
);
99 for (i
=0 ; i
< SIZE
; i
++) {
108 hash1
= attach_remote_hash(hash2
->shared
, sizeof(DATA
), HASH_MEM_ACCESS
);
115 printf("peeks=%d\n", peeks
);