Test code for checking suitability of zlib for reading and writing compressed data.
r1490 | ffr | 2007-02-15 10:05:00 +1100 (Thu, 15 Feb 2007) | 2 lines
This commit is contained in:
committed by
Douglas Clowes
parent
6afa1943e2
commit
6e9684275a
10
site_ansto/TESTS/check_zlib/Makefile
Normal file
10
site_ansto/TESTS/check_zlib/Makefile
Normal file
@@ -0,0 +1,10 @@
|
||||
all: rdata mkdata
|
||||
|
||||
rdata: rdata.c
|
||||
gcc -I/usr/include rdata.c -lz -o rdata
|
||||
|
||||
mkdata: mkdata.c
|
||||
gcc -I/usr/include mkdata.c -lz -o mkdata
|
||||
|
||||
clean:
|
||||
rm mkdata rdata data.gz data
|
||||
24
site_ansto/TESTS/check_zlib/README
Normal file
24
site_ansto/TESTS/check_zlib/README
Normal file
@@ -0,0 +1,24 @@
|
||||
PURPOSE:
|
||||
This code is used to check the suitability of zlib for writing and reading compressed histogram data.
|
||||
NOTE: zlib will transparently read uncompressed files.
|
||||
|
||||
2007-02-15
|
||||
Test reading and writing sequences of 1 to 16M ints (PASSED).
|
||||
|
||||
mkdata.c: Makes a zipped file containing a sequence of ints starting from 0.
|
||||
rdata.c: Reads a zipped/unzipped file expecting a sequence of ints starting from 0, max=16M ints.
|
||||
|
||||
USAGE:
|
||||
make
|
||||
./mkdata
|
||||
To make data.gz
|
||||
|
||||
./rdata data.gz
|
||||
To reada data.gz
|
||||
Then gunzip data.gz and run
|
||||
./rdata data
|
||||
To test reading uncompressed files.
|
||||
|
||||
To change the number of ints written, edit mkdata.c and change the DATALENGTH.
|
||||
To change the maximum number of ints that rdata.c can read, changed the DATALENGTH in rdata.c
|
||||
|
||||
23
site_ansto/TESTS/check_zlib/mkdata.c
Normal file
23
site_ansto/TESTS/check_zlib/mkdata.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#define DATALENGTH 1024*64
|
||||
|
||||
/* Writes an int array to a gzipped file
|
||||
* This has been tested with arrays from 1 to 16M integers.
|
||||
*/
|
||||
main() {
|
||||
int i;
|
||||
int data[DATALENGTH];
|
||||
gzFile *fp;
|
||||
|
||||
if ((fp=gzopen("data.gz", "wb")) == NULL) {
|
||||
printf ("Couldn't open file for writing\n");
|
||||
exit(1);
|
||||
}
|
||||
for (i=0; i<DATALENGTH; i++)
|
||||
data[i]=i;
|
||||
gzwrite(fp, data, DATALENGTH*sizeof(int));
|
||||
gzclose(fp);
|
||||
}
|
||||
39
site_ansto/TESTS/check_zlib/rdata.c
Normal file
39
site_ansto/TESTS/check_zlib/rdata.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#define DATALENGTH 1024*1024*16
|
||||
|
||||
/* Will read upto 16M integers from a file.
|
||||
* This expects the file to contain a sequence of
|
||||
* ints starting at 0, (eg 0 1 2 3 ..) and flags an
|
||||
* error if any of the ints don't match the expected sequence.
|
||||
* This has been tested on compressed and uncompressed files
|
||||
* containing 1 to 16M ints.
|
||||
*/
|
||||
main(int argc, char *argv[]) {
|
||||
int i,n, error=0;
|
||||
int rdata[DATALENGTH];
|
||||
gzFile *fp;
|
||||
|
||||
if (argc<2) {
|
||||
printf("You must supply a file name\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((fp=gzopen(argv[1], "rb")) == NULL) {
|
||||
printf ("Couldn't open file for reading\n");
|
||||
exit(1);
|
||||
}
|
||||
n=gzread(fp, rdata, DATALENGTH*sizeof(int));
|
||||
printf("Read %d bytes, ie %d ints\n", n, n/sizeof(int));
|
||||
for (i=0; i<n/sizeof(int); i++) {
|
||||
if (i != rdata[i]) {
|
||||
error=1;
|
||||
printf("ERROR expected %d, but got %d\n", i, rdata[i]);
|
||||
}
|
||||
}
|
||||
gzclose(fp);
|
||||
if (error==0)
|
||||
printf("There were no errors.\n");
|
||||
}
|
||||
Reference in New Issue
Block a user