Remove building with NOCRYPTO option
[minix.git] / crypto / external / bsd / heimdal / dist / lib / roken / tsearch-test.c
blob5f079070b36b88c7a310806b5f4f57cf63ba3ec8
1 /* $NetBSD: tsearch-test.c,v 1.1.1.2 2014/04/24 12:45:52 pettai Exp $ */
3 /*
4 * Tree search generalized from Knuth (6.2.2) Algorithm T just like
5 * the AT&T man page says.
7 * The node_t structure is for internal use only, lint doesn't grok it.
9 * Written by reading the System V Interface Definition, not the code.
11 * Totally public domain.
14 #include <config.h>
16 #include <krb5/roken.h>
17 #include "search.h"
19 struct node {
20 char *string;
21 int order;
24 extern void *rk_tdelete(const void *, void **,
25 int (*)(const void *, const void *));
26 extern void *rk_tfind(const void *, void * const *,
27 int (*)(const void *, const void *));
28 extern void *rk_tsearch(const void *, void **, int (*)(const void *, const void *));
29 extern void rk_twalk(const void *, void (*)(const void *, VISIT, int));
31 void *rootnode = NULL;
32 int numerr = 0;
35 * This routine compares two nodes, based on an
36 * alphabetical ordering of the string field.
38 int
39 node_compare(const void *node1, const void *node2)
41 return strcmp(((const struct node *) node1)->string,
42 ((const struct node *) node2)->string);
45 static int walkorder = -1;
47 void
48 list_node(const void *ptr, VISIT order, int level)
50 const struct node *p = *(const struct node **) ptr;
52 if (order == postorder || order == leaf) {
53 walkorder++;
54 if (p->order != walkorder) {
55 warnx("sort failed: expected %d next, got %d\n", walkorder,
56 p->order);
57 numerr++;
62 int
63 main(int argc, char **argv)
65 int numtest = 1;
66 struct node *t, *p, tests[] = {
67 { "", 0 },
68 { "ab", 3 },
69 { "abc", 4 },
70 { "abcdefg", 8 },
71 { "abcd", 5 },
72 { "a", 2 },
73 { "abcdef", 7 },
74 { "abcde", 6 },
75 { "=", 1 },
76 { NULL }
79 for(t = tests; t->string; t++) {
80 /* Better not be there */
81 p = (struct node *)rk_tfind((void *)t, (void **)&rootnode,
82 node_compare);
84 if (p) {
85 warnx("erroneous list: found %d\n", p->order);
86 numerr++;
89 /* Put node into the tree. */
90 p = (struct node *) rk_tsearch((void *)t, (void **)&rootnode,
91 node_compare);
93 if (!p) {
94 warnx("erroneous list: missing %d\n", t->order);
95 numerr++;
99 rk_twalk(rootnode, list_node);
101 for(t = tests; t->string; t++) {
102 /* Better be there */
103 p = (struct node *) rk_tfind((void *)t, (void **)&rootnode,
104 node_compare);
106 if (!p) {
107 warnx("erroneous list: missing %d\n", t->order);
108 numerr++;
111 /* pull out node */
112 (void) rk_tdelete((void *)t, (void **)&rootnode,
113 node_compare);
115 /* Better not be there */
116 p = (struct node *) rk_tfind((void *)t, (void **)&rootnode,
117 node_compare);
119 if (p) {
120 warnx("erroneous list: found %d\n", p->order);
121 numerr++;
126 return numerr;