1 /* Copyright (c) 2014, Google Inc.
3 * Permission to use, copy, modify, and/or distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
18 #include <openssl/pqueue.h>
19 #include <openssl/ssl.h>
22 static int trivial() {
23 pqueue q = pqueue_new();
27 int32_t data = 0xdeadbeef;
28 uint8_t priority[8] = {0};
29 pitem *item = pitem_new(priority, &data);
31 pqueue_insert(q, item) != item ||
32 pqueue_size(q) != 1 ||
33 pqueue_peek(q) != item ||
34 pqueue_pop(q) != item ||
35 pqueue_size(q) != 0 ||
36 pqueue_pop(q) != NULL) {
46 static int fixed_random() {
47 /* Random order of 10 elements, chosen by
48 random.choice(list(itertools.permutations(range(10)))) */
49 int ordering[NUM_ITEMS] = {9, 6, 3, 4, 0, 2, 7, 1, 8, 5};
51 pqueue q = pqueue_new();
55 uint8_t priority[8] = {0};
56 /* Insert the elements */
57 for (i = 0; i < NUM_ITEMS; i++) {
58 priority[7] = ordering[i];
59 pitem *item = pitem_new(priority, &ordering[i]);
60 pqueue_insert(q, item);
62 piterator iter = pqueue_iterator(q);
63 pitem *curr = pqueue_next(&iter);
68 pitem *next = pqueue_next(&iter);
72 int *curr_data = (int*)curr->data;
73 int *next_data = (int*)next->data;
74 if (*curr_data >= *next_data) {
85 if (!trivial() || !fixed_random()) {