test-loose-ends.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* test-loose-ends.c
  2. *
  3. * Test items of the Guile C API that aren't covered by any other tests.
  4. */
  5. /* Copyright (C) 2009, 2012, 2014 Free Software Foundation, Inc.
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public License
  9. * as published by the Free Software Foundation; either version 3 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. */
  22. #if HAVE_CONFIG_H
  23. # include <config.h>
  24. #endif
  25. #undef NDEBUG
  26. #include <libguile.h>
  27. #include <stdio.h>
  28. #include <assert.h>
  29. #include <string.h>
  30. #ifdef HAVE_INTTYPES_H
  31. # include <inttypes.h>
  32. #endif
  33. static void
  34. test_scm_from_locale_keywordn ()
  35. {
  36. SCM kw = scm_from_locale_keywordn ("thusly", 4);
  37. assert (scm_is_true (scm_keyword_p (kw)));
  38. }
  39. static void
  40. test_scm_local_eval ()
  41. {
  42. SCM result;
  43. scm_c_use_module ("ice-9 local-eval");
  44. result = scm_local_eval
  45. (scm_list_3 (scm_from_latin1_symbol ("+"),
  46. scm_from_latin1_symbol ("x"),
  47. scm_from_latin1_symbol ("y")),
  48. scm_c_eval_string ("(let ((x 1) (y 2)) (the-environment))"));
  49. assert (scm_is_true (scm_equal_p (result,
  50. scm_from_signed_integer (3))));
  51. }
  52. static void
  53. test_scm_call ()
  54. {
  55. SCM result;
  56. result = scm_call (scm_c_public_ref ("guile", "+"),
  57. scm_from_int (1),
  58. scm_from_int (2),
  59. SCM_UNDEFINED);
  60. assert (scm_is_true (scm_equal_p (result, scm_from_int (3))));
  61. result = scm_call (scm_c_public_ref ("guile", "list"),
  62. SCM_UNDEFINED);
  63. assert (scm_is_eq (result, SCM_EOL));
  64. }
  65. static void
  66. test_scm_to_pointer ()
  67. {
  68. int (*add3) (int a, int b, int c);
  69. SCM int_type = scm_c_public_ref ("system foreign", "int");
  70. add3 = scm_to_pointer
  71. (scm_procedure_to_pointer (int_type,
  72. scm_c_public_ref ("guile", "+"),
  73. scm_list_3 (int_type,
  74. int_type,
  75. int_type)));
  76. assert ((*add3) (1000000, 1000, -1) == 1000999);
  77. }
  78. static void
  79. tests (void *data, int argc, char **argv)
  80. {
  81. test_scm_from_locale_keywordn ();
  82. test_scm_local_eval ();
  83. test_scm_call ();
  84. test_scm_to_pointer ();
  85. }
  86. int
  87. main (int argc, char *argv[])
  88. {
  89. scm_boot_guile (argc, argv, tests, NULL);
  90. return 0;
  91. }