Mercurial > pub > dyncall > dyncall
annotate test/callback_suite/do_test.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 | f5577f6bf97a |
children | d8f0e6cecdab |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: test | |
5 File: test/callback_suite/do_test.c | |
6 Description: | |
7 License: | |
8 | |
281 | 9 Copyright (c) 2011-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 #include <assert.h> | |
27 #include "_auto_config.h" | |
28 #include "invokers.h" | |
29 #include "dyncall_callback.h" | |
30 #include "sigstrings.h" | |
31 #include "signature_utils.h" | |
32 #include "env.h" | |
33 #include "../common/platformInit.h" | |
34 | |
35 int CompareValues(char type, DCValue* a, DCValue* b) | |
36 { | |
37 int isequal = 0; | |
38 switch(type) | |
39 { | |
40 case DC_SIGCHAR_BOOL: isequal = (a->B == b->B) ? 1 : 0 ; break; | |
41 case DC_SIGCHAR_CHAR: isequal = (a->c == b->c) ? 1 : 0 ; break; | |
42 case DC_SIGCHAR_UCHAR: isequal = (a->C == b->C) ? 1 : 0 ; break; | |
43 case DC_SIGCHAR_SHORT: isequal = (a->s == b->s) ? 1 : 0 ; break; | |
44 case DC_SIGCHAR_USHORT: isequal = (a->S == b->S) ? 1 : 0 ; break; | |
45 case DC_SIGCHAR_INT: isequal = (a->i == b->i) ? 1 : 0 ; break; | |
46 case DC_SIGCHAR_UINT: isequal = (a->I == b->I) ? 1 : 0 ; break; | |
47 case DC_SIGCHAR_LONG: isequal = (a->j == b->j) ? 1 : 0 ; break; | |
48 case DC_SIGCHAR_ULONG: isequal = (a->J == b->J) ? 1 : 0 ; break; | |
49 case DC_SIGCHAR_LONGLONG: isequal = (a->l == b->l) ? 1 : 0 ; break; | |
50 case DC_SIGCHAR_ULONGLONG: isequal = (a->L == b->L) ? 1 : 0 ; break; | |
51 case DC_SIGCHAR_FLOAT: isequal = (a->f == b->f) ? 1 : 0 ; break; | |
52 case DC_SIGCHAR_DOUBLE: isequal = (a->d == b->d) ? 1 : 0 ; break; | |
53 case DC_SIGCHAR_POINTER: isequal = (a->p == b->p) ? 1 : 0 ; break; | |
54 default: assert(0); | |
55 } | |
56 return isequal; | |
57 } | |
58 | |
59 int Compare(const char* signature) | |
60 { | |
61 DCValue ref; | |
62 int total = 1; | |
63 int pos; | |
64 int isequal; | |
65 char ch; | |
66 | |
67 /* skip prefix */ | |
68 | |
69 signature = SignatureSkipCallPrefix(signature); | |
70 | |
71 /* check arguments */ | |
72 | |
73 pos = 0; | |
74 | |
75 for(;;) { | |
76 | |
77 ch = *signature++; | |
78 | |
79 if (ch == DC_SIGCHAR_ENDARG) break; | |
80 GetReferenceArg(&ref, ch, pos); | |
81 isequal = CompareValues( ch, &ref, &Args[pos] ); | |
82 if ( !isequal ) { | |
83 if (OptionVerbose) { total = 0; fprintf(stdout, " @%d[%c] ", pos, ch); } | |
84 else return 0; | |
85 } | |
86 ++ pos; | |
87 } | |
88 | |
89 ch = *signature++; | |
90 | |
91 /* check result */ | |
92 | |
93 GetReferenceResult(&ref, ch); | |
94 | |
95 isequal = CompareValues(ch, &ref, &Result); | |
96 if (!isequal) { | |
97 if (OptionVerbose) { total = 0; fprintf(stdout, " @-1 "); } | |
98 else return 0; | |
99 } | |
100 | |
101 return total; | |
102 } | |
103 | |
104 | |
105 extern DCCallbackHandler handler; /* see handler.c for implementation */ | |
106 | |
107 int DoTest(int id) | |
108 { | |
109 int index, result; | |
110 const char* signature; | |
111 DCCallback* pcb; | |
112 | |
113 assert( id > 0 && id <= CONFIG_NSIGS ); | |
114 index = id - 1; | |
115 | |
116 signature = GetSignature(index); | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
117 printf("f%d(\t%s", id, signature); |
0 | 118 |
119 pcb = dcbNewCallback( signature, handler, (void*) signature ); | |
120 assert(pcb != NULL); | |
121 DoInvoke(index, (void*) pcb); | |
122 result = Compare(signature); | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
123 printf(" :%d\n", result); |
0 | 124 dcbFreeCallback(pcb); |
125 return result; | |
126 } | |
127 |