]> jfr.im git - irc/quakenet/snircd.git/blob - libs/dbprim/tests/t_le_init.c
ircu2.10.12.06
[irc/quakenet/snircd.git] / libs / dbprim / tests / t_le_init.c
1 /*
2 ** Copyright (C) 2002 by Kevin L. Mitchell <klmitch@mit.edu>
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Library General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2 of the License, or (at your option) any later version.
8 **
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Library General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Library General Public
15 ** License along with this library; if not, write to the Free
16 ** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
17 ** MA 02111-1307, USA
18 **
19 ** @(#)$Id: t_le_init.c,v 1.1 2003/03/07 02:36:11 klmitch Exp $
20 */
21 #include <stdio.h>
22
23 #include "dbprim.h"
24
25 #define OBJECT (void *)0x91827364
26 #define DEADINT 0xdeadbeef
27 #define DEADPTR (void *)0xdeadbeef
28
29 static void
30 check_init(link_elem_t *elem, char *how)
31 {
32 if (elem->le_magic != LINK_ELEM_MAGIC) /* Verify magic was set */
33 printf("FAIL/%s_magic:Initialization failed to set magic number\n", how);
34 else
35 printf("PASS/%s_magic:Initialization set magic number properly\n", how);
36
37 if (elem->le_next != 0) /* verify next was set properly */
38 printf("FAIL/%s_next:Initialization failed to clear next\n", how);
39 else
40 printf("PASS/%s_next:Initialization set next to 0\n", how);
41
42 if (elem->le_prev != 0) /* verify prev was set properly */
43 printf("FAIL/%s_prev:Initialization failed to clear prev\n", how);
44 else
45 printf("PASS/%s_prev:Initialization set prev to 0\n", how);
46
47 if (elem->le_object != OBJECT) /* verify object was set properly */
48 printf("FAIL/%s_object:Initialization failed to set object\n", how);
49 else
50 printf("PASS/%s_object:Initialization set object properly\n", how);
51
52 if (elem->le_head != 0) /* verify head was set properly */
53 printf("FAIL/%s_head:Initialization failed to clear head\n", how);
54 else
55 printf("PASS/%s_head:Initialization set head to 0\n", how);
56
57 if (elem->le_flags != 0) /* verify flags were set properly */
58 printf("FAIL/%s_flags:Initialization failed to clear flags\n", how);
59 else
60 printf("PASS/%s_flags:Initialization set flags to 0\n", how);
61 }
62
63 int
64 main(int argc, char **argv)
65 {
66 unsigned long errcode;
67 link_elem_t elem = LINK_ELEM_INIT(OBJECT);
68
69 /* Check that the static initializer produces a passable structure */
70 check_init(&elem, "le_static");
71
72 /* now, check what le_init does with bad arguments */
73 if ((errcode = le_init(0, 0)) == DB_ERR_BADARGS)
74 printf("PASS/le_init_nothing:le_init(0, 0) returns "
75 "DB_ERR_BADARGS\n");
76 else
77 printf("FAIL/le_init_nothing:le_init(0, 0) returned "
78 "%lu instead of DB_ERR_BADARGS\n", errcode);
79 if ((errcode = le_init(0, OBJECT)) == DB_ERR_BADARGS)
80 printf("PASS/le_init_objectonly:le_init(0, OBJECT) returns "
81 "DB_ERR_BADARGS\n");
82 else
83 printf("FAIL/le_init_objectonly:le_init(0, OBJECT) returned "
84 "%lu instead of DB_ERR_BADARGS\n", errcode);
85 if ((errcode = le_init(&elem, 0)) == DB_ERR_BADARGS)
86 printf("PASS/le_init_elemonly:le_init(&elem, 0) returns "
87 "DB_ERR_BADARGS\n");
88 else
89 printf("FAIL/le_init_elemonly:le_init(&elem, 0) returned "
90 "%lu instead of DB_ERR_BADARGS\n", errcode);
91
92 /* Scramble the structure */
93 elem.le_magic = DEADINT;
94 elem.le_next = DEADPTR;
95 elem.le_prev = DEADPTR;
96 elem.le_object = DEADPTR;
97 elem.le_head = DEADPTR;
98 elem.le_flags = DEADINT;
99
100 /* Now try to initialize our structure and see what happens */
101 if ((errcode = le_init(&elem, OBJECT))) {
102 printf("FAIL/le_dynamic:le_init(&elem) returned failure (%lu)\n",
103 errcode);
104 return 0;
105 } else
106 printf("PASS/le_dynamic:le_init(&elem) returned success\n");
107
108 /* Finally, verify initialization */
109 check_init(&elem, "le_dynamic");
110
111 return 0;
112 }