• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2012 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial
14  * portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <stdint.h>
29 #include <assert.h>
30 #include "wayland-private.h"
31 #include "test-runner.h"
32 
TEST(map_insert_new)33 TEST(map_insert_new)
34 {
35 	struct wl_map map;
36 	uint32_t i, j, k, a, b, c;
37 
38 	wl_map_init(&map, WL_MAP_SERVER_SIDE);
39 	i = wl_map_insert_new(&map, 0, &a);
40 	j = wl_map_insert_new(&map, 0, &b);
41 	k = wl_map_insert_new(&map, 0, &c);
42 	assert(i == WL_SERVER_ID_START);
43 	assert(j == WL_SERVER_ID_START + 1);
44 	assert(k == WL_SERVER_ID_START + 2);
45 
46 	assert(wl_map_lookup(&map, i) == &a);
47 	assert(wl_map_lookup(&map, j) == &b);
48 	assert(wl_map_lookup(&map, k) == &c);
49     wl_map_release(&map);
50 
51 	wl_map_init(&map, WL_MAP_CLIENT_SIDE);
52 	i = wl_map_insert_new(&map, 0, &a);
53 	assert(i == 0);
54 	assert(wl_map_lookup(&map, i) == &a);
55 
56 	wl_map_release(&map);
57 }
58 
TEST(map_insert_at)59 TEST(map_insert_at)
60 {
61 	struct wl_map map;
62 	uint32_t a, b, c;
63 
64 	wl_map_init(&map, WL_MAP_CLIENT_SIDE);
65 	assert(wl_map_insert_at(&map, 0, WL_SERVER_ID_START, &a) == 0);
66 	assert(wl_map_insert_at(&map, 0, WL_SERVER_ID_START + 3, &b) == -1);
67 	assert(wl_map_insert_at(&map, 0, WL_SERVER_ID_START + 1, &c) == 0);
68 
69 	assert(wl_map_lookup(&map, WL_SERVER_ID_START) == &a);
70 	assert(wl_map_lookup(&map, WL_SERVER_ID_START + 1) == &c);
71 
72 	wl_map_release(&map);
73 }
74 
TEST(map_remove)75 TEST(map_remove)
76 {
77 	struct wl_map map;
78 	uint32_t i, j, k, l, a, b, c, d;
79 
80 	wl_map_init(&map, WL_MAP_SERVER_SIDE);
81 	i = wl_map_insert_new(&map, 0, &a);
82 	j = wl_map_insert_new(&map, 0, &b);
83 	k = wl_map_insert_new(&map, 0, &c);
84 	assert(i == WL_SERVER_ID_START);
85 	assert(j == WL_SERVER_ID_START + 1);
86 	assert(k == WL_SERVER_ID_START + 2);
87 
88 	assert(wl_map_lookup(&map, i) == &a);
89 	assert(wl_map_lookup(&map, j) == &b);
90 	assert(wl_map_lookup(&map, k) == &c);
91 
92 	wl_map_remove(&map, j);
93 	assert(wl_map_lookup(&map, j) == NULL);
94 
95 	/* Verify that we insert d at the hole left by removing b */
96 	l = wl_map_insert_new(&map, 0, &d);
97 	assert(l == WL_SERVER_ID_START + 1);
98 	assert(wl_map_lookup(&map, l) == &d);
99 
100 	wl_map_release(&map);
101 }
102 
TEST(map_flags)103 TEST(map_flags)
104 {
105 	struct wl_map map;
106 	uint32_t i, j, a, b;
107 
108 	wl_map_init(&map, WL_MAP_SERVER_SIDE);
109 	i = wl_map_insert_new(&map, 0, &a);
110 	j = wl_map_insert_new(&map, 1, &b);
111 	assert(i == WL_SERVER_ID_START);
112 	assert(j == WL_SERVER_ID_START + 1);
113 
114 	assert(wl_map_lookup(&map, i) == &a);
115 	assert(wl_map_lookup(&map, j) == &b);
116 
117     assert(wl_map_lookup_flags(&map, i) == 0);
118     assert(wl_map_lookup_flags(&map, j) == 1);
119 
120 	wl_map_release(&map);
121 }
122