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