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
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