comparison test/callf/main.c @ 0:3e629dc19168

initial from svn dyncall-1745
author Daniel Adler
date Thu, 19 Mar 2015 22:24:28 +0100
parents
children f5577f6bf97a
comparison
equal deleted inserted replaced
-1:000000000000 0:3e629dc19168
1 /*
2
3 Package: dyncall
4 Library: test
5 File: test/callf/main.c
6 Description:
7 License:
8
9 Copyright (c) 2007-2015 Daniel Adler <dadler@uni-goettingen.de>,
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 /* test dcCallF API */
29
30 #include "../../dyncall/dyncall_callf.h"
31 #include "../common/platformInit.h"
32 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */
33
34
35 /* sample void function */
36
37 int vf_iii(int x,int y,int z)
38 {
39 int r = (x == 1 && y == 2 && z == 3);
40 printf("%d %d %d: %d", x, y, z, r);
41 return r;
42 }
43
44 int vf_ffiffiffi(float a, float b, int c, float d, float e, int f, float g, float h, int i)
45 {
46 int r = (a == 1.f && b == 2.f && c == 3 && d == 4.f && e == 5.f && f == 6 && g == 7.f && h == 8.f && i == 9);
47 printf("%f %f %d %f %f %d %f %f %d: %d", a, b, c, d, e, f, g, h, i, r);
48 return r;
49 }
50
51 /* main */
52
53 int main(int argc, char* argv[])
54 {
55 DCCallVM* vm;
56 DCValue ret;
57 int r = 1;
58
59 dcTest_initPlatform();
60
61 /* allocate call vm */
62 vm = dcNewCallVM(4096);
63
64
65 /* calls using 'formatted' API */
66 dcReset(vm);
67 printf("callf iii)i: ");
68 dcCallF(vm, &ret, (void*)&vf_iii, "iii)i", 1, 2, 3);
69 r = ret.i && r;
70
71 dcReset(vm);
72 printf("\ncallf ffiffiffi)i: ");
73 dcCallF(vm, &ret, (void*)&vf_ffiffiffi, "ffiffiffi)i", 1.f, 2.f, 3, 4.f, 5.f, 6, 7.f, 8.f, 9);
74 r = ret.i && r;
75
76
77 /* arg binding then call using 'formatted' API */
78 dcReset(vm);
79 printf("\nargf iii)i then call: ");
80 dcArgF(vm, "iii)i", 1, 2, 3);
81 r = r && dcCallInt(vm, (void*)&vf_iii);
82
83 dcReset(vm);
84 printf("\nargf iii then call: ");
85 dcArgF(vm, "iii", 1, 2, 3);
86 r = r && dcCallInt(vm, (void*)&vf_iii);
87
88 dcReset(vm);
89 printf("\nargf ffiffiffi)i then call: ");
90 dcArgF(vm, "ffiffiffi)i", 1.f, 2.f, 3, 4.f, 5.f, 6, 7.f, 8.f, 9);
91 r = r && dcCallInt(vm, (void*)&vf_ffiffiffi);
92
93 dcReset(vm);
94 printf("\nargf ffiffiffi then call: ");
95 dcArgF(vm, "ffiffiffi", 1.f, 2.f, 3, 4.f, 5.f, 6, 7.f, 8.f, 9);
96 r = r && dcCallInt(vm, (void*)&vf_ffiffiffi);
97
98
99 /* free vm */
100 dcFree(vm);
101
102 printf("\nresult: callf: %d\n", r);
103
104 dcTest_deInitPlatform();
105
106 return 0;
107 }
108