0
|
1 /*
|
|
2
|
|
3 Package: dyncall
|
|
4 Library: test
|
505
|
5 File: test/callback_suite/globals.c
|
0
|
6 Description:
|
|
7 License:
|
|
8
|
505
|
9 Copyright (c) 2011-2022 Daniel Adler <dadler@uni-goettingen.de>,
|
0
|
10 Tassilo Philipp <tphilipp@potion-studios.com>
|
|
11
|
|
12 Permission to use, copy, modify, and distribute this software for any
|
|
13 purpose with or without fee is hereby granted, provided that the above
|
|
14 copyright notice and this permission notice appear in all copies.
|
|
15
|
|
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
23
|
|
24 */
|
|
25
|
505
|
26 #include <stdlib.h>
|
|
27 #include "globals.h"
|
509
|
28 #include <float.h>
|
|
29 #include <assert.h>
|
0
|
30
|
509
|
31 #define X(CH,T) T *V_##CH; T *K_##CH;
|
|
32 DEF_TYPES
|
|
33 #undef X
|
0
|
34
|
509
|
35 static double rand_d() { return ( ( (double) rand() ) / ( (double) RAND_MAX ) ); }
|
0
|
36
|
505
|
37 void init_test_data()
|
0
|
38 {
|
509
|
39 int i;
|
|
40 #define X(CH,T) V_##CH = (T*) malloc(sizeof(T)*(G_maxargs+1)); K_##CH = (T*) malloc(sizeof(T)*(G_maxargs+1));
|
|
41 DEF_TYPES
|
|
42 #undef X
|
|
43 for(i=0;i<G_maxargs+1;++i) {
|
|
44 K_B[i] = (DCbool) ((int)rand_d() & 1);
|
|
45 K_c[i] = (char) (((rand_d()-0.5)*2) * (1<<7));
|
|
46 K_s[i] = (short) (((rand_d()-0.5)*2) * (1<<(sizeof(short)*8-1)));
|
|
47 K_i[i] = (int) (((rand_d()-0.5)*2) * (1<<(sizeof(int)*8-2)));
|
|
48 K_j[i] = (long) (((rand_d()-0.5)*2) * (1L<<(sizeof(long)*8-2)));
|
|
49 K_l[i] = (long long) (((rand_d()-0.5)*2) * (1LL<<(sizeof(long long)*8-2)));
|
|
50 K_C[i] = (unsigned char) (((rand_d()-0.5)*2) * (1<<7));
|
|
51 K_S[i] = (unsigned short) (((rand_d()-0.5)*2) * (1<<(sizeof(short)*8-1)));
|
|
52 K_I[i] = (unsigned int) (((rand_d()-0.5)*2) * (1<<(sizeof(int)*8-2)));
|
|
53 K_J[i] = (unsigned long) (((rand_d()-0.5)*2) * (1L<<(sizeof(long)*8-2)));
|
|
54 K_L[i] = (unsigned long long)(((rand_d()-0.5)*2) * (1LL<<(sizeof(long long)*8-2)));
|
|
55 K_p[i] = (void*)(long) (((rand_d()-0.5)*2) * (1LL<<(sizeof(void*)*8-1)));
|
|
56 K_f[i] = (float) (rand_d() * FLT_MAX);
|
|
57 K_d[i] = (double) (((rand_d()-0.5)*2) * DBL_MAX);
|
0
|
58 }
|
|
59 }
|
|
60
|
509
|
61 void clear_V()
|
|
62 {
|
|
63 int i;
|
|
64 for(i=0;i<G_maxargs+1;++i) {
|
|
65 #define X(CH,T) V_##CH[i] = (T) 0;
|
|
66 DEF_TYPES
|
|
67 #undef X
|
|
68 }
|
|
69 }
|
0
|
70
|
505
|
71 void deinit_test_data()
|
|
72 {
|
509
|
73 #define X(CH,T) free(V_##CH); free(K_##CH);
|
|
74 DEF_TYPES
|
|
75 #undef X
|
505
|
76 }
|
|
77
|