1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1999-2013 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Eclipse Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
8 * *
9 * A copy of the License is available at *
10 * http://www.eclipse.org/org/documents/epl-v10.html *
11 * (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12 * *
13 * Information and Software Systems Research *
14 * AT&T Research *
15 * Florham Park NJ *
16 * *
17 * Glenn Fowler <glenn.s.fowler@gmail.com> *
18 * *
19 ***********************************************************************/
20 #include "dttest.h"
21
22 /* test the various insertion strategies */
23
24 typedef struct _obj_s
25 { Dtlink_t link;
26 int key;
27 } Obj_t;
28
intcompare(Dt_t * dt,Void_t * arg1,Void_t * arg2,Dtdisc_t * disc)29 static int intcompare(Dt_t* dt, Void_t* arg1, Void_t* arg2, Dtdisc_t* disc)
30 {
31 int *o1 = (int*)arg1;
32 int *o2 = (int*)arg2;
33 return *o1 - *o2;
34 }
35
36 Dtdisc_t Disc =
37 { DTOFFSET(Obj_t, key), sizeof(int),
38 DTOFFSET(Obj_t, link),
39 0, 0, intcompare, 0, 0, 0
40 };
41
tmain()42 tmain()
43 {
44 Obj_t obj, chk1, chk2, chk22;
45 Dt_t *dt;
46
47 obj.key = 1;
48 chk1.key = 1;
49 chk2.key = 2;
50 chk22.key = 2;
51
52 if(!(dt = dtopen(&Disc, Dtoset)) )
53 terror("Can't open Dtoset dictionary");
54 if(dtinsert(dt, &obj) != &obj)
55 terror("dtinsert failed");
56 if(dtinsert(dt, &chk1) != &obj)
57 terror("dtinsert should have returned obj");
58 if(dtinsert(dt, &chk2) != &chk2)
59 terror("dtinsert should have returned chk2");
60 if(dtinstall(dt, &chk1) != &chk1)
61 terror("dtinstall should have returned chk1");
62
63 if(!(dt = dtopen(&Disc, Dtobag)) )
64 terror("Can't open Dtobag dictionary");
65 if(dtinsert(dt, &obj) != &obj)
66 terror("dtinsert failed");
67 if(dtinsert(dt, &chk1) != &chk1)
68 terror("dtinsert should have returned chk1");
69 if(dtinsert(dt, &chk2) != &chk2)
70 terror("dtinsert should have returned chk2");
71 if(dtinstall(dt, &chk1) != &chk1)
72 terror("dtinsert should have returned chk1");
73 if(dtinstall(dt, &chk22) != &chk22)
74 terror("dtinsert should have returned chk22");
75
76 if(!(dt = dtopen(&Disc, Dtset)) )
77 terror("Can't open Dtset dictionary");
78 if(dtinsert(dt, &obj) != &obj)
79 terror("dtinsert failed");
80 if(dtinsert(dt, &chk1) != &obj)
81 terror("dtinsert should have returned obj");
82 if(dtinsert(dt, &chk2) != &chk2)
83 terror("dtinsert should have returned chk2");
84 if(dtinstall(dt, &chk1) != &chk1)
85 terror("dtinsert should have returned chk1");
86
87 if(!(dt = dtopen(&Disc, Dtbag)) )
88 terror("Can't open Dtbag dictionary");
89 if(dtinsert(dt, &obj) != &obj)
90 terror("dtinsert failed");
91 if(dtinsert(dt, &chk1) != &chk1)
92 terror("dtinsert should have returned chk1");
93 if(dtinsert(dt, &chk2) != &chk2)
94 terror("dtinsert should have returned chk2");
95 if(dtinstall(dt, &chk1) != &chk1)
96 terror("dtinsert should have returned chk1");
97 if(dtinstall(dt, &chk22) != &chk22)
98 terror("dtinsert should have returned chk22");
99
100 if(!(dt = dtopen(&Disc, Dtrhset)) )
101 terror("Can't open Dtrhset dictionary");
102 if(dtinsert(dt, &obj) != &obj)
103 terror("dtinsert failed");
104 if(dtinsert(dt, &chk1) != &obj)
105 terror("dtinsert should have returned obj");
106 if(dtinsert(dt, &chk2) != &chk2)
107 terror("dtinsert should have returned chk2");
108 if(dtinstall(dt, &chk1) != &chk1)
109 terror("dtinsert should have returned chk1");
110
111 if(!(dt = dtopen(&Disc, Dtrhbag)) )
112 terror("Can't open Dtrhbag dictionary");
113 if(dtinsert(dt, &obj) != &obj)
114 terror("dtinsert failed");
115 if(dtinsert(dt, &chk1) != &chk1)
116 terror("dtinsert should have returned chk1");
117 if(dtinsert(dt, &chk2) != &chk2)
118 terror("dtinsert should have returned chk2");
119 if(dtinstall(dt, &chk1) != &chk1)
120 terror("dtinsert should have returned chk1");
121 if(dtinstall(dt, &chk22) != &chk22)
122 terror("dtinsert should have returned chk22");
123
124 texit(0);
125 }
126