test_gzip.cpp

Go to the documentation of this file.
00001 // ============================================================================
00002 // gzstream, C++ iostream classes wrapping the zlib compression library.
00003 // Copyright (C) 2001  Deepak Bandyopadhyay, Lutz Kettner
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 // ============================================================================
00019 //
00020 // File          : test_gzip.C
00021 // Revision      : $Revision: 1.1 $
00022 // Revision_date : $Date: 2007/09/05 21:34:54 $
00023 // Author(s)     : Deepak Bandyopadhyay, Lutz Kettner
00024 // 
00025 // Short test program reading a file, compressing it, and writing it.
00026 // ============================================================================
00027 
00028 #include <gzstream.h>
00029 #include <iostream>
00030 #include <fstream>
00031 #include <stdlib.h>
00032 
00033 int main( int argc, char*argv[]) {
00034     if ( argc != 3) {
00035         std::cerr << "Usage: " << argv[0] <<" <in-file> <out-file>\n";
00036         return EXIT_FAILURE;
00037     }
00038     // check alternate way of opening file
00039     ogzstream    out2;
00040     out2.open( argv[2]);
00041     if ( ! out2.good()) {
00042         std::cerr << "ERROR: Opening file `" << argv[2] << "' failed.\n";
00043         return EXIT_FAILURE;
00044     }
00045     out2.close();
00046     if ( ! out2.good()) {
00047         std::cerr << "ERROR: Closing file `" << argv[2] << "' failed.\n";
00048         return EXIT_FAILURE;
00049     }
00050     // now use the shorter way with the constructor to open the same file
00051     ogzstream  out( argv[2]);
00052     if ( ! out.good()) {
00053         std::cerr << "ERROR: Opening file `" << argv[2] << "' failed.\n";
00054         return EXIT_FAILURE;
00055     }
00056     std::ifstream in(  argv[1]);
00057     if ( ! in.good()) {
00058         std::cerr << "ERROR: Opening file `" << argv[1] << "' failed.\n";
00059         return EXIT_FAILURE;
00060     }
00061     char c;
00062     while ( in.get(c))
00063         out << c;
00064     in.close();
00065     out.close();
00066     if ( ! in.eof()) {
00067         std::cerr << "ERROR: Reading file `" << argv[1] << "' failed.\n";
00068         return EXIT_FAILURE;
00069     }
00070     if ( ! out.good()) {
00071         std::cerr << "ERROR: Writing file `" << argv[2] << "' failed.\n";
00072         return EXIT_FAILURE;
00073     }
00074     return EXIT_SUCCESS;
00075 }
00076 
00077 // ============================================================================
00078 // EOF