test-scm-take-u8vector.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Copyright (C) 2009 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. /* Make sure `scm_take_u8vector ()' returns a u8vector that actually uses the
  19. provided storage. */
  20. #ifdef HAVE_CONFIG_H
  21. # include <config.h>
  22. #endif
  23. #include <libguile.h>
  24. #include <stdlib.h>
  25. static void *
  26. do_test (void *result)
  27. {
  28. #define LEN 123
  29. SCM u8v;
  30. scm_t_uint8 *data;
  31. scm_t_array_handle handle;
  32. data = scm_malloc (LEN);
  33. u8v = scm_take_u8vector (data, LEN);
  34. scm_array_get_handle (u8v, &handle);
  35. if (scm_array_handle_u8_writable_elements (&handle) == data
  36. && scm_array_handle_u8_elements (&handle) == data)
  37. * (int *) result = EXIT_SUCCESS;
  38. else
  39. * (int *) result = EXIT_FAILURE;
  40. scm_array_handle_release (&handle);
  41. return NULL;
  42. #undef LEN
  43. }
  44. int
  45. main (int argc, char *argv[])
  46. {
  47. int result;
  48. scm_with_guile (do_test, &result);
  49. return result;
  50. }