]>
jfr.im git - irc/quakenet/snircd.git/blob - libs/dbprim/tests/t_ll_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_ll_init.c,v 1.1 2003/03/07 02:36:11 klmitch Exp $
25 #define DEADINT 0xdeadbeef
26 #define DEADPTR (void *)0xdeadbeef
29 check_init(link_head_t
*head
, char *how
)
31 if (head
->lh_magic
!= LINK_HEAD_MAGIC
) /* Verify magic was set */
32 printf("FAIL/%s_magic:Initialization failed to set magic number\n", how
);
34 printf("PASS/%s_magic:Initialization set magic number properly\n", how
);
36 if (head
->lh_count
!= 0) /* verify count was set */
37 printf("FAIL/%s_count:Initialization failed to clear count\n", how
);
39 printf("PASS/%s_count:Initialization set count to 0\n", how
);
41 if (head
->lh_first
!= 0) /* verify first was set */
42 printf("FAIL/%s_first:Initialization failed to clear first pointer\n",
45 printf("PASS/%s_first:Initialization set first pointer to 0\n", how
);
47 if (head
->lh_last
!= 0) /* verify last was set */
48 printf("FAIL/%s_last:Initialization failed to clear last pointer\n", how
);
50 printf("PASS/%s_last:Initialization set last pointer to 0\n", how
);
54 main(int argc
, char **argv
)
56 unsigned long errcode
;
57 link_head_t head
= LINK_HEAD_INIT(0);
59 /* Check that the static initializer produces a passable structure */
60 check_init(&head
, "ll_static");
62 /* now, check what ll_init does with bad arguments */
63 if ((errcode
= ll_init(0, 0)) == DB_ERR_BADARGS
)
64 printf("PASS/ll_init_nohead:ll_init(0, 0) returns DB_ERR_BADARGS\n");
66 printf("FAIL/ll_init_nohead:ll_init(0, 0) returned %lu instead of "
67 "DB_ERR_BADARGS\n", errcode
);
69 /* Scramble the structure */
70 head
.lh_magic
= DEADINT
;
71 head
.lh_count
= DEADINT
;
72 head
.lh_first
= DEADPTR
;
73 head
.lh_last
= DEADPTR
;
74 head
.lh_extra
= DEADPTR
;
76 /* Now try to initialize our structure and see what happens */
77 if ((errcode
= ll_init(&head
, 0))) {
78 printf("FAIL/ll_dynamic:ll_init(&head, 0) returned failure (%lu)\n",
82 printf("PASS/ll_dynamic:ll_init(&head, 0) returned success\n");
84 /* Finally, verify initialization */
85 check_init(&head
, "ll_dynamic");