1baed1080e51e5dc6975e95f4ce119e91dc9c784
[ircu2.10.12-pk.git] / libs / dbprim / tests / t_ll_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$
20 */
21 #include <stdio.h>
22
23 #include "dbprim.h"
24
25 #define DEADINT 0xdeadbeef
26 #define DEADPTR (void *)0xdeadbeef
27
28 static void
29 check_init(link_head_t *head, char *how)
30 {
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);
33   else
34     printf("PASS/%s_magic:Initialization set magic number properly\n", how);
35
36   if (head->lh_count != 0) /* verify count was set */
37     printf("FAIL/%s_count:Initialization failed to clear count\n", how);
38   else
39     printf("PASS/%s_count:Initialization set count to 0\n", how);
40
41   if (head->lh_first != 0) /* verify first was set */
42     printf("FAIL/%s_first:Initialization failed to clear first pointer\n",
43            how);
44   else
45     printf("PASS/%s_first:Initialization set first pointer to 0\n", how);
46
47   if (head->lh_last != 0) /* verify last was set */
48     printf("FAIL/%s_last:Initialization failed to clear last pointer\n", how);
49   else
50     printf("PASS/%s_last:Initialization set last pointer to 0\n", how);
51 }
52
53 int
54 main(int argc, char **argv)
55 {
56   unsigned long errcode;
57   link_head_t head = LINK_HEAD_INIT(0);
58
59   /* Check that the static initializer produces a passable structure */
60   check_init(&head, "ll_static");
61
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");
65   else
66     printf("FAIL/ll_init_nohead:ll_init(0, 0) returned %lu instead of "
67            "DB_ERR_BADARGS\n", errcode);
68
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;
75
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",
79            errcode);
80     return 0;
81   } else
82     printf("PASS/ll_dynamic:ll_init(&head, 0) returned success\n");
83
84   /* Finally, verify initialization */
85   check_init(&head, "ll_dynamic");
86
87   return 0;
88 }