]>
jfr.im git - irc/quakenet/snircd.git/blob - libs/dbprim/tests/t_le_init.c
2 ** Copyright (C) 2002 by Kevin L. Mitchell <klmitch@mit.edu>
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.
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.
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,
19 ** @(#)$Id: t_le_init.c,v 1.1 2003/03/07 02:36:11 klmitch Exp $
25 #define OBJECT (void *)0x91827364
26 #define DEADINT 0xdeadbeef
27 #define DEADPTR (void *)0xdeadbeef
30 check_init(link_elem_t
*elem
, char *how
)
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
);
35 printf("PASS/%s_magic:Initialization set magic number properly\n", how
);
37 if (elem
->le_next
!= 0) /* verify next was set properly */
38 printf("FAIL/%s_next:Initialization failed to clear next\n", how
);
40 printf("PASS/%s_next:Initialization set next to 0\n", how
);
42 if (elem
->le_prev
!= 0) /* verify prev was set properly */
43 printf("FAIL/%s_prev:Initialization failed to clear prev\n", how
);
45 printf("PASS/%s_prev:Initialization set prev to 0\n", how
);
47 if (elem
->le_object
!= OBJECT
) /* verify object was set properly */
48 printf("FAIL/%s_object:Initialization failed to set object\n", how
);
50 printf("PASS/%s_object:Initialization set object properly\n", how
);
52 if (elem
->le_head
!= 0) /* verify head was set properly */
53 printf("FAIL/%s_head:Initialization failed to clear head\n", how
);
55 printf("PASS/%s_head:Initialization set head to 0\n", how
);
57 if (elem
->le_flags
!= 0) /* verify flags were set properly */
58 printf("FAIL/%s_flags:Initialization failed to clear flags\n", how
);
60 printf("PASS/%s_flags:Initialization set flags to 0\n", how
);
64 main(int argc
, char **argv
)
66 unsigned long errcode
;
67 link_elem_t elem
= LINK_ELEM_INIT(OBJECT
);
69 /* Check that the static initializer produces a passable structure */
70 check_init(&elem
, "le_static");
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 "
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 "
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 "
89 printf("FAIL/le_init_elemonly:le_init(&elem, 0) returned "
90 "%lu instead of DB_ERR_BADARGS\n", errcode
);
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
;
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",
106 printf("PASS/le_dynamic:le_init(&elem) returned success\n");
108 /* Finally, verify initialization */
109 check_init(&elem
, "le_dynamic");