test-scm-to-latin1-string.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Copyright (C) 2011 Free Software Foundation, Inc.
  2. *
  3. * This library is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU Lesser General Public License
  5. * as published by the Free Software Foundation; either version 3 of
  6. * the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * Lesser General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Lesser General Public
  14. * License along with this library; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. * 02110-1301 USA
  17. */
  18. #ifdef HAVE_CONFIG_H
  19. # include <config.h>
  20. #endif
  21. #include <libguile.h>
  22. #include <stdlib.h>
  23. /*
  24. This outputs:
  25. dhansen@localhorst ~/tmp $ ./a.out
  26. foo,bar
  27. bar
  28. */
  29. #define TEST(x) \
  30. if (!(x)) abort()
  31. static void
  32. inner_main (void *data, int argc, char **argv)
  33. {
  34. char *cstr;
  35. SCM string, tokens, tok;
  36. string = scm_from_latin1_string ("foo,bar");
  37. tokens = scm_string_split (string, SCM_MAKE_CHAR (','));
  38. TEST (scm_is_pair (tokens));
  39. tok = scm_car (tokens);
  40. TEST (scm_is_string (tok));
  41. cstr = scm_to_latin1_string (tok);
  42. TEST (strcmp (cstr, "foo") == 0);
  43. free (cstr);
  44. tokens = scm_cdr (tokens);
  45. TEST (scm_is_pair (tokens));
  46. tok = scm_car (tokens);
  47. TEST (scm_is_string (tok));
  48. cstr = scm_to_latin1_string (tok);
  49. TEST (strcmp (cstr, "bar") == 0);
  50. free (cstr);
  51. tokens = scm_cdr (tokens);
  52. TEST (scm_is_null (tokens));
  53. }
  54. int
  55. main (int argc, char **argv)
  56. {
  57. scm_boot_guile (argc, argv, inner_main, NULL);
  58. return EXIT_SUCCESS;
  59. }
  60. /* Local Variables: */
  61. /* compile-command: "gcc `pkg-config --cflags --libs guile-2.0` main.c" */
  62. /* End: */