xref: /openbsd-src/regress/lib/libssl/pqueue/pq_test.c (revision 050203f5a34cd108916f81265cd30c21ee5417cc)
1*050203f5Sjsing /* crypto/pqueue/pq_test.c */
2*050203f5Sjsing /*
3*050203f5Sjsing  * DTLS implementation written by Nagendra Modadugu
4*050203f5Sjsing  * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
5*050203f5Sjsing  */
6*050203f5Sjsing /* ====================================================================
7*050203f5Sjsing  * Copyright (c) 1999-2005 The OpenSSL Project.  All rights reserved.
8*050203f5Sjsing  *
9*050203f5Sjsing  * Redistribution and use in source and binary forms, with or without
10*050203f5Sjsing  * modification, are permitted provided that the following conditions
11*050203f5Sjsing  * are met:
12*050203f5Sjsing  *
13*050203f5Sjsing  * 1. Redistributions of source code must retain the above copyright
14*050203f5Sjsing  *    notice, this list of conditions and the following disclaimer.
15*050203f5Sjsing  *
16*050203f5Sjsing  * 2. Redistributions in binary form must reproduce the above copyright
17*050203f5Sjsing  *    notice, this list of conditions and the following disclaimer in
18*050203f5Sjsing  *    the documentation and/or other materials provided with the
19*050203f5Sjsing  *    distribution.
20*050203f5Sjsing  *
21*050203f5Sjsing  * 3. All advertising materials mentioning features or use of this
22*050203f5Sjsing  *    software must display the following acknowledgment:
23*050203f5Sjsing  *    "This product includes software developed by the OpenSSL Project
24*050203f5Sjsing  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25*050203f5Sjsing  *
26*050203f5Sjsing  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27*050203f5Sjsing  *    endorse or promote products derived from this software without
28*050203f5Sjsing  *    prior written permission. For written permission, please contact
29*050203f5Sjsing  *    openssl-core@OpenSSL.org.
30*050203f5Sjsing  *
31*050203f5Sjsing  * 5. Products derived from this software may not be called "OpenSSL"
32*050203f5Sjsing  *    nor may "OpenSSL" appear in their names without prior written
33*050203f5Sjsing  *    permission of the OpenSSL Project.
34*050203f5Sjsing  *
35*050203f5Sjsing  * 6. Redistributions of any form whatsoever must retain the following
36*050203f5Sjsing  *    acknowledgment:
37*050203f5Sjsing  *    "This product includes software developed by the OpenSSL Project
38*050203f5Sjsing  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39*050203f5Sjsing  *
40*050203f5Sjsing  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41*050203f5Sjsing  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42*050203f5Sjsing  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43*050203f5Sjsing  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
44*050203f5Sjsing  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45*050203f5Sjsing  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46*050203f5Sjsing  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47*050203f5Sjsing  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48*050203f5Sjsing  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49*050203f5Sjsing  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50*050203f5Sjsing  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51*050203f5Sjsing  * OF THE POSSIBILITY OF SUCH DAMAGE.
52*050203f5Sjsing  * ====================================================================
53*050203f5Sjsing  *
54*050203f5Sjsing  * This product includes cryptographic software written by Eric Young
55*050203f5Sjsing  * (eay@cryptsoft.com).  This product includes software written by Tim
56*050203f5Sjsing  * Hudson (tjh@cryptsoft.com).
57*050203f5Sjsing  *
58*050203f5Sjsing  */
59*050203f5Sjsing #include <stdio.h>
60*050203f5Sjsing #include <stdlib.h>
61*050203f5Sjsing #include <string.h>
62*050203f5Sjsing #include "pqueue.h"
63*050203f5Sjsing 
64*050203f5Sjsing /* remember to change expected.txt if you change these values */
65*050203f5Sjsing unsigned char prio1[8] = "supercal";
66*050203f5Sjsing unsigned char prio2[8] = "ifragili";
67*050203f5Sjsing unsigned char prio3[8] = "sticexpi";
68*050203f5Sjsing 
69*050203f5Sjsing static void
pqueue_print(pqueue pq)70*050203f5Sjsing pqueue_print(pqueue pq)
71*050203f5Sjsing {
72*050203f5Sjsing 	pitem *iter, *item;
73*050203f5Sjsing 
74*050203f5Sjsing 	iter = pqueue_iterator(pq);
75*050203f5Sjsing 	for (item = pqueue_next(&iter); item != NULL;
76*050203f5Sjsing 	    item = pqueue_next(&iter)) {
77*050203f5Sjsing 		printf("item\t%02x%02x%02x%02x%02x%02x%02x%02x\n",
78*050203f5Sjsing 		    item->priority[0], item->priority[1],
79*050203f5Sjsing 		    item->priority[2], item->priority[3],
80*050203f5Sjsing 		    item->priority[4], item->priority[5],
81*050203f5Sjsing 		    item->priority[6], item->priority[7]);
82*050203f5Sjsing 	}
83*050203f5Sjsing }
84*050203f5Sjsing 
85*050203f5Sjsing int
main(void)86*050203f5Sjsing main(void)
87*050203f5Sjsing {
88*050203f5Sjsing 	pitem *item;
89*050203f5Sjsing 	pqueue pq;
90*050203f5Sjsing 
91*050203f5Sjsing 	pq = pqueue_new();
92*050203f5Sjsing 
93*050203f5Sjsing 	item = pitem_new(prio3, NULL);
94*050203f5Sjsing 	pqueue_insert(pq, item);
95*050203f5Sjsing 
96*050203f5Sjsing 	item = pitem_new(prio1, NULL);
97*050203f5Sjsing 	pqueue_insert(pq, item);
98*050203f5Sjsing 
99*050203f5Sjsing 	item = pitem_new(prio2, NULL);
100*050203f5Sjsing 	pqueue_insert(pq, item);
101*050203f5Sjsing 
102*050203f5Sjsing 	item = pqueue_find(pq, prio1);
103*050203f5Sjsing 	fprintf(stderr, "found %p\n", item->priority);
104*050203f5Sjsing 
105*050203f5Sjsing 	item = pqueue_find(pq, prio2);
106*050203f5Sjsing 	fprintf(stderr, "found %p\n", item->priority);
107*050203f5Sjsing 
108*050203f5Sjsing 	item = pqueue_find(pq, prio3);
109*050203f5Sjsing 	fprintf(stderr, "found %p\n", item ? item->priority: 0);
110*050203f5Sjsing 
111*050203f5Sjsing 	pqueue_print(pq);
112*050203f5Sjsing 
113*050203f5Sjsing 	for (item = pqueue_pop(pq); item != NULL; item = pqueue_pop(pq))
114*050203f5Sjsing 		pitem_free(item);
115*050203f5Sjsing 
116*050203f5Sjsing 	pqueue_free(pq);
117*050203f5Sjsing 	return 0;
118*050203f5Sjsing }
119