Zipios++

zipoutputstreamtest.cpp

Go to the documentation of this file.
00001 
00002 #include <stdlib.h>
00003 
00004 #include "zipios++/zipios-config.h"
00005 #include "zipios++/meta-iostreams.h"
00006 
00007 #include "zipios++/zipoutputstream.h"
00008 
00009 #include "zipoutputstreamtest.h"
00010 
00011 using namespace zipios ;
00012 
00013 using std::cout ;
00014 using std::cerr ;
00015 using std::endl ;
00016 using std::istream ;
00017 using std::ios ;
00018 using std::ofstream ;
00019 using std::string ;
00020 
00021 const string zipios::ZipOutputStreamTest::TEST_ZIPFILE_NAME = "testout.zip";
00022 const TestFiles zipios::ZipOutputStreamTest::TEST_FILES;
00023 
00024 
00025 void zipios::ZipOutputStreamTest::testNativeUnzip() {
00026   if (! hasUnzip()) {
00027     cout << "'unzip' not present, skipping ZipFileTest::testNativeUnzip" 
00028               << endl;
00029     return;
00030   }
00031 
00032   ZipOutputStream zos(TEST_ZIPFILE_NAME);
00033   
00034   std::vector<string>::const_iterator it;
00035   for(it=TEST_FILES.begin(); it!=TEST_FILES.end(); ++it)
00036     writeFileToZipOutputStream(zos, *it);
00037   zos.close();
00038 
00039   for(it=TEST_FILES.begin(); it!=TEST_FILES.end(); ++it)
00040     assertEntry(TEST_ZIPFILE_NAME, *it);
00041 }
00042 
00043 void zipios::ZipOutputStreamTest::writeFileToZipOutputStream(ZipOutputStream& zos,
00044  const string& entryName) {
00045   CPPUNIT_FAIL("Implement this");
00046 }
00047 
00048 void zipios::ZipOutputStreamTest::assertEntry(const string& zipFileName,
00049                                               const string& entryName) {
00050   CPPUNIT_FAIL("Implement this");
00051 }
00052 
00053 bool zipios::ZipOutputStreamTest::hasUnzip() {
00054   return system("unzip >/dev/null") == 0;
00055 }
00056 
00057 
00058 void zipios::ZipOutputStreamTest::entryToFile(const string &ent_name, istream &is, 
00059                                               const string &outfile,
00060                                               bool cerr_report) {
00061   ofstream ofs( outfile.c_str(), ios::out | ios::binary ) ;
00062   
00063   
00064   ofs << is.rdbuf() ;
00065   if ( cerr_report ) {
00066     cerr << "writing " << ent_name << " to " << outfile << endl ;
00067     cerr << "Stream state: "  ;
00068     cerr << "good() = " << is.good() << ",\t" ;
00069     cerr << "fail() = " << is.fail() << ",\t" ;
00070     cerr << "bad()  = " << is.bad()  << ",\t" ;
00071     cerr << "eof()  = " << is.eof()  << endl << endl;
00072   }
00073   ofs.close() ;
00074 }
00075 
00076 
00082 /*
00083   Zipios++ - a small C++ library that provides easy access to .zip files.
00084   Copyright (C) 2000  Thomas Søndergaard
00085   
00086   This library is free software; you can redistribute it and/or
00087   modify it under the terms of the GNU Lesser General Public
00088   License as published by the Free Software Foundation; either
00089   version 2 of the License, or (at your option) any later version.
00090   
00091   This library is distributed in the hope that it will be useful,
00092   but WITHOUT ANY WARRANTY; without even the implied warranty of
00093   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00094   Lesser General Public License for more details.
00095   
00096   You should have received a copy of the GNU Lesser General Public
00097   License along with this library; if not, write to the Free Software
00098   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00099 */
00100 
00101