test: move all module tests to the test/ directory
This commit is contained in:
76
test/compress/mix-decompress.c
Normal file
76
test/compress/mix-decompress.c
Normal file
@@ -0,0 +1,76 @@
|
||||
#include <assert.h>
|
||||
#include <blue/compress/compressor.h>
|
||||
#include <blue/compress/cstream.h>
|
||||
#include <blue/compress/zstd.h>
|
||||
#include <blue/core/ringbuffer.h>
|
||||
#include <blue/core/stream.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "usage: %s <inpath>\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_compressor_mode mode = B_COMPRESSOR_MODE_DECOMPRESS;
|
||||
|
||||
FILE *in_fp = fopen(argv[1], "rb");
|
||||
if (!in_fp) {
|
||||
fprintf(stderr, "cannot open input file %s\n", argv[1]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_stream *in_stream = b_stream_open_fp(in_fp);
|
||||
b_cstream *cstream;
|
||||
b_cstream_open(in_stream, B_TYPE_ZSTD_COMPRESSOR, mode, &cstream);
|
||||
|
||||
bool compressed = false;
|
||||
char buf[513];
|
||||
|
||||
for (int i = 0;; i++) {
|
||||
if (compressed) {
|
||||
b_cstream_begin_compressed_section(cstream, NULL);
|
||||
}
|
||||
|
||||
memset(buf, 0x0, sizeof buf);
|
||||
|
||||
size_t nr_read = 0;
|
||||
b_status status
|
||||
= b_cstream_read(cstream, buf, sizeof buf - 1, &nr_read);
|
||||
if (!B_OK(status)) {
|
||||
fprintf(stderr, "write error: %s\n",
|
||||
b_status_description(status));
|
||||
break;
|
||||
}
|
||||
|
||||
if (nr_read == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
size_t nr_read_compressed = 0;
|
||||
if (compressed) {
|
||||
b_cstream_end_compressed_section(
|
||||
cstream, &nr_read_compressed, &nr_read);
|
||||
}
|
||||
|
||||
size_t tx_total = 0;
|
||||
b_cstream_tx_bytes(cstream, &tx_total);
|
||||
printf(" * iteration %d: read %zu (compressed) / %zu "
|
||||
"(uncompressed) / %zu (total) bytes (%s)\n",
|
||||
i, nr_read_compressed, nr_read, tx_total,
|
||||
compressed ? "compressed" : "uncompressed");
|
||||
printf("%s\n", buf);
|
||||
|
||||
compressed = !compressed;
|
||||
}
|
||||
|
||||
printf("Done\n");
|
||||
|
||||
b_cstream_unref(cstream);
|
||||
b_stream_unref(in_stream);
|
||||
fclose(in_fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user