|
28 | 28 | #define WEAK
|
29 | 29 | #endif
|
30 | 30 |
|
| 31 | +#ifndef __MSC_VER |
31 | 32 | #include <inttypes.h> /* intmax_t, uintmax_t, PRI* */
|
| 33 | +#endif |
| 34 | + |
32 | 35 | #include <stddef.h> /* size_t */
|
33 | 36 |
|
34 | 37 | typedef void (*SetupFunc)(void*);
|
@@ -72,6 +75,13 @@ struct ctest {
|
72 | 75 | #define __CTEST_NO_TIME
|
73 | 76 | #define CTEST_NO_COLORS
|
74 | 77 |
|
| 78 | +#if __MSC_VER >= 1500 |
| 79 | +#include <inttypes.h> |
| 80 | +#else |
| 81 | +#include <stdint.h> |
| 82 | +#define CTEST_NO_INTTYPES |
| 83 | +#endif |
| 84 | + |
75 | 85 | #ifndef CTEST_ADD_TESTS_MANUALLY
|
76 | 86 | #pragma section(".ctest$a")
|
77 | 87 | #pragma section(".ctest$u")
|
@@ -480,43 +490,71 @@ void assert_data(const unsigned char* exp, size_t expsize,
|
480 | 490 | const char* caller, int line) {
|
481 | 491 | size_t i;
|
482 | 492 | if (expsize != realsize) {
|
| 493 | +#ifndef CTEST_NO_INTTYPES |
483 | 494 | CTEST_ERR("%s:%d expected %" PRIuMAX " bytes, got %" PRIuMAX, caller, line, (uintmax_t) expsize, (uintmax_t) realsize);
|
| 495 | +#else |
| 496 | + CTEST_ERR("%s:%d expected %u bytes, got %u", caller, line, (uintmax_t) expsize, (uintmax_t) realsize); |
| 497 | +#endif |
484 | 498 | }
|
485 | 499 | for (i=0; i<expsize; i++) {
|
486 | 500 | if (exp[i] != real[i]) {
|
| 501 | +#ifndef CTEST_NO_INTTYPES |
487 | 502 | CTEST_ERR("%s:%d expected 0x%02x at offset %" PRIuMAX " got 0x%02x",
|
| 503 | +#else |
| 504 | + CTEST_ERR("%s:%d expected 0x%02x at offset %u got 0x%02x", |
| 505 | +#endif |
488 | 506 | caller, line, exp[i], (uintmax_t) i, real[i]);
|
489 | 507 | }
|
490 | 508 | }
|
491 | 509 | }
|
492 | 510 |
|
493 | 511 | void assert_equal(intmax_t exp, intmax_t real, const char* caller, int line) {
|
494 | 512 | if (exp != real) {
|
| 513 | +#ifndef CTEST_NO_INTTYPES |
495 | 514 | CTEST_ERR("%s:%d expected %" PRIdMAX ", got %" PRIdMAX, caller, line, exp, real);
|
| 515 | +#else |
| 516 | + CTEST_ERR("%s:%d expected %d, got %d", caller, line, exp, real); |
| 517 | +#endif |
496 | 518 | }
|
497 | 519 | }
|
498 | 520 |
|
499 | 521 | void assert_equal_u(uintmax_t exp, uintmax_t real, const char* caller, int line) {
|
500 | 522 | if (exp != real) {
|
| 523 | +#ifndef CTEST_NO_INTTYPES |
501 | 524 | CTEST_ERR("%s:%d expected %" PRIuMAX ", got %" PRIuMAX, caller, line, exp, real);
|
| 525 | +#else |
| 526 | + CTEST_ERR("%s:%d expected %u, got %u", caller, line, exp, real); |
| 527 | +#endif |
502 | 528 | }
|
503 | 529 | }
|
504 | 530 |
|
505 | 531 | void assert_not_equal(intmax_t exp, intmax_t real, const char* caller, int line) {
|
506 | 532 | if ((exp) == (real)) {
|
| 533 | +#ifndef CTEST_NO_INTTYPES |
507 | 534 | CTEST_ERR("%s:%d should not be %" PRIdMAX, caller, line, real);
|
| 535 | +#else |
| 536 | + CTEST_ERR("%s:%d should not be %d", caller, line, real); |
| 537 | +#endif |
508 | 538 | }
|
509 | 539 | }
|
510 | 540 |
|
511 | 541 | void assert_not_equal_u(uintmax_t exp, uintmax_t real, const char* caller, int line) {
|
512 | 542 | if ((exp) == (real)) {
|
| 543 | +#ifndef CTEST_NO_INTTYPES |
513 | 544 | CTEST_ERR("%s:%d should not be %" PRIuMAX, caller, line, real);
|
| 545 | +#else |
| 546 | + CTEST_ERR("%s:%d should not be %u", caller, line, real); |
| 547 | +#endif |
514 | 548 | }
|
515 | 549 | }
|
516 | 550 |
|
517 | 551 | void assert_interval(intmax_t exp1, intmax_t exp2, intmax_t real, const char* caller, int line) {
|
518 | 552 | if (real < exp1 || real > exp2) {
|
| 553 | +#ifndef CTEST_NO_INTTYPES |
519 | 554 | CTEST_ERR("%s:%d expected %" PRIdMAX "-%" PRIdMAX ", got %" PRIdMAX, caller, line, exp1, exp2, real);
|
| 555 | +#else |
| 556 | + CTEST_ERR("%s:%d expected %d-%d, got %d", caller, line, exp1, exp2, real); |
| 557 | +#endif |
520 | 558 | }
|
521 | 559 | }
|
522 | 560 |
|
|
0 commit comments