Mercurial > pub > dyncall > dyncall
annotate test/suite3/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/suite3/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 <stdlib.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 DCint valueInt [NARGS]; | |
43 DClonglong valueLongLong[NARGS]; | |
44 DCdouble valueDouble [NARGS]; | |
45 DCfloat valueFloat [NARGS]; | |
46 | |
47 | |
48 bool equals(int select, int pos, void* data) | |
49 { | |
50 switch(select) | |
51 { | |
52 case 0: return ( getArg(pos)->i == valueInt [pos] ); break; | |
53 case 1: return ( getArg(pos)->l == valueLongLong[pos] ); break; | |
54 case 2: return ( getArg(pos)->d == valueDouble [pos] ); break; | |
55 case 3: return ( getArg(pos)->f == valueFloat [pos] ); break; | |
56 } | |
57 return false; | |
58 } | |
59 | |
60 | |
61 void clearValues(); | |
62 | |
63 | |
64 void init() | |
65 { | |
66 for (int i = 0 ; i < NARGS ; ++i ) { | |
67 | |
68 valueInt[i] = DCint(i); | |
69 valueLongLong[i] = DClonglong(i); | |
70 valueDouble[i] = DCdouble(i); | |
71 valueFloat[i] = DCfloat(i); | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
72 } |
0 | 73 } |
74 | |
75 | |
76 void push(DCCallVM* pCall, int select, int pos) | |
77 { | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
78 switch(select) |
0 | 79 { |
80 case 0: dcArgInt ( pCall, valueInt [pos] ); break; | |
81 case 1: dcArgLongLong( pCall, valueLongLong[pos] ); break; | |
82 case 2: dcArgDouble ( pCall, valueDouble [pos] ); break; | |
83 case 3: dcArgFloat ( pCall, valueFloat [pos] ); break; | |
84 } | |
85 } | |
86 | |
87 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
88 #define test(x) if (!(x)) return false |
0 | 89 |
90 | |
91 bool test(int x) | |
92 { | |
93 clearValues(); | |
94 | |
95 DCCallVM* pCall = dcNewCallVM(4096); | |
96 dcReset(pCall); | |
97 int y = x; | |
98 int selects[NARGS] = { 0, }; | |
99 int pos = 0; | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
100 for(pos = 0;y>0;++pos) |
0 | 101 { |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
102 int select = (y-1) % NTYPES; |
0 | 103 selects[pos] = select; |
104 push(pCall,select,pos); | |
105 y = (y-1) / NTYPES; | |
106 } | |
107 dcCallVoid(pCall,getFunc(x)); | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
108 |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
109 test( getId() == x ); |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
110 |
0 | 111 for(int i = 0;i<pos;++i) { |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
112 test( equals( selects[i], i, getArg(i) ) ); |
0 | 113 } |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
114 |
0 | 115 dcFree(pCall); |
116 return true; | |
117 } | |
118 | |
119 | |
120 int powerfact(int x, int n) | |
121 { | |
122 if (n==0) return 0; | |
123 return static_cast<int>( pow((double)x,n)+powerfact(x,n-1) ); | |
124 } | |
125 | |
126 | |
127 bool run_range(int from, int to) | |
128 { | |
129 bool tr = true; | |
130 for (int i = from ; i < to ; ++i ) { | |
131 printf("%d:",i); | |
132 bool r = test(i); | |
133 printf("%d\n", r); | |
134 tr &= r; | |
135 } | |
136 return tr; | |
137 } | |
138 | |
139 extern "C" { | |
140 | |
141 int main(int argc, char* argv[]) | |
142 { | |
143 dcTest_initPlatform(); | |
144 | |
145 bool success = false; | |
146 init(); | |
147 if (argc == 2) { | |
148 int index = atoi(argv[1]); | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
149 success = run_range( index, index+1 ); |
0 | 150 } else if (argc == 3) { |
151 int from = atoi(argv[1]); | |
152 int to = atoi(argv[2])+1; | |
153 success = run_range(from,to); | |
154 } else { | |
155 int ncalls = powerfact(NTYPES,NARGS)+1; | |
156 success = run_range(0,ncalls); | |
157 } | |
158 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
159 printf("result: suite3: %d\n", success); |
0 | 160 |
161 dcTest_deInitPlatform(); | |
162 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
163 return !success; |
0 | 164 } |
165 | |
166 } // extern "C" | |
167 |