os: if inet_ntop() is available, use it for IPv4 addresses as well
[xserver.git] / test / xfree86.c
blobd964f0b0be25ef0cad2d820575c51ab277c3a46f
1 /**
2 * Copyright © 2011 Red Hat, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 /* Test relies on assert() */
25 #undef NDEBUG
27 #include <dix-config.h>
29 #include <assert.h>
31 #include "xf86.h"
32 #include "xf86Parser.h"
34 #include "tests-common.h"
36 static void
37 xfree86_option_list_duplicate(void)
39 XF86OptionPtr options;
40 XF86OptionPtr duplicate;
41 const char *o1 = "foo", *o2 = "bar", *v1 = "one", *v2 = "two";
42 const char *o_null = "NULL";
43 char *val1, *val2;
44 XF86OptionPtr a, b;
46 duplicate = xf86OptionListDuplicate(NULL);
47 assert(!duplicate);
49 options = xf86AddNewOption(NULL, o1, v1);
50 assert(options);
51 options = xf86AddNewOption(options, o2, v2);
52 assert(options);
53 options = xf86AddNewOption(options, o_null, NULL);
54 assert(options);
56 duplicate = xf86OptionListDuplicate(options);
57 assert(duplicate);
59 val1 = xf86CheckStrOption(options, o1, "1");
60 val2 = xf86CheckStrOption(duplicate, o1, "2");
62 assert(strcmp(val1, v1) == 0);
63 assert(strcmp(val1, val2) == 0);
64 free(val1);
65 free(val2);
67 val1 = xf86CheckStrOption(options, o2, "1");
68 val2 = xf86CheckStrOption(duplicate, o2, "2");
70 assert(strcmp(val1, v2) == 0);
71 assert(strcmp(val1, val2) == 0);
72 free(val1);
73 free(val2);
75 a = xf86FindOption(options, o_null);
76 b = xf86FindOption(duplicate, o_null);
77 assert(a);
78 assert(b);
80 xf86OptionListFree(duplicate);
81 xf86OptionListFree(options);
84 static void
85 xfree86_add_comment(void)
87 char *current = NULL;
88 const char *comment;
89 char compare[1024] = { 0 };
91 comment = "# foo";
92 current = xf86addComment(current, comment);
93 strcpy(compare, comment);
94 strcat(compare, "\n");
96 assert(!strcmp(current, compare));
98 /* this used to overflow */
99 strcpy(current, "\n");
100 comment = "foobar\n";
101 current = xf86addComment(current, comment);
102 strcpy(compare, "\n#");
103 strcat(compare, comment);
104 assert(!strcmp(current, compare));
106 free(current);
109 const testfunc_t*
110 xfree86_test(void)
112 static const testfunc_t testfuncs[] = {
113 xfree86_option_list_duplicate,
114 xfree86_add_comment,
115 NULL,
117 return testfuncs;