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