]> git.saurik.com Git - wxWidgets.git/blob - tests/lltest.cpp
fixed c++ style comments
[wxWidgets.git] / tests / lltest.cpp
1 #include "wx/wxprec.h"
2
3 #include "wx/longlong.h"
4
5 #include <time.h>
6 #include <stdlib.h>
7 #if defined(__MWERKS__) && macintosh
8 #include <SIOUX.h>
9 #include <Events.h>
10 #endif
11
12 static const unsigned wxLongLong_t NumberOfTests = 100000l;
13
14 //using namespace std;
15 int oddbits(unsigned int number);
16
17 int oddbits(unsigned int number)
18 {
19 int sum = 0;
20 while(number > 0)
21 {
22 sum += number & 1;
23 number >>= 1;
24 }
25
26 return sum & 1;
27 }
28 void random(long& hi, unsigned long& lo);
29
30 void random(long& hi, unsigned long& lo)
31 {
32 hi = 0;
33 lo = 0;
34
35 for (int i = 0; i < 32; i++)
36 {
37 hi |= oddbits(rand()) << i;
38 lo |= oddbits(rand()) << i;
39 }
40 }
41
42 int shifttest();
43
44 int shifttest()
45 {
46 cout << endl << "Starting shift tests." << endl;
47
48 long hi = 0;
49 unsigned long lo = 0;
50
51 unsigned wxLongLong_t counter = 0;
52
53 while (counter < NumberOfTests)
54 {
55 if ((counter % 1000) == 999)
56 {
57 cerr << "+";
58 #if defined(__MWERKS__) && macintosh
59 GetNextEvent(0, NULL);
60 #endif
61 }
62
63 random(hi, lo);
64 wxLongLongWx l1a(hi, lo);
65 wxLongLongWx l1c(hi, lo);
66 wxLongLongWx l1b;
67 wxLongLongNative l2a(hi, lo);
68 wxLongLongNative l2c(hi, lo);
69 wxLongLongNative l2b;
70
71 int shift = rand() % 64;
72 int leftshift = oddbits(rand());
73
74 if (leftshift)
75 {
76 l1b = l1a << shift;
77 l2b = l2a << shift;
78 l1c <<= shift;
79 l2c <<= shift;
80 }
81 else
82 {
83 l1b = l1a >> shift;
84 l2b = l2a >> shift;
85 l1c >>= shift;
86 l2c >>= shift;
87 }
88
89 void *oneb = l1b.asArray();
90 void *twob = l2b.asArray();
91 void *onec = l1c.asArray();
92 void *twoc = l2c.asArray();
93
94 if ((memcmp(oneb, twob, 8) != 0) || (memcmp(onec, twoc, 8) != 0) || (memcmp(oneb, onec, 8) != 0))
95 {
96 cout << endl << "After " << wxLongLongNative(counter) << " successful trials: " << endl;
97 cout << l1a << endl;
98 cout << l2a << endl;
99 if (leftshift)
100 cout << "<< ";
101 else
102 cout << ">> ";
103 cout << shift << endl;
104 cout << l1b << endl;
105 cout << l2b << endl;
106 cout << l1c << endl;
107 cout << l2c << endl;
108 return 0;
109 }
110 counter++;
111 }
112
113 cout << endl << wxLongLongNative(counter) << " successful trial" << (counter == 1 ? "." : "s.") << endl;
114
115 return 1;
116 }
117
118 int add1test();
119
120 int add1test()
121 {
122 cout << endl << "Starting first addition tests." << endl;
123
124 long hi = 0;
125 unsigned long lo = 0;
126
127 unsigned wxLongLong_t counter = 0;
128
129 while (counter < NumberOfTests)
130 {
131 if ((counter % 1000) == 999)
132 {
133 cerr << "+";
134 #if defined(__MWERKS__) && macintosh
135 GetNextEvent(0, NULL);
136 #endif
137 }
138
139 random(hi, lo);
140 wxLongLongWx l1a(hi, lo);
141 wxLongLongNative l2a(hi, lo);
142 wxLongLongWx l1d(hi, lo);
143 wxLongLongNative l2d(hi, lo);
144 random(hi, lo);
145 wxLongLongWx l1b(hi, lo);
146 wxLongLongNative l2b(hi, lo);
147 wxLongLongWx l1c;
148 wxLongLongNative l2c;
149
150 l1c = l1a + l1b;
151 l2c = l2a + l2b;
152 l1d += l1b;
153 l2d += l2b;
154
155 void *onec = l1c.asArray();
156 void *twoc = l2c.asArray();
157 void *oned = l1d.asArray();
158 void *twod = l2d.asArray();
159
160 if ((memcmp(onec, twoc, 8) != 0) || (memcmp(oned, twod, 8) != 0) || (memcmp(onec, oned, 8) != 0))
161 {
162 cout << endl << "After " << wxLongLongNative(counter) << " successful trials: " << endl;
163 cout << l1a << endl;
164 cout << l2a << endl;
165 cout << l1b << endl;
166 cout << l2b << endl;
167 cout << l1c << endl;
168 cout << l2c << endl;
169 return 0;
170 }
171 counter++;
172 }
173
174 cout << endl << wxLongLongNative(counter) << " successful trial" << (counter == 1 ? "." : "s.") << endl;
175
176 return 1;
177 }
178
179 /*
180 int add2test();
181
182 int add2test()
183 {
184 cout << endl << "Starting second addition tests." << endl;
185
186 long hi = 0;
187 unsigned long lo = 0;
188
189 unsigned wxLongLong_t counter = 0;
190
191 while (counter < NumberOfTests)
192 {
193 if ((counter % 1000) == 999)
194 {
195 cerr << "+";
196 #if defined(__MWERKS__) && macintosh
197 GetNextEvent(0, NULL);
198 #endif
199 }
200
201 random(hi, lo);
202 wxLongLongWx l1a(hi, lo);
203 wxLongLongNative l2a(hi, lo);
204 wxLongLongWx l1c(hi, lo);
205 wxLongLongNative l2c(hi, lo);
206 random(hi, lo);
207 wxLongLongWx l1b(hi, lo);
208 wxLongLongNative l2b(hi, lo);
209
210 l1b += l1a;
211 l2b += l2a;
212
213 void *one = l1b.asArray();
214 void *two = l2b.asArray();
215
216 if (memcmp(one, two, 8) != 0)
217 {
218 cout << endl << "After " << counter << " successful trials: " << endl;
219 cout << l1c << endl;
220 cout << l2c << endl;
221 cout << l1a << endl;
222 cout << l2a << endl;
223 cout << l1b << endl;
224 cout << l2b << endl;
225 return 0;
226 }
227 counter++;
228 }
229
230 cout << endl << counter << " successful trial" << (counter == 1 ? "." : "s.") << endl;
231
232 return 1;
233 }
234 */
235
236 int sub1test();
237
238 int sub1test()
239 {
240 cout << endl << "Starting first subtraction tests." << endl;
241
242 long hi = 0;
243 unsigned long lo = 0;
244
245 unsigned wxLongLong_t counter = 0;
246
247 while (counter < NumberOfTests)
248 {
249 if ((counter % 1000) == 999)
250 {
251 cerr << "+";
252 #if defined(__MWERKS__) && macintosh
253 GetNextEvent(0, NULL);
254 #endif
255 }
256
257 random(hi, lo);
258 wxLongLongWx l1a(hi, lo);
259 wxLongLongNative l2a(hi, lo);
260 wxLongLongWx l1d(hi, lo);
261 wxLongLongNative l2d(hi, lo);
262 random(hi, lo);
263 wxLongLongWx l1b(hi, lo);
264 wxLongLongNative l2b(hi, lo);
265 wxLongLongWx l1c;
266 wxLongLongNative l2c;
267
268 l1c = l1a - l1b;
269 l2c = l2a - l2b;
270 l1d -= l1b;
271 l2d -= l2b;
272
273 void *onec = l1c.asArray();
274 void *twoc = l2c.asArray();
275 void *oned = l1d.asArray();
276 void *twod = l2d.asArray();
277
278 if ((memcmp(onec, twoc, 8) != 0) || (memcmp(oned, twod, 8) != 0) || (memcmp(onec, oned, 8) != 0))
279 {
280 cout << endl << "After " << wxLongLongNative(counter) << " successful trials: " << endl;
281 cout << l1a << endl;
282 cout << l2a << endl;
283 cout << l1b << endl;
284 cout << l2b << endl;
285 cout << l1c << endl;
286 cout << l2c << endl;
287 cout << l1d << endl;
288 cout << l2d << endl;
289 return 0;
290 }
291 counter++;
292 }
293
294 cout << endl << wxLongLongNative(counter) << " successful trial" << (counter == 1 ? "." : "s.") << endl;
295
296 return 1;
297 }
298
299 /*
300 int sub2test();
301
302 int sub2test()
303 {
304 cout << endl << "Starting second subtraction tests." << endl;
305
306 long hi = 0;
307 unsigned long lo = 0;
308
309 unsigned wxLongLong_t counter = 0;
310
311 while (counter < NumberOfTests)
312 {
313 if ((counter % 1000) == 999)
314 {
315 cerr << "+";
316 #if defined(__MWERKS__) && macintosh
317 GetNextEvent(0, NULL);
318 #endif
319 }
320
321 random(hi, lo);
322 wxLongLongWx l1a(hi, lo);
323 wxLongLongNative l2a(hi, lo);
324 wxLongLongWx l1c(hi, lo);
325 wxLongLongNative l2c(hi, lo);
326 random(hi, lo);
327 wxLongLongWx l1b(hi, lo);
328 wxLongLongNative l2b(hi, lo);
329
330 l1b -= l1a;
331 l2b -= l2a;
332
333 void *one = l1b.asArray();
334 void *two = l2b.asArray();
335
336 if (memcmp(one, two, 8) != 0)
337 {
338 cout << endl << "After " << counter << " successful trials: " << endl;
339 cout << l1c << endl;
340 cout << l2c << endl;
341 cout << l1a << endl;
342 cout << l2a << endl;
343 cout << l1b << endl;
344 cout << l2b << endl;
345 return 0;
346 }
347 counter++;
348 }
349
350 cout << endl << counter << " successful trial" << (counter == 1 ? "." : "s.") << endl;
351
352 return 1;
353 }
354
355 */
356
357 int incdectest();
358
359 int incdectest()
360 {
361 cout << endl << "Starting pre/post increment/decrement tests." << endl;
362
363 long hi = 0;
364 unsigned long lo = 0;
365
366 unsigned wxLongLong_t counter = 0;
367
368 while (counter < NumberOfTests)
369 {
370 if ((counter % 1000) == 999)
371 {
372 cerr << "+";
373 #if defined(__MWERKS__) && macintosh
374 GetNextEvent(0, NULL);
375 #endif
376 }
377
378 random(hi, lo);
379 wxLongLongWx l1a(hi, lo);
380 wxLongLongNative l2a(hi, lo);
381 wxLongLongWx l1b(hi, lo);
382 wxLongLongNative l2b(hi, lo);
383
384 int increment = oddbits(rand());
385 int pre = oddbits(rand());
386
387 if (increment)
388 if (pre)
389 {
390 ++l1b;
391 ++l2b;
392 }
393 else
394 {
395 l1b++;
396 l2b++;
397 }
398 else
399 if (pre)
400 {
401 --l1b;
402 --l2b;
403 }
404 else
405 {
406 l1b--;
407 l2b--;
408 }
409
410 void *one = l1b.asArray();
411 void *two = l2b.asArray();
412
413 if (memcmp(one, two, 8) != 0)
414 {
415 cout << endl << "After " << wxLongLongNative(counter) << " successful trials: " << endl;
416 cout << l1a << endl;
417 cout << l2a << endl;
418 cout << (pre ? "pre" : "post") << (increment ? "increment" : "decrement") << endl;
419 cout << l1b << endl;
420 cout << l2b << endl;
421 return 0;
422 }
423 counter++;
424 }
425
426 cout << endl << wxLongLongNative(counter) << " successful trial" << (counter == 1 ? "." : "s.") << endl;
427
428 return 1;
429 }
430
431 int negationtest();
432
433 int negationtest()
434 {
435 cout << endl << "Starting negation tests." << endl;
436
437 long hi = 0;
438 unsigned long lo = 0;
439
440 unsigned wxLongLong_t counter = 0;
441
442 while (counter < NumberOfTests)
443 {
444 if ((counter % 1000) == 999)
445 {
446 cerr << "+";
447 #if defined(__MWERKS__) && macintosh
448 GetNextEvent(0, NULL);
449 #endif
450 }
451
452 random(hi, lo);
453 wxLongLongWx l1a(hi, lo);
454 wxLongLongNative l2a(hi, lo);
455 wxLongLongWx l1b(-l1a);
456 wxLongLongNative l2b(-l2a);
457
458 void *one = l1b.asArray();
459 void *two = l2b.asArray();
460
461 if (memcmp(one, two, 8) != 0)
462 {
463 cout << endl << "After " << wxLongLongNative(counter) << " successful trials: " << endl;
464 cout << l1a << endl;
465 cout << l2a << endl;
466 cout << l1b << endl;
467 cout << l2b << endl;
468 return 0;
469 }
470 counter++;
471 }
472
473 cout << endl << wxLongLongNative(counter) << " successful trial" << (counter == 1 ? "." : "s.") << endl;
474
475 return 1;
476 }
477
478 int multiplicationtest();
479
480 int multiplicationtest()
481 {
482 cout << endl << "Starting multiplication tests." << endl;
483
484 long hi = 0;
485 unsigned long lo = 0;
486
487 unsigned wxLongLong_t counter = 0;
488
489 while (counter < NumberOfTests)
490 {
491 if ((counter % 1000) == 999)
492 {
493 cerr << "+";
494 #if defined(__MWERKS__) && macintosh
495 GetNextEvent(0, NULL);
496 #endif
497 }
498
499 random(hi, lo);
500 wxLongLongWx l1a(hi, lo);
501 wxLongLongNative l2a(hi, lo);
502 wxLongLongWx l1d(hi, lo);
503 wxLongLongNative l2d(hi, lo);
504 random(hi, lo);
505 wxLongLongWx l1b(hi, lo);
506 wxLongLongNative l2b(hi, lo);
507
508 wxLongLongWx l1c(l1a * l1b);
509 wxLongLongNative l2c(l2a * l2b);
510
511 l1d *= l1b;
512 l2d *= l2b;
513
514 void *onec = l1c.asArray();
515 void *twoc = l2c.asArray();
516 void *oned = l1c.asArray();
517 void *twod = l2c.asArray();
518
519 if ((memcmp(onec, twoc, 8) != 0) || (memcmp(oned, twod, 8) != 0) || (memcmp(onec, oned, 8) != 0))
520 {
521 cout << endl << "After " << wxLongLongNative(counter) << " successful trials: " << endl;
522 cout << l1a << endl;
523 cout << l2a << endl;
524 cout << l1b << endl;
525 cout << l2b << endl;
526 cout << l1c << endl;
527 cout << l2c << endl;
528 cout << l1d << endl;
529 cout << l2d << endl;
530 return 0;
531 }
532 counter++;
533 }
534
535 cout << endl << wxLongLongNative(counter) << " successful trial" << (counter == 1 ? "." : "s.") << endl;
536
537 return 1;
538 }
539
540 int bitwisetest();
541
542 int bitwisetest()
543 {
544 cout << endl << "Starting bitwise tests." << endl;
545
546 long hi = 0;
547 unsigned long lo = 0;
548
549 unsigned wxLongLong_t counter = 0;
550
551 while (counter < NumberOfTests)
552 {
553 if ((counter % 1000) == 999)
554 {
555 cerr << "+";
556 #if defined(__MWERKS__) && macintosh
557 GetNextEvent(0, NULL);
558 #endif
559 }
560
561 random(hi, lo);
562 wxLongLongWx l1a(hi, lo);
563 wxLongLongNative l2a(hi, lo);
564 wxLongLongWx l1d(hi, lo);
565 wxLongLongNative l2d(hi, lo);
566 random(hi, lo);
567 wxLongLongWx l1b(hi, lo);
568 wxLongLongNative l2b(hi, lo);
569
570 wxLongLongWx l1c(l1a * l1b);
571 wxLongLongNative l2c(l2a * l2b);
572
573 l1d *= l1b;
574 l2d *= l2b;
575
576 void *onec = l1c.asArray();
577 void *twoc = l2c.asArray();
578 void *oned = l1c.asArray();
579 void *twod = l2c.asArray();
580
581 if ((memcmp(onec, twoc, 8) != 0) || (memcmp(oned, twod, 8) != 0) || (memcmp(onec, oned, 8) != 0))
582 {
583 cout << endl << "After " << wxLongLongNative(counter) << " successful trials: " << endl;
584 cout << l1a << endl;
585 cout << l2a << endl;
586 cout << l1b << endl;
587 cout << l2b << endl;
588 cout << l1c << endl;
589 cout << l2c << endl;
590 cout << l1d << endl;
591 cout << l2d << endl;
592 return 0;
593 }
594 counter++;
595 }
596
597 cout << endl << wxLongLongNative(counter) << " successful trial" << (counter == 1 ? "." : "s.") << endl;
598
599 return 1;
600 }
601
602 int main()
603 {
604 #if defined(__MWERKS__) && macintosh
605 SIOUXSettings.asktosaveonclose = 0;
606 SIOUXSettings.showstatusline = 1;
607 SIOUXSettings.autocloseonquit = 0;
608 #endif
609
610 cout << "Starting tests." << endl;
611
612 #if defined(__MWERKS__) && macintosh
613 GetNextEvent(0, NULL);
614 #endif
615
616 srand(time(NULL));
617
618 if (!multiplicationtest())
619 return 1;
620
621 if (!shifttest())
622 return 1;
623
624 if (!add1test())
625 return 1;
626
627 // if (!add2test())
628 // return 1;
629
630 if (!sub1test())
631 return 1;
632
633 // if (!sub2test())
634 // return 1;
635
636 if (!incdectest())
637 return 1;
638
639 if (!negationtest())
640 return 1;
641
642 cout << endl << "The tests are finished." << endl;
643
644 return 0;
645 }