3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 void FUNCTION (test, func) (void);
21 void FUNCTION (test, binary) (void);
22 void FUNCTION (test, trap) (void);
25 FUNCTION (test, func) (void)
31 v = FUNCTION (gsl_block, alloc) (N);
33 gsl_test (v->data == 0, NAME (gsl_block) "_alloc returns valid pointer");
34 gsl_test (v->size != N, NAME (gsl_block) "_alloc returns valid size");
36 data = FUNCTION(gsl_block, data) (v);
37 size = FUNCTION(gsl_block, size) (v);
39 gsl_test (data == 0, NAME (gsl_block) "_data returns valid pointer");
40 gsl_test (size != N, NAME (gsl_block) "_size returns valid size");
43 FUNCTION (gsl_block, free) (v); /* free whatever is in v */
45 v = FUNCTION (gsl_block, calloc) (N);
47 gsl_test (v->data == 0, NAME (gsl_block) "_calloc returns valid pointer");
48 gsl_test (v->size != N, NAME (gsl_block) "_calloc returns valid size");
50 data = FUNCTION(gsl_block, data) (v);
51 size = FUNCTION(gsl_block, size) (v);
53 gsl_test (data == 0, NAME (gsl_block) "_data returns valid pointer from calloc");
54 gsl_test (size != N, NAME (gsl_block) "_size returns valid size from calloc");
58 for (i = 0; i < N; i++)
60 if (v->data[i] != 0.0)
64 gsl_test (status, NAME (gsl_block) "_calloc initializes array to zero");
66 FUNCTION (gsl_block, free) (v); /* free whatever is in v */
71 FUNCTION (test, binary) (void)
76 TYPE (gsl_block) * v = FUNCTION (gsl_block, calloc) (N);
78 FILE *f = fopen ("test.dat", "wb");
80 for (i = 0; i < N; i++)
82 v->data[i] = (ATOMIC)(N - i);
85 FUNCTION (gsl_block, fwrite) (f, v);
89 FUNCTION (gsl_block, free) (v);
93 TYPE (gsl_block) * w = FUNCTION (gsl_block, calloc) (N);
95 FILE *f = fopen ("test.dat", "rb");
97 FUNCTION (gsl_block, fread) (f, w);
101 for (i = 0; i < N; i++)
103 if (w->data[i] != (ATOMIC) (N - i))
109 FUNCTION (gsl_block, free) (w);
112 gsl_test (status, NAME (gsl_block) "_write and read");
116 FUNCTION (test, trap) (void)
118 TYPE (gsl_block) * b = FUNCTION (gsl_block, alloc) (0);
120 gsl_test (b != 0, NAME (gsl_block) "_alloc traps zero length");