1 /* block/test_complex_source.c
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 b = FUNCTION (gsl_block, alloc) (N);
33 gsl_test (b->data == 0, NAME (gsl_block) "_alloc returns valid pointer");
34 gsl_test (b->size != N, NAME (gsl_block) "_alloc returns valid size");
36 data = FUNCTION(gsl_block, data) (b);
37 size = FUNCTION(gsl_block, size) (b);
39 gsl_test (data == 0, NAME (gsl_block) "_data returns valid pointer");
40 gsl_test (size != N, NAME (gsl_block) "_size returns valid size");
42 FUNCTION (gsl_block, free) (b); /* free whatever is in v */
44 b = FUNCTION (gsl_block, calloc) (N);
46 gsl_test (b->data == 0, NAME (gsl_block) "_calloc returns valid pointer");
47 gsl_test (b->size != N, NAME (gsl_block) "_calloc returns valid size");
49 data = FUNCTION(gsl_block, data) (b);
50 size = FUNCTION(gsl_block, size) (b);
52 gsl_test (data == 0, NAME (gsl_block) "_data returns valid pointer from calloc");
53 gsl_test (size != N, NAME (gsl_block) "_size returns valid size from calloc");
57 for (i = 0; i < N; i++)
59 if (b->data[2 * i] != 0.0 || b->data[2 * i + 1] != 0.0)
63 gsl_test (status, NAME (gsl_block) "_calloc initializes array to zero");
65 FUNCTION (gsl_block, free) (b);
69 FUNCTION (test, binary) (void)
74 TYPE (gsl_block) * v = FUNCTION (gsl_block, calloc) (N);
76 FILE *f = fopen ("test.dat", "wb");
78 for (i = 0; i < N; i++)
80 v->data[2*i] = (ATOMIC)(N - i);
81 v->data[2*i + 1] = (ATOMIC)(10*(N-i) + 1);
84 FUNCTION (gsl_block, fwrite) (f, v);
88 FUNCTION (gsl_block, free) (v);
92 TYPE (gsl_block) * w = FUNCTION (gsl_block, calloc) (N);
94 FILE *f = fopen ("test.dat", "rb");
96 FUNCTION (gsl_block, fread) (f, w);
99 for (i = 0; i < N; i++)
101 if (w->data[2 * i] != (ATOMIC) (N - i) || w->data[2 * i + 1] != (ATOMIC) (10*(N - i) + 1))
106 FUNCTION (gsl_block, free) (w);
109 gsl_test (status, NAME (gsl_block) "_write and read");
115 FUNCTION (test, trap) (void)
117 TYPE (gsl_block) * b = FUNCTION (gsl_block, alloc) (0);
119 gsl_test (b != 0, NAME (gsl_block) "_alloc traps zero length");