xfree86.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #ifdef HAVE_DIX_CONFIG_H
  24. #include <dix-config.h>
  25. #endif
  26. #include <assert.h>
  27. #include "xf86.h"
  28. #include "xf86Parser.h"
  29. static void
  30. xfree86_option_list_duplicate(void)
  31. {
  32. XF86OptionPtr options;
  33. XF86OptionPtr duplicate;
  34. const char *o1 = "foo", *o2 = "bar", *v1 = "one", *v2 = "two";
  35. const char *o_null = "NULL";
  36. char *val1, *val2;
  37. XF86OptionPtr a, b;
  38. duplicate = xf86OptionListDuplicate(NULL);
  39. assert(!duplicate);
  40. options = xf86AddNewOption(NULL, o1, v1);
  41. assert(options);
  42. options = xf86AddNewOption(options, o2, v2);
  43. assert(options);
  44. options = xf86AddNewOption(options, o_null, NULL);
  45. assert(options);
  46. duplicate = xf86OptionListDuplicate(options);
  47. assert(duplicate);
  48. val1 = xf86CheckStrOption(options, o1, "1");
  49. val2 = xf86CheckStrOption(duplicate, o1, "2");
  50. assert(strcmp(val1, v1) == 0);
  51. assert(strcmp(val1, val2) == 0);
  52. val1 = xf86CheckStrOption(options, o2, "1");
  53. val2 = xf86CheckStrOption(duplicate, o2, "2");
  54. assert(strcmp(val1, v2) == 0);
  55. assert(strcmp(val1, val2) == 0);
  56. a = xf86FindOption(options, o_null);
  57. b = xf86FindOption(duplicate, o_null);
  58. assert(a && b);
  59. }
  60. static void
  61. xfree86_add_comment(void)
  62. {
  63. char *current = NULL;
  64. const char *comment;
  65. char compare[1024] = { 0 };
  66. comment = "# foo";
  67. current = xf86addComment(current, comment);
  68. strcpy(compare, comment);
  69. strcat(compare, "\n");
  70. assert(!strcmp(current, compare));
  71. /* this used to overflow */
  72. strcpy(current, "\n");
  73. comment = "foobar\n";
  74. current = xf86addComment(current, comment);
  75. strcpy(compare, "\n#");
  76. strcat(compare, comment);
  77. assert(!strcmp(current, compare));
  78. free(current);
  79. }
  80. int
  81. main(int argc, char **argv)
  82. {
  83. xfree86_option_list_duplicate();
  84. xfree86_add_comment();
  85. return 0;
  86. }