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