@@ -55,8 +55,7 @@ TEST_CASE("successful decompress - pointer")
55
55
const char * pointer = data.data ();
56
56
std::string compressed_data = gzip::compress (pointer, data.size ());
57
57
const char * compressed_pointer = compressed_data.data ();
58
-
59
- std::string value = gzip::decompress (compressed_pointer, data.size ());
58
+ std::string value = gzip::decompress (compressed_pointer, compressed_data.size ());
60
59
REQUIRE (data == value);
61
60
}
62
61
@@ -90,194 +89,42 @@ TEST_CASE("round trip compression - gzip")
90
89
{
91
90
const std::string data (" this is a sentence that will be compressed into something" );
92
91
93
- CHECK (!gzip::is_compressed (data));
94
-
95
- int strategy;
96
-
97
- SECTION (" strategy - invalid compression" )
98
- {
99
- strategy = 99 ;
100
- int level = Z_DEFAULT_COMPRESSION;
101
-
102
- CHECK_THROWS (gzip::compress (data, level, strategy));
103
- }
92
+ CHECK (!gzip::is_compressed (data.data (),data.size ()));
104
93
105
94
SECTION (" compression level - invalid" )
106
95
{
107
- strategy = Z_DEFAULT_STRATEGY;
108
96
int level = 99 ;
109
97
110
- CHECK_THROWS (gzip::compress (data, level, strategy));
111
- }
112
-
113
- SECTION (" strategy - default" )
114
- {
115
- strategy = Z_DEFAULT_STRATEGY;
116
-
117
- SECTION (" no compression" )
118
- {
119
- int level = Z_NO_COMPRESSION;
120
- std::string compressed_data = gzip::compress (data, level, strategy);
121
- CHECK (gzip::is_compressed (compressed_data));
122
- std::string new_data = gzip::decompress (compressed_data);
123
- CHECK (data == new_data);
124
- }
125
-
126
- SECTION (" default compression level" )
127
- {
128
- int level = Z_DEFAULT_COMPRESSION;
129
- std::string compressed_data = gzip::compress (data, level, strategy);
130
- CHECK (gzip::is_compressed (compressed_data));
131
- std::string new_data = gzip::decompress (compressed_data);
132
- CHECK (data == new_data);
133
- }
134
-
135
- SECTION (" compression level -- min to max" )
136
- {
137
- for (int level = Z_BEST_SPEED; level <= Z_BEST_COMPRESSION; ++level)
138
- {
139
- std::string compressed_data = gzip::compress (data, level, strategy);
140
- CHECK (gzip::is_compressed (compressed_data));
141
- std::string new_data = gzip::decompress (compressed_data);
142
- CHECK (data == new_data);
143
- }
144
- }
145
- }
146
-
147
- SECTION (" strategy - filtered" )
148
- {
149
- strategy = Z_FILTERED;
150
-
151
- SECTION (" no compression" )
152
- {
153
- int level = Z_NO_COMPRESSION;
154
- std::string compressed_data = gzip::compress (data, level, strategy);
155
- CHECK (gzip::is_compressed (compressed_data));
156
- std::string new_data = gzip::decompress (compressed_data);
157
- CHECK (data == new_data);
158
- }
159
-
160
- SECTION (" default compression level" )
161
- {
162
- int level = Z_DEFAULT_COMPRESSION;
163
- std::string compressed_data = gzip::compress (data, level, strategy);
164
- CHECK (gzip::is_compressed (compressed_data));
165
- std::string new_data = gzip::decompress (compressed_data);
166
- CHECK (data == new_data);
167
- }
168
-
169
- SECTION (" compression level -- min to max" )
170
- {
171
- for (int level = Z_BEST_SPEED; level <= Z_BEST_COMPRESSION; ++level)
172
- {
173
- std::string compressed_data = gzip::compress (data, level, strategy);
174
- CHECK (gzip::is_compressed (compressed_data));
175
- std::string new_data = gzip::decompress (compressed_data);
176
- CHECK (data == new_data);
177
- }
178
- }
98
+ CHECK_THROWS (gzip::compress (data.data (), data.size (), level));
179
99
}
180
100
181
- SECTION (" strategy - huffman only " )
101
+ SECTION (" no compression " )
182
102
{
183
- strategy = Z_HUFFMAN_ONLY;
184
-
185
- SECTION (" no compression" )
186
- {
187
- int level = Z_NO_COMPRESSION;
188
- std::string compressed_data = gzip::compress (data, level, strategy);
189
- CHECK (gzip::is_compressed (compressed_data));
190
- std::string new_data = gzip::decompress (compressed_data);
191
- CHECK (data == new_data);
192
- }
193
-
194
- SECTION (" default compression level" )
195
- {
196
- int level = Z_DEFAULT_COMPRESSION;
197
- std::string compressed_data = gzip::compress (data, level, strategy);
198
- CHECK (gzip::is_compressed (compressed_data));
199
- std::string new_data = gzip::decompress (compressed_data);
200
- CHECK (data == new_data);
201
- }
202
-
203
- SECTION (" compression level -- min to max" )
204
- {
205
- for (int level = Z_BEST_SPEED; level <= Z_BEST_COMPRESSION; ++level)
206
- {
207
- std::string compressed_data = gzip::compress (data, level, strategy);
208
- CHECK (gzip::is_compressed (compressed_data));
209
- std::string new_data = gzip::decompress (compressed_data);
210
- CHECK (data == new_data);
211
- }
212
- }
103
+ int level = Z_NO_COMPRESSION;
104
+ std::string compressed_data = gzip::compress (data.data (),data.size ());
105
+ CHECK (gzip::is_compressed (compressed_data.data (),compressed_data.size ()));
106
+ std::string new_data = gzip::decompress (compressed_data.data (),compressed_data.size ());
107
+ CHECK (data == new_data);
213
108
}
214
109
215
- SECTION (" strategy - rle " )
110
+ SECTION (" default compression level " )
216
111
{
217
- strategy = Z_RLE;
218
-
219
- SECTION (" no compression" )
220
- {
221
- int level = Z_NO_COMPRESSION;
222
- std::string compressed_data = gzip::compress (data, level, strategy);
223
- CHECK (gzip::is_compressed (compressed_data));
224
- std::string new_data = gzip::decompress (compressed_data);
225
- CHECK (data == new_data);
226
- }
227
-
228
- SECTION (" default compression level" )
229
- {
230
- int level = Z_DEFAULT_COMPRESSION;
231
- std::string compressed_data = gzip::compress (data, level, strategy);
232
- CHECK (gzip::is_compressed (compressed_data));
233
- std::string new_data = gzip::decompress (compressed_data);
234
- CHECK (data == new_data);
235
- }
236
-
237
- SECTION (" compression level -- min to max" )
238
- {
239
- for (int level = Z_BEST_SPEED; level <= Z_BEST_COMPRESSION; ++level)
240
- {
241
- std::string compressed_data = gzip::compress (data, level, strategy);
242
- CHECK (gzip::is_compressed (compressed_data));
243
- std::string new_data = gzip::decompress (compressed_data);
244
- CHECK (data == new_data);
245
- }
246
- }
112
+ int level = Z_DEFAULT_COMPRESSION;
113
+ std::string compressed_data = gzip::compress (data.data (),data.size ());
114
+ CHECK (gzip::is_compressed (compressed_data.data (),compressed_data.size ()));
115
+ std::string new_data = gzip::decompress (compressed_data.data (),compressed_data.size ());
116
+ CHECK (data == new_data);
247
117
}
248
118
249
- SECTION (" strategy - fixed " )
119
+ SECTION (" compression level -- min to max " )
250
120
{
251
- strategy = Z_FIXED;
252
-
253
- SECTION (" no compression" )
254
- {
255
- int level = Z_NO_COMPRESSION;
256
- std::string compressed_data = gzip::compress (data, level, strategy);
257
- CHECK (gzip::is_compressed (compressed_data));
258
- std::string new_data = gzip::decompress (compressed_data);
259
- CHECK (data == new_data);
260
- }
261
-
262
- SECTION (" default compression level" )
121
+ for (int level = Z_BEST_SPEED; level <= Z_BEST_COMPRESSION; ++level)
263
122
{
264
- int level = Z_DEFAULT_COMPRESSION;
265
- std::string compressed_data = gzip::compress (data, level, strategy);
266
- CHECK (gzip::is_compressed (compressed_data));
267
- std::string new_data = gzip::decompress (compressed_data);
123
+ std::string compressed_data = gzip::compress (data.data (),data.size ());
124
+ CHECK (gzip::is_compressed (compressed_data.data (),compressed_data.size ()));
125
+ std::string new_data = gzip::decompress (compressed_data.data (),compressed_data.size ());
268
126
CHECK (data == new_data);
269
127
}
270
-
271
- SECTION (" compression level -- min to max" )
272
- {
273
- for (int level = Z_BEST_SPEED; level <= Z_BEST_COMPRESSION; ++level)
274
- {
275
- std::string compressed_data = gzip::compress (data, level, strategy);
276
- CHECK (gzip::is_compressed (compressed_data));
277
- std::string new_data = gzip::decompress (compressed_data);
278
- CHECK (data == new_data);
279
- }
280
- }
281
128
}
282
129
}
283
130
0 commit comments