# HG changeset patch # User Matti Hamalainen # Date 1425254916 -7200 # Node ID 2e997dd888b9de014056d360a232dee24b76aec2 # Parent a6c5be712b535f11ded18974dd1e988f47ce21ed Work on testdmzlib. diff -r a6c5be712b53 -r 2e997dd888b9 tests/testdmzlib.c --- a/tests/testdmzlib.c Mon Mar 02 01:49:14 2015 +0200 +++ b/tests/testdmzlib.c Mon Mar 02 02:08:36 2015 +0200 @@ -7,16 +7,21 @@ #define SET_TMPBUF_SIZE (16 * 1024) -char *optInFilename = NULL, - *optOutFilename = NULL; +char *optInFilename = NULL, + *optOutFilename = NULL; -int optCompressLevel = Z_BEST_COMPRESSION; +int optCompressLevel = Z_BEST_COMPRESSION; +BOOL optCompress = FALSE, + optUseZLIB = FALSE; static const DMOptArg optList[] = { { 0, '?', "help", "Show this help", OPT_NONE }, { 1, 'q', "quiet", "Decrease verbosity", OPT_NONE }, + { 2, 'Z', "zlib", "Use ZLIB instead of dmzlib", OPT_NONE }, + { 3, 'c', "compress", "Compress instead of decompressing (ZLIB only)", OPT_NONE }, + { 10, 'l', "level", "Set zlib compression level 1-9", OPT_ARGREQ }, }; static const int optListN = sizeof(optList) / sizeof(optList[0]); @@ -44,6 +49,14 @@ dmVerbosity = 0; break; + case 2: + optUseZLIB = TRUE; + break; + + case 3: + optCompress = TRUE; + break; + case 10: optCompressLevel = atoi(optArg); if (optCompressLevel < 1 || optCompressLevel > 9) @@ -77,12 +90,21 @@ } -int dmTestDMZlib(FILE *inFile, FILE *outFile, size_t *inSize, size_t *outSize) +int dmTestDMZlib(FILE *inFile, FILE *outFile, size_t *inSize, size_t *outSize, BOOL compress, int level) { Uint8 *inBuffer = NULL, *outBuffer = NULL; DMZLibContext ctx; int ret; + (void) level; + + if (compress) + { + ret = dmError(DMERR_NOT_SUPPORTED, + "Compression is not supported with dmzlib.\n"); + goto out; + } + if ((ret = dmReadDataFile(inFile, "-", &inBuffer, inSize)) != DMERR_OK) { dmErrorMsg("Failed to read file.\n"); @@ -234,8 +256,9 @@ { FILE *inFile = NULL, *outFile = NULL; size_t inSize, outSize; + int ret; - dmInitProg("testdmzlib", "zlib/dmzlib test", NULL, NULL, NULL); + dmInitProg("testdmzlib", "ZLIB/dmzlib tester", NULL, NULL, NULL); dmVerbosity = 1; if (!dmArgsProcess(argc, argv, optList, optListN, @@ -243,11 +266,36 @@ exit(1); // Input and output files - inFile = stdin; - outFile = stdout; + if (optInFilename == NULL) + inFile = stdin; + else + if ((inFile = fopen(optInFilename, "rb")) == NULL) + { + int res = dmGetErrno(); + dmErrorMsg("Failed to open input file '%s': %s\n", + optInFilename, dmErrorStr(res)); + goto out; + } + + if (optOutFilename == NULL) + outFile = stdout; + else + if ((outFile = fopen(optOutFilename, "wb")) == NULL) + { + int res = dmGetErrno(); + dmErrorMsg("Failed to open output file '%s': %s\n", + optOutFilename, dmErrorStr(res)); + goto out; + } - dmMsg(0, "In: %d, out %d bytes.\n", inSize, outSize); + if (optUseZLIB) + ret = dmTestZlib(inFile, outFile, &inSize, &outSize, optCompress, optCompressLevel); + else + ret = dmTestDMZlib(inFile, outFile, &inSize, &outSize, optCompress, optCompressLevel); + dmMsg(0, "[%d] In %d, out %d bytes.\n", ret, inSize, outSize); + +out: // Cleanup if (outFile != NULL) fclose(outFile);