diff options
author | marha <marha@users.sourceforge.net> | 2011-04-27 06:58:32 +0000 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2011-04-27 06:58:32 +0000 |
commit | 96d6df5da9cddedf4931bf8e17f96e242467c661 (patch) | |
tree | 07977c913b04e80b7dbd302e7a5890422aeacb1b /xorg-server/test/list.c | |
parent | 71372d36e1a3f0230b88808f70d35446fda12260 (diff) | |
download | vcxsrv-96d6df5da9cddedf4931bf8e17f96e242467c661.tar.gz vcxsrv-96d6df5da9cddedf4931bf8e17f96e242467c661.tar.bz2 vcxsrv-96d6df5da9cddedf4931bf8e17f96e242467c661.zip |
xserver libX11 libxtrans mesa pixman xkeyboard-config git update 27 Apr 2011
Diffstat (limited to 'xorg-server/test/list.c')
-rw-r--r-- | xorg-server/test/list.c | 349 |
1 files changed, 173 insertions, 176 deletions
diff --git a/xorg-server/test/list.c b/xorg-server/test/list.c index 7e035fe58..b101c7619 100644 --- a/xorg-server/test/list.c +++ b/xorg-server/test/list.c @@ -1,176 +1,173 @@ -/**
- * Copyright © 2011 Red Hat, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <X11/Xlib.h>
-#include <list.h>
-#include <string.h>
-#include <glib.h>
-
-struct parent {
- int a;
- struct list children;
- int b;
-};
-
-struct child {
- int foo;
- int bar;
- struct list node;
-};
-
-static void
-test_list_init(void)
-{
- struct parent parent, tmp;
-
- memset(&parent, 0, sizeof(parent));
- parent.a = 0xa5a5a5;
- parent.b = ~0xa5a5a5;
-
- tmp = parent;
-
- list_init(&parent.children);
-
- /* test we haven't touched anything else. */
- g_assert(parent.a == tmp.a);
- g_assert(parent.b == tmp.b);
-
- g_assert(list_is_empty(&parent.children));
-}
-
-static void
-test_list_add(void)
-{
- struct parent parent = {0};
- struct child child[3];
- struct child *c;
-
- list_init(&parent.children);
-
- list_add(&child[0].node, &parent.children);
- g_assert(!list_is_empty(&parent.children));
-
- c = list_first_entry(&parent.children, struct child, node);
- g_assert(memcmp(c, &child[0], sizeof(struct child)) == 0);
-
- /* note: list_add prepends */
- list_add(&child[1].node, &parent.children);
- c = list_first_entry(&parent.children, struct child, node);
- g_assert(memcmp(c, &child[1], sizeof(struct child)) == 0);
-
- list_add(&child[2].node, &parent.children);
- c = list_first_entry(&parent.children, struct child, node);
- g_assert(memcmp(c, &child[2], sizeof(struct child)) == 0);
-};
-
-static void
-test_list_del(void)
-{
- struct parent parent = {0};
- struct child child[3];
- struct child *c;
-
- list_init(&parent.children);
-
- list_add(&child[0].node, &parent.children);
- g_assert(!list_is_empty(&parent.children));
-
- list_del(&parent.children);
- g_assert(list_is_empty(&parent.children));
-
- list_add(&child[0].node, &parent.children);
- list_del(&child[0].node);
- g_assert(list_is_empty(&parent.children));
-
- list_add(&child[0].node, &parent.children);
- list_add(&child[1].node, &parent.children);
-
- c = list_first_entry(&parent.children, struct child, node);
- g_assert(memcmp(c, &child[1], sizeof(struct child)) == 0);
-
- /* delete first node */
- list_del(&child[1].node);
- g_assert(!list_is_empty(&parent.children));
- g_assert(list_is_empty(&child[1].node));
- c = list_first_entry(&parent.children, struct child, node);
- g_assert(memcmp(c, &child[0], sizeof(struct child)) == 0);
-
- /* delete last node */
- list_add(&child[1].node, &parent.children);
- list_del(&child[0].node);
- c = list_first_entry(&parent.children, struct child, node);
- g_assert(memcmp(c, &child[1], sizeof(struct child)) == 0);
-
- /* delete list head */
- list_add(&child[0].node, &parent.children);
- list_del(&parent.children);
- g_assert(list_is_empty(&parent.children));
- g_assert(!list_is_empty(&child[1].node));
- g_assert(!list_is_empty(&child[2].node));
-}
-
-static void
-test_list_for_each(void)
-{
- struct parent parent = {0};
- struct child child[3];
- struct child *c;
- int i = 0;
-
- list_init(&parent.children);
-
- list_add(&child[2].node, &parent.children);
- list_add(&child[1].node, &parent.children);
- list_add(&child[0].node, &parent.children);
-
- list_for_each_entry(c, &parent.children, node) {
- g_assert(memcmp(c, &child[i], sizeof(struct child)) == 0);
- i++;
- }
-
- /* foreach on empty list */
- list_del(&parent.children);
- g_assert(list_is_empty(&parent.children));
-
- list_for_each_entry(c, &parent.children, node) {
- g_assert(0); /* we must not get here */
- }
-}
-
-
-int main(int argc, char** argv)
-{
- g_test_init(&argc, &argv,NULL);
- g_test_bug_base("https://bugzilla.freedesktop.org/show_bug.cgi?id=");
-
- g_test_add_func("/list/init", test_list_init);
- g_test_add_func("/list/add", test_list_add);
- g_test_add_func("/list/del", test_list_del);
- g_test_add_func("/list/for_each", test_list_for_each);
-
- return g_test_run();
-}
+/** + * Copyright © 2011 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include <X11/Xlib.h> +#include <list.h> +#include <string.h> +#include <assert.h> + +struct parent { + int a; + struct list children; + int b; +}; + +struct child { + int foo; + int bar; + struct list node; +}; + +static void +test_list_init(void) +{ + struct parent parent, tmp; + + memset(&parent, 0, sizeof(parent)); + parent.a = 0xa5a5a5; + parent.b = ~0xa5a5a5; + + tmp = parent; + + list_init(&parent.children); + + /* test we haven't touched anything else. */ + assert(parent.a == tmp.a); + assert(parent.b == tmp.b); + + assert(list_is_empty(&parent.children)); +} + +static void +test_list_add(void) +{ + struct parent parent = {0}; + struct child child[3]; + struct child *c; + + list_init(&parent.children); + + list_add(&child[0].node, &parent.children); + assert(!list_is_empty(&parent.children)); + + c = list_first_entry(&parent.children, struct child, node); + assert(memcmp(c, &child[0], sizeof(struct child)) == 0); + + /* note: list_add prepends */ + list_add(&child[1].node, &parent.children); + c = list_first_entry(&parent.children, struct child, node); + assert(memcmp(c, &child[1], sizeof(struct child)) == 0); + + list_add(&child[2].node, &parent.children); + c = list_first_entry(&parent.children, struct child, node); + assert(memcmp(c, &child[2], sizeof(struct child)) == 0); +}; + +static void +test_list_del(void) +{ + struct parent parent = {0}; + struct child child[3]; + struct child *c; + + list_init(&parent.children); + + list_add(&child[0].node, &parent.children); + assert(!list_is_empty(&parent.children)); + + list_del(&parent.children); + assert(list_is_empty(&parent.children)); + + list_add(&child[0].node, &parent.children); + list_del(&child[0].node); + assert(list_is_empty(&parent.children)); + + list_add(&child[0].node, &parent.children); + list_add(&child[1].node, &parent.children); + + c = list_first_entry(&parent.children, struct child, node); + assert(memcmp(c, &child[1], sizeof(struct child)) == 0); + + /* delete first node */ + list_del(&child[1].node); + assert(!list_is_empty(&parent.children)); + assert(list_is_empty(&child[1].node)); + c = list_first_entry(&parent.children, struct child, node); + assert(memcmp(c, &child[0], sizeof(struct child)) == 0); + + /* delete last node */ + list_add(&child[1].node, &parent.children); + list_del(&child[0].node); + c = list_first_entry(&parent.children, struct child, node); + assert(memcmp(c, &child[1], sizeof(struct child)) == 0); + + /* delete list head */ + list_add(&child[0].node, &parent.children); + list_del(&parent.children); + assert(list_is_empty(&parent.children)); + assert(!list_is_empty(&child[1].node)); + assert(!list_is_empty(&child[2].node)); +} + +static void +test_list_for_each(void) +{ + struct parent parent = {0}; + struct child child[3]; + struct child *c; + int i = 0; + + list_init(&parent.children); + + list_add(&child[2].node, &parent.children); + list_add(&child[1].node, &parent.children); + list_add(&child[0].node, &parent.children); + + list_for_each_entry(c, &parent.children, node) { + assert(memcmp(c, &child[i], sizeof(struct child)) == 0); + i++; + } + + /* foreach on empty list */ + list_del(&parent.children); + assert(list_is_empty(&parent.children)); + + list_for_each_entry(c, &parent.children, node) { + assert(0); /* we must not get here */ + } +} + + +int main(int argc, char** argv) +{ + test_list_init(); + test_list_add(); + test_list_del(); + test_list_for_each(); + + return 0; +} |