From b278e33aac39549e8f280bfe6cfdf45e1c343d6f Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Fri, 18 Apr 2025 11:27:12 -0400 Subject: [PATCH] Update unit test program to use test header. --- Makefile.in | 1 + test.h | 281 +++++++++++++++ testpdfio.c | 1000 +++++++++++++++++++++++++++------------------------ 3 files changed, 811 insertions(+), 471 deletions(-) create mode 100644 test.h diff --git a/Makefile.in b/Makefile.in index f2759ed..73398db 100644 --- a/Makefile.in +++ b/Makefile.in @@ -241,6 +241,7 @@ testttf: ttf.o testttf.o # Dependencies $(OBJS): pdfio.h pdfio-private.h Makefile pdfio-content.o: pdfio-content.h ttf.h +testpdfio.o: test.h testttf.o: ttf.h ttf.o: ttf.h diff --git a/test.h b/test.h new file mode 100644 index 0000000..7b30c38 --- /dev/null +++ b/test.h @@ -0,0 +1,281 @@ +// +// Unit test header for C/C++ programs. +// +// Copyright © 2021-2022 by Michael R Sweet. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// + +#ifndef TEST_H +# define TEST_H +# include +# include +# include +# include +# include +# if _WIN32 +# define isatty(f) _isatty(f) +# else +# include +# endif // !_WIN32 +# ifdef __cplusplus +extern "C" { +# endif // __cplusplus + + +// +// This header implements a simple unit test framework for C/C++ programs. +// Inline functions are provided to write a test summary to stdout and the +// details to stderr. This allows unit test programs to output a summary to +// stdout with details sent to stderr, e.g.: +// +// mytestprogram 2>test.log +// +// Documentation: +// +// void testBegin(const char *title, ...) +// +// Start a test with a printf-style title message. "Title:" (the formatted +// title followed by a colon) is output. +// +// void testEnd(bool pass) +// +// End a test without an additional message. "pass" should be `true` if the +// test passed and `false` otherwise. "PASS" or "FAIL" is output. +// +// void testEndMessage(bool pass, const char *message, ...) +// +// End a test with an additional printf-style message. "pass" should be +// `true` if the test passed and `false` otherwise. "PASS (message)" or +// "FAIL (message)" is output. +// +// testError(const char *error, ...) +// +// Sends a formatted error string to stderr. +// +// testHexDump(const unsigned char *buffer, size_t bytes) +// +// Sends a hex dump of the specified buffer to stderr. +// +// testMessage(const char *error, ...) +// +// Outputs a formatted message string. +// +// testProgress(void) +// +// Shows a progress spinner for long-running tests. +// +// bool testsPassed +// +// This global variable specifies whether all tests have passed (`true`) +// or one or more have failed (`false`). +// + +static bool testsPassed = true; // All tests passed? +static int test_progress; // Current progress +static char test_title[1024] = ""; // Current test title + + +// Start a test +static inline void +testBegin(const char *title, ...) // I - printf-style title string +{ + va_list ap; // Pointer to additional arguments + + + // Format the title string + va_start(ap, title); + vsnprintf(test_title, sizeof(test_title), title, ap); + va_end(ap); + + // Send the title to stdout and stderr... + test_progress = 0; + + printf("%s: ", test_title); + fflush(stdout); + + if (!isatty(2)) + fprintf(stderr, "%s: ", test_title); +} + + +// End a test with no additional information +static inline void +testEnd(bool pass) // I - `true` if the test passed, `false` otherwise +{ + // Send the test result to stdout and stderr + if (test_progress) + putchar('\b'); + + if (!pass) + testsPassed = false; + + puts(pass ? "PASS" : "FAIL"); + if (!isatty(2)) + fputs(pass ? "PASS\n" : "FAIL\n", stderr); + + test_title[0] = '\0'; +} + + +// End a test with no additional information +static inline void +testEndMessage(bool pass, // I - `true` if the test passed, `false` otherwise + const char *message, ...)// I - printf-style message +{ + char buffer[1024]; // Formatted title string + va_list ap; // Pointer to additional arguments + + + // Format the title string + va_start(ap, message); + vsnprintf(buffer, sizeof(buffer), message, ap); + va_end(ap); + + // Send the test result to stdout and stderr + if (test_progress) + putchar('\b'); + + printf(pass ? "PASS (%s)\n" : "FAIL (%s)\n", buffer); + if (!isatty(2)) + fprintf(stderr, pass ? "PASS (%s)\n" : "FAIL (%s)\n", buffer); + + test_title[0] = '\0'; +} + + +// Show/update a progress spinner +static inline void +testProgress(void) +{ + if (test_progress) + putchar('\b'); + putchar("-\\|/"[test_progress & 3]); + fflush(stdout); + + test_progress ++; +} + + +// Show an error to stderr... +static inline void +testError(const char *error, ...) // I - printf-style error string +{ + char buffer[1024]; // Formatted title string + va_list ap; // Pointer to additional arguments + + + // Format the error string + va_start(ap, error); + vsnprintf(buffer, sizeof(buffer), error, ap); + va_end(ap); + + // Send the error to stderr... + fprintf(stderr, "%s\n", buffer); + + if (test_title[0]) + fprintf(stderr, "%s: ", test_title); +} + + +// Show a message to stdout and stderr... +static inline void +testMessage(const char *error, ...) // I - printf-style error string +{ + char buffer[1024]; // Formatted title string + va_list ap; // Pointer to additional arguments + + + // Format the error string + va_start(ap, error); + vsnprintf(buffer, sizeof(buffer), error, ap); + va_end(ap); + + // Send the message to stdout and stderr too if needed... + printf("%s\n", buffer); + if (test_title[0]) + { + printf("%s: ", test_title); + fflush(stdout); + } + + if (!isatty(2)) + { + fprintf(stderr, "%s\n", buffer); + + if (test_title[0]) + fprintf(stderr, "%s: ", test_title); + } +} + + +// Show a hex dump of a buffer to stderr... +static inline void +testHexDump(const unsigned char *buffer,// I - Buffer + size_t bytes) // I - Number of bytes +{ + size_t i, j; // Looping vars + int ch; // Current ASCII char + + + if (test_title[0]) + fputs("\n", stderr); + + // Show lines of 16 bytes at a time... + for (i = 0; i < bytes; i += 16) + { + // Show the offset... + fprintf(stderr, "%04x ", (unsigned)i); + + // Then up to 16 bytes in hex... + for (j = 0; j < 16; j ++) + { + if ((i + j) < bytes) + fprintf(stderr, " %02x", buffer[i + j]); + else + fputs(" ", stderr); + } + + // Then the ASCII representation of the bytes... + fputs(" ", stderr); + + for (j = 0; j < 16 && (i + j) < bytes; j ++) + { + ch = buffer[i + j] & 127; + + if (ch < ' ' || ch == 127) + fputc('.', stderr); + else + fputc(ch, stderr); + } + + fputc('\n', stderr); + } + + if (test_title[0]) + fprintf(stderr, "%s: ", test_title); +} + +# ifdef __cplusplus +} +# endif // __cplusplus +#endif // !TEST_H diff --git a/testpdfio.c b/testpdfio.c index 3c78718..19fed4b 100644 --- a/testpdfio.c +++ b/testpdfio.c @@ -13,6 +13,7 @@ // ./testpdfio [--verbose] FILENAME [OBJECT-NUMBER] [FILENAME [OBJECT-NUMBER]] ... // +#include "test.h" #include "pdfio-private.h" #include "pdfio-content.h" #include @@ -163,11 +164,11 @@ do_crypto_tests(void) // Expected SHA-256 hash result - fputs("_pdfioAESInit(128-bit sample key): ", stdout); + testBegin("_pdfioAESInit(128-bit sample key)"); _pdfioCryptoAESInit(&aes, aes128key, sizeof(aes128key), NULL); if (!memcmp(aes128rounds, aes.round_key, sizeof(aes128rounds))) { - puts("PASS"); + testEnd(true); } else { @@ -180,11 +181,11 @@ do_crypto_tests(void) prefix = i > 0 ? "..." : ""; suffix = i < (sizeof(aes128rounds) - 4) ? "..." : ""; - printf("FAIL (got '%s%02X%02X%02X%02X%s', expected '%s%02X%02X%02X%02X%s')\n", prefix, aes.round_key[i], aes.round_key[i + 1], aes.round_key[i + 2], aes.round_key[i + 3], suffix, prefix, aes128rounds[i], aes128rounds[i + 1], aes128rounds[i + 2], aes128rounds[i + 3], suffix); + testEndMessage(false, "got '%s%02X%02X%02X%02X%s', expected '%s%02X%02X%02X%02X%s'", prefix, aes.round_key[i], aes.round_key[i + 1], aes.round_key[i + 2], aes.round_key[i + 3], suffix, prefix, aes128rounds[i], aes128rounds[i + 1], aes128rounds[i + 2], aes128rounds[i + 3], suffix); ret = 1; } - fputs("_pdfioAESInit/Encrypt(128-bit CBC): ", stdout); + testBegin("_pdfioAESInit/Encrypt(128-bit CBC)"); for (i = 0; i < 16; i ++) { key[i] = (uint8_t)i + 1; @@ -196,7 +197,7 @@ do_crypto_tests(void) if (!memcmp(aes128text, buffer, sizeof(aes128text))) { - puts("PASS"); + testEnd(true); } else { @@ -209,17 +210,17 @@ do_crypto_tests(void) prefix = i > 0 ? "..." : ""; suffix = i < (sizeof(aes128text) - 4) ? "..." : ""; - printf("FAIL (got '%s%02X%02X%02X%02X%s', expected '%s%02X%02X%02X%02X%s')\n", prefix, buffer[i], buffer[i + 1], buffer[i + 2], buffer[i + 3], suffix, prefix, aes128text[i], aes128text[i + 1], aes128text[i + 2], aes128text[i + 3], suffix); + testEndMessage(false, "got '%s%02X%02X%02X%02X%s', expected '%s%02X%02X%02X%02X%s'", prefix, buffer[i], buffer[i + 1], buffer[i + 2], buffer[i + 3], suffix, prefix, aes128text[i], aes128text[i + 1], aes128text[i + 2], aes128text[i + 3], suffix); ret = 1; } - fputs("_pdfioAESInit/Decrypt(128-bit CBC): ", stdout); + testBegin("_pdfioAESInit/Decrypt(128-bit CBC)"); _pdfioCryptoAESInit(&aes, key, 16, iv); _pdfioCryptoAESDecrypt(&aes, buffer2, buffer, sizeof(aes128text)); if (!memcmp(buffer2, text, strlen(text))) { - puts("PASS"); + testEnd(true); } else { @@ -232,11 +233,11 @@ do_crypto_tests(void) prefix = i > 0 ? "..." : ""; suffix = text[i + 4] ? "..." : ""; - printf("FAIL (got '%s%02X%02X%02X%02X%s', expected '%s%02X%02X%02X%02X%s')\n", prefix, buffer2[i], buffer2[i + 1], buffer2[i + 2], buffer2[i + 3], suffix, prefix, text[i], text[i + 1], text[i + 2], text[i + 3], suffix); + testEndMessage(false, "got '%s%02X%02X%02X%02X%s', expected '%s%02X%02X%02X%02X%s'", prefix, buffer2[i], buffer2[i + 1], buffer2[i + 2], buffer2[i + 3], suffix, prefix, text[i], text[i + 1], text[i + 2], text[i + 3], suffix); ret = 1; } - fputs("_pdfioAESInit/Encrypt(256-bit CBC): ", stdout); + testBegin("_pdfioAESInit/Encrypt(256-bit CBC)"); for (i = 0; i < 32; i ++) { key[i] = (uint8_t)i + 1; @@ -248,7 +249,7 @@ do_crypto_tests(void) if (!memcmp(aes256text, buffer, sizeof(aes256text))) { - puts("PASS"); + testEnd(true); } else { @@ -261,17 +262,17 @@ do_crypto_tests(void) prefix = i > 0 ? "..." : ""; suffix = i < (sizeof(aes256text) - 4) ? "..." : ""; - printf("FAIL (got '%s%02X%02X%02X%02X%s', expected '%s%02X%02X%02X%02X%s')\n", prefix, buffer[i], buffer[i + 1], buffer[i + 2], buffer[i + 3], suffix, prefix, aes256text[i], aes256text[i + 1], aes256text[i + 2], aes256text[i + 3], suffix); + testEndMessage(false, "got '%s%02X%02X%02X%02X%s', expected '%s%02X%02X%02X%02X%s'", prefix, buffer[i], buffer[i + 1], buffer[i + 2], buffer[i + 3], suffix, prefix, aes256text[i], aes256text[i + 1], aes256text[i + 2], aes256text[i + 3], suffix); ret = 1; } - fputs("_pdfioAESInit/Decrypt(256-bit CBC): ", stdout); + testBegin("_pdfioAESInit/Decrypt(256-bit CBC)"); _pdfioCryptoAESInit(&aes, key, 32, iv); _pdfioCryptoAESDecrypt(&aes, buffer2, buffer, sizeof(aes256text)); if (!memcmp(buffer2, text, strlen(text))) { - puts("PASS"); + testEnd(true); } else { @@ -284,26 +285,26 @@ do_crypto_tests(void) prefix = i > 0 ? "..." : ""; suffix = text[i + 4] ? "..." : ""; - printf("FAIL (got '%s%02X%02X%02X%02X%s', expected '%s%02X%02X%02X%02X%s')\n", prefix, buffer2[i], buffer2[i + 1], buffer2[i + 2], buffer2[i + 3], suffix, prefix, text[i], text[i + 1], text[i + 2], text[i + 3], suffix); + testEndMessage(false, "got '%s%02X%02X%02X%02X%s', expected '%s%02X%02X%02X%02X%s'", prefix, buffer2[i], buffer2[i + 1], buffer2[i + 2], buffer2[i + 3], suffix, prefix, text[i], text[i + 1], text[i + 2], text[i + 3], suffix); ret = 1; } - fputs("_pdfioMD5Init/Append/Finish: ", stdout); + testBegin("_pdfioMD5Init/Append/Finish"); _pdfioCryptoMD5Init(&md5); _pdfioCryptoMD5Append(&md5, (uint8_t *)text, strlen(text)); _pdfioCryptoMD5Finish(&md5, buffer); if (!memcmp(md5text, buffer, sizeof(md5text))) { - puts("PASS"); + testEnd(true); } else { - printf("FAIL (got '%02X%02X%02X%02X...%02X%02X%02X%02X', expected '%02X%02X%02X%02X...%02X%02X%02X%02X')\n", buffer[0], buffer[1], buffer[2], buffer[3], buffer[12], buffer[13], buffer[14], buffer[15], md5text[0], md5text[1], md5text[2], md5text[3], md5text[12], md5text[13], md5text[14], md5text[15]); + testEndMessage(false, "got '%02X%02X%02X%02X...%02X%02X%02X%02X', expected '%02X%02X%02X%02X...%02X%02X%02X%02X'", buffer[0], buffer[1], buffer[2], buffer[3], buffer[12], buffer[13], buffer[14], buffer[15], md5text[0], md5text[1], md5text[2], md5text[3], md5text[12], md5text[13], md5text[14], md5text[15]); ret = 1; } - fputs("_pdfioRC4Init/Encrypt(128-bit): ", stdout); + testBegin("_pdfioRC4Init/Encrypt(128-bit)"); for (i = 0; i < 16; i ++) key[i] = (uint8_t)i + 1; @@ -312,7 +313,7 @@ do_crypto_tests(void) if (!memcmp(rc4text, buffer, sizeof(rc4text))) { - puts("PASS"); + testEnd(true); } else { @@ -325,17 +326,17 @@ do_crypto_tests(void) prefix = i > 0 ? "..." : ""; suffix = i < (sizeof(rc4text) - 4) ? "..." : ""; - printf("FAIL (got '%s%02X%02X%02X%02X%s', expected '%s%02X%02X%02X%02X%s')\n", prefix, buffer[i], buffer[i + 1], buffer[i + 2], buffer[i + 3], suffix, prefix, rc4text[i], rc4text[i + 1], rc4text[i + 2], rc4text[i + 3], suffix); + testEndMessage(false, "got '%s%02X%02X%02X%02X%s', expected '%s%02X%02X%02X%02X%s'", prefix, buffer[i], buffer[i + 1], buffer[i + 2], buffer[i + 3], suffix, prefix, rc4text[i], rc4text[i + 1], rc4text[i + 2], rc4text[i + 3], suffix); ret = 1; } - fputs("_pdfioRC4Init/Decrypt(128-bit): ", stdout); + testBegin("_pdfioRC4Init/Decrypt(128-bit)"); _pdfioCryptoRC4Init(&rc4, key, 16); _pdfioCryptoRC4Crypt(&rc4, buffer2, buffer, strlen(text)); if (!memcmp(buffer2, text, strlen(text))) { - puts("PASS"); + testEnd(true); } else { @@ -348,22 +349,22 @@ do_crypto_tests(void) prefix = i > 0 ? "..." : ""; suffix = text[i + 4] ? "..." : ""; - printf("FAIL (got '%s%02X%02X%02X%02X%s', expected '%s%02X%02X%02X%02X%s')\n", prefix, buffer2[i], buffer2[i + 1], buffer2[i + 2], buffer2[i + 3], suffix, prefix, text[i], text[i + 1], text[i + 2], text[i + 3], suffix); + testEndMessage(false, "got '%s%02X%02X%02X%02X%s', expected '%s%02X%02X%02X%02X%s'", prefix, buffer2[i], buffer2[i + 1], buffer2[i + 2], buffer2[i + 3], suffix, prefix, text[i], text[i + 1], text[i + 2], text[i + 3], suffix); ret = 1; } - fputs("_pdfioSHA256Init/Append/Finish: ", stdout); + testBegin("_pdfioSHA256Init/Append/Finish"); _pdfioCryptoSHA256Init(&sha256); _pdfioCryptoSHA256Append(&sha256, (uint8_t *)text, strlen(text)); _pdfioCryptoSHA256Finish(&sha256, buffer); if (!memcmp(sha256text, buffer, sizeof(sha256text))) { - puts("PASS"); + testEnd(true); } else { - printf("FAIL (got '%02X%02X%02X%02X...%02X%02X%02X%02X', expected '%02X%02X%02X%02X...%02X%02X%02X%02X')\n", buffer[0], buffer[1], buffer[2], buffer[3], buffer[28], buffer[29], buffer[30], buffer[31], sha256text[0], sha256text[1], sha256text[2], sha256text[3], sha256text[28], sha256text[29], sha256text[30], sha256text[31]); + testEndMessage(false, "got '%02X%02X%02X%02X...%02X%02X%02X%02X', expected '%02X%02X%02X%02X...%02X%02X%02X%02X'", buffer[0], buffer[1], buffer[2], buffer[3], buffer[28], buffer[29], buffer[30], buffer[31], sha256text[0], sha256text[1], sha256text[2], sha256text[3], sha256text[28], sha256text[29], sha256text[30], sha256text[31]); ret = 1; } @@ -393,7 +394,7 @@ do_test_file(const char *filename, // I - PDF filename // Try opening the file... if (!objnum) { - printf("%s: ", filename); + testBegin("%s", filename); fflush(stdout); } @@ -437,7 +438,7 @@ do_test_file(const char *filename, // I - PDF filename } else { - puts("PASS"); + testEnd(true); // Show basic stats... num_objs = pdfioFileGetNumObjs(pdf); @@ -978,73 +979,71 @@ do_unit_tests(void) setbuf(stdout, NULL); // First open the test PDF file... - fputs("pdfioFileOpen(\"testfiles/testpdfio.pdf\"): ", stdout); + testBegin("pdfioFileOpen(\"testfiles/testpdfio.pdf\")"); if ((inpdf = pdfioFileOpen("testfiles/testpdfio.pdf", /*password_cb*/NULL, /*password_data*/NULL, (pdfio_error_cb_t)error_cb, &error)) != NULL) - puts("PASS"); + testEnd(true); else return (1); // TODO: Test for known values in this test file. // Test dictionary APIs - fputs("pdfioDictCreate: ", stdout); + testBegin("pdfioDictCreate"); if ((dict = pdfioDictCreate(inpdf)) != NULL) { - puts("PASS"); + testEnd(true); - fputs("pdfioDictSet*: ", stdout); + testBegin("pdfioDictSet*"); if (pdfioDictSetBoolean(dict, "Boolean", true) && pdfioDictSetName(dict, "Name", "Name") && pdfioDictSetNumber(dict, "Number", 42.0) && pdfioDictSetString(dict, "String", "String")) { - puts("PASS"); + testEnd(true); } else { - puts("FAIL"); + testEnd(false); return (1); } - fputs("pdfioDictIterateKeys: ", stdout); + testBegin("pdfioDictIterateKeys"); pdfioDictIterateKeys(dict, iterate_cb, &count); if (count == 4) { - puts("PASS"); + testEnd(true); } else { - printf("FAIL (got %d, expected 4)\n", count); + testEndMessage(false, "got %d, expected 4", count); return (1); } } else { - puts("FAIL"); + testEnd(false); return (1); } // Test the value parsers for edge cases... - fputs("_pdfioValueRead(complex_dict): ", stdout); + testBegin("_pdfioValueRead(complex_dict)"); s = complex_dict; _pdfioTokenInit(&tb, inpdf, (_pdfio_tconsume_cb_t)token_consume_cb, (_pdfio_tpeek_cb_t)token_peek_cb, (void *)&s); if (_pdfioValueRead(inpdf, NULL, &tb, &value, 0)) { // TODO: Check value... - fputs("PASS: ", stdout); + testEnd(true); _pdfioValueDebug(&value, stdout); - puts("\n"); } else goto fail; // Test the value parsers for edge cases... - fputs("_pdfioValueRead(cid_dict): ", stdout); + testBegin("_pdfioValueRead(cid_dict)"); s = cid_dict; _pdfioTokenInit(&tb, inpdf, (_pdfio_tconsume_cb_t)token_consume_cb, (_pdfio_tpeek_cb_t)token_peek_cb, (void *)&s); if (_pdfioValueRead(inpdf, NULL, &tb, &value, 0)) { // TODO: Check value... - fputs("PASS: ", stdout); + testEnd(true); _pdfioValueDebug(&value, stdout); - puts("\n"); } else goto fail; @@ -1054,9 +1053,9 @@ do_unit_tests(void) return (1); // Create a new PDF file... - fputs("pdfioFileCreate(\"testpdfio-out.pdf\", ...): ", stdout); + testBegin("pdfioFileCreate(\"testpdfio-out.pdf\", ...)"); if ((outpdf = pdfioFileCreate("testpdfio-out.pdf", NULL, NULL, NULL, (pdfio_error_cb_t)error_cb, &error)) != NULL) - puts("PASS"); + testEnd(true); else goto fail; @@ -1073,9 +1072,9 @@ do_unit_tests(void) goto fail; } - fputs("pdfioFileCreateOutput(...): ", stdout); + testBegin("pdfioFileCreateOutput(...)"); if ((outpdf = pdfioFileCreateOutput((pdfio_output_cb_t)output_cb, &outfd, NULL, NULL, NULL, (pdfio_error_cb_t)error_cb, &error)) != NULL) - puts("PASS"); + testEnd(true); else goto fail; @@ -1088,15 +1087,15 @@ do_unit_tests(void) goto fail; // Create new encrypted PDF files... - fputs("pdfioFileCreate(\"testpdfio-rc4.pdf\", ...): ", stdout); + testBegin("pdfioFileCreate(\"testpdfio-rc4.pdf\", ...)"); if ((outpdf = pdfioFileCreate("testpdfio-rc4.pdf", NULL, NULL, NULL, (pdfio_error_cb_t)error_cb, &error)) != NULL) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioFileSetPermissions(all, RC4-128, no passwords): ", stdout); + testBegin("pdfioFileSetPermissions(all, RC4-128, no passwords)"); if (pdfioFileSetPermissions(outpdf, PDFIO_PERMISSION_ALL, PDFIO_ENCRYPTION_RC4_128, NULL, NULL)) - puts("PASS"); + testEnd(true); else return (1); @@ -1107,15 +1106,15 @@ do_unit_tests(void) return (1); // Create new encrypted PDF files... - fputs("pdfioFileCreate(\"testpdfio-rc4p.pdf\", ...): ", stdout); + testBegin("pdfioFileCreate(\"testpdfio-rc4p.pdf\", ...)"); if ((outpdf = pdfioFileCreate("testpdfio-rc4p.pdf", NULL, NULL, NULL, (pdfio_error_cb_t)error_cb, &error)) != NULL) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioFileSetPermissions(no-print, RC4-128, passwords='owner' and 'user'): ", stdout); + testBegin("pdfioFileSetPermissions(no-print, RC4-128, passwords='owner' and 'user')"); if (pdfioFileSetPermissions(outpdf, PDFIO_PERMISSION_ALL ^ PDFIO_PERMISSION_PRINT, PDFIO_ENCRYPTION_RC4_128, "owner", "user")) - puts("PASS"); + testEnd(true); else return (1); @@ -1125,15 +1124,15 @@ do_unit_tests(void) if (read_unit_file("testpdfio-rc4p.pdf", num_pages, first_image, false)) return (1); - fputs("pdfioFileCreate(\"testpdfio-aes.pdf\", ...): ", stdout); + testBegin("pdfioFileCreate(\"testpdfio-aes.pdf\", ...)"); if ((outpdf = pdfioFileCreate("testpdfio-aes.pdf", NULL, NULL, NULL, (pdfio_error_cb_t)error_cb, &error)) != NULL) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioFileSetPermissions(all, AES-128, no passwords): ", stdout); + testBegin("pdfioFileSetPermissions(all, AES-128, no passwords)"); if (pdfioFileSetPermissions(outpdf, PDFIO_PERMISSION_ALL, PDFIO_ENCRYPTION_AES_128, NULL, NULL)) - puts("PASS"); + testEnd(true); else return (1); @@ -1143,15 +1142,15 @@ do_unit_tests(void) if (read_unit_file("testpdfio-aes.pdf", num_pages, first_image, false)) return (1); - fputs("pdfioFileCreate(\"testpdfio-aesp.pdf\", ...): ", stdout); + testBegin("pdfioFileCreate(\"testpdfio-aesp.pdf\", ...)"); if ((outpdf = pdfioFileCreate("testpdfio-aesp.pdf", NULL, NULL, NULL, (pdfio_error_cb_t)error_cb, &error)) != NULL) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioFileSetPermissions(no-print, AES-128, passwords='owner' and 'user'): ", stdout); + testBegin("pdfioFileSetPermissions(no-print, AES-128, passwords='owner' and 'user')"); if (pdfioFileSetPermissions(outpdf, PDFIO_PERMISSION_ALL ^ PDFIO_PERMISSION_PRINT, PDFIO_ENCRYPTION_AES_128, "owner", "user")) - puts("PASS"); + testEnd(true); else return (1); @@ -1161,9 +1160,9 @@ do_unit_tests(void) if (read_unit_file("testpdfio-aesp.pdf", num_pages, first_image, false)) return (1); - fputs("pdfioFileCreateTemporary: ", stdout); + testBegin("pdfioFileCreateTemporary"); if ((outpdf = pdfioFileCreateTemporary(temppdf, sizeof(temppdf), NULL, NULL, NULL, (pdfio_error_cb_t)error_cb, &error)) != NULL) - printf("PASS (%s)\n", temppdf); + testEndMessage(true, "%s", temppdf); else return (1); @@ -1198,39 +1197,39 @@ draw_image(pdfio_stream_t *st, double h, // I - Image height const char *label) // I - Label { - printf("pdfioContentDrawImage(name=\"%s\", x=%g, y=%g, w=%g, h=%g): ", name, x, y, w, h); + testBegin("pdfioContentDrawImage(name=\"%s\", x=%g, y=%g, w=%g, h=%g)", name, x, y, w, h); if (pdfioContentDrawImage(st, name, x, y, w, h)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioContentTextBegin(): ", stdout); + testBegin("pdfioContentTextBegin()"); if (pdfioContentTextBegin(st)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioContentSetTextFont(\"F1\", 18.0): ", stdout); + testBegin("pdfioContentSetTextFont(\"F1\", 18.0)"); if (pdfioContentSetTextFont(st, "F1", 18.0)) - puts("PASS"); + testEnd(true); else return (1); - printf("pdfioContentTextMoveTo(%g, %g): ", x, y + h + 9); + testBegin("pdfioContentTextMoveTo(%g, %g)", x, y + h + 9); if (pdfioContentTextMoveTo(st, x, y + h + 9)) - puts("PASS"); + testEnd(true); else return (1); - printf("pdfioContentTextShow(\"%s\"): ", label); + testBegin("pdfioContentTextShow(\"%s\")", label); if (pdfioContentTextShow(st, false, label)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioContentTextEnd(): ", stdout); + testBegin("pdfioContentTextEnd()"); if (pdfioContentTextEnd(st)) - puts("PASS"); + testEnd(true); else return (1); @@ -1254,7 +1253,7 @@ error_cb(pdfio_file_t *pdf, // I - PDF file // First error, so show a "FAIL" indicator *error = true; - puts("FAIL"); + testEnd(false); } // Indent error messages... @@ -1331,17 +1330,17 @@ read_unit_file(const char *filename, // I - File to read // Open the new PDF file to read it... - printf("pdfioFileOpen(\"%s\", ...): ", filename); + testBegin("pdfioFileOpen(\"%s\", ...)", filename); if ((pdf = pdfioFileOpen(filename, password_cb, (void *)"user", (pdfio_error_cb_t)error_cb, &error)) != NULL) - puts("PASS"); + testEnd(true); else return (1); // Get the root object/catalog dictionary - fputs("pdfioFileGetCatalog: ", stdout); + testBegin("pdfioFileGetCatalog"); if ((catalog = pdfioFileGetCatalog(pdf)) != NULL) { - puts("PASS"); + testEnd(true); } else { @@ -1350,14 +1349,14 @@ read_unit_file(const char *filename, // I - File to read } // Verify some catalog values... - fputs("pdfioDictGetName(PageLayout): ", stdout); + testBegin("pdfioDictGetName(PageLayout)"); if ((s = pdfioDictGetName(catalog, "PageLayout")) != NULL && !strcmp(s, "SinglePage")) { - puts("PASS"); + testEnd(true); } else if (s) { - printf("FAIL (got '%s', expected 'SinglePage')\n", s); + testEndMessage(false, "got '%s', expected 'SinglePage'", s); return (1); } else @@ -1366,14 +1365,14 @@ read_unit_file(const char *filename, // I - File to read return (1); } - fputs("pdfioDictGetName(PageLayout): ", stdout); + testBegin("pdfioDictGetName(PageLayout)"); if ((s = pdfioDictGetName(catalog, "PageLayout")) != NULL && !strcmp(s, "SinglePage")) { - puts("PASS"); + testEnd(true); } else if (s) { - printf("FAIL (got '%s', expected 'SinglePage')\n", s); + testEndMessage(false, "got '%s', expected 'SinglePage'", s); return (1); } else @@ -1382,14 +1381,14 @@ read_unit_file(const char *filename, // I - File to read return (1); } - fputs("pdfioDictGetName(PageMode): ", stdout); + testBegin("pdfioDictGetName(PageMode)"); if ((s = pdfioDictGetName(catalog, "PageMode")) != NULL && !strcmp(s, "UseThumbs")) { - puts("PASS"); + testEnd(true); } else if (s) { - printf("FAIL (got '%s', expected 'UseThumbs')\n", s); + testEndMessage(false, "got '%s', expected 'UseThumbs'", s); return (1); } else @@ -1398,14 +1397,14 @@ read_unit_file(const char *filename, // I - File to read return (1); } - fputs("pdfioDictGetString(Lang): ", stdout); + testBegin("pdfioDictGetString(Lang)"); if ((s = pdfioDictGetString(catalog, "Lang")) != NULL && !strcmp(s, "en-CA")) { - puts("PASS"); + testEnd(true); } else if (s) { - printf("FAIL (got '%s', expected 'en-CA')\n", s); + testEndMessage(false, "got '%s', expected 'en-CA'", s); return (1); } else @@ -1415,14 +1414,14 @@ read_unit_file(const char *filename, // I - File to read } // Verify metadata... - fputs("pdfioFileGetAuthor: ", stdout); + testBegin("pdfioFileGetAuthor"); if ((s = pdfioFileGetAuthor(pdf)) != NULL && !strcmp(s, "Michael R Sweet")) { - puts("PASS"); + testEnd(true); } else if (s) { - printf("FAIL (got '%s', expected 'Michael R Sweet')\n", s); + testEndMessage(false, "got '%s', expected 'Michael R Sweet'", s); return (1); } else @@ -1431,14 +1430,14 @@ read_unit_file(const char *filename, // I - File to read return (1); } - fputs("pdfioFileGetCreator: ", stdout); + testBegin("pdfioFileGetCreator"); if ((s = pdfioFileGetCreator(pdf)) != NULL && !strcmp(s, "testpdfio")) { - puts("PASS"); + testEnd(true); } else if (s) { - printf("FAIL (got '%s', expected 'testpdfio')\n", s); + testEndMessage(false, "got '%s', expected 'testpdfio'", s); return (1); } else @@ -1447,14 +1446,14 @@ read_unit_file(const char *filename, // I - File to read return (1); } - fputs("pdfioFileGetKeywords: ", stdout); + testBegin("pdfioFileGetKeywords"); if ((s = pdfioFileGetKeywords(pdf)) != NULL && !strcmp(s, "one fish,two fish,red fish,blue fish")) { - puts("PASS"); + testEnd(true); } else if (s) { - printf("FAIL (got '%s', expected 'one fish,two fish,red fish,blue fish')\n", s); + testEndMessage(false, "got '%s', expected 'one fish,two fish,red fish,blue fish'", s); return (1); } else @@ -1463,14 +1462,14 @@ read_unit_file(const char *filename, // I - File to read return (1); } - fputs("pdfioFileGetSubject: ", stdout); + testBegin("pdfioFileGetSubject"); if ((s = pdfioFileGetSubject(pdf)) != NULL && !strcmp(s, "Unit test document")) { - puts("PASS"); + testEnd(true); } else if (s) { - printf("FAIL (got '%s', expected 'Unit test document')\n", s); + testEndMessage(false, "got '%s', expected 'Unit test document'", s); return (1); } else @@ -1479,14 +1478,14 @@ read_unit_file(const char *filename, // I - File to read return (1); } - fputs("pdfioFileGetTitle: ", stdout); + testBegin("pdfioFileGetTitle"); if ((s = pdfioFileGetTitle(pdf)) != NULL && !strcmp(s, "Test Document")) { - puts("PASS"); + testEnd(true); } else if (s) { - printf("FAIL (got '%s', expected 'Test Document')\n", s); + testEndMessage(false, "got '%s', expected 'Test Document'", s); return (1); } else @@ -1496,14 +1495,14 @@ read_unit_file(const char *filename, // I - File to read } // Verify the number of pages is the same... - fputs("pdfioFileGetNumPages: ", stdout); + testBegin("pdfioFileGetNumPages"); if (num_pages == pdfioFileGetNumPages(pdf)) { - puts("PASS"); + testEnd(true); } else { - printf("FAIL (%lu != %lu)\n", (unsigned long)num_pages, (unsigned long)pdfioFileGetNumPages(pdf)); + testEndMessage(false, "%lu != %lu", (unsigned long)num_pages, (unsigned long)pdfioFileGetNumPages(pdf)); return (1); } @@ -1520,9 +1519,9 @@ read_unit_file(const char *filename, // I - File to read } // Close the new PDF file... - fputs("pdfioFileClose(\"testpdfio-out.pdf\"): ", stdout); + testBegin("pdfioFileClose(\"testpdfio-out.pdf\")"); if (pdfioFileClose(pdf)) - puts("PASS"); + testEnd(true); else return (1); @@ -1613,62 +1612,69 @@ verify_image(pdfio_file_t *pdf, // I - PDF file ssize_t bytes; // Bytes read from stream - printf("pdfioFileFindObj(%lu): ", (unsigned long)number); + testBegin("pdfioFileFindObj(%lu)", (unsigned long)number); if ((obj = pdfioFileFindObj(pdf, number)) != NULL) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioObjGetType: ", stdout); + testBegin("pdfioObjGetType"); if ((type = pdfioObjGetType(obj)) != NULL && !strcmp(type, "XObject")) { - puts("PASS"); + testEnd(true); } else { - printf("FAIL (got %s, expected XObject)\n", type); + testEndMessage(false, "got %s, expected XObject", type); return (1); } - fputs("pdfioObjGetSubtype: ", stdout); + testBegin("pdfioObjGetSubtype"); if ((subtype = pdfioObjGetSubtype(obj)) != NULL && !strcmp(subtype, "Image")) { - puts("PASS"); + testEnd(true); } else { - printf("FAIL (got %s, expected Image)\n", subtype); + testEndMessage(false, "got %s, expected Image", subtype); return (1); } - fputs("pdfioImageGetWidth: ", stdout); + testBegin("pdfioImageGetWidth"); if ((width = pdfioImageGetWidth(obj)) == 256.0) { - puts("PASS"); + testEnd(true); } else { - printf("FAIL (got %g, expected 256)\n", width); + testEndMessage(false, "got %g, expected 256", width); return (1); } - fputs("pdfioImageGetHeight: ", stdout); + testBegin("pdfioImageGetHeight"); if ((height = pdfioImageGetHeight(obj)) == 256.0) { - puts("PASS"); + testEnd(true); } else { - printf("FAIL (got %g, expected 256)\n", height); + testEndMessage(false, "got %g, expected 256", height); return (1); } // Open the image stream, read the image, and verify it matches expectations... - fputs("pdfioObjOpenStream: ", stdout); + testBegin("pdfioObjOpenStream"); if ((st = pdfioObjOpenStream(obj, PDFIO_FILTER_FLATE)) != NULL) - puts("PASS"); + { + testEnd(true); + } else + { + testEnd(false); return (1); + } + + testBegin("pdfioStreamRead"); for (y = 0; y < 256; y ++) { @@ -1681,14 +1687,14 @@ verify_image(pdfio_file_t *pdf, // I - PDF file if ((bytes = pdfioStreamRead(st, line, sizeof(line))) != (ssize_t)sizeof(line)) { - printf("pdfioStreamRead: FAIL (got %d for line %d, expected 768)\n", y, (int)bytes); + testEndMessage(false, "got %d for line %d, expected 768", y, (int)bytes); pdfioStreamClose(st); return (1); } if (memcmp(buffer, line, sizeof(buffer))) { - printf("pdfioStreamRead: FAIL (line %d doesn't match expectations)\n", y); + testEndMessage(false, "line %d doesn't match expectations", y); pdfioStreamClose(st); return (1); } @@ -1696,6 +1702,8 @@ verify_image(pdfio_file_t *pdf, // I - PDF file pdfioStreamClose(st); + testEnd(true); + return (0); } @@ -1806,45 +1814,45 @@ write_alpha_test( } // Write the image... - printf("pdfioFileCreateImageObjFromData(num_colors=%u, alpha=%s): ", (unsigned)num_colors, i > 2 ? "true" : "false"); + testBegin("pdfioFileCreateImageObjFromData(num_colors=%u, alpha=%s)", (unsigned)num_colors, i > 2 ? "true" : "false"); if ((images[i] = pdfioFileCreateImageObjFromData(pdf, buffer, 256, 256, num_colors, NULL, i > 2, false)) != NULL) { - printf("PASS (%u)\n", (unsigned)pdfioObjGetNumber(images[i])); + testEndMessage(true, "%u", (unsigned)pdfioObjGetNumber(images[i])); } else { - puts("FAIL"); + testEnd(false); return (1); } } // Create the page dictionary, object, and stream... - fputs("pdfioDictCreate: ", stdout); + testBegin("pdfioDictCreate"); if ((dict = pdfioDictCreate(pdf)) != NULL) - puts("PASS"); + testEnd(true); else return (1); for (i = 0; i < 6; i ++) { - printf("pdfioPageDictAddImage(%d): ", i + 1); + testBegin("pdfioPageDictAddImage(%d)", i + 1); snprintf(iname, sizeof(iname), "IM%d", i + 1); if (pdfioPageDictAddImage(dict, pdfioStringCreate(pdf, iname), images[i])) - puts("PASS"); + testEnd(true); else return (1); } - fputs("pdfioPageDictAddFont(F1): ", stdout); + testBegin("pdfioPageDictAddFont(F1)"); if (pdfioPageDictAddFont(dict, "F1", font)) - puts("PASS"); + testEnd(true); else return (1); - printf("pdfioFileCreatePage(%d): ", number); + testBegin("pdfioFileCreatePage(%d)", number); if ((st = pdfioFileCreatePage(pdf, dict)) != NULL) - puts("PASS"); + testEnd(true); else return (1); @@ -1870,9 +1878,9 @@ write_alpha_test( } // Wrap up... - fputs("pdfioStreamClose: ", stdout); + testBegin("pdfioStreamClose"); if (pdfioStreamClose(st)) - puts("PASS"); + testEnd(true); else return (1); @@ -1987,31 +1995,31 @@ write_color_patch(pdfio_stream_t *st, // I - Content stream magenta -= black; yellow -= black; - printf("pdfioContentSetFillColorDeviceCMYK(c=%g, m=%g, y=%g, k=%g): ", cyan, magenta, yellow, black); + testBegin("pdfioContentSetFillColorDeviceCMYK(c=%g, m=%g, y=%g, k=%g)", cyan, magenta, yellow, black); if (pdfioContentSetFillColorDeviceCMYK(st, cyan, magenta, yellow, black)) - puts("PASS"); + testEnd(true); else return (1); } else { // Use calibrate RGB space... - printf("pdfioContentSetFillColorRGB(r=%g, g=%g, b=%g): ", red, green, blue); + testBegin("pdfioContentSetFillColorRGB(r=%g, g=%g, b=%g)", red, green, blue); if (pdfioContentSetFillColorRGB(st, red, green, blue)) - puts("PASS"); + testEnd(true); else return (1); } - printf("pdfioContentPathRect(x=%g, y=%g, w=%g, h=%g): ", col * 6.0, row * 6.0, 6.0, 6.0); + testBegin("pdfioContentPathRect(x=%g, y=%g, w=%g, h=%g)", col * 6.0, row * 6.0, 6.0, 6.0); if (pdfioContentPathRect(st, col * 6.0, row * 6.0, 6.0, 6.0)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioContentFill(even_odd=false): ", stdout); + testBegin("pdfioContentFill(even_odd=false)"); if (pdfioContentFill(st, false)) - puts("PASS"); + testEnd(true); else return (1); } @@ -2036,292 +2044,292 @@ write_color_test(pdfio_file_t *pdf, // I - PDF file pdfio_obj_t *prophoto; // ProPhotoRGB ICC profile object - fputs("pdfioFileCreateICCObjFromFile(ProPhotoRGB): ", stdout); + testBegin("pdfioFileCreateICCObjFromFile(ProPhotoRGB)"); if ((prophoto = pdfioFileCreateICCObjFromFile(pdf, "testfiles/iso22028-2-romm-rgb.icc", 3)) != NULL) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioDictCreate: ", stdout); + testBegin("pdfioDictCreate"); if ((dict = pdfioDictCreate(pdf)) != NULL) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioArrayCreateColorFromStandard(AdobeRGB): ", stdout); + testBegin("pdfioArrayCreateColorFromStandard(AdobeRGB)"); if ((cs = pdfioArrayCreateColorFromStandard(pdf, 3, PDFIO_CS_ADOBE)) != NULL) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioPageDictAddColorSpace(AdobeRGB): ", stdout); + testBegin("pdfioPageDictAddColorSpace(AdobeRGB)"); if (pdfioPageDictAddColorSpace(dict, "AdobeRGB", cs)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioArrayCreateColorFromStandard(DisplayP3): ", stdout); + testBegin("pdfioArrayCreateColorFromStandard(DisplayP3)"); if ((cs = pdfioArrayCreateColorFromStandard(pdf, 3, PDFIO_CS_P3_D65)) != NULL) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioPageDictAddColorSpace(DisplayP3): ", stdout); + testBegin("pdfioPageDictAddColorSpace(DisplayP3)"); if (pdfioPageDictAddColorSpace(dict, "DisplayP3", cs)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioArrayCreateColorFromICCObj(ProPhotoRGB): ", stdout); + testBegin("pdfioArrayCreateColorFromICCObj(ProPhotoRGB)"); if ((cs = pdfioArrayCreateColorFromICCObj(pdf, prophoto)) != NULL) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioPageDictAddColorSpace(ProPhotoRGB): ", stdout); + testBegin("pdfioPageDictAddColorSpace(ProPhotoRGB)"); if (pdfioPageDictAddColorSpace(dict, "ProPhotoRGB", cs)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioArrayCreateColorFromStandard(sRGB): ", stdout); + testBegin("pdfioArrayCreateColorFromStandard(sRGB)"); if ((cs = pdfioArrayCreateColorFromStandard(pdf, 3, PDFIO_CS_SRGB)) != NULL) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioPageDictAddColorSpace(sRGB): ", stdout); + testBegin("pdfioPageDictAddColorSpace(sRGB)"); if (pdfioPageDictAddColorSpace(dict, "sRGB", cs)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioPageDictAddFont(F1): ", stdout); + testBegin("pdfioPageDictAddFont(F1)"); if (pdfioPageDictAddFont(dict, "F1", font)) - puts("PASS"); + testEnd(true); else return (1); - printf("pdfioFileCreatePage(%d): ", number); + testBegin("pdfioFileCreatePage(%d)", number); if ((st = pdfioFileCreatePage(pdf, dict)) != NULL) - puts("PASS"); + testEnd(true); else return (1); if (write_header_footer(st, "Color Space Test", number)) goto error; - fputs("pdfioContentTextBegin(): ", stdout); + testBegin("pdfioContentTextBegin()"); if (pdfioContentTextBegin(st)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentSetTextFont(\"F1\", 18.0): ", stdout); + testBegin("pdfioContentSetTextFont(\"F1\", 18.0)"); if (pdfioContentSetTextFont(st, "F1", 18.0)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentTextMoveTo(82, 234): ", stdout); + testBegin("pdfioContentTextMoveTo(82, 234)"); if (pdfioContentTextMoveTo(st, 82, 234)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentTextShow(\"AdobeRGB\"): ", stdout); + testBegin("pdfioContentTextShow(\"AdobeRGB\")"); if (pdfioContentTextShow(st, false, "AdobeRGB")) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentTextMoveTo(234, 0): ", stdout); + testBegin("pdfioContentTextMoveTo(234, 0)"); if (pdfioContentTextMoveTo(st, 234, 0)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentTextShow(\"DisplayP3\"): ", stdout); + testBegin("pdfioContentTextShow(\"DisplayP3\")"); if (pdfioContentTextShow(st, false, "DisplayP3")) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentTextMoveTo(-234, 216): ", stdout); + testBegin("pdfioContentTextMoveTo(-234, 216)"); if (pdfioContentTextMoveTo(st, -234, 216)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentTextShow(\"sRGB\"): ", stdout); + testBegin("pdfioContentTextShow(\"sRGB\")"); if (pdfioContentTextShow(st, false, "sRGB")) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentTextMoveTo(234, 0): ", stdout); + testBegin("pdfioContentTextMoveTo(234, 0)"); if (pdfioContentTextMoveTo(st, 234, 0)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentTextShow(\"ProPhotoRGB\"): ", stdout); + testBegin("pdfioContentTextShow(\"ProPhotoRGB\")"); if (pdfioContentTextShow(st, false, "ProPhotoRGB")) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentTextMoveTo(-234, 216): ", stdout); + testBegin("pdfioContentTextMoveTo(-234, 216)"); if (pdfioContentTextMoveTo(st, -234, 216)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentTextShow(\"DeviceCMYK\"): ", stdout); + testBegin("pdfioContentTextShow(\"DeviceCMYK\")"); if (pdfioContentTextShow(st, false, "DeviceCMYK")) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentTextEnd(): ", stdout); + testBegin("pdfioContentTextEnd()"); if (pdfioContentTextEnd(st)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentSave(): ", stdout); + testBegin("pdfioContentSave()"); if (pdfioContentSave(st)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentSetFillColorSpace(AdobeRGB): ", stdout); + testBegin("pdfioContentSetFillColorSpace(AdobeRGB)"); if (pdfioContentSetFillColorSpace(st, "AdobeRGB")) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentMatrixTranslate(82, 90): ", stdout); + testBegin("pdfioContentMatrixTranslate(82, 90)"); if (pdfioContentMatrixTranslate(st, 82, 90)) - puts("PASS"); + testEnd(true); else goto error; if (write_color_patch(st, false)) goto error; - fputs("pdfioContentRestore(): ", stdout); + testBegin("pdfioContentRestore()"); if (pdfioContentRestore(st)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentSave(): ", stdout); + testBegin("pdfioContentSave()"); if (pdfioContentSave(st)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentSetFillColorSpace(DisplayP3): ", stdout); + testBegin("pdfioContentSetFillColorSpace(DisplayP3)"); if (pdfioContentSetFillColorSpace(st, "DisplayP3")) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentMatrixTranslate(316, 90): ", stdout); + testBegin("pdfioContentMatrixTranslate(316, 90)"); if (pdfioContentMatrixTranslate(st, 316, 90)) - puts("PASS"); + testEnd(true); else goto error; if (write_color_patch(st, false)) goto error; - fputs("pdfioContentRestore(): ", stdout); + testBegin("pdfioContentRestore()"); if (pdfioContentRestore(st)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentSave(): ", stdout); + testBegin("pdfioContentSave()"); if (pdfioContentSave(st)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentSetFillColorSpace(sRGB): ", stdout); + testBegin("pdfioContentSetFillColorSpace(sRGB)"); if (pdfioContentSetFillColorSpace(st, "sRGB")) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentMatrixTranslate(82, 306): ", stdout); + testBegin("pdfioContentMatrixTranslate(82, 306)"); if (pdfioContentMatrixTranslate(st, 82, 306)) - puts("PASS"); + testEnd(true); else goto error; if (write_color_patch(st, false)) goto error; - fputs("pdfioContentRestore(): ", stdout); + testBegin("pdfioContentRestore()"); if (pdfioContentRestore(st)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentSave(): ", stdout); + testBegin("pdfioContentSave()"); if (pdfioContentSave(st)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentSetFillColorSpace(ProPhotoRGB): ", stdout); + testBegin("pdfioContentSetFillColorSpace(ProPhotoRGB)"); if (pdfioContentSetFillColorSpace(st, "ProPhotoRGB")) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentMatrixTranslate(316, 306): ", stdout); + testBegin("pdfioContentMatrixTranslate(316, 306)"); if (pdfioContentMatrixTranslate(st, 316, 306)) - puts("PASS"); + testEnd(true); else goto error; if (write_color_patch(st, false)) goto error; - fputs("pdfioContentRestore(): ", stdout); + testBegin("pdfioContentRestore()"); if (pdfioContentRestore(st)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentSave(): ", stdout); + testBegin("pdfioContentSave()"); if (pdfioContentSave(st)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentMatrixTranslate(82, 522): ", stdout); + testBegin("pdfioContentMatrixTranslate(82, 522)"); if (pdfioContentMatrixTranslate(st, 82, 522)) - puts("PASS"); + testEnd(true); else goto error; if (write_color_patch(st, true)) goto error; - fputs("pdfioContentRestore(): ", stdout); + testBegin("pdfioContentRestore()"); if (pdfioContentRestore(st)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioStreamClose: ", stdout); + testBegin("pdfioStreamClose"); if (pdfioStreamClose(st)) - puts("PASS"); + testEnd(true); else return (1); @@ -2508,34 +2516,34 @@ write_font_test( }; - printf("pdfioFileCreateFontObjFromFile(%s): ", textfontfile); + testBegin("pdfioFileCreateFontObjFromFile(%s)", textfontfile); if ((textfont = pdfioFileCreateFontObjFromFile(pdf, textfontfile, unicode)) != NULL) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioDictCreate: ", stdout); + testBegin("pdfioDictCreate"); if ((dict = pdfioDictCreate(pdf)) != NULL) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioPageDictAddFont(F1): ", stdout); + testBegin("pdfioPageDictAddFont(F1)"); if (pdfioPageDictAddFont(dict, "F1", font)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioPageDictAddFont(F2): ", stdout); + testBegin("pdfioPageDictAddFont(F2)"); if (pdfioPageDictAddFont(dict, "F2", textfont)) - puts("PASS"); + testEnd(true); else return (1); - printf("pdfioFileCreatePage(%d): ", number); + testBegin("pdfioFileCreatePage(%d)", number); if ((st = pdfioFileCreatePage(pdf, dict)) != NULL) - puts("PASS"); + testEnd(true); else return (1); @@ -2556,27 +2564,27 @@ write_font_test( if (write_header_footer(st, title, number)) goto error; - fputs("pdfioContentTextBegin(): ", stdout); + testBegin("pdfioContentTextBegin()"); if (pdfioContentTextBegin(st)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioContentSetTextFont(\"F2\", 10.0): ", stdout); + testBegin("pdfioContentSetTextFont(\"F2\", 10.0)"); if (pdfioContentSetTextFont(st, "F2", 10.0)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioContentSetTextLeading(12.0): ", stdout); + testBegin("pdfioContentSetTextLeading(12.0)"); if (pdfioContentSetTextLeading(st, 12.0)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentTextMoveTo(198.0, 702.0): ", stdout); + testBegin("pdfioContentTextMoveTo(198.0, 702.0)"); if (pdfioContentTextMoveTo(st, 198.0, 702.0)) - puts("PASS"); + testEnd(true); else return (1); @@ -2584,47 +2592,47 @@ write_font_test( { if (i > 0 && (i % 50) == 0) { - fputs("pdfioContentTextMoveTo(162.0, 600.0): ", stdout); + testBegin("pdfioContentTextMoveTo(162.0, 600.0)"); if (pdfioContentTextMoveTo(st, 162.0, 600.0)) - puts("PASS"); + testEnd(true); else return (1); } - printf("pdfioContentTextMeasure(\"%s\"): ", welcomes[i]); + testBegin("pdfioContentTextMeasure(\"%s\")", welcomes[i]); if ((width = pdfioContentTextMeasure(textfont, welcomes[i], 10.0)) >= 0.0) - puts("PASS"); + testEnd(true); else return (1); - printf("pdfioContextTextMoveTo(%g, 0.0): ", -width); + testBegin("pdfioContextTextMoveTo(%g, 0.0)", -width); if (pdfioContentTextMoveTo(st, -width, 0.0)) - puts("PASS"); + testEnd(true); else return (1); - printf("pdfioContentTextShowf(\"%s\"): ", welcomes[i]); + testBegin("pdfioContentTextShowf(\"%s\")", welcomes[i]); if (pdfioContentTextShowf(st, unicode, "%s\n", welcomes[i])) - puts("PASS"); + testEnd(true); else return (1); - printf("pdfioContextTextMoveTo(%g, 0.0): ", width); + testBegin("pdfioContextTextMoveTo(%g, 0.0)", width); if (pdfioContentTextMoveTo(st, width, 0.0)) - puts("PASS"); + testEnd(true); else return (1); } - fputs("pdfioContentTextEnd(): ", stdout); + testBegin("pdfioContentTextEnd()"); if (pdfioContentTextEnd(st)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioStreamClose: ", stdout); + testBegin("pdfioStreamClose"); if (pdfioStreamClose(st)) - puts("PASS"); + testEnd(true); else return (1); @@ -2647,57 +2655,57 @@ write_header_footer( const char *title, // I - Title int number) // I - Page number { - fputs("pdfioContentSetFillColorDeviceGray(0.0): ", stdout); + testBegin("pdfioContentSetFillColorDeviceGray(0.0)"); if (pdfioContentSetFillColorDeviceGray(st, 0.0)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioContentTextBegin(): ", stdout); + testBegin("pdfioContentTextBegin()"); if (pdfioContentTextBegin(st)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioContentSetTextFont(\"F1\", 18.0): ", stdout); + testBegin("pdfioContentSetTextFont(\"F1\", 18.0)"); if (pdfioContentSetTextFont(st, "F1", 18.0)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioContentTextMoveTo(36.0, 738.0): ", stdout); + testBegin("pdfioContentTextMoveTo(36.0, 738.0)"); if (pdfioContentTextMoveTo(st, 36.0, 738.0)) - puts("PASS"); + testEnd(true); else return (1); - printf("pdfioContentTextShow(\"%s\"): ", title); + testBegin("pdfioContentTextShow(\"%s\")", title); if (pdfioContentTextShow(st, false, title)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioContentSetTextFont(\"F1\", 12.0): ", stdout); + testBegin("pdfioContentSetTextFont(\"F1\", 12.0)"); if (pdfioContentSetTextFont(st, "F1", 12.0)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioContentTextMoveTo(514.0, -702.0): ", stdout); + testBegin("pdfioContentTextMoveTo(514.0, -702.0)"); if (pdfioContentTextMoveTo(st, 514.0, -702.0)) - puts("PASS"); + testEnd(true); else return (1); - printf("pdfioContentTextShowf(\"%d\"): ", number); + testBegin("pdfioContentTextShowf(\"%d\")", number); if (pdfioContentTextShowf(st, false, "%d", number)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioContentTextEnd(): ", stdout); + testBegin("pdfioContentTextEnd()"); if (pdfioContentTextEnd(st)) - puts("PASS"); + testEnd(true); else return (1); @@ -2797,54 +2805,54 @@ write_images_test( // Create the images... - fputs("Create Image (Predictor 1): ", stdout); + testBegin("Create Image (Predictor 1)"); if ((noimage = write_image_object(pdf, _PDFIO_PREDICTOR_NONE)) != NULL) - puts("PASS"); + testEnd(true); else return (1); for (p = _PDFIO_PREDICTOR_PNG_NONE; p <= _PDFIO_PREDICTOR_PNG_AUTO; p ++) { - printf("Create Image (Predictor %d): ", p); + testBegin("Create Image (Predictor %d)", p); if ((pimages[p - _PDFIO_PREDICTOR_PNG_NONE] = write_image_object(pdf, p)) != NULL) - puts("PASS"); + testEnd(true); else return (1); } // Create the page dictionary, object, and stream... - fputs("pdfioDictCreate: ", stdout); + testBegin("pdfioDictCreate"); if ((dict = pdfioDictCreate(pdf)) != NULL) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioPageDictAddImage(1): ", stdout); + testBegin("pdfioPageDictAddImage(1)"); if (pdfioPageDictAddImage(dict, "IM1", noimage)) - puts("PASS"); + testEnd(true); else return (1); for (p = _PDFIO_PREDICTOR_PNG_NONE; p <= _PDFIO_PREDICTOR_PNG_AUTO; p ++) { - printf("pdfioPageDictAddImage(%d): ", p); + testBegin("pdfioPageDictAddImage(%d)", p); snprintf(pname, sizeof(pname), "IM%d", p); if (pdfioPageDictAddImage(dict, pdfioStringCreate(pdf, pname), pimages[p - _PDFIO_PREDICTOR_PNG_NONE])) - puts("PASS"); + testEnd(true); else return (1); } - fputs("pdfioPageDictAddFont(F1): ", stdout); + testBegin("pdfioPageDictAddFont(F1)"); if (pdfioPageDictAddFont(dict, "F1", font)) - puts("PASS"); + testEnd(true); else return (1); - printf("pdfioFileCreatePage(%d): ", number); + testBegin("pdfioFileCreatePage(%d)", number); if ((st = pdfioFileCreatePage(pdf, dict)) != NULL) - puts("PASS"); + testEnd(true); else return (1); @@ -2867,9 +2875,9 @@ write_images_test( } // Wrap up... - fputs("pdfioStreamClose: ", stdout); + testBegin("pdfioStreamClose"); if (pdfioStreamClose(st)) - puts("PASS"); + testEnd(true); else return (1); @@ -2904,28 +2912,28 @@ write_jpeg_test(pdfio_file_t *pdf, // I - PDF file // Create the page dictionary, object, and stream... - fputs("pdfioDictCreate: ", stdout); + testBegin("pdfioDictCreate"); if ((dict = pdfioDictCreate(pdf)) != NULL) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioPageDictAddImage: ", stdout); + testBegin("pdfioPageDictAddImage"); if (pdfioPageDictAddImage(dict, "IM1", image)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioPageDictAddFont(F1): ", stdout); + testBegin("pdfioPageDictAddFont(F1)"); if (pdfioPageDictAddFont(dict, "F1", font)) - puts("PASS"); + testEnd(true); else return (1); - printf("pdfioFileCreatePage(%d): ", number); + testBegin("pdfioFileCreatePage(%d)", number); if ((st = pdfioFileCreatePage(pdf, dict)) != NULL) - puts("PASS"); + testEnd(true); else return (1); @@ -2933,15 +2941,15 @@ write_jpeg_test(pdfio_file_t *pdf, // I - PDF file goto error; // Calculate the scaled size of the image... - fputs("pdfioImageGetWidth(): ", stdout); + testBegin("pdfioImageGetWidth()"); if ((width = pdfioImageGetWidth(image)) > 0.0) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioImageGetHeight(): ", stdout); + testBegin("pdfioImageGetHeight()"); if ((height = pdfioImageGetHeight(image)) > 0.0) - puts("PASS"); + testEnd(true); else goto error; @@ -2957,25 +2965,25 @@ write_jpeg_test(pdfio_file_t *pdf, // I - PDF file ty = 0.5 * (792 - sheight); // Show "raw" content (a bordered box for the image...) - fputs("pdfioStreamPrintf(...): ", stdout); + testBegin("pdfioStreamPrintf(...)"); if (pdfioStreamPrintf(st, "1 0 0 RG 0 g 5 w\n" "%g %g %g %g re %g %g %g %g re B*\n", tx - 36, ty - 36, swidth + 72, sheight + 72, tx - 1, ty - 1, swidth + 2, sheight + 2)) - puts("PASS"); + testEnd(true); else goto error; // Draw the image inside the border box... - printf("pdfioContentDrawImage(\"IM1\", x=%g, y=%g, w=%g, h=%g): ", tx, ty, swidth, sheight); + testBegin("pdfioContentDrawImage(\"IM1\", x=%g, y=%g, w=%g, h=%g)", tx, ty, swidth, sheight); if (pdfioContentDrawImage(st, "IM1", tx, ty, swidth, sheight)) - puts("PASS"); + testEnd(true); else goto error; // Close the page stream/object... - fputs("pdfioStreamClose: ", stdout); + testBegin("pdfioStreamClose"); if (pdfioStreamClose(st)) - puts("PASS"); + testEnd(true); else return (1); @@ -3070,60 +3078,60 @@ write_png_tests(pdfio_file_t *pdf, // I - PDF file // Import the PNG test images - fputs("pdfioFileCreateImageObjFromFile(\"testfiles/pdfio-color.png\"): ", stdout); + testBegin("pdfioFileCreateImageObjFromFile(\"testfiles/pdfio-color.png\")"); if ((color = pdfioFileCreateImageObjFromFile(pdf, "testfiles/pdfio-color.png", false)) != NULL) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioFileCreateImageObjFromFile(\"testfiles/pdfio-gray.png\"): ", stdout); + testBegin("pdfioFileCreateImageObjFromFile(\"testfiles/pdfio-gray.png\")"); if ((gray = pdfioFileCreateImageObjFromFile(pdf, "testfiles/pdfio-gray.png", false)) != NULL) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioFileCreateImageObjFromFile(\"testfiles/pdfio-indexed.png\"): ", stdout); + testBegin("pdfioFileCreateImageObjFromFile(\"testfiles/pdfio-indexed.png\")"); if ((indexed = pdfioFileCreateImageObjFromFile(pdf, "testfiles/pdfio-indexed.png", false)) != NULL) - puts("PASS"); + testEnd(true); else return (1); ////// PDFio PNG image test page... // Create the page dictionary, object, and stream... - fputs("pdfioDictCreate: ", stdout); + testBegin("pdfioDictCreate"); if ((dict = pdfioDictCreate(pdf)) != NULL) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioPageDictAddImage(color): ", stdout); + testBegin("pdfioPageDictAddImage(color)"); if (pdfioPageDictAddImage(dict, "IM1", color)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioPageDictAddImage(gray): ", stdout); + testBegin("pdfioPageDictAddImage(gray)"); if (pdfioPageDictAddImage(dict, "IM2", gray)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioPageDictAddImage(indexed): ", stdout); + testBegin("pdfioPageDictAddImage(indexed)"); if (pdfioPageDictAddImage(dict, "IM3", indexed)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioPageDictAddFont(F1): ", stdout); + testBegin("pdfioPageDictAddFont(F1)"); if (pdfioPageDictAddFont(dict, "F1", font)) - puts("PASS"); + testEnd(true); else return (1); - printf("pdfioFileCreatePage(%d): ", number); + testBegin("pdfioFileCreatePage(%d)", number); if ((st = pdfioFileCreatePage(pdf, dict)) != NULL) - puts("PASS"); + testEnd(true); else return (1); @@ -3131,106 +3139,106 @@ write_png_tests(pdfio_file_t *pdf, // I - PDF file goto error; // Show content... - fputs("pdfioContentTextBegin(): ", stdout); + testBegin("pdfioContentTextBegin()"); if (pdfioContentTextBegin(st)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentSetTextFont(\"F1\", 18.0): ", stdout); + testBegin("pdfioContentSetTextFont(\"F1\", 18.0)"); if (pdfioContentSetTextFont(st, "F1", 18.0)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentTextMoveTo(36.0, 342.0): ", stdout); + testBegin("pdfioContentTextMoveTo(36.0, 342.0)"); if (pdfioContentTextMoveTo(st, 36.0, 342.0)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentTextShow(\"PNG RGB Color\"): ", stdout); + testBegin("pdfioContentTextShow(\"PNG RGB Color\")"); if (pdfioContentTextShow(st, false, "PNG RGB Color")) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentTextMoveTo(288.0, 0.0): ", stdout); + testBegin("pdfioContentTextMoveTo(288.0, 0.0)"); if (pdfioContentTextMoveTo(st, 288.0, 0.0)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentTextShow(\"PNG Gray\"): ", stdout); + testBegin("pdfioContentTextShow(\"PNG Gray\")"); if (pdfioContentTextShow(st, false, "PNG Gray")) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentTextMoveTo(-288.0, 288.0): ", stdout); + testBegin("pdfioContentTextMoveTo(-288.0, 288.0)"); if (pdfioContentTextMoveTo(st, -288.0, 288.0)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentTextShow(\"PNG Indexed\"): ", stdout); + testBegin("pdfioContentTextShow(\"PNG Indexed\")"); if (pdfioContentTextShow(st, false, "PNG Indexed")) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentTextEnd(): ", stdout); + testBegin("pdfioContentTextEnd()"); if (pdfioContentTextEnd(st)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentDrawImage(\"IM1\"): ", stdout); + testBegin("pdfioContentDrawImage(\"IM1\")"); if (pdfioContentDrawImage(st, "IM1", 36, 108, 216, 216)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentDrawImage(\"IM2\"): ", stdout); + testBegin("pdfioContentDrawImage(\"IM2\")"); if (pdfioContentDrawImage(st, "IM2", 324, 108, 216, 216)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentDrawImage(\"IM3\"): ", stdout); + testBegin("pdfioContentDrawImage(\"IM3\")"); if (pdfioContentDrawImage(st, "IM3", 36, 396, 216, 216)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentSetFillColorDeviceRGB(0, 1, 1): ", stdout); + testBegin("pdfioContentSetFillColorDeviceRGB(0, 1, 1)"); if (pdfioContentSetFillColorDeviceRGB(st, 0.0, 1.0, 1.0)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentPathRect(315, 387, 234, 234): ", stdout); + testBegin("pdfioContentPathRect(315, 387, 234, 234)"); if (pdfioContentPathRect(st, 315, 387, 234, 234)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentFill(false): ", stdout); + testBegin("pdfioContentFill(false)"); if (pdfioContentFill(st, false)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentDrawImage(\"IM3\"): ", stdout); + testBegin("pdfioContentDrawImage(\"IM3\")"); if (pdfioContentDrawImage(st, "IM3", 324, 396, 216, 216)) - puts("PASS"); + testEnd(true); else goto error; // Close the object and stream... - fputs("pdfioStreamClose: ", stdout); + testBegin("pdfioStreamClose"); if (pdfioStreamClose(st)) - puts("PASS"); + testEnd(true); else return (1); @@ -3239,81 +3247,121 @@ write_png_tests(pdfio_file_t *pdf, // I - PDF file // Create the image objects... for (i = 0; i < (sizeof(pngsuite_files) / sizeof(pngsuite_files[0])); i ++) { - fprintf(stdout, "pdfioFileCreateImageObjFromFile(\"%s\"): ", pngsuite_files[i]); + testBegin("pdfioFileCreateImageObjFromFile(\"%s\")", pngsuite_files[i]); if ((pngsuite[i] = pdfioFileCreateImageObjFromFile(pdf, pngsuite_files[i], false)) != NULL) - puts("PASS"); + { + testEnd(true); + } else + { + testEnd(false); return (1); + } } // Create the page dictionary, object, and stream... - fputs("pdfioDictCreate: ", stdout); + testBegin("pdfioDictCreate"); if ((dict = pdfioDictCreate(pdf)) != NULL) - puts("PASS"); + testEnd(true); else return (1); for (i = 0; i < (sizeof(pngsuite_files) / sizeof(pngsuite_files[0])); i ++) { - fprintf(stdout, "pdfioPageDictAddImage(\"%s\"): ", pngsuite_labels[i]); + testBegin("pdfioPageDictAddImage(\"%s\")", pngsuite_labels[i]); snprintf(imgname, sizeof(imgname), "IM%u", (unsigned)(i + 1)); if (pdfioPageDictAddImage(dict, pdfioStringCreate(pdf, imgname), pngsuite[i])) - puts("PASS"); + { + testEnd(true); + } else + { + testEnd(false); return (1); + } } - fputs("pdfioPageDictAddFont(F1): ", stdout); + testBegin("pdfioPageDictAddFont(F1)"); if (pdfioPageDictAddFont(dict, "F1", font)) - puts("PASS"); + { + testEnd(true); + } else + { + testEnd(false); return (1); + } - printf("pdfioFileCreatePage(%d): ", number + 1); + testBegin("pdfioFileCreatePage(%d)", number + 1); if ((st = pdfioFileCreatePage(pdf, dict)) != NULL) - puts("PASS"); + { + testEnd(true); + } else + { + testEnd(false); return (1); + } if (write_header_footer(st, "PngSuite Test Page", number + 1)) goto error; // Show content... - fputs("pdfioContentSetTextFont(\"F1\", 9.0): ", stdout); + testBegin("pdfioContentSetTextFont(\"F1\", 9.0)"); if (pdfioContentSetTextFont(st, "F1", 8.0)) - puts("PASS"); + { + testEnd(true); + } else + { + testEnd(false); goto error; + } for (i = 0; i < (sizeof(pngsuite_files) / sizeof(pngsuite_files[0])); i ++) { double x = (i % 8) * 69.0 + 36; // X position double y = 671 - (i / 8) * 64.0; // Y position - fputs("pdfioContentTextBegin(): ", stdout); + testBegin("pdfioContentTextBegin()"); if (pdfioContentTextBegin(st)) - puts("PASS"); + { + testEnd(true); + } else + { + testEnd(false); goto error; + } - printf("pdfioContentTextMoveTo(%g, %g): ", x, y); + testBegin("pdfioContentTextMoveTo(%g, %g)", x, y); if (pdfioContentTextMoveTo(st, x, y)) - puts("PASS"); + testEnd(true); else goto error; - printf("pdfioContentTextShow(\"%s\"): ", pngsuite_labels[i]); + testBegin("pdfioContentTextShow(\"%s\")", pngsuite_labels[i]); if (pdfioContentTextShow(st, false, pngsuite_labels[i])) - puts("PASS"); + { + testEnd(true); + } else + { + testEnd(false); goto error; + } - fputs("pdfioContentTextEnd(): ", stdout); + testBegin("pdfioContentTextEnd()"); if (pdfioContentTextEnd(st)) - puts("PASS"); + { + testEnd(true); + } else + { + testEnd(false); goto error; + } } for (i = 0; i < (sizeof(pngsuite_files) / sizeof(pngsuite_files[0])); i ++) @@ -3322,19 +3370,29 @@ write_png_tests(pdfio_file_t *pdf, // I - PDF file double y = 671 - (i / 8) * 64.0; // Y position snprintf(imgname, sizeof(imgname), "IM%u", (unsigned)(i + 1)); - printf("pdfioContentDrawImage(\"%s\"): ", imgname); + testBegin("pdfioContentDrawImage(\"%s\")", imgname); if (pdfioContentDrawImage(st, imgname, x, y + 9, 32, 32)) - puts("PASS"); + { + testEnd(true); + } else + { + testEnd(false); goto error; + } } // Close the object and stream... - fputs("pdfioStreamClose: ", stdout); + testBegin("pdfioStreamClose"); if (pdfioStreamClose(st)) - puts("PASS"); + { + testEnd(true); + } else + { + testEnd(false); return (1); + } #endif // HAVE_LIBPNG return (0); @@ -3367,28 +3425,28 @@ write_text_test(pdfio_file_t *pdf, // I - PDF file // Create text font... - fputs("pdfioFileCreateFontObjFromBase(\"Courier\"): ", stdout); + testBegin("pdfioFileCreateFontObjFromBase(\"Courier\")"); if ((courier = pdfioFileCreateFontObjFromBase(pdf, "Courier")) != NULL) - puts("PASS"); + testEnd(true); else return (1); // Create the page dictionary... - fputs("pdfioDictCreate: ", stdout); + testBegin("pdfioDictCreate"); if ((dict = pdfioDictCreate(pdf)) != NULL) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioPageDictAddFont(F1): ", stdout); + testBegin("pdfioPageDictAddFont(F1)"); if (pdfioPageDictAddFont(dict, "F1", font)) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioPageDictAddFont(F2): ", stdout); + testBegin("pdfioPageDictAddFont(F2)"); if (pdfioPageDictAddFont(dict, "F2", courier)) - puts("PASS"); + testEnd(true); else return (1); @@ -3409,10 +3467,10 @@ write_text_test(pdfio_file_t *pdf, // I - PDF file if (plinenum == 0) { - printf("pdfioFileCreatePage(%d): ", page); + testBegin("pdfioFileCreatePage(%d)", page); if ((st = pdfioFileCreatePage(pdf, dict)) != NULL) - puts("PASS"); + testEnd(true); else goto error; @@ -3422,27 +3480,27 @@ write_text_test(pdfio_file_t *pdf, // I - PDF file page ++; plinenum ++; - fputs("pdfioContentTextBegin(): ", stdout); + testBegin("pdfioContentTextBegin()"); if (pdfioContentTextBegin(st)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentSetTextFont(\"F2\", 10.0): ", stdout); + testBegin("pdfioContentSetTextFont(\"F2\", 10.0)"); if (pdfioContentSetTextFont(st, "F2", 10.0)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentSetTextLeading(12.0): ", stdout); + testBegin("pdfioContentSetTextLeading(12.0)"); if (pdfioContentSetTextLeading(st, 12.0)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioContentTextMoveTo(36.0, 708.0): ", stdout); + testBegin("pdfioContentTextMoveTo(36.0, 708.0)"); if (pdfioContentTextMoveTo(st, 36.0, 708.0)) - puts("PASS"); + testEnd(true); else goto error; } @@ -3475,15 +3533,15 @@ write_text_test(pdfio_file_t *pdf, // I - PDF file plinenum ++; if (plinenum >= 56) { - fputs("pdfioContentTextEnd(): ", stdout); + testBegin("pdfioContentTextEnd()"); if (pdfioContentTextEnd(st)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioStreamClose: ", stdout); + testBegin("pdfioStreamClose"); if (pdfioStreamClose(st)) - puts("PASS"); + testEnd(true); else goto error; @@ -3494,15 +3552,15 @@ write_text_test(pdfio_file_t *pdf, // I - PDF file if (plinenum > 0) { - fputs("pdfioContentTextEnd(): ", stdout); + testBegin("pdfioContentTextEnd()"); if (pdfioContentTextEnd(st)) - puts("PASS"); + testEnd(true); else goto error; - fputs("pdfioStreamClose: ", stdout); + testBegin("pdfioStreamClose"); if (pdfioStreamClose(st)) - puts("PASS"); + testEnd(true); else return (1); } @@ -3541,10 +3599,10 @@ write_unit_file( // Get the root object/catalog dictionary - fputs("pdfioFileGetCatalog: ", stdout); + testBegin("pdfioFileGetCatalog"); if ((catalog = pdfioFileGetCatalog(outpdf)) != NULL) { - puts("PASS"); + testEnd(true); } else { @@ -3557,15 +3615,15 @@ write_unit_file( pdfioDictSetName(catalog, "PageMode", "UseThumbs"); // Set info values... - fputs("pdfioFileGet/SetAuthor: ", stdout); + testBegin("pdfioFileGet/SetAuthor"); pdfioFileSetAuthor(outpdf, "Michael R Sweet"); if ((s = pdfioFileGetAuthor(outpdf)) != NULL && !strcmp(s, "Michael R Sweet")) { - puts("PASS"); + testEnd(true); } else if (s) { - printf("FAIL (got '%s', expected 'Michael R Sweet')\n", s); + testEndMessage(false, "got '%s', expected 'Michael R Sweet'", s); return (1); } else @@ -3574,15 +3632,15 @@ write_unit_file( return (1); } - fputs("pdfioFileGet/SetCreator: ", stdout); + testBegin("pdfioFileGet/SetCreator"); pdfioFileSetCreator(outpdf, "testpdfio"); if ((s = pdfioFileGetCreator(outpdf)) != NULL && !strcmp(s, "testpdfio")) { - puts("PASS"); + testEnd(true); } else if (s) { - printf("FAIL (got '%s', expected 'testpdfio')\n", s); + testEndMessage(false, "got '%s', expected 'testpdfio'", s); return (1); } else @@ -3591,15 +3649,15 @@ write_unit_file( return (1); } - fputs("pdfioFileGet/SetKeywords: ", stdout); + testBegin("pdfioFileGet/SetKeywords"); pdfioFileSetKeywords(outpdf, "one fish,two fish,red fish,blue fish"); if ((s = pdfioFileGetKeywords(outpdf)) != NULL && !strcmp(s, "one fish,two fish,red fish,blue fish")) { - puts("PASS"); + testEnd(true); } else if (s) { - printf("FAIL (got '%s', expected 'one fish,two fish,red fish,blue fish')\n", s); + testEndMessage(false, "got '%s', expected 'one fish,two fish,red fish,blue fish'", s); return (1); } else @@ -3608,15 +3666,15 @@ write_unit_file( return (1); } - fputs("pdfioFileGet/SetLanguage: ", stdout); + testBegin("pdfioFileGet/SetLanguage"); pdfioFileSetLanguage(outpdf, "en-CA"); if ((s = pdfioFileGetLanguage(outpdf)) != NULL && !strcmp(s, "en-CA")) { - puts("PASS"); + testEnd(true); } else if (s) { - printf("FAIL (got '%s', expected 'en-CA')\n", s); + testEndMessage(false, "got '%s', expected 'en-CA'", s); return (1); } else @@ -3625,15 +3683,15 @@ write_unit_file( return (1); } - fputs("pdfioFileGet/SetSubject: ", stdout); + testBegin("pdfioFileGet/SetSubject"); pdfioFileSetSubject(outpdf, "Unit test document"); if ((s = pdfioFileGetSubject(outpdf)) != NULL && !strcmp(s, "Unit test document")) { - puts("PASS"); + testEnd(true); } else if (s) { - printf("FAIL (got '%s', expected 'Unit test document')\n", s); + testEndMessage(false, "got '%s', expected 'Unit test document'", s); return (1); } else @@ -3642,15 +3700,15 @@ write_unit_file( return (1); } - fputs("pdfioFileGet/SetTitle: ", stdout); + testBegin("pdfioFileGet/SetTitle"); pdfioFileSetTitle(outpdf, "Test Document"); if ((s = pdfioFileGetTitle(outpdf)) != NULL && !strcmp(s, "Test Document")) { - puts("PASS"); + testEnd(true); } else if (s) { - printf("FAIL (got '%s', expected 'Test Document')\n", s); + testEndMessage(false, "got '%s', expected 'Test Document'", s); return (1); } else @@ -3660,35 +3718,35 @@ write_unit_file( } // Create some image objects... - fputs("pdfioFileCreateImageObjFromFile(\"testfiles/color.jpg\"): ", stdout); + testBegin("pdfioFileCreateImageObjFromFile(\"testfiles/color.jpg\")"); if ((color_jpg = pdfioFileCreateImageObjFromFile(outpdf, "testfiles/color.jpg", true)) != NULL) - printf("PASS (%u)\n", (unsigned)pdfioObjGetNumber(color_jpg)); + testEndMessage(true, "%u", (unsigned)pdfioObjGetNumber(color_jpg)); else return (1); - fputs("pdfioFileCreateImageObjFromFile(\"testfiles/gray.jpg\"): ", stdout); + testBegin("pdfioFileCreateImageObjFromFile(\"testfiles/gray.jpg\")"); if ((gray_jpg = pdfioFileCreateImageObjFromFile(outpdf, "testfiles/gray.jpg", true)) != NULL) - printf("PASS (%u)\n", (unsigned)pdfioObjGetNumber(gray_jpg)); + testEndMessage(true, "%u", (unsigned)pdfioObjGetNumber(gray_jpg)); else return (1); // Create fonts... - fputs("pdfioFileCreateFontObjFromBase(\"Helvetica\"): ", stdout); + testBegin("pdfioFileCreateFontObjFromBase(\"Helvetica\")"); if ((helvetica = pdfioFileCreateFontObjFromBase(outpdf, "Helvetica")) != NULL) - puts("PASS"); + testEnd(true); else return (1); // Copy the first page from the test PDF file... - fputs("pdfioFileGetPage(0): ", stdout); + testBegin("pdfioFileGetPage(0)"); if ((page = pdfioFileGetPage(inpdf, 0)) != NULL) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioPageCopy(first page): ", stdout); + testBegin("pdfioPageCopy(first page)"); if (pdfioPageCopy(outpdf, page)) - puts("PASS"); + testEnd(true); else return (1); @@ -3701,15 +3759,15 @@ write_unit_file( pagenum ++; // Copy the third page from the test PDF file... - fputs("pdfioFileGetPage(2): ", stdout); + testBegin("pdfioFileGetPage(2)"); if ((page = pdfioFileGetPage(inpdf, 2)) != NULL) - puts("PASS"); + testEnd(true); else return (1); - fputs("pdfioPageCopy(third page): ", stdout); + testBegin("pdfioPageCopy(third page)"); if (pdfioPageCopy(outpdf, page)) - puts("PASS"); + testEnd(true); else return (1); @@ -3769,21 +3827,21 @@ write_unit_file( if (write_text_test(outpdf, pagenum, helvetica, "README.md")) return (1); - fputs("pdfioFileGetNumPages: ", stdout); + testBegin("pdfioFileGetNumPages"); if ((*num_pages = pdfioFileGetNumPages(outpdf)) > 0) { - printf("PASS (%lu)\n", (unsigned long)*num_pages); + testEndMessage(true, "%lu", (unsigned long)*num_pages); } else { - puts("FAIL"); + testEnd(false); return (1); } // Close the new PDF file... - printf("pdfioFileClose(\"%s\"): ", outname); + testBegin("pdfioFileClose(\"%s\")", outname); if (pdfioFileClose(outpdf)) - puts("PASS"); + testEnd(true); else return (1);