annotate test/call_suite/globals.c @ 515:c9c546f8598b

- added _Bool type to call_suite* tests
author Tassilo Philipp
date Sun, 10 Apr 2022 21:05:33 +0200
parents e3bf15207d93
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 /*
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 Package: dyncall
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 Library: test
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 File: test/call_suite/globals.c
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 Description:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 License:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8
436
23b12c7ad462 - call_suite cleanup (no change in functionality): removal of unused decl, freeing memory at end, func renaming for clarity, static for tu-local symbols, ...
Tassilo Philipp
parents: 430
diff changeset
9 Copyright (c) 2011-2022 Daniel Adler <dadler@uni-goettingen.de>,
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 Tassilo Philipp <tphilipp@potion-studios.com>
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 Permission to use, copy, modify, and distribute this software for any
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 purpose with or without fee is hereby granted, provided that the above
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 copyright notice and this permission notice appear in all copies.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26 #include <stdlib.h>
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27 #include "globals.h"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28 #include <float.h>
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29
429
2b708397bba1 - simplified and decluttered test/call_suite
Tassilo Philipp
parents: 281
diff changeset
30 #define X(CH,T) T *V_##CH; T *K_##CH;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31 DEF_TYPES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32 #undef X
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33
436
23b12c7ad462 - call_suite cleanup (no change in functionality): removal of unused decl, freeing memory at end, func renaming for clarity, static for tu-local symbols, ...
Tassilo Philipp
parents: 430
diff changeset
34 static double rand_d() { return ( ( (double) rand() ) / ( (double) RAND_MAX ) ); }
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
35
436
23b12c7ad462 - call_suite cleanup (no change in functionality): removal of unused decl, freeing memory at end, func renaming for clarity, static for tu-local symbols, ...
Tassilo Philipp
parents: 430
diff changeset
36 void init_test_data()
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
37 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
38 int i;
429
2b708397bba1 - simplified and decluttered test/call_suite
Tassilo Philipp
parents: 281
diff changeset
39 #define X(CH,T) V_##CH = (T*) malloc(sizeof(T)*(G_maxargs+1)); K_##CH = (T*) malloc(sizeof(T)*(G_maxargs+1));
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
40 DEF_TYPES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
41 #undef X
48
dc0bcee2c847 bugfix: value and control-group arrays need to be max-arg size + 1 (... futher cleanup is needed as index 0 in array is not used at all ;-/ )
Daniel Adler <dadler@dyncall.org>
parents: 0
diff changeset
42 for(i=0;i<G_maxargs+1;++i) {
515
c9c546f8598b - added _Bool type to call_suite* tests
Tassilo Philipp
parents: 491
diff changeset
43 K_B[i] = (DCbool) ((int)rand_d() & 1);
491
e3bf15207d93 - added unsigned types to call_suite test
Tassilo Philipp
parents: 442
diff changeset
44 K_c[i] = (char) (((rand_d()-0.5)*2) * (1<<7));
e3bf15207d93 - added unsigned types to call_suite test
Tassilo Philipp
parents: 442
diff changeset
45 K_s[i] = (short) (((rand_d()-0.5)*2) * (1<<(sizeof(short)*8-1)));
e3bf15207d93 - added unsigned types to call_suite test
Tassilo Philipp
parents: 442
diff changeset
46 K_i[i] = (int) (((rand_d()-0.5)*2) * (1<<(sizeof(int)*8-2)));
e3bf15207d93 - added unsigned types to call_suite test
Tassilo Philipp
parents: 442
diff changeset
47 K_j[i] = (long) (((rand_d()-0.5)*2) * (1L<<(sizeof(long)*8-2)));
e3bf15207d93 - added unsigned types to call_suite test
Tassilo Philipp
parents: 442
diff changeset
48 K_l[i] = (long long) (((rand_d()-0.5)*2) * (1LL<<(sizeof(long long)*8-2)));
e3bf15207d93 - added unsigned types to call_suite test
Tassilo Philipp
parents: 442
diff changeset
49 K_C[i] = (unsigned char) (((rand_d()-0.5)*2) * (1<<7));
e3bf15207d93 - added unsigned types to call_suite test
Tassilo Philipp
parents: 442
diff changeset
50 K_S[i] = (unsigned short) (((rand_d()-0.5)*2) * (1<<(sizeof(short)*8-1)));
e3bf15207d93 - added unsigned types to call_suite test
Tassilo Philipp
parents: 442
diff changeset
51 K_I[i] = (unsigned int) (((rand_d()-0.5)*2) * (1<<(sizeof(int)*8-2)));
e3bf15207d93 - added unsigned types to call_suite test
Tassilo Philipp
parents: 442
diff changeset
52 K_J[i] = (unsigned long) (((rand_d()-0.5)*2) * (1L<<(sizeof(long)*8-2)));
e3bf15207d93 - added unsigned types to call_suite test
Tassilo Philipp
parents: 442
diff changeset
53 K_L[i] = (unsigned long long)(((rand_d()-0.5)*2) * (1LL<<(sizeof(long long)*8-2)));
e3bf15207d93 - added unsigned types to call_suite test
Tassilo Philipp
parents: 442
diff changeset
54 K_p[i] = (void*)(long) (((rand_d()-0.5)*2) * (1LL<<(sizeof(void*)*8-1)));
e3bf15207d93 - added unsigned types to call_suite test
Tassilo Philipp
parents: 442
diff changeset
55 K_f[i] = (float) (rand_d() * FLT_MAX);
e3bf15207d93 - added unsigned types to call_suite test
Tassilo Philipp
parents: 442
diff changeset
56 K_d[i] = (double) (((rand_d()-0.5)*2) * DBL_MAX);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
57 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
58 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
59
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
60 void clear_V()
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
61 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
62 int i;
48
dc0bcee2c847 bugfix: value and control-group arrays need to be max-arg size + 1 (... futher cleanup is needed as index 0 in array is not used at all ;-/ )
Daniel Adler <dadler@dyncall.org>
parents: 0
diff changeset
63 for(i=0;i<G_maxargs+1;++i) {
429
2b708397bba1 - simplified and decluttered test/call_suite
Tassilo Philipp
parents: 281
diff changeset
64 #define X(CH,T) V_##CH[i] = (T) 0;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
65 DEF_TYPES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
66 #undef X
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
67 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
68 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
69
436
23b12c7ad462 - call_suite cleanup (no change in functionality): removal of unused decl, freeing memory at end, func renaming for clarity, static for tu-local symbols, ...
Tassilo Philipp
parents: 430
diff changeset
70 void deinit_test_data()
23b12c7ad462 - call_suite cleanup (no change in functionality): removal of unused decl, freeing memory at end, func renaming for clarity, static for tu-local symbols, ...
Tassilo Philipp
parents: 430
diff changeset
71 {
23b12c7ad462 - call_suite cleanup (no change in functionality): removal of unused decl, freeing memory at end, func renaming for clarity, static for tu-local symbols, ...
Tassilo Philipp
parents: 430
diff changeset
72 #define X(CH,T) free(V_##CH); free(K_##CH);
23b12c7ad462 - call_suite cleanup (no change in functionality): removal of unused decl, freeing memory at end, func renaming for clarity, static for tu-local symbols, ...
Tassilo Philipp
parents: 430
diff changeset
73 DEF_TYPES
23b12c7ad462 - call_suite cleanup (no change in functionality): removal of unused decl, freeing memory at end, func renaming for clarity, static for tu-local symbols, ...
Tassilo Philipp
parents: 430
diff changeset
74 #undef X
23b12c7ad462 - call_suite cleanup (no change in functionality): removal of unused decl, freeing memory at end, func renaming for clarity, static for tu-local symbols, ...
Tassilo Philipp
parents: 430
diff changeset
75 }
491
e3bf15207d93 - added unsigned types to call_suite test
Tassilo Philipp
parents: 442
diff changeset
76