test_ini.c 3.0 KB

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