test_ini.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /******************************************************************************
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; either version 2 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  13. $Id$
  14. ******************************************************************************/
  15. #include "common.h"
  16. #include "parse_ini.h"
  17. #include "tap.h"
  18. void my_free(char *string) {
  19. if (string != NULL) {
  20. printf("string:\n\t|%s|\n", string);
  21. free(string);
  22. }
  23. }
  24. int
  25. main (int argc, char **argv)
  26. {
  27. char *optstr=NULL;
  28. plan_tests(4);
  29. optstr=np_get_defaults("section@./config-tiny.ini", "check_disk");
  30. ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "config-tiny.ini's section as expected");
  31. my_free(optstr);
  32. optstr=np_get_defaults("@./config-tiny.ini", "section");
  33. ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "Used default section name, without specific");
  34. my_free(optstr);
  35. /* This test currently crashes */
  36. /*
  37. optstr=np_get_defaults("section_unknown@./config-tiny.ini", "section");
  38. ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "Used default section name over specified one");
  39. my_free(optstr);
  40. */
  41. optstr=np_get_defaults("Section Two@./config-tiny.ini", "check_disk");
  42. ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-tiny.ini's Section Two as expected");
  43. my_free(optstr);
  44. /* These tests currently crash parse_ini.c */
  45. /*
  46. optstr=np_get_defaults("/path/to/file.txt@./config-tiny.ini", "check_disk");
  47. ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's filename as section name");
  48. my_free(optstr);
  49. optstr=np_get_defaults("section2@./config-tiny.ini", "check_disk");
  50. ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's section2 with whitespace before section name");
  51. my_free(optstr);
  52. optstr=np_get_defaults("section3@./config-tiny.ini", "check_disk");
  53. ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's section3 with whitespace after section name");
  54. my_free(optstr);
  55. */
  56. optstr=np_get_defaults("check_mysql@./plugin.ini", "check_disk");
  57. ok( !strcmp(optstr, "--username=operator --password=secret"), "plugin.ini's check_mysql as expected");
  58. my_free(optstr);
  59. /* This test crashes at the moment. I think it is not expecting single character parameter names */
  60. /*
  61. optstr=np_get_defaults("check_mysql2@./config-tiny.ini", "check_disk");
  62. ok( !strcmp(optstr, "-u=admin -p=secret"), "plugin.ini's check_mysql2 as expected");
  63. my_free(optstr);
  64. */
  65. return exit_status();
  66. }