test-loose-ends.c 2.7 KB

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