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
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101