test-scm-values.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Copyright 2012,2014,2018
  2. Free Software Foundation, Inc.
  3. This file is part of Guile.
  4. Guile is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Lesser General Public License as published
  6. by the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. Guile is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  11. License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with Guile. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifdef HAVE_CONFIG_H
  16. # include <config.h>
  17. #endif
  18. #undef NDEBUG
  19. #include <assert.h>
  20. #include <libguile.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. static void
  24. test_scm_c_value_ref_on_multiple_values ()
  25. {
  26. SCM values = scm_values (scm_list_3 (scm_from_latin1_string ("foo"),
  27. scm_from_latin1_string ("bar"),
  28. scm_from_latin1_string ("baz")));
  29. char *foo = scm_to_latin1_string (scm_c_value_ref (values, 0));
  30. char *bar = scm_to_latin1_string (scm_c_value_ref (values, 1));
  31. char *baz = scm_to_latin1_string (scm_c_value_ref (values, 2));
  32. assert (strcmp (foo, "foo") == 0);
  33. assert (strcmp (bar, "bar") == 0);
  34. assert (strcmp (baz, "baz") == 0);
  35. free (foo);
  36. free (bar);
  37. free (baz);
  38. }
  39. static void
  40. test_scm_c_value_ref_on_a_single_value ()
  41. {
  42. SCM value = scm_from_latin1_string ("foo");
  43. char *foo = scm_to_latin1_string (scm_c_value_ref (value, 0));
  44. assert (strcmp (foo, "foo") == 0);
  45. free (foo);
  46. }
  47. static void
  48. tests (void *data, int argc, char **argv)
  49. {
  50. test_scm_c_value_ref_on_multiple_values ();
  51. test_scm_c_value_ref_on_a_single_value ();
  52. }
  53. int
  54. main (int argc, char *argv[])
  55. {
  56. scm_boot_guile (argc, argv, tests, NULL);
  57. return 0;
  58. }