Reify bytevector? in the correct module
[bpt/guile.git] / test-suite / standalone / test-srfi-4.c
CommitLineData
2be7131e
AW
1/* Copyright (C) 2014 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
19#ifdef HAVE_CONFIG_H
20# include <config.h>
21#endif
22
0c1f2b0e
LC
23/* Make sure the assertions are tested. */
24#undef NDEBUG
25
2be7131e
AW
26#include <libguile.h>
27
28#include <stdio.h>
29#include <assert.h>
30
31static void
32test_writable_elements ()
33{
34 SCM elts = scm_list_4 (scm_from_int (1), scm_from_int (2),
35 scm_from_int (3), scm_from_int (4));
36
37 {
38 SCM v = scm_u32vector (elts);
39 size_t len;
40 ssize_t inc;
41 scm_t_array_handle h;
42 scm_t_uint32 *elts = scm_u32vector_writable_elements (v, &h, &len, &inc);
43 assert (len == 4);
44 assert (inc == 1);
45 assert (elts[0] == 1);
46 assert (elts[3] == 4);
47 scm_array_handle_release (&h);
48 }
49
50 {
51 SCM v = scm_f32vector (elts);
52 size_t len;
53 ssize_t inc;
54 scm_t_array_handle h;
55 float *elts = scm_f32vector_writable_elements (v, &h, &len, &inc);
56 assert (len == 4);
57 assert (inc == 1);
58 assert (elts[0] == 1.0);
59 assert (elts[3] == 4.0);
60 scm_array_handle_release (&h);
61 }
62
63 {
64 SCM v = scm_c32vector (elts);
65 size_t len;
66 ssize_t inc;
67 scm_t_array_handle h;
68 float *elts = scm_c32vector_writable_elements (v, &h, &len, &inc);
69 assert (len == 4);
70 assert (inc == 1);
71 assert (elts[0] == 1.0);
72 assert (elts[1] == 0.0);
73 assert (elts[6] == 4.0);
74 assert (elts[7] == 0.0);
75 scm_array_handle_release (&h);
76 }
77}
78
79static void
80tests (void *data, int argc, char **argv)
81{
82 test_writable_elements ();
83}
84
85int
86main (int argc, char *argv[])
87{
88 scm_boot_guile (argc, argv, tests, NULL);
89 return 0;
90}