Mercurial > pub > dyncall > dyncall
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 |
rev | line source |
---|---|
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 | |
26 #include <assert.h> | |
487 | 27 #include <stdint.h> |
505 | 28 #include <stdlib.h> |
0 | 29 #include "dyncall_signature.h" |
505 | 30 #include "globals.h" |
0 | 31 |
505 | 32 |
33 extern int G_maxargs; | |
0 | 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 | 36 DCValueSet* ValueMatrix; |
37 DCValue* Args; | |
38 DCValue Result; | |
0 | 39 |
505 | 40 void get_reference_arg(DCValue* output, char ch, int pos) |
0 | 41 { |
42 output->L = 0xCAFEBABEDEADC0DELL; | |
505 | 43 pos = pos + 2; //@@@STRUCT unsure about indexing, here |
0 | 44 switch(ch) { |
487 | 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; | |
0 | 59 default: assert(0); |
60 } | |
61 } | |
62 | |
505 | 63 void get_reference_result(DCValue* output, char ch) |
0 | 64 { |
505 | 65 get_reference_arg(output, ch, -1); |
0 | 66 } |
67 | |
505 | 68 void init_test_data() |
0 | 69 { |
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 | 72 ValueMatrix = malloc(sizeof(DCValueSet)*G_maxargs); |
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 | 89 for(pos = 0 ;pos < G_maxargs ;++pos) { |
0 | 90 DCValue ref; |
505 | 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; | |
0 | 105 } |
505 | 106 |
107 Args = malloc(sizeof(DCValue)*G_maxargs); | |
0 | 108 } |
109 | |
110 | |
505 | 111 void deinit_test_data() |
112 { | |
113 free(Args); | |
114 | |
115 free(ValueMatrix); | |
116 } | |
117 |