annotate tests/dzlibtest.c @ 2298:b5abfff07ca9

Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and dmGrowBufConstCopyOffsSize().
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 04 Jul 2019 10:54:16 +0300
parents 161e731eb152
children 647671a9a0b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #include "dmlib.h"
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 #include "dmzlib.h"
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 #include "dmfile.h"
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 #include "dmargs.h"
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 #include <zlib.h>
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7
1977
33c29e7d1861 Increase the zlib compression buffer size to 1MB to improve the efficiency.
Matti Hamalainen <ccr@tnsp.org>
parents: 1551
diff changeset
8 #define SET_TMPBUF_SIZE (1024 * 1024)
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
10 char *optInFilename = NULL,
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
11 *optOutFilename = NULL;
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
1104
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
13 unsigned int optSkip = 0;
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
14 unsigned int optCompressLevel = Z_BEST_COMPRESSION;
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
15 BOOL optCompress = FALSE,
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
16 optUseZLIB = FALSE;
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 static const DMOptArg optList[] =
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 { 0, '?', "help", "Show this help", OPT_NONE },
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 { 1, 'q', "quiet", "Decrease verbosity", OPT_NONE },
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
23 { 2, 'Z', "zlib", "Use ZLIB instead of dmzlib", OPT_NONE },
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
24 { 3, 'c', "compress", "Compress instead of decompressing (ZLIB only)", OPT_NONE },
1104
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
25 { 4, 'l', "level", "Set zlib compression level 1-9", OPT_ARGREQ },
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
26 { 5, 's', "skip", "Skip bytes from input start", OPT_ARGREQ },
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 };
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 static const int optListN = sizeof(optList) / sizeof(optList[0]);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 void argShowHelp()
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 dmPrintBanner(stdout, dmProgName, "[options] [input filename] [output filename]");
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 dmArgsPrintHelp(stdout, optList, optListN, 0);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 (void) currArg;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 switch (optN)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 case 0:
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 argShowHelp();
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 exit(0);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 break;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 case 1:
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 dmVerbosity = 0;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 break;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
54 case 2:
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
55 optUseZLIB = TRUE;
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
56 break;
1066
dfde748d9c1f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1065
diff changeset
57
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
58 case 3:
1978
cd5643794195 If compressing, use zlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1977
diff changeset
59 optUseZLIB = TRUE;
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
60 optCompress = TRUE;
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
61 break;
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
62
1104
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
63 case 4:
2004
161e731eb152 Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents: 1978
diff changeset
64 if (!dmGetIntVal(optArg, &optCompressLevel, NULL) ||
1104
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
65 optCompressLevel < 1 || optCompressLevel > 9)
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 dmErrorMsg("Invalid compression level argument '%s', must be 1 .. 9.\n", optArg);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 return FALSE;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 break;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71
1104
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
72 case 5:
2004
161e731eb152 Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents: 1978
diff changeset
73 if (!dmGetIntVal(optArg, &optSkip, NULL))
1104
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
74 {
2004
161e731eb152 Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents: 1978
diff changeset
75 dmErrorMsg("Invalid skip value '%s'.\n", optArg);
1104
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
76 return FALSE;
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
77 }
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
78 break;
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
79
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 default:
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 return FALSE;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 return TRUE;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 BOOL argHandleFile(char *currArg)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 if (optInFilename == NULL)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 optInFilename = currArg;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 else
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 if (optOutFilename == NULL)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 optOutFilename = currArg;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 else
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 dmErrorMsg("Excess filenames specified.\n");
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 return FALSE;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 return TRUE;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
104 int dmTestDMZlib(FILE *inFile, FILE *outFile, size_t *inSize, size_t *outSize, BOOL compress, int level)
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 Uint8 *inBuffer = NULL, *outBuffer = NULL;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 DMZLibContext ctx;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 int ret;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
110 (void) level;
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
111
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
112 if (compress)
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
113 {
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
114 ret = dmError(DMERR_NOT_SUPPORTED,
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
115 "Compression is not supported with dmzlib.\n");
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
116 goto out;
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
117 }
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
118
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 if ((ret = dmReadDataFile(inFile, "-", &inBuffer, inSize)) != DMERR_OK)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 dmErrorMsg("Failed to read file.\n");
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 goto out;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 }
1066
dfde748d9c1f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1065
diff changeset
124
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 if ((outBuffer = dmMalloc(SET_TMPBUF_SIZE)) == NULL)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 ret = dmError(DMERR_MALLOC,
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 "Malloc failed.\n");
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 goto out;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 // Initialize decompression structures
1121
043b5942fdb6 Rename some dmzlib functions and add context init/close functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
133 if ((ret = dmZLibInitInflate(&ctx)) != DMERR_OK)
043b5942fdb6 Rename some dmzlib functions and add context init/close functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
134 goto out;
043b5942fdb6 Rename some dmzlib functions and add context init/close functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
135
1076
21b0aedb7b5c Also initialize DMZLibContext.inBufferStart where needed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1074
diff changeset
136 ctx.inBuffer = ctx.inBufferStart = inBuffer;
1074
e98bc627ad08 Rename dmzlib structure members.
Matti Hamalainen <ccr@tnsp.org>
parents: 1068
diff changeset
137 ctx.inBufferEnd = inBuffer + *inSize;
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138
1074
e98bc627ad08 Rename dmzlib structure members.
Matti Hamalainen <ccr@tnsp.org>
parents: 1068
diff changeset
139 ctx.outBuffer = ctx.outBufferStart = outBuffer;
e98bc627ad08 Rename dmzlib structure members.
Matti Hamalainen <ccr@tnsp.org>
parents: 1068
diff changeset
140 ctx.outBufferEnd = outBuffer + SET_TMPBUF_SIZE;
e98bc627ad08 Rename dmzlib structure members.
Matti Hamalainen <ccr@tnsp.org>
parents: 1068
diff changeset
141 ctx.expandable = TRUE;
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 // Attempt decompression
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 if ((ret = dmZLibParseHeader(&ctx, TRUE)) != DMERR_OK)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 dmErrorMsg("Error parsing ZLIB header: %d, %s\n", ret, dmErrorStr(ret));
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 goto out;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149
1121
043b5942fdb6 Rename some dmzlib functions and add context init/close functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
150 if ((ret = dmZLibInflate(&ctx)) != DMERR_OK)
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 dmErrorMsg("Error in ZLIB decompress: %d, %s\n", ret, dmErrorStr(ret));
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 goto out;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155
1074
e98bc627ad08 Rename dmzlib structure members.
Matti Hamalainen <ccr@tnsp.org>
parents: 1068
diff changeset
156 outBuffer = ctx.outBufferStart;
e98bc627ad08 Rename dmzlib structure members.
Matti Hamalainen <ccr@tnsp.org>
parents: 1068
diff changeset
157 *outSize = ctx.outBuffer - ctx.outBufferStart;
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 if (fwrite(outBuffer, sizeof(Uint8), *outSize, outFile) != *outSize)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 ret = dmError(DMERR_FWRITE, "File write error.\n");
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 goto out;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 out:
1121
043b5942fdb6 Rename some dmzlib functions and add context init/close functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
166 dmZLibCloseInflate(&ctx);
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 dmFree(inBuffer);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 dmFree(outBuffer);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 return ret;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 int dmTestZlib(FILE *inFile, FILE *outFile, size_t *inSize, size_t *outSize, BOOL compress, int level)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 Uint8 *inBuffer = NULL, *outBuffer = NULL;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 int zret, zinit = FALSE;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 int ret = DMERR_OK;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 z_stream zstr;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 dmMsg(0, "Operating mode: %s\n",
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 compress ? "compress" : "decompress");
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182
1170
ef5a9c51569c Use dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1134
diff changeset
183 dmMemset(&zstr, 0, sizeof(zstr));
1134
d0898867ec4c Various fixes for issues reported by clang static analyzer.
Matti Hamalainen <ccr@tnsp.org>
parents: 1121
diff changeset
184
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 if ((inBuffer = malloc(SET_TMPBUF_SIZE)) == NULL ||
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 (outBuffer = malloc(SET_TMPBUF_SIZE)) == NULL)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 ret = dmError(DMERR_MALLOC, "Malloc failed.\n");
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 goto out;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 if (compress)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 zret = deflateInit(&zstr, level);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 else
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 zret = inflateInit(&zstr);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 if (zret != Z_OK)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 ret = dmError(DMERR_INIT_FAIL, "Zlib init fail.\n");
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 goto out;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 zinit = TRUE;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 // Initialize compression streams
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 zret = Z_OK;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 *outSize = 0;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 while (!feof(inFile) && zret == Z_OK)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 zstr.avail_in = fread(inBuffer, sizeof(Uint8), SET_TMPBUF_SIZE, inFile);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 zstr.next_in = inBuffer;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 zstr.next_out = outBuffer;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 zstr.avail_out = SET_TMPBUF_SIZE;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 zstr.total_out = 0;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 if (compress)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 zret = deflate(&zstr, Z_FULL_FLUSH);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 else
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 zret = inflate(&zstr, Z_FULL_FLUSH);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220
1105
62ccecea1317 Fix ZLIB decompressor mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
221 if (zstr.total_out > 0)
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 {
1068
01114659bdd3 Oops, fix a nasty bug.
Matti Hamalainen <ccr@tnsp.org>
parents: 1067
diff changeset
223 *outSize += zstr.total_out;
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 if (fwrite(outBuffer, sizeof(Uint8), zstr.total_out, outFile) != zstr.total_out)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 ret = dmError(DMERR_FWRITE,
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 "File write error.\n");
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 goto out;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 switch (zret)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 case Z_OK:
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 break;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 case Z_ERRNO:
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 dmErrorMsg("Error: errno\n");
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 break;
1066
dfde748d9c1f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1065
diff changeset
241
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 case Z_STREAM_END:
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 dmErrorMsg("Stream end.\n");
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 break;
1066
dfde748d9c1f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1065
diff changeset
245
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 default:
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 ret = dmError(DMERR_COMPRESSION,
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 "Error: %d, %s\n", zret, zError(zret));
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 out:
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 *inSize = zstr.total_in;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 if (zinit)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 if (compress)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 deflateEnd(&zstr);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 else
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 inflateEnd(&zstr);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 dmFree(inBuffer);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 dmFree(outBuffer);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 return ret;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 int main(int argc, char *argv[])
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 FILE *inFile = NULL, *outFile = NULL;
1067
b3a54ecdb86f Initialize output and input size variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1066
diff changeset
272 size_t inSize = 0, outSize = 0;
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
273 int ret;
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
275 dmInitProg("testdmzlib", "ZLIB/dmzlib tester", NULL, NULL, NULL);
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 dmVerbosity = 1;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 if (!dmArgsProcess(argc, argv, optList, optListN,
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279 argHandleOpt, argHandleFile, OPTH_BAILOUT))
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 exit(1);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281
1121
043b5942fdb6 Rename some dmzlib functions and add context init/close functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
282 dmZLibInit();
043b5942fdb6 Rename some dmzlib functions and add context init/close functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
283
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 // Input and output files
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
285 if (optInFilename == NULL)
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
286 inFile = stdin;
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
287 else
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
288 if ((inFile = fopen(optInFilename, "rb")) == NULL)
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
289 {
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
290 int res = dmGetErrno();
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
291 dmErrorMsg("Failed to open input file '%s': %s\n",
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
292 optInFilename, dmErrorStr(res));
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
293 goto out;
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
294 }
1066
dfde748d9c1f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1065
diff changeset
295
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
296 if (optOutFilename == NULL)
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
297 outFile = stdout;
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
298 else
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
299 if ((outFile = fopen(optOutFilename, "wb")) == NULL)
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
300 {
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
301 int res = dmGetErrno();
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
302 dmErrorMsg("Failed to open output file '%s': %s\n",
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
303 optOutFilename, dmErrorStr(res));
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
304 goto out;
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
305 }
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306
1108
5a8d29b88431 More fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1105
diff changeset
307 if (optSkip > 0 && fseeko(inFile, optSkip, SEEK_CUR) != 0)
1104
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
308 {
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
309 int res = dmGetErrno();
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
310 dmErrorMsg("Failed to seek in input stream: %s\n",
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
311 dmErrorStr(res));
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
312 goto out;
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
313 }
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
314
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
315 if (optUseZLIB)
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
316 ret = dmTestZlib(inFile, outFile, &inSize, &outSize, optCompress, optCompressLevel);
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
317 else
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
318 ret = dmTestDMZlib(inFile, outFile, &inSize, &outSize, optCompress, optCompressLevel);
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
320 dmMsg(0, "[%d] In %d, out %d bytes.\n", ret, inSize, outSize);
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
321
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
322 out:
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 // Cleanup
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 if (outFile != NULL)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325 fclose(outFile);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 if (inFile != NULL)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 fclose(inFile);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329
1121
043b5942fdb6 Rename some dmzlib functions and add context init/close functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
330 dmZLibClose();
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 return 0;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 }