Mercurial > pub > dyncall > dyncall
comparison test/suite_x86win32std/main.cc @ 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 | d73dc7ad37e4 |
comparison
equal
deleted
inserted
replaced
409:15698dc0cba3 | 410:7608e34098b0 |
---|---|
1 /* | 1 /* |
2 | 2 |
3 Package: dyncall | 3 Package: dyncall |
4 Library: test | 4 Library: test |
5 File: test/suite_x86win32std/main.cc | 5 File: test/suite_x86win32std/main.cc |
6 Description: | 6 Description: |
7 License: | 7 License: |
8 | 8 |
9 Copyright (c) 2007-2018 Daniel Adler <dadler@uni-goettingen.de>, | 9 Copyright (c) 2007-2018 Daniel Adler <dadler@uni-goettingen.de>, |
10 Tassilo Philipp <tphilipp@potion-studios.com> | 10 Tassilo Philipp <tphilipp@potion-studios.com> |
11 | 11 |
12 Permission to use, copy, modify, and distribute this software for any | 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 | 13 purpose with or without fee is hereby granted, provided that the above |
14 copyright notice and this permission notice appear in all copies. | 14 copyright notice and this permission notice appear in all copies. |
77 valueInt[i] = DCint(i); | 77 valueInt[i] = DCint(i); |
78 valueLongLong[i] = DClonglong(i); | 78 valueLongLong[i] = DClonglong(i); |
79 valueDouble[i] = DCdouble(i); | 79 valueDouble[i] = DCdouble(i); |
80 valuePointer[i] = DCpointer(i); | 80 valuePointer[i] = DCpointer(i); |
81 valueFloat[i] = DCfloat(i); | 81 valueFloat[i] = DCfloat(i); |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 | 85 |
86 void push(DCCallVM* pCall, int select, int pos) | 86 void push(DCCallVM* pCall, int select, int pos) |
87 { | 87 { |
88 switch(select) | 88 switch(select) |
89 { | 89 { |
90 case 0: dcArgBool( pCall, valueBool[pos] ); break; | 90 case 0: dcArgBool( pCall, valueBool[pos] ); break; |
91 case 1: dcArgInt( pCall, valueInt[pos] ); break; | 91 case 1: dcArgInt( pCall, valueInt[pos] ); break; |
92 case 2: dcArgLongLong( pCall, valueLongLong[pos] ); break; | 92 case 2: dcArgLongLong( pCall, valueLongLong[pos] ); break; |
93 case 3: dcArgDouble( pCall, valueDouble[pos] ); break; | 93 case 3: dcArgDouble( pCall, valueDouble[pos] ); break; |
95 case 5: dcArgFloat( pCall, valueFloat[pos] ); break; | 95 case 5: dcArgFloat( pCall, valueFloat[pos] ); break; |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 | 99 |
100 #define assert(x) if (!(x)) return false | 100 #define test(x) if (!(x)) return false |
101 | 101 |
102 | 102 |
103 bool test(int x) | 103 bool test(int x) |
104 { | 104 { |
105 clearValues(); | 105 clearValues(); |
108 dcMode(pCall, DC_CALL_C_X86_WIN32_STD); | 108 dcMode(pCall, DC_CALL_C_X86_WIN32_STD); |
109 dcReset(pCall); | 109 dcReset(pCall); |
110 int y = x; | 110 int y = x; |
111 int selects[NARGS] = { 0, }; | 111 int selects[NARGS] = { 0, }; |
112 int pos = 0; | 112 int pos = 0; |
113 for(pos = 0;y>0;++pos) | 113 for(pos = 0;y>0;++pos) |
114 { | 114 { |
115 int select = (y-1) % NTYPES; | 115 int select = (y-1) % NTYPES; |
116 selects[pos] = select; | 116 selects[pos] = select; |
117 push(pCall,select,pos); | 117 push(pCall,select,pos); |
118 y = (y-1) / NTYPES; | 118 y = (y-1) / NTYPES; |
119 } | 119 } |
120 dcCallVoid(pCall,getFunc(x)); | 120 dcCallVoid(pCall,getFunc(x)); |
121 | 121 |
122 assert( getId() == x ); | 122 test( getId() == x ); |
123 | 123 |
124 for(int i = 0;i<pos;++i) { | 124 for(int i = 0;i<pos;++i) { |
125 assert( equals( selects[i], i, getArg(i) ) ); | 125 test( equals( selects[i], i, getArg(i) ) ); |
126 } | 126 } |
127 | 127 |
128 dcFree(pCall); | 128 dcFree(pCall); |
129 return true; | 129 return true; |
130 } | 130 } |
131 | 131 |
132 | 132 |
159 | 159 |
160 bool success = false; | 160 bool success = false; |
161 init(); | 161 init(); |
162 if (argc == 2) { | 162 if (argc == 2) { |
163 int index = atoi(argv[1]); | 163 int index = atoi(argv[1]); |
164 success = run_range( index, index+1 ); | 164 success = run_range( index, index+1 ); |
165 } else if (argc == 3) { | 165 } else if (argc == 3) { |
166 int from = atoi(argv[1]); | 166 int from = atoi(argv[1]); |
167 int to = atoi(argv[2])+1; | 167 int to = atoi(argv[2])+1; |
168 success = run_range(from,to); | 168 success = run_range(from,to); |
169 } else { | 169 } else { |
170 int ncalls = powerfact(NTYPES,NARGS)+1; | 170 int ncalls = powerfact(NTYPES,NARGS)+1; |
171 success = run_range(0,ncalls); | 171 success = run_range(0,ncalls); |
172 } | 172 } |
173 | 173 |
174 printf("result: suite_x86win32std: %s\n", success ? "1" : "0"); | 174 printf("result: suite_x86win32std: %d\n", success); |
175 | 175 |
176 dcTest_deInitPlatform(); | 176 dcTest_deInitPlatform(); |
177 | 177 |
178 return (success) ? 0 : -1; | 178 return !success; |
179 } | 179 } |
180 | 180 |
181 } // extern "C" | 181 } // extern "C" |
182 | 182 |