Mercurial > pub > dyncall > dyncall
comparison test/callback_suite/globals.c @ 509:f3d44195dbdf
callback_suite:
- further, big refactoring to make the test data setup be a lot more in line with call_suite and call_suite_aggrs
- added support to test void return values (was missing in prev version)
author | Tassilo Philipp |
---|---|
date | Sat, 09 Apr 2022 23:00:24 +0200 |
parents | 5a3c07a0f376 |
children |
comparison
equal
deleted
inserted
replaced
508:1aa2af848e8a | 509:f3d44195dbdf |
---|---|
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | 21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
23 | 23 |
24 */ | 24 */ |
25 | 25 |
26 #include <stdlib.h> | |
27 #include "globals.h" | |
28 #include <float.h> | |
26 #include <assert.h> | 29 #include <assert.h> |
27 #include <stdint.h> | |
28 #include <stdlib.h> | |
29 #include "dyncall_signature.h" | |
30 #include "globals.h" | |
31 | 30 |
31 #define X(CH,T) T *V_##CH; T *K_##CH; | |
32 DEF_TYPES | |
33 #undef X | |
32 | 34 |
33 extern int G_maxargs; | 35 static double rand_d() { return ( ( (double) rand() ) / ( (double) RAND_MAX ) ); } |
34 | 36 |
35 static DCValueSet K; | 37 void init_test_data() |
36 DCValueSet* ValueMatrix; | |
37 DCValue* Args; | |
38 DCValue Result; | |
39 | |
40 void get_reference_arg(DCValue* output, char ch, int pos) | |
41 { | 38 { |
42 output->L = 0xCAFEBABEDEADC0DELL; | 39 int i; |
43 pos = pos + 2; | 40 #define X(CH,T) V_##CH = (T*) malloc(sizeof(T)*(G_maxargs+1)); K_##CH = (T*) malloc(sizeof(T)*(G_maxargs+1)); |
44 switch(ch) { | 41 DEF_TYPES |
45 case DC_SIGCHAR_BOOL: output->B = ((pos*K.i) & 1) ? DC_TRUE : DC_FALSE ; break; | 42 #undef X |
46 case DC_SIGCHAR_CHAR: output->c = pos * K.c; break; | 43 for(i=0;i<G_maxargs+1;++i) { |
47 case DC_SIGCHAR_UCHAR: output->C = pos * K.C; break; | 44 K_B[i] = (DCbool) ((int)rand_d() & 1); |
48 case DC_SIGCHAR_SHORT: output->s = pos * K.s; break; | 45 K_c[i] = (char) (((rand_d()-0.5)*2) * (1<<7)); |
49 case DC_SIGCHAR_USHORT: output->S = pos * K.S; break; | 46 K_s[i] = (short) (((rand_d()-0.5)*2) * (1<<(sizeof(short)*8-1))); |
50 case DC_SIGCHAR_INT: output->i = pos * K.i; break; | 47 K_i[i] = (int) (((rand_d()-0.5)*2) * (1<<(sizeof(int)*8-2))); |
51 case DC_SIGCHAR_UINT: output->I = pos * K.I; break; | 48 K_j[i] = (long) (((rand_d()-0.5)*2) * (1L<<(sizeof(long)*8-2))); |
52 case DC_SIGCHAR_LONG: output->j = pos * K.j; break; | 49 K_l[i] = (long long) (((rand_d()-0.5)*2) * (1LL<<(sizeof(long long)*8-2))); |
53 case DC_SIGCHAR_ULONG: output->J = pos * K.J; break; | 50 K_C[i] = (unsigned char) (((rand_d()-0.5)*2) * (1<<7)); |
54 case DC_SIGCHAR_LONGLONG: output->l = pos * K.l; break; | 51 K_S[i] = (unsigned short) (((rand_d()-0.5)*2) * (1<<(sizeof(short)*8-1))); |
55 case DC_SIGCHAR_ULONGLONG:output->L = pos * K.L; break; | 52 K_I[i] = (unsigned int) (((rand_d()-0.5)*2) * (1<<(sizeof(int)*8-2))); |
56 case DC_SIGCHAR_FLOAT: output->f = (float)pos * K.f; break; | 53 K_J[i] = (unsigned long) (((rand_d()-0.5)*2) * (1L<<(sizeof(long)*8-2))); |
57 case DC_SIGCHAR_DOUBLE: output->d = (double)pos * K.d; break; | 54 K_L[i] = (unsigned long long)(((rand_d()-0.5)*2) * (1LL<<(sizeof(long long)*8-2))); |
58 case DC_SIGCHAR_POINTER: output->p = (DCpointer)(pos * (intptr_t)K.p); break; | 55 K_p[i] = (void*)(long) (((rand_d()-0.5)*2) * (1LL<<(sizeof(void*)*8-1))); |
59 default: assert(0); | 56 K_f[i] = (float) (rand_d() * FLT_MAX); |
57 K_d[i] = (double) (((rand_d()-0.5)*2) * DBL_MAX); | |
60 } | 58 } |
61 } | 59 } |
62 | 60 |
63 void get_reference_result(DCValue* output, char ch) | 61 void clear_V() |
64 { | 62 { |
65 get_reference_arg(output, ch, -1); | 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 } | |
66 } | 69 } |
67 | |
68 void init_test_data() | |
69 { | |
70 int pos; | |
71 | |
72 ValueMatrix = malloc(sizeof(DCValueSet)*G_maxargs); | |
73 | |
74 K.B = DC_TRUE; | |
75 K.c = 13; | |
76 K.C = 19; | |
77 K.s = -23; | |
78 K.S = 41; | |
79 K.i = 134; | |
80 K.I = 257; | |
81 K.j = -12357; | |
82 K.J = 356; | |
83 K.l = -1234556687721LL; | |
84 K.L = 23564634576581ULL; | |
85 K.f = 1.20432545f; | |
86 K.d = 1.0123456; | |
87 K.p = (void*)0x1020345; | |
88 | |
89 for(pos = 0 ;pos < G_maxargs ;++pos) { | |
90 DCValue ref; | |
91 get_reference_arg(&ref, DC_SIGCHAR_BOOL , pos); ValueMatrix[pos].B = ref.B; | |
92 get_reference_arg(&ref, DC_SIGCHAR_CHAR , pos); ValueMatrix[pos].c = ref.c; | |
93 get_reference_arg(&ref, DC_SIGCHAR_UCHAR , pos); ValueMatrix[pos].C = ref.C; | |
94 get_reference_arg(&ref, DC_SIGCHAR_SHORT , pos); ValueMatrix[pos].s = ref.s; | |
95 get_reference_arg(&ref, DC_SIGCHAR_USHORT , pos); ValueMatrix[pos].S = ref.S; | |
96 get_reference_arg(&ref, DC_SIGCHAR_INT , pos); ValueMatrix[pos].i = ref.i; | |
97 get_reference_arg(&ref, DC_SIGCHAR_UINT , pos); ValueMatrix[pos].I = ref.I; | |
98 get_reference_arg(&ref, DC_SIGCHAR_LONG , pos); ValueMatrix[pos].j = ref.j; | |
99 get_reference_arg(&ref, DC_SIGCHAR_ULONG , pos); ValueMatrix[pos].J = ref.J; | |
100 get_reference_arg(&ref, DC_SIGCHAR_LONGLONG , pos); ValueMatrix[pos].l = ref.l; | |
101 get_reference_arg(&ref, DC_SIGCHAR_ULONGLONG, pos); ValueMatrix[pos].L = ref.L; | |
102 get_reference_arg(&ref, DC_SIGCHAR_FLOAT , pos); ValueMatrix[pos].f = ref.f; | |
103 get_reference_arg(&ref, DC_SIGCHAR_DOUBLE , pos); ValueMatrix[pos].d = ref.d; | |
104 get_reference_arg(&ref, DC_SIGCHAR_POINTER , pos); ValueMatrix[pos].p = ref.p; | |
105 } | |
106 | |
107 Args = malloc(sizeof(DCValue)*G_maxargs); | |
108 } | |
109 | |
110 | 70 |
111 void deinit_test_data() | 71 void deinit_test_data() |
112 { | 72 { |
113 free(Args); | 73 #define X(CH,T) free(V_##CH); free(K_##CH); |
114 | 74 DEF_TYPES |
115 free(ValueMatrix); | 75 #undef X |
116 } | 76 } |
117 | 77 |