annotate 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
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
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
5 File: test/callback_suite/globals.c
0
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
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
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 <assert.h>
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 281
diff changeset
27 #include <stdint.h>
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
28 #include <stdlib.h>
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29 #include "dyncall_signature.h"
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
30 #include "globals.h"
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
32
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
33 extern int G_maxargs;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
34
489
63f623bff0b9 - test/callback_suite: reverted designated aggr initialization back to what it was, b/c of MSVCs before 2013 not handling a lot of C99
Tassilo Philipp
parents: 487
diff changeset
35 static DCValueSet K;
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
36 DCValueSet* ValueMatrix;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
37 DCValue* Args;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
38 DCValue Result;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
39
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
40 void get_reference_arg(DCValue* output, char ch, int pos)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
41 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
42 output->L = 0xCAFEBABEDEADC0DELL;
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
43 pos = pos + 2; //@@@STRUCT unsure about indexing, here
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
44 switch(ch) {
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 281
diff changeset
45 case DC_SIGCHAR_BOOL: output->B = ((pos*K.i) & 1) ? DC_TRUE : DC_FALSE ; break;
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 281
diff changeset
46 case DC_SIGCHAR_CHAR: output->c = pos * K.c; break;
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 281
diff changeset
47 case DC_SIGCHAR_UCHAR: output->C = pos * K.C; break;
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 281
diff changeset
48 case DC_SIGCHAR_SHORT: output->s = pos * K.s; break;
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 281
diff changeset
49 case DC_SIGCHAR_USHORT: output->S = pos * K.S; break;
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 281
diff changeset
50 case DC_SIGCHAR_INT: output->i = pos * K.i; break;
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 281
diff changeset
51 case DC_SIGCHAR_UINT: output->I = pos * K.I; break;
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 281
diff changeset
52 case DC_SIGCHAR_LONG: output->j = pos * K.j; break;
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 281
diff changeset
53 case DC_SIGCHAR_ULONG: output->J = pos * K.J; break;
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 281
diff changeset
54 case DC_SIGCHAR_LONGLONG: output->l = pos * K.l; break;
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 281
diff changeset
55 case DC_SIGCHAR_ULONGLONG:output->L = pos * K.L; break;
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 281
diff changeset
56 case DC_SIGCHAR_FLOAT: output->f = (float)pos * K.f; break;
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 281
diff changeset
57 case DC_SIGCHAR_DOUBLE: output->d = (double)pos * K.d; break;
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 281
diff changeset
58 case DC_SIGCHAR_POINTER: output->p = (DCpointer)(pos * (intptr_t)K.p); break;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
59 default: assert(0);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
60 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
61 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
62
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
63 void get_reference_result(DCValue* output, char ch)
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
64 {
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
65 get_reference_arg(output, ch, -1);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
66 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
67
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
68 void init_test_data()
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
69 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
70 int pos;
489
63f623bff0b9 - test/callback_suite: reverted designated aggr initialization back to what it was, b/c of MSVCs before 2013 not handling a lot of C99
Tassilo Philipp
parents: 487
diff changeset
71
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
72 ValueMatrix = malloc(sizeof(DCValueSet)*G_maxargs);
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
73
489
63f623bff0b9 - test/callback_suite: reverted designated aggr initialization back to what it was, b/c of MSVCs before 2013 not handling a lot of C99
Tassilo Philipp
parents: 487
diff changeset
74 K.B = DC_TRUE;
63f623bff0b9 - test/callback_suite: reverted designated aggr initialization back to what it was, b/c of MSVCs before 2013 not handling a lot of C99
Tassilo Philipp
parents: 487
diff changeset
75 K.c = 13;
63f623bff0b9 - test/callback_suite: reverted designated aggr initialization back to what it was, b/c of MSVCs before 2013 not handling a lot of C99
Tassilo Philipp
parents: 487
diff changeset
76 K.C = 19;
63f623bff0b9 - test/callback_suite: reverted designated aggr initialization back to what it was, b/c of MSVCs before 2013 not handling a lot of C99
Tassilo Philipp
parents: 487
diff changeset
77 K.s = -23;
63f623bff0b9 - test/callback_suite: reverted designated aggr initialization back to what it was, b/c of MSVCs before 2013 not handling a lot of C99
Tassilo Philipp
parents: 487
diff changeset
78 K.S = 41;
63f623bff0b9 - test/callback_suite: reverted designated aggr initialization back to what it was, b/c of MSVCs before 2013 not handling a lot of C99
Tassilo Philipp
parents: 487
diff changeset
79 K.i = 134;
63f623bff0b9 - test/callback_suite: reverted designated aggr initialization back to what it was, b/c of MSVCs before 2013 not handling a lot of C99
Tassilo Philipp
parents: 487
diff changeset
80 K.I = 257;
63f623bff0b9 - test/callback_suite: reverted designated aggr initialization back to what it was, b/c of MSVCs before 2013 not handling a lot of C99
Tassilo Philipp
parents: 487
diff changeset
81 K.j = -12357;
63f623bff0b9 - test/callback_suite: reverted designated aggr initialization back to what it was, b/c of MSVCs before 2013 not handling a lot of C99
Tassilo Philipp
parents: 487
diff changeset
82 K.J = 356;
63f623bff0b9 - test/callback_suite: reverted designated aggr initialization back to what it was, b/c of MSVCs before 2013 not handling a lot of C99
Tassilo Philipp
parents: 487
diff changeset
83 K.l = -1234556687721LL;
63f623bff0b9 - test/callback_suite: reverted designated aggr initialization back to what it was, b/c of MSVCs before 2013 not handling a lot of C99
Tassilo Philipp
parents: 487
diff changeset
84 K.L = 23564634576581ULL;
63f623bff0b9 - test/callback_suite: reverted designated aggr initialization back to what it was, b/c of MSVCs before 2013 not handling a lot of C99
Tassilo Philipp
parents: 487
diff changeset
85 K.f = 1.20432545f;
63f623bff0b9 - test/callback_suite: reverted designated aggr initialization back to what it was, b/c of MSVCs before 2013 not handling a lot of C99
Tassilo Philipp
parents: 487
diff changeset
86 K.d = 1.0123456;
63f623bff0b9 - test/callback_suite: reverted designated aggr initialization back to what it was, b/c of MSVCs before 2013 not handling a lot of C99
Tassilo Philipp
parents: 487
diff changeset
87 K.p = (void*)0x1020345;
63f623bff0b9 - test/callback_suite: reverted designated aggr initialization back to what it was, b/c of MSVCs before 2013 not handling a lot of C99
Tassilo Philipp
parents: 487
diff changeset
88
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
89 for(pos = 0 ;pos < G_maxargs ;++pos) {
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
90 DCValue ref;
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
91 get_reference_arg(&ref, DC_SIGCHAR_BOOL , pos); ValueMatrix[pos].B = ref.B;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
92 get_reference_arg(&ref, DC_SIGCHAR_CHAR , pos); ValueMatrix[pos].c = ref.c;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
93 get_reference_arg(&ref, DC_SIGCHAR_UCHAR , pos); ValueMatrix[pos].C = ref.C;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
94 get_reference_arg(&ref, DC_SIGCHAR_SHORT , pos); ValueMatrix[pos].s = ref.s;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
95 get_reference_arg(&ref, DC_SIGCHAR_USHORT , pos); ValueMatrix[pos].S = ref.S;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
96 get_reference_arg(&ref, DC_SIGCHAR_INT , pos); ValueMatrix[pos].i = ref.i;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
97 get_reference_arg(&ref, DC_SIGCHAR_UINT , pos); ValueMatrix[pos].I = ref.I;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
98 get_reference_arg(&ref, DC_SIGCHAR_LONG , pos); ValueMatrix[pos].j = ref.j;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
99 get_reference_arg(&ref, DC_SIGCHAR_ULONG , pos); ValueMatrix[pos].J = ref.J;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
100 get_reference_arg(&ref, DC_SIGCHAR_LONGLONG , pos); ValueMatrix[pos].l = ref.l;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
101 get_reference_arg(&ref, DC_SIGCHAR_ULONGLONG, pos); ValueMatrix[pos].L = ref.L;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
102 get_reference_arg(&ref, DC_SIGCHAR_FLOAT , pos); ValueMatrix[pos].f = ref.f;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
103 get_reference_arg(&ref, DC_SIGCHAR_DOUBLE , pos); ValueMatrix[pos].d = ref.d;
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
104 get_reference_arg(&ref, DC_SIGCHAR_POINTER , pos); ValueMatrix[pos].p = ref.p;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
105 }
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
106
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
107 Args = malloc(sizeof(DCValue)*G_maxargs);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
108 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
109
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
110
505
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
111 void deinit_test_data()
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
112 {
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
113 free(Args);
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
114
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
115 free(ValueMatrix);
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
116 }
049e04af13c8 test/callback_suite:
Tassilo Philipp
parents: 489
diff changeset
117