Mercurial > hg > sv-dependency-builds
annotate src/zlib-1.2.8/contrib/iostream3/test.cc @ 128:5b4145a0d408
Current zlib source
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Tue, 18 Oct 2016 14:33:52 +0100 |
parents | |
children |
rev | line source |
---|---|
cannam@128 | 1 /* |
cannam@128 | 2 * Test program for gzifstream and gzofstream |
cannam@128 | 3 * |
cannam@128 | 4 * by Ludwig Schwardt <schwardt@sun.ac.za> |
cannam@128 | 5 * original version by Kevin Ruland <kevin@rodin.wustl.edu> |
cannam@128 | 6 */ |
cannam@128 | 7 |
cannam@128 | 8 #include "zfstream.h" |
cannam@128 | 9 #include <iostream> // for cout |
cannam@128 | 10 |
cannam@128 | 11 int main() { |
cannam@128 | 12 |
cannam@128 | 13 gzofstream outf; |
cannam@128 | 14 gzifstream inf; |
cannam@128 | 15 char buf[80]; |
cannam@128 | 16 |
cannam@128 | 17 outf.open("test1.txt.gz"); |
cannam@128 | 18 outf << "The quick brown fox sidestepped the lazy canine\n" |
cannam@128 | 19 << 1.3 << "\nPlan " << 9 << std::endl; |
cannam@128 | 20 outf.close(); |
cannam@128 | 21 std::cout << "Wrote the following message to 'test1.txt.gz' (check with zcat or zless):\n" |
cannam@128 | 22 << "The quick brown fox sidestepped the lazy canine\n" |
cannam@128 | 23 << 1.3 << "\nPlan " << 9 << std::endl; |
cannam@128 | 24 |
cannam@128 | 25 std::cout << "\nReading 'test1.txt.gz' (buffered) produces:\n"; |
cannam@128 | 26 inf.open("test1.txt.gz"); |
cannam@128 | 27 while (inf.getline(buf,80,'\n')) { |
cannam@128 | 28 std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n"; |
cannam@128 | 29 } |
cannam@128 | 30 inf.close(); |
cannam@128 | 31 |
cannam@128 | 32 outf.rdbuf()->pubsetbuf(0,0); |
cannam@128 | 33 outf.open("test2.txt.gz"); |
cannam@128 | 34 outf << setcompression(Z_NO_COMPRESSION) |
cannam@128 | 35 << "The quick brown fox sidestepped the lazy canine\n" |
cannam@128 | 36 << 1.3 << "\nPlan " << 9 << std::endl; |
cannam@128 | 37 outf.close(); |
cannam@128 | 38 std::cout << "\nWrote the same message to 'test2.txt.gz' in uncompressed form"; |
cannam@128 | 39 |
cannam@128 | 40 std::cout << "\nReading 'test2.txt.gz' (unbuffered) produces:\n"; |
cannam@128 | 41 inf.rdbuf()->pubsetbuf(0,0); |
cannam@128 | 42 inf.open("test2.txt.gz"); |
cannam@128 | 43 while (inf.getline(buf,80,'\n')) { |
cannam@128 | 44 std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n"; |
cannam@128 | 45 } |
cannam@128 | 46 inf.close(); |
cannam@128 | 47 |
cannam@128 | 48 return 0; |
cannam@128 | 49 |
cannam@128 | 50 } |