annotate tests/testdmzlib.c @ 1121:043b5942fdb6

Rename some dmzlib functions and add context init/close functions.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 04 Mar 2015 04:37:58 +0200
parents 5a8d29b88431
children d0898867ec4c
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
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #define SET_TMPBUF_SIZE (16 * 1024)
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:
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
59 optCompress = TRUE;
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
60 break;
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
61
1104
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
62 case 4:
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
63 if (!dmGetIntVal(optArg, &optCompressLevel) ||
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
64 optCompressLevel < 1 || optCompressLevel > 9)
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 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
67 return FALSE;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 break;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70
1104
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
71 case 5:
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
72 if (!dmGetIntVal(optArg, &optSkip))
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
73 {
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
74 dmErrorMsg("Invalid skip value.\n", optArg);
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
75 return FALSE;
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
76 }
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
77 break;
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
78
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 default:
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 return FALSE;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 }
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 return TRUE;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 }
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 BOOL argHandleFile(char *currArg)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 if (optInFilename == NULL)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 optInFilename = currArg;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 else
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 if (optOutFilename == NULL)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 optOutFilename = currArg;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 else
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 dmErrorMsg("Excess filenames specified.\n");
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 return FALSE;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 return TRUE;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 }
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
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
103 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
104 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 Uint8 *inBuffer = NULL, *outBuffer = NULL;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 DMZLibContext ctx;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 int ret;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
109 (void) level;
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
110
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
111 if (compress)
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
112 {
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
113 ret = dmError(DMERR_NOT_SUPPORTED,
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
114 "Compression is not supported with dmzlib.\n");
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
115 goto out;
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
116 }
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
117
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 if ((ret = dmReadDataFile(inFile, "-", &inBuffer, inSize)) != DMERR_OK)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 dmErrorMsg("Failed to read file.\n");
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 goto out;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 }
1066
dfde748d9c1f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1065
diff changeset
123
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 if ((outBuffer = dmMalloc(SET_TMPBUF_SIZE)) == NULL)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 ret = dmError(DMERR_MALLOC,
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 "Malloc failed.\n");
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 goto out;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 }
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 // Initialize decompression structures
1121
043b5942fdb6 Rename some dmzlib functions and add context init/close functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
132 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
133 goto out;
043b5942fdb6 Rename some dmzlib functions and add context init/close functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
134
1076
21b0aedb7b5c Also initialize DMZLibContext.inBufferStart where needed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1074
diff changeset
135 ctx.inBuffer = ctx.inBufferStart = inBuffer;
1074
e98bc627ad08 Rename dmzlib structure members.
Matti Hamalainen <ccr@tnsp.org>
parents: 1068
diff changeset
136 ctx.inBufferEnd = inBuffer + *inSize;
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137
1074
e98bc627ad08 Rename dmzlib structure members.
Matti Hamalainen <ccr@tnsp.org>
parents: 1068
diff changeset
138 ctx.outBuffer = ctx.outBufferStart = outBuffer;
e98bc627ad08 Rename dmzlib structure members.
Matti Hamalainen <ccr@tnsp.org>
parents: 1068
diff changeset
139 ctx.outBufferEnd = outBuffer + SET_TMPBUF_SIZE;
e98bc627ad08 Rename dmzlib structure members.
Matti Hamalainen <ccr@tnsp.org>
parents: 1068
diff changeset
140 ctx.expandable = TRUE;
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 // Attempt decompression
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 if ((ret = dmZLibParseHeader(&ctx, TRUE)) != DMERR_OK)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 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
146 goto out;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148
1121
043b5942fdb6 Rename some dmzlib functions and add context init/close functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
149 if ((ret = dmZLibInflate(&ctx)) != DMERR_OK)
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 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
152 goto out;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154
1074
e98bc627ad08 Rename dmzlib structure members.
Matti Hamalainen <ccr@tnsp.org>
parents: 1068
diff changeset
155 outBuffer = ctx.outBufferStart;
e98bc627ad08 Rename dmzlib structure members.
Matti Hamalainen <ccr@tnsp.org>
parents: 1068
diff changeset
156 *outSize = ctx.outBuffer - ctx.outBufferStart;
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 if (fwrite(outBuffer, sizeof(Uint8), *outSize, outFile) != *outSize)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 ret = dmError(DMERR_FWRITE, "File write error.\n");
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 goto out;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 }
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 out:
1121
043b5942fdb6 Rename some dmzlib functions and add context init/close functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
165 dmZLibCloseInflate(&ctx);
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 dmFree(inBuffer);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 dmFree(outBuffer);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 return ret;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 }
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 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
173 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 Uint8 *inBuffer = NULL, *outBuffer = NULL;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 int zret, zinit = FALSE;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 int ret = DMERR_OK;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 z_stream zstr;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 dmMsg(0, "Operating mode: %s\n",
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 compress ? "compress" : "decompress");
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 if ((inBuffer = malloc(SET_TMPBUF_SIZE)) == NULL ||
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 (outBuffer = malloc(SET_TMPBUF_SIZE)) == NULL)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 ret = dmError(DMERR_MALLOC, "Malloc failed.\n");
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 goto out;
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
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 memset(&zstr, 0, sizeof(zstr));
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 if (compress)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 zret = deflateInit(&zstr, level);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 else
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 zret = inflateInit(&zstr);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 if (zret != Z_OK)
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 ret = dmError(DMERR_INIT_FAIL, "Zlib init fail.\n");
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 goto out;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 zinit = TRUE;
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 // Initialize compression streams
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 zret = Z_OK;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 *outSize = 0;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 while (!feof(inFile) && zret == Z_OK)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 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
208
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 zstr.next_in = inBuffer;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 zstr.next_out = outBuffer;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 zstr.avail_out = SET_TMPBUF_SIZE;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 zstr.total_out = 0;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 if (compress)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 zret = deflate(&zstr, Z_FULL_FLUSH);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 else
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 zret = inflate(&zstr, Z_FULL_FLUSH);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218
1105
62ccecea1317 Fix ZLIB decompressor mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 1104
diff changeset
219 if (zstr.total_out > 0)
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 {
1068
01114659bdd3 Oops, fix a nasty bug.
Matti Hamalainen <ccr@tnsp.org>
parents: 1067
diff changeset
221 *outSize += zstr.total_out;
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 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
223 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 ret = dmError(DMERR_FWRITE,
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 "File write error.\n");
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 goto out;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 }
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 }
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 switch (zret)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 case Z_OK:
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 break;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 case Z_ERRNO:
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 dmErrorMsg("Error: errno\n");
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 break;
1066
dfde748d9c1f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1065
diff changeset
240
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 case Z_STREAM_END:
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 dmErrorMsg("Stream end.\n");
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 break;
1066
dfde748d9c1f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1065
diff changeset
244
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 default:
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 ret = dmError(DMERR_COMPRESSION,
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 "Error: %d, %s\n", zret, zError(zret));
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 }
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 out:
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 *inSize = zstr.total_in;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 if (zinit)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 if (compress)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 deflateEnd(&zstr);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 else
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 inflateEnd(&zstr);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 }
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 dmFree(inBuffer);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 dmFree(outBuffer);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 return ret;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 }
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 int main(int argc, char *argv[])
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 {
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 FILE *inFile = NULL, *outFile = NULL;
1067
b3a54ecdb86f Initialize output and input size variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1066
diff changeset
271 size_t inSize = 0, outSize = 0;
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
272 int ret;
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
274 dmInitProg("testdmzlib", "ZLIB/dmzlib tester", NULL, NULL, NULL);
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 dmVerbosity = 1;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 if (!dmArgsProcess(argc, argv, optList, optListN,
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 argHandleOpt, argHandleFile, OPTH_BAILOUT))
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279 exit(1);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280
1121
043b5942fdb6 Rename some dmzlib functions and add context init/close functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
281 dmZLibInit();
043b5942fdb6 Rename some dmzlib functions and add context init/close functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
282
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 // Input and output files
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
284 if (optInFilename == NULL)
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
285 inFile = stdin;
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
286 else
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
287 if ((inFile = fopen(optInFilename, "rb")) == NULL)
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
288 {
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
289 int res = dmGetErrno();
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
290 dmErrorMsg("Failed to open input file '%s': %s\n",
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
291 optInFilename, dmErrorStr(res));
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
292 goto out;
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
293 }
1066
dfde748d9c1f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1065
diff changeset
294
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
295 if (optOutFilename == NULL)
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
296 outFile = stdout;
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
297 else
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
298 if ((outFile = fopen(optOutFilename, "wb")) == NULL)
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
299 {
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
300 int res = dmGetErrno();
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
301 dmErrorMsg("Failed to open output file '%s': %s\n",
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
302 optOutFilename, dmErrorStr(res));
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
303 goto out;
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
304 }
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305
1108
5a8d29b88431 More fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1105
diff changeset
306 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
307 {
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
308 int res = dmGetErrno();
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
309 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
310 dmErrorStr(res));
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
311 goto out;
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
312 }
8a4df37ffe13 Add header skip option to the dmzlib test.
Matti Hamalainen <ccr@tnsp.org>
parents: 1076
diff changeset
313
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
314 if (optUseZLIB)
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
315 ret = dmTestZlib(inFile, outFile, &inSize, &outSize, optCompress, optCompressLevel);
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
316 else
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
317 ret = dmTestDMZlib(inFile, outFile, &inSize, &outSize, optCompress, optCompressLevel);
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318
1065
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
319 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
320
2e997dd888b9 Work on testdmzlib.
Matti Hamalainen <ccr@tnsp.org>
parents: 1064
diff changeset
321 out:
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 // Cleanup
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 if (outFile != NULL)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 fclose(outFile);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 if (inFile != NULL)
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 fclose(inFile);
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328
1121
043b5942fdb6 Rename some dmzlib functions and add context init/close functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1108
diff changeset
329 dmZLibClose();
1064
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330 return 0;
a6c5be712b53 Add dmzlib / zlib test utility.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 }