Mercurial > pub > dyncall > dyncall
annotate test/call_suite/main.c @ 448:987a2af078c8
test/Makefile.generic fix (copy/paste error)
author | Tassilo Philipp |
---|---|
date | Thu, 27 Jan 2022 11:39:35 +0100 |
parents | 135c7fb49c2f |
children | e3bf15207d93 |
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 | |
26 #include "dyncall.h" | |
27 #include "globals.h" | |
28 #include <string.h> | |
29 #include "../common/platformInit.h" | |
30 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */ | |
31 | |
32 | |
437
135c7fb49c2f
- call_suite: made generator produce unique signatures; regenerated case list
Tassilo Philipp
parents:
436
diff
changeset
|
33 static void* G_callvm; |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
34 |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
35 |
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
|
36 static int invoke(char const* signature, void* t) |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
37 { |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
38 DCCallVM * p = (DCCallVM*) G_callvm; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
39 char const * sig = signature; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
40 char rtype; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
41 char atype; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
42 int pos = 0; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
43 int s = 0; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
44 |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
45 clear_V(); |
0 | 46 |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
47 rtype = *sig++; |
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 |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
50 while ( (atype = *sig++) != '\0') { |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
51 pos++; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
52 switch(atype) { |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
53 case 'c': dcArgChar (p,K_c[pos]); break; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
54 case 's': dcArgShort (p,K_s[pos]); break; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
55 case 'i': dcArgInt (p,K_i[pos]); break; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
56 case 'j': dcArgLong (p,K_j[pos]); break; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
57 case 'l': dcArgLongLong(p,K_l[pos]); break; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
58 case 'p': dcArgPointer (p,K_p[pos]); break; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
59 case 'f': dcArgFloat (p,K_f[pos]); break; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
60 case 'd': dcArgDouble (p,K_d[pos]); break; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
61 default: printf("unknown atype '%c' (1) ;", atype); return 0; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
62 } |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
63 } |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
64 |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
65 switch(rtype) |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
66 { |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
67 case 'v': dcCallVoid(p,t); s=1; /*TODO:check that no return-arg was touched.*/ break; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
68 case 'c': s = (dcCallChar (p,t) == K_c[pos]) ; break; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
69 case 's': s = (dcCallShort (p,t) == K_s[pos]) ; break; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
70 case 'i': s = (dcCallInt (p,t) == K_i[pos]) ; break; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
71 case 'j': s = (dcCallLong (p,t) == K_j[pos]) ; break; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
72 case 'l': s = (dcCallLongLong(p,t) == K_l[pos]) ; break; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
73 case 'p': s = (dcCallPointer (p,t) == K_p[pos]) ; break; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
74 case 'f': s = (dcCallFloat (p,t) == K_f[pos]) ; break; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
75 case 'd': s = (dcCallDouble (p,t) == K_d[pos]) ; break; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
76 default: printf("unknown rtype '%c'", rtype); return 0; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
77 } |
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 if (!s) { printf("rval wrong;"); return 0; } |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
80 /* test: */ |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
81 sig = signature+1; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
82 pos = 1; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
83 while ( (atype = *sig++) != '\0') { |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
84 switch(atype) { |
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
|
85 case 'c': s = ( V_c[pos] == K_c[pos] ); if (!s) printf("'c':%d: %d != %d ; ", pos, V_c[pos], K_c[pos]); break; |
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
|
86 case 's': s = ( V_s[pos] == K_s[pos] ); if (!s) printf("'s':%d: %d != %d ; ", pos, V_s[pos], K_s[pos]); break; |
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
|
87 case 'i': s = ( V_i[pos] == K_i[pos] ); if (!s) printf("'i':%d: %d != %d ; ", pos, V_i[pos], K_i[pos]); break; |
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
|
88 case 'j': s = ( V_j[pos] == K_j[pos] ); if (!s) printf("'j':%d: %ld != %ld ; ", pos, V_j[pos], K_j[pos]); break; |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
89 case 'l': s = ( V_l[pos] == K_l[pos] ); if (!s) printf("'l':%d: %lld != %lld ; ", pos, V_l[pos], K_l[pos]); break; |
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
|
90 case 'p': s = ( V_p[pos] == K_p[pos] ); if (!s) printf("'p':%d: %p != %p ; ", pos, V_p[pos], K_p[pos]); break; |
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
|
91 case 'f': s = ( V_f[pos] == K_f[pos] ); if (!s) printf("'f':%d: %f != %f ; ", pos, V_f[pos], K_f[pos]); break; |
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
|
92 case 'd': s = ( V_d[pos] == K_d[pos] ); if (!s) printf("'d':%d: %f != %f ; ", pos, V_d[pos], K_d[pos]); break; |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
93 default: printf("unknown atype '%c' ; ", atype); return 0; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
94 } |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
95 if (!s) { |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
96 printf("arg mismatch at %d ; ", pos); |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
97 return 0; |
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 pos++; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
100 } |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
101 return 1; |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
102 } |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
103 |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
104 int run_test(int i) |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
105 { |
0 | 106 char const * sig; |
107 void * target; | |
108 int success; | |
109 sig = G_sigtab[i]; | |
110 target = (void*) G_funtab[i]; | |
111 printf("%d:%s:",i,sig); | |
112 success = invoke(sig,target); | |
113 printf("%d\n",success); | |
114 return success; | |
115 } | |
116 | |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
117 int run_all() |
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
118 { |
0 | 119 int i; |
120 int failure = 0; | |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
121 for(i=0;i<G_ncases;++i) |
0 | 122 failure |= !( run_test(i) ); |
429
2b708397bba1
- simplified and decluttered test/call_suite
Tassilo Philipp
parents:
410
diff
changeset
|
123 |
0 | 124 return !failure; |
125 } | |
126 | |
127 int main(int argc, char* argv[]) | |
128 { | |
129 int total; | |
130 | |
131 dcTest_initPlatform(); | |
132 | |
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
|
133 init_test_data(G_maxargs); |
0 | 134 G_callvm = (DCCallVM*) dcNewCallVM(4096); |
135 dcReset(G_callvm); | |
136 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
|
137 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
|
138 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
|
139 |
0 | 140 printf("result: call_suite: %d\n", total); |
141 | |
142 dcTest_deInitPlatform(); | |
143 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
144 return !total; |
0 | 145 } |
146 |