2 * Copyright © 2012 Intel Corporation
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
26 #include "wayland-private.h"
27 #include "test-runner.h"
34 assert(list.next == &list);
35 assert(list.prev == &list);
36 assert(wl_list_empty(&list));
50 wl_list_insert(&list, &e.link);
51 assert(list.next == &e.link);
52 assert(list.prev == &e.link);
53 assert(e.link.next == &list);
54 assert(e.link.prev == &list);
60 struct element e1, e2, e3, e4, *e;
61 int reference[] = { 708090, 102030, 5588, 12 };
70 wl_list_insert(list.prev, &e1.link);
71 wl_list_insert(list.prev, &e2.link);
72 wl_list_insert(list.prev, &e3.link);
73 wl_list_insert(list.prev, &e4.link);
76 wl_list_for_each(e, &list, link) {
77 assert(i < ARRAY_LENGTH(reference));
78 assert(e->i == reference[i]);
81 assert(i == ARRAY_LENGTH(reference));
84 wl_list_for_each_reverse(e, &list, link) {
85 assert(i < ARRAY_LENGTH(reference));
86 assert(e->i == reference[ARRAY_LENGTH(reference) - i - 1]);
89 assert(i == ARRAY_LENGTH(reference));
93 validate_list(struct wl_list *list, int *reference, int length)
99 wl_list_for_each(e, list, link) {
102 if (e->i != reference[i])
116 struct element e1, e2, e3;
117 int reference1[] = { 17, 8888, 1000 }, reference2[] = { 17, 1000 };
124 wl_list_insert(&list, &e1.link);
125 wl_list_insert(list.prev, &e2.link);
126 wl_list_insert(list.prev, &e3.link);
127 assert(validate_list(&list, reference1, ARRAY_LENGTH(reference1)));
129 wl_list_remove(&e2.link);
130 assert(validate_list(&list, reference2, ARRAY_LENGTH(reference2)));
133 TEST(list_insert_list)
135 struct wl_list list, other;
136 struct element e1, e2, e3, e4, e5, e6;
137 int reference1[] = { 17, 8888, 1000 };
138 int reference2[] = { 76543, 1, -500 };
139 int reference3[] = { 17, 76543, 1, -500, 8888, 1000 };
146 wl_list_insert(&list, &e1.link);
147 wl_list_insert(list.prev, &e2.link);
148 wl_list_insert(list.prev, &e3.link);
149 assert(validate_list(&list, reference1, ARRAY_LENGTH(reference1)));
155 wl_list_init(&other);
156 wl_list_insert(&other, &e4.link);
157 wl_list_insert(other.prev, &e5.link);
158 wl_list_insert(other.prev, &e6.link);
159 assert(validate_list(&other, reference2, ARRAY_LENGTH(reference2)));
161 wl_list_insert_list(list.next, &other);
162 assert(validate_list(&list, reference3, ARRAY_LENGTH(reference3)));