Mercurial > pub > dyncall > dyncall
annotate test/call_suite/main.c @ 515:c9c546f8598b
- added _Bool type to call_suite* tests
author | Tassilo Philipp |
---|---|
date | Sun, 10 Apr 2022 21:05:33 +0200 |
parents | a0c51f34023a |
children | ed8835abe05f |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: test | |
5 File: test/call_suite/main.c | |
6 Description: | |
7 License: | |
8 | |
436
23b12c7ad462
- call_suite cleanup (no change in functionality): removal of unused decl, freeing memory at end, func renaming for clarity, static for tu-local symbols, ...
Tassilo Philipp
parents:
429
diff
changeset
|
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 | |
511 | 26 |
0 | 27 #include "dyncall.h" |
28 #include "globals.h" | |
29 #include <string.h> | |
30 #include "../common/platformInit.h" | |
31 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */ | |
32 | |
33 | |
437
135c7fb49c2f
- call_suite: made generator produce unique signatures; regenerated case list
Tassilo Philipp
parents:
436
diff
changeset
|
34 static void* G_callvm; |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
35 |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
36 |
506 | 37 static int invoke(const char *signature, void* t) |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
38 { |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
39 DCCallVM * p = (DCCallVM*) G_callvm; |
504
f263eb7a206e
- call_suite: made output more consistent with dyncall sig style
Tassilo Philipp
parents:
491
diff
changeset
|
40 const char * sig = signature; |
f263eb7a206e
- call_suite: made output more consistent with dyncall sig style
Tassilo Philipp
parents:
491
diff
changeset
|
41 const char * rtype; |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
42 char atype; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
43 int pos = 0; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
44 int s = 0; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
45 |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
46 clear_V(); |
0 | 47 |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
48 dcReset(p); |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
49 |
504
f263eb7a206e
- call_suite: made output more consistent with dyncall sig style
Tassilo Philipp
parents:
491
diff
changeset
|
50 /* locate return type in sig; if no ')' separator, test failed */ |
f263eb7a206e
- call_suite: made output more consistent with dyncall sig style
Tassilo Philipp
parents:
491
diff
changeset
|
51 rtype = strchr(sig, ')'); |
f263eb7a206e
- call_suite: made output more consistent with dyncall sig style
Tassilo Philipp
parents:
491
diff
changeset
|
52 if(!rtype) { |
f263eb7a206e
- call_suite: made output more consistent with dyncall sig style
Tassilo Philipp
parents:
491
diff
changeset
|
53 printf("cannot locate rtype in sig '%s' ;", signature); |
f263eb7a206e
- call_suite: made output more consistent with dyncall sig style
Tassilo Philipp
parents:
491
diff
changeset
|
54 return 0; |
f263eb7a206e
- call_suite: made output more consistent with dyncall sig style
Tassilo Philipp
parents:
491
diff
changeset
|
55 } |
f263eb7a206e
- call_suite: made output more consistent with dyncall sig style
Tassilo Philipp
parents:
491
diff
changeset
|
56 |
f263eb7a206e
- call_suite: made output more consistent with dyncall sig style
Tassilo Philipp
parents:
491
diff
changeset
|
57 ++rtype; |
f263eb7a206e
- call_suite: made output more consistent with dyncall sig style
Tassilo Philipp
parents:
491
diff
changeset
|
58 |
f263eb7a206e
- call_suite: made output more consistent with dyncall sig style
Tassilo Philipp
parents:
491
diff
changeset
|
59 while ( (atype = *sig++) != ')') { |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
60 switch(atype) { |
515 | 61 case 'B': dcArgBool (p,K_B[pos]); break; |
491 | 62 case 'c': dcArgChar (p,K_c[pos]); break; |
63 case 's': dcArgShort (p,K_s[pos]); break; | |
64 case 'i': dcArgInt (p,K_i[pos]); break; | |
65 case 'j': dcArgLong (p,K_j[pos]); break; | |
66 case 'l': dcArgLongLong(p,K_l[pos]); break; | |
67 case 'C': dcArgChar (p,K_C[pos]); break; | |
68 case 'S': dcArgShort (p,K_S[pos]); break; | |
69 case 'I': dcArgInt (p,K_I[pos]); break; | |
70 case 'J': dcArgLong (p,K_J[pos]); break; | |
71 case 'L': dcArgLongLong(p,K_L[pos]); break; | |
72 case 'p': dcArgPointer (p,K_p[pos]); break; | |
73 case 'f': dcArgFloat (p,K_f[pos]); break; | |
74 case 'd': dcArgDouble (p,K_d[pos]); break; | |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
75 default: printf("unknown atype '%c' (1) ;", atype); return 0; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
76 } |
511 | 77 ++pos; |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
78 } |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
79 |
504
f263eb7a206e
- call_suite: made output more consistent with dyncall sig style
Tassilo Philipp
parents:
491
diff
changeset
|
80 switch(*rtype) |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
81 { |
491 | 82 case 'v': dcCallVoid (p,t); s=1; break; /*TODO:check that no return-arg was touched.*/ |
515 | 83 case 'B': s = ( dcCallBool (p,t) == K_B[pos]); break; |
491 | 84 case 'c': s = ( dcCallChar (p,t) == K_c[pos]); break; |
85 case 's': s = ( dcCallShort (p,t) == K_s[pos]); break; | |
86 case 'i': s = ( dcCallInt (p,t) == K_i[pos]); break; | |
87 case 'j': s = ( dcCallLong (p,t) == K_j[pos]); break; | |
88 case 'l': s = ( dcCallLongLong(p,t) == K_l[pos]); break; | |
89 case 'C': s = ((unsigned char) dcCallChar (p,t) == K_C[pos]); break; | |
90 case 'S': s = ((unsigned short) dcCallShort (p,t) == K_S[pos]); break; | |
91 case 'I': s = ((unsigned int) dcCallInt (p,t) == K_I[pos]); break; | |
92 case 'J': s = ((unsigned long) dcCallLong (p,t) == K_J[pos]); break; | |
93 case 'L': s = ((unsigned long long)dcCallLongLong(p,t) == K_L[pos]); break; | |
94 case 'p': s = ( dcCallPointer (p,t) == K_p[pos]); break; | |
95 case 'f': s = ( dcCallFloat (p,t) == K_f[pos]); break; | |
96 case 'd': s = ( dcCallDouble (p,t) == K_d[pos]); break; | |
504
f263eb7a206e
- call_suite: made output more consistent with dyncall sig style
Tassilo Philipp
parents:
491
diff
changeset
|
97 default: printf("unknown rtype '%s'", rtype); return 0; |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
98 } |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
99 |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
100 if (!s) { printf("rval wrong;"); return 0; } |
504
f263eb7a206e
- call_suite: made output more consistent with dyncall sig style
Tassilo Philipp
parents:
491
diff
changeset
|
101 |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
102 /* test: */ |
504
f263eb7a206e
- call_suite: made output more consistent with dyncall sig style
Tassilo Philipp
parents:
491
diff
changeset
|
103 sig = signature; |
511 | 104 pos = 0; |
504
f263eb7a206e
- call_suite: made output more consistent with dyncall sig style
Tassilo Philipp
parents:
491
diff
changeset
|
105 while ( (atype = *sig++) != ')') { |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
106 switch(atype) { |
515 | 107 case 'B': s = ( V_B[pos] == K_B[pos] ); if (!s) printf("'%c':%d: %d != %d ; ", atype, pos, V_B[pos], K_B[pos]); break; |
491 | 108 case 'c': s = ( V_c[pos] == K_c[pos] ); if (!s) printf("'%c':%d: %d != %d ; ", atype, pos, V_c[pos], K_c[pos]); break; |
109 case 's': s = ( V_s[pos] == K_s[pos] ); if (!s) printf("'%c':%d: %d != %d ; ", atype, pos, V_s[pos], K_s[pos]); break; | |
110 case 'i': s = ( V_i[pos] == K_i[pos] ); if (!s) printf("'%c':%d: %d != %d ; ", atype, pos, V_i[pos], K_i[pos]); break; | |
111 case 'j': s = ( V_j[pos] == K_j[pos] ); if (!s) printf("'%c':%d: %ld != %ld ; ", atype, pos, V_j[pos], K_j[pos]); break; | |
112 case 'l': s = ( V_l[pos] == K_l[pos] ); if (!s) printf("'%c':%d: %lld != %lld ; ", atype, pos, V_l[pos], K_l[pos]); break; | |
113 case 'C': s = ( V_C[pos] == K_C[pos] ); if (!s) printf("'%c':%d: %u != %u ; ", atype, pos, V_C[pos], K_C[pos]); break; | |
114 case 'S': s = ( V_S[pos] == K_S[pos] ); if (!s) printf("'%c':%d: %u != %u ; ", atype, pos, V_S[pos], K_S[pos]); break; | |
115 case 'I': s = ( V_I[pos] == K_I[pos] ); if (!s) printf("'%c':%d: %u != %u ; ", atype, pos, V_I[pos], K_I[pos]); break; | |
116 case 'J': s = ( V_J[pos] == K_J[pos] ); if (!s) printf("'%c':%d: %lu != %lu ; ", atype, pos, V_J[pos], K_J[pos]); break; | |
117 case 'L': s = ( V_L[pos] == K_L[pos] ); if (!s) printf("'%c':%d: %llu != %llu ; ", atype, pos, V_L[pos], K_L[pos]); break; | |
118 case 'p': s = ( V_p[pos] == K_p[pos] ); if (!s) printf("'%c':%d: %p != %p ; ", atype, pos, V_p[pos], K_p[pos]); break; | |
119 case 'f': s = ( V_f[pos] == K_f[pos] ); if (!s) printf("'%c':%d: %f != %f ; ", atype, pos, V_f[pos], K_f[pos]); break; | |
120 case 'd': s = ( V_d[pos] == K_d[pos] ); if (!s) printf("'%c':%d: %f != %f ; ", atype, pos, V_d[pos], K_d[pos]); break; | |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
121 default: printf("unknown atype '%c' ; ", atype); return 0; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
122 } |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
123 if (!s) { |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
124 printf("arg mismatch at %d ; ", pos); |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
125 return 0; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
126 } |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
127 pos++; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
128 } |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
129 return 1; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
130 } |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
131 |
506 | 132 static int run_test(int i) |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
133 { |
0 | 134 char const * sig; |
135 void * target; | |
136 int success; | |
137 sig = G_sigtab[i]; | |
138 target = (void*) G_funtab[i]; | |
139 printf("%d:%s:",i,sig); | |
140 success = invoke(sig,target); | |
141 printf("%d\n",success); | |
142 return success; | |
143 } | |
144 | |
506 | 145 static int run_all() |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
146 { |
0 | 147 int i; |
148 int failure = 0; | |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
149 for(i=0;i<G_ncases;++i) |
0 | 150 failure |= !( run_test(i) ); |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
151 |
0 | 152 return !failure; |
153 } | |
154 | |
155 int main(int argc, char* argv[]) | |
156 { | |
157 int total; | |
158 | |
159 dcTest_initPlatform(); | |
160 | |
436
23b12c7ad462
- call_suite cleanup (no change in functionality): removal of unused decl, freeing memory at end, func renaming for clarity, static for tu-local symbols, ...
Tassilo Philipp
parents:
429
diff
changeset
|
161 init_test_data(G_maxargs); |
0 | 162 G_callvm = (DCCallVM*) dcNewCallVM(4096); |
163 dcReset(G_callvm); | |
164 total = run_all(); | |
436
23b12c7ad462
- call_suite cleanup (no change in functionality): removal of unused decl, freeing memory at end, func renaming for clarity, static for tu-local symbols, ...
Tassilo Philipp
parents:
429
diff
changeset
|
165 dcFree(G_callvm); |
23b12c7ad462
- call_suite cleanup (no change in functionality): removal of unused decl, freeing memory at end, func renaming for clarity, static for tu-local symbols, ...
Tassilo Philipp
parents:
429
diff
changeset
|
166 deinit_test_data(G_maxargs); |
23b12c7ad462
- call_suite cleanup (no change in functionality): removal of unused decl, freeing memory at end, func renaming for clarity, static for tu-local symbols, ...
Tassilo Philipp
parents:
429
diff
changeset
|
167 |
0 | 168 printf("result: call_suite: %d\n", total); |
169 | |
170 dcTest_deInitPlatform(); | |
171 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
172 return !total; |
0 | 173 } |
174 |