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