Mercurial > pub > dyncall > dyncall
annotate test/callback_plain/callback_plain.c @ 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 | 9269d17a8f99 |
children | 71c884e610f0 |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: test | |
5 File: test/callback_plain/callback_plain.c | |
6 Description: | |
7 License: | |
8 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
293
diff
changeset
|
9 Copyright (c) 2011-2021 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 "../../dyncallback/dyncall_callback.h" | |
27 #include "../common/platformInit.h" | |
28 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */ | |
29 | |
30 | |
31 char cbHandler(DCCallback* cb, DCArgs* args, DCValue* result, void* userdata) | |
32 { | |
33 int* ud = (int*)userdata; | |
34 int arg1 = dcbArgInt (args); | |
35 float arg2 = dcbArgFloat (args); | |
36 short arg3 = dcbArgShort (args); | |
37 double arg4 = dcbArgDouble (args); | |
38 long long arg5 = dcbArgLongLong(args); | |
39 | |
40 printf("reached callback\n"); | |
41 printf("userdata (should be 1337): %d\n", *ud); | |
42 printf("1st argument (should be 123): %d\n", arg1); | |
43 printf("2nd argument (should be 23.f): %f\n", arg2); | |
44 printf("3rd argument (should be 3): %d\n", arg3); | |
45 printf("4th argument (should be 1.82): %f\n", arg4); | |
46 printf("5th argument (should be 9909): %lld\n", arg5); | |
47 | |
48 if(*ud == 1337) *ud = 1; | |
49 if(arg1 == 123) ++*ud; | |
50 if(arg2 == 23.f) ++*ud; | |
51 if(arg3 == 3) ++*ud; | |
52 if(arg4 == 1.82) ++*ud; | |
53 if(arg5 == 9909) ++*ud; | |
7 | 54 |
0 | 55 result->s = 1234; |
56 return 's'; | |
57 } | |
58 | |
59 | |
60 int main() | |
61 { | |
62 DCCallback* cb; | |
63 short result = 0; | |
64 int userdata = 1337; | |
65 | |
66 dcTest_initPlatform(); | |
67 | |
68 cb = dcbNewCallback("ifsdl)s", &cbHandler, &userdata); | |
139 | 69 printf("about to callback (trampoline for 0x%tx at 0x%tx)...\n", &cbHandler, cb); |
70 | |
0 | 71 result = ((short(*)(int, float, short, double, long long))cb)(123, 23.f, 3, 1.82, 9909ull); |
72 dcbFreeCallback(cb); | |
139 | 73 |
0 | 74 printf("successfully returned from callback\n"); |
75 printf("return value (should be 1234): %d\n", result); | |
76 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
293
diff
changeset
|
77 result = (userdata == 6) && (result == 1234); |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
293
diff
changeset
|
78 printf("result: callback_plain: %d\n", result); |
0 | 79 |
80 dcTest_deInitPlatform(); | |
81 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
293
diff
changeset
|
82 return !result; |
0 | 83 } |
84 |