xref: /minix3/crypto/external/bsd/heimdal/dist/base/test_base.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: test_base.c,v 1.1.1.2 2014/04/24 12:45:26 pettai Exp $	*/
2ebfedea0SLionel Sambuc 
3ebfedea0SLionel Sambuc /*
4ebfedea0SLionel Sambuc  * Copyright (c) 2010 Kungliga Tekniska Högskolan
5ebfedea0SLionel Sambuc  * (Royal Institute of Technology, Stockholm, Sweden).
6ebfedea0SLionel Sambuc  * All rights reserved.
7ebfedea0SLionel Sambuc  *
8ebfedea0SLionel Sambuc  * Portions Copyright (c) 2010 Apple Inc. All rights reserved.
9ebfedea0SLionel Sambuc  *
10ebfedea0SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
11ebfedea0SLionel Sambuc  * modification, are permitted provided that the following conditions
12ebfedea0SLionel Sambuc  * are met:
13ebfedea0SLionel Sambuc  *
14ebfedea0SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
15ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
16ebfedea0SLionel Sambuc  *
17ebfedea0SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
18ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
19ebfedea0SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
20ebfedea0SLionel Sambuc  *
21ebfedea0SLionel Sambuc  * 3. Neither the name of the Institute nor the names of its contributors
22ebfedea0SLionel Sambuc  *    may be used to endorse or promote products derived from this software
23ebfedea0SLionel Sambuc  *    without specific prior written permission.
24ebfedea0SLionel Sambuc  *
25ebfedea0SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
26ebfedea0SLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27ebfedea0SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28ebfedea0SLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
29ebfedea0SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30ebfedea0SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31ebfedea0SLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32ebfedea0SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33ebfedea0SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34ebfedea0SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35ebfedea0SLionel Sambuc  * SUCH DAMAGE.
36ebfedea0SLionel Sambuc  */
37ebfedea0SLionel Sambuc 
38ebfedea0SLionel Sambuc #include <stdio.h>
39ebfedea0SLionel Sambuc #include <err.h>
40ebfedea0SLionel Sambuc 
41ebfedea0SLionel Sambuc #include <krb5/heimbase.h>
42ebfedea0SLionel Sambuc #include "heimbasepriv.h"
43ebfedea0SLionel Sambuc 
44ebfedea0SLionel Sambuc static void
memory_free(heim_object_t obj)45ebfedea0SLionel Sambuc memory_free(heim_object_t obj)
46ebfedea0SLionel Sambuc {
47ebfedea0SLionel Sambuc }
48ebfedea0SLionel Sambuc 
49ebfedea0SLionel Sambuc static int
test_memory(void)50ebfedea0SLionel Sambuc test_memory(void)
51ebfedea0SLionel Sambuc {
52ebfedea0SLionel Sambuc     void *ptr;
53ebfedea0SLionel Sambuc 
54ebfedea0SLionel Sambuc     ptr = heim_alloc(10, "memory", memory_free);
55ebfedea0SLionel Sambuc 
56ebfedea0SLionel Sambuc     heim_retain(ptr);
57ebfedea0SLionel Sambuc     heim_release(ptr);
58ebfedea0SLionel Sambuc 
59ebfedea0SLionel Sambuc     heim_retain(ptr);
60ebfedea0SLionel Sambuc     heim_release(ptr);
61ebfedea0SLionel Sambuc 
62ebfedea0SLionel Sambuc     heim_release(ptr);
63ebfedea0SLionel Sambuc 
64ebfedea0SLionel Sambuc     ptr = heim_alloc(10, "memory", NULL);
65ebfedea0SLionel Sambuc     heim_release(ptr);
66ebfedea0SLionel Sambuc 
67ebfedea0SLionel Sambuc     return 0;
68ebfedea0SLionel Sambuc }
69ebfedea0SLionel Sambuc 
70ebfedea0SLionel Sambuc static int
test_dict(void)71ebfedea0SLionel Sambuc test_dict(void)
72ebfedea0SLionel Sambuc {
73ebfedea0SLionel Sambuc     heim_dict_t dict;
74ebfedea0SLionel Sambuc     heim_number_t a1 = heim_number_create(1);
75ebfedea0SLionel Sambuc     heim_string_t a2 = heim_string_create("hejsan");
76ebfedea0SLionel Sambuc     heim_number_t a3 = heim_number_create(3);
77ebfedea0SLionel Sambuc     heim_string_t a4 = heim_string_create("foosan");
78ebfedea0SLionel Sambuc 
79ebfedea0SLionel Sambuc     dict = heim_dict_create(10);
80ebfedea0SLionel Sambuc 
81ebfedea0SLionel Sambuc     heim_dict_add_value(dict, a1, a2);
82ebfedea0SLionel Sambuc     heim_dict_add_value(dict, a3, a4);
83ebfedea0SLionel Sambuc 
84ebfedea0SLionel Sambuc     heim_dict_delete_key(dict, a3);
85ebfedea0SLionel Sambuc     heim_dict_delete_key(dict, a1);
86ebfedea0SLionel Sambuc 
87ebfedea0SLionel Sambuc     heim_release(a1);
88ebfedea0SLionel Sambuc     heim_release(a2);
89ebfedea0SLionel Sambuc     heim_release(a3);
90ebfedea0SLionel Sambuc     heim_release(a4);
91ebfedea0SLionel Sambuc 
92ebfedea0SLionel Sambuc     heim_release(dict);
93ebfedea0SLionel Sambuc 
94ebfedea0SLionel Sambuc     return 0;
95ebfedea0SLionel Sambuc }
96ebfedea0SLionel Sambuc 
97ebfedea0SLionel Sambuc static int
test_auto_release(void)98ebfedea0SLionel Sambuc test_auto_release(void)
99ebfedea0SLionel Sambuc {
100ebfedea0SLionel Sambuc     heim_auto_release_t ar1, ar2;
101ebfedea0SLionel Sambuc     heim_number_t n1;
102ebfedea0SLionel Sambuc     heim_string_t s1;
103ebfedea0SLionel Sambuc 
104ebfedea0SLionel Sambuc     ar1 = heim_auto_release_create();
105ebfedea0SLionel Sambuc 
106ebfedea0SLionel Sambuc     s1 = heim_string_create("hejsan");
107ebfedea0SLionel Sambuc     heim_auto_release(s1);
108ebfedea0SLionel Sambuc 
109ebfedea0SLionel Sambuc     n1 = heim_number_create(1);
110ebfedea0SLionel Sambuc     heim_auto_release(n1);
111ebfedea0SLionel Sambuc 
112ebfedea0SLionel Sambuc     ar2 = heim_auto_release_create();
113ebfedea0SLionel Sambuc 
114ebfedea0SLionel Sambuc     n1 = heim_number_create(1);
115ebfedea0SLionel Sambuc     heim_auto_release(n1);
116ebfedea0SLionel Sambuc 
117ebfedea0SLionel Sambuc     heim_release(ar2);
118ebfedea0SLionel Sambuc     heim_release(ar1);
119ebfedea0SLionel Sambuc 
120ebfedea0SLionel Sambuc     return 0;
121ebfedea0SLionel Sambuc }
122ebfedea0SLionel Sambuc 
123ebfedea0SLionel Sambuc static int
test_string(void)124ebfedea0SLionel Sambuc test_string(void)
125ebfedea0SLionel Sambuc {
126ebfedea0SLionel Sambuc     heim_string_t s1, s2;
127ebfedea0SLionel Sambuc     const char *string = "hejsan";
128ebfedea0SLionel Sambuc 
129ebfedea0SLionel Sambuc     s1 = heim_string_create(string);
130ebfedea0SLionel Sambuc     s2 = heim_string_create(string);
131ebfedea0SLionel Sambuc 
132*0a6a1f1dSLionel Sambuc     if (heim_cmp(s1, s2) != 0) {
133*0a6a1f1dSLionel Sambuc 	printf("the same string is not the same\n");
134*0a6a1f1dSLionel Sambuc 	exit(1);
135*0a6a1f1dSLionel Sambuc     }
136ebfedea0SLionel Sambuc 
137ebfedea0SLionel Sambuc     heim_release(s1);
138ebfedea0SLionel Sambuc     heim_release(s2);
139ebfedea0SLionel Sambuc 
140ebfedea0SLionel Sambuc     return 0;
141ebfedea0SLionel Sambuc }
142ebfedea0SLionel Sambuc 
143ebfedea0SLionel Sambuc int
main(int argc,char ** argv)144ebfedea0SLionel Sambuc main(int argc, char **argv)
145ebfedea0SLionel Sambuc {
146ebfedea0SLionel Sambuc     int res = 0;
147ebfedea0SLionel Sambuc 
148ebfedea0SLionel Sambuc     res |= test_memory();
149ebfedea0SLionel Sambuc     res |= test_dict();
150ebfedea0SLionel Sambuc     res |= test_auto_release();
151ebfedea0SLionel Sambuc     res |= test_string();
152ebfedea0SLionel Sambuc 
153ebfedea0SLionel Sambuc     return res;
154ebfedea0SLionel Sambuc }
155