2 #include "zipios++/zipios-config.h"
4 #include "zipios++/meta-iostreams.h"
15 #include "zipfiletest.h"
17 using namespace zipios ;
27 void zipios::ZipFileTest::testUnzip() {
28 vector<string> entries;
29 entries.push_back(
"file1.txt");
30 entries.push_back(
"file2.txt");
31 entries.push_back(
"file3.txt");
32 entries.push_back(
"testfile.bin");
35 CPPUNIT_ASSERT_EQUAL(4, zipFile.size());
36 compareZipFile(
"test.zip", entries);
39 void zipios::ZipFileTest::testZipUnzip() {
40 const string zipFileName =
"gentest.zip";
41 vector<string> entries;
42 entries.push_back(
"testfile.bin");
43 entries.push_back(
"Makefile.in");
44 entries.push_back(
"zipfiletest.cpp");
45 entries.push_back(
"zipfiletest.h");
46 entries.push_back(
"all_tests");
47 writeZipFile(zipFileName, entries);
48 compareZipFile(zipFileName, entries);
51 void zipios::ZipFileTest::testComment(){
56 void zipios::ZipFileTest::writeZipFile(
const string &zipFileName, vector<string> entryFileNames) {
58 std::vector<string>::const_iterator it = entryFileNames.begin();
59 for ( ; it != entryFileNames.end() ; ++it ) {
60 writeFileToZipOutputStream(zos, *it);
65 void zipios::ZipFileTest::compareZipFile(
const string &zipFileName, vector<string> entryFileNames) {
68 vector<string>::const_iterator it = entryFileNames.begin();
69 for ( ; it != entryFileNames.end() ; ++it ) {
70 auto_ptr<istream> zis(zipFile.getInputStream(*it));
72 CPPUNIT_FAIL(
"Entry '"+*it+
"' not found in zip file");
73 ifstream fis((*it).c_str(), ios::in | ios::binary);
74 compareStreams(*it, *zis, fis);
78 void zipios::ZipFileTest::writeFileToZipOutputStream(
ZipOutputStream &zos,
const string &filename ) {
80 ifstream ifs( filename.c_str(), ios::in | ios::binary ) ;
82 CPPUNIT_FAIL(
"Could not open file '"+filename+
"'");
99 void zipios::ZipFileTest::compareStreams(
const std::string& entryName,
100 istream &is1, istream &is2) {
104 CPPUNIT_ASSERT_MESSAGE(
"Streams differ for entry '"+entryName+
"'",
105 buf1.
str() == buf2.
str());
108 void zipios::ZipFileTest::testClone(){
110 std::cout<<
"Testing cloning..need some help here"<<std::endl;
Header file that defines ZipFile.
Specialization of ZipLocalEntry, that add fields for storing the extra information, that is only present in the entries in the zip central directory and not in the local entry headers.
OutputStringStream is typedefed to ostringstream if sstream is part of the standard library (unless Z...
Header file that defines OutputStringStream.
void putNextEntry(const ZipCDirEntry &entry)
string str()
Specialization of ostrstream::str() that takes care of null-terminating the string and unfreezing the...