Mercurial > pub > dyncall > dyncall
annotate test/suite_x86win32fast/main.cc @ 605:0f40e13a2f0a
- cleanups
author | Tassilo Philipp |
---|---|
date | Wed, 21 Sep 2022 14:37:09 +0200 |
parents | d73dc7ad37e4 |
children | 85b7a117b807 |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: test | |
5 File: test/suite_x86win32fast/main.cc | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
6 Description: |
0 | 7 License: |
8 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
9 Copyright (c) 2007-2018 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 | |
27 | |
28 #include "../../dyncall/dyncall.h" | |
29 #include "config.h" | |
30 #include "../../dyncall/dyncall_value.h" | |
31 #include "../../dyncall/dyncall_macros.h" | |
32 #include <math.h> | |
33 #include "../common/platformInit.h" | |
34 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */ | |
35 | |
36 | |
37 int getId(); | |
38 DCpointer getFunc(int x); | |
39 DCValue* getArg(int pos); | |
40 | |
41 | |
42 DCbool valueBool[NARGS]; | |
43 DCshort valueShort[NARGS]; | |
44 DCchar valueChar[NARGS]; | |
45 DCint valueInt[NARGS]; | |
46 DClonglong valueLongLong[NARGS]; | |
47 DCdouble valueDouble[NARGS]; | |
48 DCpointer valuePointer[NARGS]; | |
49 DCfloat valueFloat[NARGS]; | |
50 | |
51 | |
52 bool equals(int select, int pos, void* data) | |
53 { | |
54 switch(select) | |
55 { | |
56 case 0: return ( getArg(pos)->B == valueBool[pos] ); break; | |
57 case 1: return ( getArg(pos)->i == valueInt[pos] ); break; | |
58 case 2: return ( getArg(pos)->l == valueLongLong[pos] ); break; | |
59 case 3: return ( getArg(pos)->d == valueDouble[pos] ); break; | |
60 case 4: return ( getArg(pos)->p == valuePointer[pos] ); break; | |
61 case 5: return ( getArg(pos)->f == valueFloat[pos] ); break; | |
62 } | |
63 return false; | |
64 } | |
65 | |
66 | |
67 void clearValues(); | |
68 | |
69 | |
70 void init() | |
71 { | |
72 for (int i = 0 ; i < NARGS ; ++i ) { | |
73 | |
74 valueBool[i] = DCbool( (i % 1) ? DC_TRUE : DC_FALSE ); | |
75 valueInt[i] = DCint(i); | |
76 valueLongLong[i] = DClonglong(i); | |
77 valueDouble[i] = DCdouble(i); | |
78 valuePointer[i] = DCpointer(i); | |
79 valueFloat[i] = DCfloat(i); | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
80 } |
0 | 81 } |
82 | |
83 | |
84 void push(DCCallVM* pCall, int select, int pos) | |
85 { | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
86 switch(select) |
0 | 87 { |
88 case 0: dcArgBool( pCall, valueBool[pos] ); break; | |
89 case 1: dcArgInt( pCall, valueInt[pos] ); break; | |
90 case 2: dcArgLongLong( pCall, valueLongLong[pos] ); break; | |
91 case 3: dcArgDouble( pCall, valueDouble[pos] ); break; | |
92 case 4: dcArgPointer( pCall, valuePointer[pos] ); break; | |
93 case 5: dcArgFloat( pCall, valueFloat[pos] ); break; | |
94 } | |
95 } | |
96 | |
97 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
98 #define test(x) if (!(x)) return false |
0 | 99 |
100 | |
413
d73dc7ad37e4
- fix nameclash due to a previous and bad cleanup
Tassilo Philipp
parents:
410
diff
changeset
|
101 bool test_case(int x) |
0 | 102 { |
103 clearValues(); | |
104 | |
105 DCCallVM* pCall = dcNewCallVM(4096); | |
106 #ifdef DC__C_GNU | |
107 dcMode(pCall, DC_CALL_C_X86_WIN32_FAST_GNU); | |
108 #else | |
109 dcMode(pCall, DC_CALL_C_X86_WIN32_FAST_MS); | |
110 #endif | |
111 dcReset(pCall); | |
112 | |
113 int y = x; | |
114 int selects[NARGS] = { 0, }; | |
115 int pos = 0; | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
116 for(pos = 0;y>0;++pos) |
0 | 117 { |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
118 int select = (y-1) % NTYPES; |
0 | 119 selects[pos] = select; |
120 push(pCall,select,pos); | |
121 y = (y-1) / NTYPES; | |
122 } | |
123 dcCallVoid(pCall,getFunc(x)); | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
124 |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
125 test( getId() == x ); |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
126 |
0 | 127 for(int i = 0;i<pos;++i) { |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
128 test( equals( selects[i], i, getArg(i) ) ); |
0 | 129 } |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
130 |
0 | 131 dcFree(pCall); |
132 return true; | |
133 } | |
134 | |
135 | |
136 int powerfact(int x, int n) | |
137 { | |
138 if (n==0) return 0; | |
139 return static_cast<int>( pow((double)x,n)+powerfact(x,n-1) ); | |
140 } | |
141 | |
142 #include <stdio.h> | |
143 #include <stdlib.h> | |
144 | |
145 bool run_range(int from, int to) | |
146 { | |
147 bool tr = true; | |
148 for (int i = from ; i < to ; ++i ) { | |
149 printf("%d:",i); | |
413
d73dc7ad37e4
- fix nameclash due to a previous and bad cleanup
Tassilo Philipp
parents:
410
diff
changeset
|
150 bool r = test_case(i); |
0 | 151 printf("%d\n", r); |
152 tr &= r; | |
153 } | |
154 return tr; | |
155 } | |
156 | |
157 extern "C" { | |
158 | |
159 int main(int argc, char* argv[]) | |
160 { | |
161 dcTest_initPlatform(); | |
162 | |
163 bool success = false; | |
164 init(); | |
165 if (argc == 2) { | |
166 int index = atoi(argv[1]); | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
167 success = run_range( index, index+1 ); |
0 | 168 } else if (argc == 3) { |
169 int from = atoi(argv[1]); | |
170 int to = atoi(argv[2])+1; | |
171 success = run_range(from,to); | |
172 } else { | |
173 int ncalls = powerfact(NTYPES,NARGS)+1; | |
174 success = run_range(0,ncalls); | |
175 } | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
176 |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
177 printf("result: suite_x86win32fast: %d\n", success); |
0 | 178 |
179 dcTest_deInitPlatform(); | |
180 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
181 return !success; |
0 | 182 } |
183 | |
184 } // extern "C" | |
185 |