Mercurial > pub > dyncall > dyncall
annotate test/suite_x86win32std/main.cc @ 410:7608e34098b0
- cleanups, simplifications, some api clarification, ...
- test cases consistency:
* return status code depending on test results (for actual conformance tests, not stuff that is not an example or hack to check something, ..)
* platform init helper added for some
author | Tassilo Philipp |
---|---|
date | Tue, 05 Oct 2021 21:53:04 +0200 |
parents | f5577f6bf97a |
children | d73dc7ad37e4 |
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 typedef double precise; | |
42 | |
43 | |
44 DCbool valueBool[NARGS]; | |
45 DCshort valueShort[NARGS]; | |
46 DCchar valueChar[NARGS]; | |
47 DCint valueInt[NARGS]; | |
48 DClonglong valueLongLong[NARGS]; | |
49 DCdouble valueDouble[NARGS]; | |
50 DCpointer valuePointer[NARGS]; | |
51 DCfloat valueFloat[NARGS]; | |
52 | |
53 | |
54 bool equals(int select, int pos, void* data) | |
55 { | |
56 switch(select) | |
57 { | |
58 case 0: return ( getArg(pos)->B == valueBool[pos] ); break; | |
59 case 1: return ( getArg(pos)->i == valueInt[pos] ); break; | |
60 case 2: return ( getArg(pos)->L == valueLongLong[pos] ); break; | |
61 case 3: return ( getArg(pos)->d == valueDouble[pos] ); break; | |
62 case 4: return ( getArg(pos)->p == valuePointer[pos] ); break; | |
63 case 5: return ( getArg(pos)->f == valueFloat[pos] ); break; | |
64 } | |
65 return false; | |
66 } | |
67 | |
68 | |
69 void clearValues(); | |
70 | |
71 | |
72 void init() | |
73 { | |
74 for (int i = 0 ; i < NARGS ; ++i ) { | |
75 | |
76 valueBool[i] = DCbool( (i % 1) ? DC_TRUE : DC_FALSE ); | |
77 valueInt[i] = DCint(i); | |
78 valueLongLong[i] = DClonglong(i); | |
79 valueDouble[i] = DCdouble(i); | |
80 valuePointer[i] = DCpointer(i); | |
81 valueFloat[i] = DCfloat(i); | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
82 } |
0 | 83 } |
84 | |
85 | |
86 void push(DCCallVM* pCall, int select, int pos) | |
87 { | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
88 switch(select) |
0 | 89 { |
90 case 0: dcArgBool( pCall, valueBool[pos] ); break; | |
91 case 1: dcArgInt( pCall, valueInt[pos] ); break; | |
92 case 2: dcArgLongLong( pCall, valueLongLong[pos] ); break; | |
93 case 3: dcArgDouble( pCall, valueDouble[pos] ); break; | |
94 case 4: dcArgPointer( pCall, valuePointer[pos] ); break; | |
95 case 5: dcArgFloat( pCall, valueFloat[pos] ); break; | |
96 } | |
97 } | |
98 | |
99 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
100 #define test(x) if (!(x)) return false |
0 | 101 |
102 | |
103 bool test(int x) | |
104 { | |
105 clearValues(); | |
106 | |
107 DCCallVM* pCall = dcNewCallVM(4096); | |
108 dcMode(pCall, DC_CALL_C_X86_WIN32_STD); | |
109 dcReset(pCall); | |
110 int y = x; | |
111 int selects[NARGS] = { 0, }; | |
112 int pos = 0; | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
113 for(pos = 0;y>0;++pos) |
0 | 114 { |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
115 int select = (y-1) % NTYPES; |
0 | 116 selects[pos] = select; |
117 push(pCall,select,pos); | |
118 y = (y-1) / NTYPES; | |
119 } | |
120 dcCallVoid(pCall,getFunc(x)); | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
121 |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
122 test( getId() == x ); |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
123 |
0 | 124 for(int i = 0;i<pos;++i) { |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
125 test( equals( selects[i], i, getArg(i) ) ); |
0 | 126 } |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
127 |
0 | 128 dcFree(pCall); |
129 return true; | |
130 } | |
131 | |
132 | |
133 int powerfact(int x, int n) | |
134 { | |
135 if (n==0) return 0; | |
136 return static_cast<int>( pow((double)x,n)+powerfact(x,n-1) ); | |
137 } | |
138 | |
139 #include <stdio.h> | |
140 #include <stdlib.h> | |
141 | |
142 bool run_range(int from, int to) | |
143 { | |
144 bool tr = true; | |
145 for (int i = from ; i < to ; ++i ) { | |
146 printf("%d:",i); | |
147 bool r = test(i); | |
148 printf("%d\n", r); | |
149 tr &= r; | |
150 } | |
151 return tr; | |
152 } | |
153 | |
154 extern "C" { | |
155 | |
156 int main(int argc, char* argv[]) | |
157 { | |
158 dcTest_initPlatform(); | |
159 | |
160 bool success = false; | |
161 init(); | |
162 if (argc == 2) { | |
163 int index = atoi(argv[1]); | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
164 success = run_range( index, index+1 ); |
0 | 165 } else if (argc == 3) { |
166 int from = atoi(argv[1]); | |
167 int to = atoi(argv[2])+1; | |
168 success = run_range(from,to); | |
169 } else { | |
170 int ncalls = powerfact(NTYPES,NARGS)+1; | |
171 success = run_range(0,ncalls); | |
172 } | |
173 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
174 printf("result: suite_x86win32std: %d\n", success); |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
175 |
0 | 176 dcTest_deInitPlatform(); |
177 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
178 return !success; |
0 | 179 } |
180 | |
181 } // extern "C" | |
182 |