comparison test/suite3/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/suite3/main.cc 5 File: test/suite3/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.
67 67
68 valueInt[i] = DCint(i); 68 valueInt[i] = DCint(i);
69 valueLongLong[i] = DClonglong(i); 69 valueLongLong[i] = DClonglong(i);
70 valueDouble[i] = DCdouble(i); 70 valueDouble[i] = DCdouble(i);
71 valueFloat[i] = DCfloat(i); 71 valueFloat[i] = DCfloat(i);
72 } 72 }
73 } 73 }
74 74
75 75
76 void push(DCCallVM* pCall, int select, int pos) 76 void push(DCCallVM* pCall, int select, int pos)
77 { 77 {
78 switch(select) 78 switch(select)
79 { 79 {
80 case 0: dcArgInt ( pCall, valueInt [pos] ); break; 80 case 0: dcArgInt ( pCall, valueInt [pos] ); break;
81 case 1: dcArgLongLong( pCall, valueLongLong[pos] ); break; 81 case 1: dcArgLongLong( pCall, valueLongLong[pos] ); break;
82 case 2: dcArgDouble ( pCall, valueDouble [pos] ); break; 82 case 2: dcArgDouble ( pCall, valueDouble [pos] ); break;
83 case 3: dcArgFloat ( pCall, valueFloat [pos] ); break; 83 case 3: dcArgFloat ( pCall, valueFloat [pos] ); break;
84 } 84 }
85 } 85 }
86 86
87 87
88 #define assert(x) if (!(x)) return false 88 #define test(x) if (!(x)) return false
89 89
90 90
91 bool test(int x) 91 bool test(int x)
92 { 92 {
93 clearValues(); 93 clearValues();
95 DCCallVM* pCall = dcNewCallVM(4096); 95 DCCallVM* pCall = dcNewCallVM(4096);
96 dcReset(pCall); 96 dcReset(pCall);
97 int y = x; 97 int y = x;
98 int selects[NARGS] = { 0, }; 98 int selects[NARGS] = { 0, };
99 int pos = 0; 99 int pos = 0;
100 for(pos = 0;y>0;++pos) 100 for(pos = 0;y>0;++pos)
101 { 101 {
102 int select = (y-1) % NTYPES; 102 int select = (y-1) % NTYPES;
103 selects[pos] = select; 103 selects[pos] = select;
104 push(pCall,select,pos); 104 push(pCall,select,pos);
105 y = (y-1) / NTYPES; 105 y = (y-1) / NTYPES;
106 } 106 }
107 dcCallVoid(pCall,getFunc(x)); 107 dcCallVoid(pCall,getFunc(x));
108 108
109 assert( getId() == x ); 109 test( getId() == x );
110 110
111 for(int i = 0;i<pos;++i) { 111 for(int i = 0;i<pos;++i) {
112 assert( equals( selects[i], i, getArg(i) ) ); 112 test( equals( selects[i], i, getArg(i) ) );
113 } 113 }
114 114
115 dcFree(pCall); 115 dcFree(pCall);
116 return true; 116 return true;
117 } 117 }
118 118
119 119
144 144
145 bool success = false; 145 bool success = false;
146 init(); 146 init();
147 if (argc == 2) { 147 if (argc == 2) {
148 int index = atoi(argv[1]); 148 int index = atoi(argv[1]);
149 success = run_range( index, index+1 ); 149 success = run_range( index, index+1 );
150 } else if (argc == 3) { 150 } else if (argc == 3) {
151 int from = atoi(argv[1]); 151 int from = atoi(argv[1]);
152 int to = atoi(argv[2])+1; 152 int to = atoi(argv[2])+1;
153 success = run_range(from,to); 153 success = run_range(from,to);
154 } else { 154 } else {
155 int ncalls = powerfact(NTYPES,NARGS)+1; 155 int ncalls = powerfact(NTYPES,NARGS)+1;
156 success = run_range(0,ncalls); 156 success = run_range(0,ncalls);
157 } 157 }
158 158
159 printf("result: suite3: %s\n", success ? "1" : "0"); 159 printf("result: suite3: %d\n", success);
160 160
161 dcTest_deInitPlatform(); 161 dcTest_deInitPlatform();
162 162
163 return (success) ? 0 : -1; 163 return !success;
164 } 164 }
165 165
166 } // extern "C" 166 } // extern "C"
167 167