comparison test/callback_suite/globals.c @ 505:049e04af13c8

test/callback_suite: - greatly simplified - refactored to look more like other test cases (especially call_suite{,_aggrs} for consistency/maintainablity/future code sharing
author Tassilo Philipp
date Sat, 09 Apr 2022 13:53:58 +0200
parents test/callback_suite/env.c@63f623bff0b9
children 5a3c07a0f376
comparison
equal deleted inserted replaced
504:f263eb7a206e 505:049e04af13c8
1 /*
2
3 Package: dyncall
4 Library: test
5 File: test/callback_suite/globals.c
6 Description:
7 License:
8
9 Copyright (c) 2011-2022 Daniel Adler <dadler@uni-goettingen.de>,
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
26 #include <assert.h>
27 #include <stdint.h>
28 #include <stdlib.h>
29 #include "dyncall_signature.h"
30 #include "globals.h"
31
32
33 extern int G_maxargs;
34
35 static DCValueSet K;
36 DCValueSet* ValueMatrix;
37 DCValue* Args;
38 DCValue Result;
39
40 void get_reference_arg(DCValue* output, char ch, int pos)
41 {
42 output->L = 0xCAFEBABEDEADC0DELL;
43 pos = pos + 2; //@@@STRUCT unsure about indexing, here
44 switch(ch) {
45 case DC_SIGCHAR_BOOL: output->B = ((pos*K.i) & 1) ? DC_TRUE : DC_FALSE ; break;
46 case DC_SIGCHAR_CHAR: output->c = pos * K.c; break;
47 case DC_SIGCHAR_UCHAR: output->C = pos * K.C; break;
48 case DC_SIGCHAR_SHORT: output->s = pos * K.s; break;
49 case DC_SIGCHAR_USHORT: output->S = pos * K.S; break;
50 case DC_SIGCHAR_INT: output->i = pos * K.i; break;
51 case DC_SIGCHAR_UINT: output->I = pos * K.I; break;
52 case DC_SIGCHAR_LONG: output->j = pos * K.j; break;
53 case DC_SIGCHAR_ULONG: output->J = pos * K.J; break;
54 case DC_SIGCHAR_LONGLONG: output->l = pos * K.l; break;
55 case DC_SIGCHAR_ULONGLONG:output->L = pos * K.L; break;
56 case DC_SIGCHAR_FLOAT: output->f = (float)pos * K.f; break;
57 case DC_SIGCHAR_DOUBLE: output->d = (double)pos * K.d; break;
58 case DC_SIGCHAR_POINTER: output->p = (DCpointer)(pos * (intptr_t)K.p); break;
59 default: assert(0);
60 }
61 }
62
63 void get_reference_result(DCValue* output, char ch)
64 {
65 get_reference_arg(output, ch, -1);
66 }
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
111 void deinit_test_data()
112 {
113 free(Args);
114
115 free(ValueMatrix);
116 }
117