xfree86.c revision 1b5d61b8
1/** 2 * Copyright © 2011 Red Hat, Inc. 3 * 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: 10 * 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. 14 * 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. 22 */ 23 24#ifdef HAVE_DIX_CONFIG_H 25#include <dix-config.h> 26#endif 27 28#include <assert.h> 29 30#include "xf86.h" 31#include "xf86Parser.h" 32 33#include "tests-common.h" 34 35static void 36xfree86_option_list_duplicate(void) 37{ 38 XF86OptionPtr options; 39 XF86OptionPtr duplicate; 40 const char *o1 = "foo", *o2 = "bar", *v1 = "one", *v2 = "two"; 41 const char *o_null = "NULL"; 42 char *val1, *val2; 43 XF86OptionPtr a, b; 44 45 duplicate = xf86OptionListDuplicate(NULL); 46 assert(!duplicate); 47 48 options = xf86AddNewOption(NULL, o1, v1); 49 assert(options); 50 options = xf86AddNewOption(options, o2, v2); 51 assert(options); 52 options = xf86AddNewOption(options, o_null, NULL); 53 assert(options); 54 55 duplicate = xf86OptionListDuplicate(options); 56 assert(duplicate); 57 58 val1 = xf86CheckStrOption(options, o1, "1"); 59 val2 = xf86CheckStrOption(duplicate, o1, "2"); 60 61 assert(strcmp(val1, v1) == 0); 62 assert(strcmp(val1, val2) == 0); 63 64 val1 = xf86CheckStrOption(options, o2, "1"); 65 val2 = xf86CheckStrOption(duplicate, o2, "2"); 66 67 assert(strcmp(val1, v2) == 0); 68 assert(strcmp(val1, val2) == 0); 69 70 a = xf86FindOption(options, o_null); 71 b = xf86FindOption(duplicate, o_null); 72 assert(a && b); 73} 74 75static void 76xfree86_add_comment(void) 77{ 78 char *current = NULL; 79 const char *comment; 80 char compare[1024] = { 0 }; 81 82 comment = "# foo"; 83 current = xf86addComment(current, comment); 84 strcpy(compare, comment); 85 strcat(compare, "\n"); 86 87 assert(!strcmp(current, compare)); 88 89 /* this used to overflow */ 90 strcpy(current, "\n"); 91 comment = "foobar\n"; 92 current = xf86addComment(current, comment); 93 strcpy(compare, "\n#"); 94 strcat(compare, comment); 95 assert(!strcmp(current, compare)); 96 97 free(current); 98} 99 100int 101xfree86_test(void) 102{ 103 xfree86_option_list_duplicate(); 104 xfree86_add_comment(); 105 106 return 0; 107} 108