2 * Copyright (c) 2012 Your File System Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #include <afsconfig.h>
26 #include <afs/param.h>
28 #include <tests/tap/basic.h>
37 find(struct opr_dict *dict, int value, struct myentry **entryp)
40 struct opr_queue *cursor;
43 for (opr_dict_ScanBucket(dict, value, cursor)) {
44 ent = opr_queue_Entry(cursor, struct myentry, d);
47 if (ent->value == value) {
59 struct opr_dict *dict;
60 struct myentry *entry;
61 int members[] = {1,2,3,4,5,6,7,8,9,10,17,0};
66 ok(opr_dict_Init(3) == NULL,
67 "Initialising a dictionary with a bad size fails");
69 dict = opr_dict_Init(8);
71 "Initialising a dictionary succeeds");
73 for (i = 0; members[i] !=0; i++) {
74 entry = malloc(sizeof(struct myentry));
75 entry->value = members[i];
76 opr_dict_Append(dict, entry->value, &entry->d);
78 ok(1, "Hash populated successfully");
80 is_int(1, find(dict, 1, NULL),
81 "Entry 1 is first in hash chain");
82 is_int(2, find(dict, 9, NULL),
83 "Entry 9 is second in hash chain");
84 is_int(3, find(dict, 17, NULL),
85 "Entry 17 is third in hash chain");
86 is_int(1, find(dict, 2, NULL),
87 "Entry 2 is first in hash chain");
88 is_int(1, find(dict, 8, NULL),
89 "Entry 8 is first in hash chain");
91 find(dict, 17, &entry);
92 ok(entry != NULL && entry->value == 17, "Retrieved entry 17");
93 opr_dict_Promote(dict, entry->value, &entry->d);
94 is_int(1, find(dict, 17, NULL),
95 "Entry 17 is first in hash chain following promotion");