test-scm-values.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Copyright (C) 2012, 2014 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. #undef NDEBUG
  22. #include <assert.h>
  23. #include <libguile.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. static void
  27. test_scm_c_value_ref_on_multiple_values ()
  28. {
  29. SCM values = scm_values (scm_list_3 (scm_from_latin1_string ("foo"),
  30. scm_from_latin1_string ("bar"),
  31. scm_from_latin1_string ("baz")));
  32. char *foo = scm_to_latin1_string (scm_c_value_ref (values, 0));
  33. char *bar = scm_to_latin1_string (scm_c_value_ref (values, 1));
  34. char *baz = scm_to_latin1_string (scm_c_value_ref (values, 2));
  35. assert (strcmp (foo, "foo") == 0);
  36. assert (strcmp (bar, "bar") == 0);
  37. assert (strcmp (baz, "baz") == 0);
  38. free (foo);
  39. free (bar);
  40. free (baz);
  41. }
  42. static void
  43. test_scm_c_value_ref_on_a_single_value ()
  44. {
  45. SCM value = scm_from_latin1_string ("foo");
  46. char *foo = scm_to_latin1_string (scm_c_value_ref (value, 0));
  47. assert (strcmp (foo, "foo") == 0);
  48. free (foo);
  49. }
  50. static void
  51. tests (void *data, int argc, char **argv)
  52. {
  53. test_scm_c_value_ref_on_multiple_values ();
  54. test_scm_c_value_ref_on_a_single_value ();
  55. }
  56. int
  57. main (int argc, char *argv[])
  58. {
  59. scm_boot_guile (argc, argv, tests, NULL);
  60. return 0;
  61. }