test-scm-values.c 2.0 KB

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