Commit 98c82193 authored by Peter Sommerlad's avatar Peter Sommerlad Committed by Marcel Huber
Browse files

adjusted license headers and added license.txt

parents
[submodule "scripts"]
path = scripts
url = ssh://sifs-coast1.hsr.ch/var/repositories/git/wdscripts.git
This diff is collapsed.
/*! \mainpage Coast API Documentation
*
* Coast is a C++ platform for developing and deploying (World Wide Web) Server applications.
* It provides an extensible framework, reusable components, and a configuration mechanism
* that is used to create (web) server applications.
* For deployment, it provides an efficient and scaleable server and additional flexible
* communication infrastructure.
*
* <br>
* <center>Oberseestrasse 10, CH-8640 Rapperswil
* <a href="mailto:info@ifs.hsr.ch">info@ifs.hsr.ch</a>,
* <a href="http://www.ifs.hsr.ch">www.ifs.hsr.ch</a></center>
*/
#-----------------------------------------------------------------------------------------------------
# Copyright (c) 2005, Peter Sommerlad and IFS Institute for Software at HSR Rapperswil, Switzerland
# All rights reserved.
#
# This library/application is free software; you can redistribute and/or modify it under the terms of
# the license that is included with this library/application in the file license.txt.
#-----------------------------------------------------------------------------------------------------
{
/LowerBound 0 # define lower bound of debug range, 0 turns it off completly
/UpperBound 1 # define upper bound of debug range
/DumpAnythings 1 # print full Anythings
/ZipIStreamBuf
{
/MainSwitch 150
/EnableAll 150
}
/ZipOStreamBuf
{
/MainSwitch 50
/EnableAll 50
}
/ZipStreamTest {
/MainSwitch 150
/EnableAll 150
}
}
/*
* Copyright (c) 2005, Peter Sommerlad and IFS Institute for Software at HSR Rapperswil, Switzerland
* All rights reserved.
*
* This library/application is free software; you can redistribute and/or modify it under the terms of
* the license that is included with this library/application in the file license.txt.
*/
//
// Possible runner file, add your TestCase subclasses here and initialize
// necessary services if desired.
//
#include "TestRunner.h"
#include "ZipStreamTest.h"
void setupRunner(TestRunner &runner)
{
// add a whole suite with the ADD_SUITE(runner,"Suites's Classname") macro
ADD_SUITE(runner, ZipStreamTest);
} // setupRunner
/*
* Copyright (c) 2005, Peter Sommerlad and IFS Institute for Software at HSR Rapperswil, Switzerland
* All rights reserved.
*
* This library/application is free software; you can redistribute and/or modify it under the terms of
* the license that is included with this library/application in the file license.txt.
*/
//--- interface include --------------------------------------------------------
#include "ZipStreamTest.h"
//--- test modules used --------------------------------------------------------
#include "TestSuite.h"
//--- module under test --------------------------------------------------------
#include "ZipStream.h"
//--- standard modules used ----------------------------------------------------
#include "System.h"
#include "Dbg.h"
//--- c-modules used -----------------------------------------------------------
#include <stdlib.h>
//---- ZipStreamTest ----------------------------------------------------------------
ZipStreamTest::ZipStreamTest(TString name) : TestCase(name)
{
StartTrace(ZipStreamTest.Ctor);
}
ZipStreamTest::~ZipStreamTest()
{
StartTrace(ZipStreamTest.Dtor);
}
// setup for this TestCase
void ZipStreamTest::setUp ()
{
StartTrace(ZipStreamTest.setUp);
}
void ZipStreamTest::tearDown ()
{
StartTrace(ZipStreamTest.tearDown);
}
void ZipStreamTest::testCase()
{
StartTrace(ZipStreamTest.testCase);
}
static String content("Hello Hello Peter\nhallo\n");
void ZipStreamTest::GzipZlibTest()
{
StartTrace(ZipStreamTest.GzipZlibTest);
// check our prezipped master file
VerifyFile("master.gz");
// generate a zipped file
gzFile *outFile = (gzFile *)gzopen("tt.gz", "w");
t_assert(outFile != NULL);
t_assert(gzwrite(outFile, (void *)(const char *)content, content.Length()) > 0L);
int err = gzclose(outFile);
Trace("closing zip err=" << (long)err);
t_assert(err == Z_OK);
VerifyFile("tt.gz");
}
static String ReadStream(istream &is)
{
StartTrace(TestSequence.ReadStream);
String ret(Storage::Global());
while (is.good() && !is.eof()) {
char buff[4096];
long nread = is.read(buff, sizeof(buff)).gcount();
ret.Append((void *)buff, nread);
Trace("read: " << nread);
}
Trace("returning: " << ret.Length());
return ret;
}
void ZipStreamTest::GzipLongFileCheck()
{
StartTrace(ZipStreamTest.GzipLongFileCheck);
istream *is = System::OpenIStream("longpage", "html");
if (!t_assertm((is != NULL), "file longpage.html not found")) {
return;
}
String raw;
raw = ReadStream(*is);
delete is;
String encoded;
StringStream ssenc(encoded);
ZipOStream zos(ssenc);
zos << raw;
zos.close();
StringStream ssdec(encoded);
ZipIStream zis(ssdec);
String cooked;
cooked = ReadStream(zis);
t_assert(raw.Length() == cooked.Length());
t_assert(raw == cooked);
}
void ZipStreamTest::GzipSimpleFileCheck()
{
StartTrace(ZipStreamTest.GzipSimpleFileCheck);
ostream *os = System::OpenOStream ("testzip", "gz", ios::binary);
if (!t_assert(os != NULL)) {
return;
}
ZipOStream zos(*os);
t_assert(!!zos);
zos << content << flush;
t_assert(!!zos);
zos.close();
delete os;
// should check for consistency of the file
VerifyFile("testzip.gz");
istream *is = System::OpenIStream("testzip", "gz", ios::binary);
if (!t_assert(is != NULL)) {
return;
}
ZipIStream zis(*is);
t_assert(!!zis);
String strRead;
while (!!zis && !zis.eof()) {
String buff(1024);
long nread = zis.read((char *)(const char *)buff, buff.Capacity()).gcount();
strRead.Append((const char *)buff, nread);
}
t_assert(!zis != 0);
assertEqual(content, strRead);
zis.close();
delete is;
}
void ZipStreamTest::GzipConstantBufferCheck()
{
StartTrace(ZipStreamTest.GzipConstantBufferCheck);
srand(12345);
char inFile[89000];
{
for (unsigned i = 0; i < sizeof(inFile); i++) {
inFile[i] = (char) rand();
}
}
String encoded;
StringStream ssout(encoded);
ZipOStream zos(ssout);
{
for (unsigned i = 0; i < sizeof(inFile); i += 1024) {
unsigned long toWrite = 1024;
if (toWrite > (sizeof(inFile) - i)) {
toWrite = (sizeof(inFile) - i);
}
zos.write(inFile + i, toWrite);
}
}
zos.close();
Trace("Encoded size: " << encoded.Length());
StringStream ssin(encoded);
ZipIStream zis(ssin);
String decoded;
while (zis.good() && !zis.eof()) {
char buff[24096];
long nread = zis.read(buff, sizeof(buff)).gcount();
decoded.Append((void *)buff, nread);
}
t_assert(sizeof(inFile) == decoded.Length());
{
for (unsigned i = 0; i < sizeof(inFile); i++) {
if (!t_assert(inFile[i] == decoded[(long)i])) {
break;
}
}
}
encoded << "a bit of garbage at the end" ;
StringStream ssin2(encoded);
ZipIStream zis2(ssin2);
String decoded2;
while (zis2.good() && !zis2.eof()) {
char buff[24096];
long nread = zis2.read(buff, sizeof(buff)).gcount();
decoded2.Append((void *)buff, nread);
}
t_assert(sizeof(inFile) == decoded2.Length());
{
for (unsigned i = 0; i < sizeof(inFile); i++) {
if (!t_assert(inFile[i] == decoded2[(long)i])) {
break;
}
}
}
}
void ZipStreamTest::GzipBigFileCheck()
{
StartTrace(ZipStreamTest.GzipBigFileCheck);
srand(12345);
char inFile[1024*64];
{
for (unsigned i = 0; i < sizeof(inFile); i++) {
inFile[i] = (char) rand();
}
}
ostream *os = System::OpenOStream("big", "gz", ios::binary);
if (!t_assert(os != NULL)) {
return;
}
ZipOStream zos(*os);
zos.write(inFile, sizeof(inFile));
zos.close();
delete os;
char outFile[sizeof(inFile)];
istream *is = System::OpenIStream("big", "gz", ios::binary);
if (!t_assert(is != NULL)) {
return ;
}
ZipIStream zis(*is);
unsigned nread = 0;
while ( nread < sizeof(outFile) && !zis.eof()) {
nread += zis.read(outFile + nread, sizeof(outFile) - nread).gcount();
Trace("read: " << (long)nread);
}
t_assert(zis.get() == EOF);
t_assert(zis.eof() != 0);
t_assert(!zis.bad());
zis.close();
for (unsigned i = 0; i < sizeof(inFile); i++) {
if ( !t_assert(inFile[i] == outFile[i])) {
Trace("files not equal: " << (long)i);
break;
}
}
delete is;
istream *is2 = System::OpenIStream("big", "gz", ios::binary);
if (!t_assert(is2 != NULL)) {
return ;
}
ZipIStream zis2(*is2);
unsigned nread2 = 0;
while ( nread2 < 20000 && !zis2.eof()) {
nread2 += zis2.read(outFile + nread2, sizeof(outFile) - nread2).gcount();
Trace("read: " << (long)nread2);
}
t_assert(!zis2.eof());
t_assert(!zis2.bad());
zis2.close();
delete is2;
}
void ZipStreamTest::GzipCorruptInputCheck()
{
String noZip("no zip at all!");
StringStream ss1(noZip);
ZipIStream zis1(ss1);
zis1.get();
t_assert(!zis1 != 0);
String buff;
StringStream ss3(buff);
ZipOStream zos(ss3);
zos << noZip;
zos.close();
StringStream ss4(buff);
ZipIStream zis2(ss4);
zis2.get();
t_assert(!!zis2);
t_assert(!zis2.eof());
zis2.close();
}
void ZipStreamTest::GzipHeaderCheck()
{
StartTrace(ZipStreamTest.GzipHeaderCheck);
OStringStream os;
ZipOStream zos(os);
t_assert(os.flush() != NULL);
assertEqual(0L, os.str().Length());
zos << 'a';
zos.flush();
// header must be written after first byte streamd to stream
assertEqual(10L, sizeof(ZipOStreamBuf::fgcGzSimpleHeader));
t_assert(os.str().Length() == 10L);
String headerstr((const char *)ZipOStreamBuf::fgcGzSimpleHeader, 10L);
String writtenHeader = os.str();
writtenHeader.Trim(10);
assertEqual(headerstr, writtenHeader);
}
// builds up a suite of testcases, add a line for each testmethod
Test *ZipStreamTest::suite ()
{
StartTrace(ZipStreamTest.suite);
TestSuite *testSuite = new TestSuite;
testSuite->addTest (NEW_CASE(ZipStreamTest, GzipHeaderCheck));
testSuite->addTest (NEW_CASE(ZipStreamTest, GzipSimpleFileCheck));
testSuite->addTest (NEW_CASE(ZipStreamTest, GzipBigFileCheck));
testSuite->addTest (NEW_CASE(ZipStreamTest, GzipLongFileCheck));
testSuite->addTest (NEW_CASE(ZipStreamTest, GzipZlibTest));
testSuite->addTest (NEW_CASE(ZipStreamTest, GzipCorruptInputCheck));
testSuite->addTest (NEW_CASE(ZipStreamTest, GzipConstantBufferCheck));
return testSuite;
}
void ZipStreamTest::VerifyFile(const char *fileName)
{
const long length = content.Length();
gzFile *inFile = (gzFile *)gzopen(fileName, "r");
t_assertm(inFile != NULL, (const char *)(String("File '") << fileName << "' must exist!"));
char *buffer = new char[length];
t_assert(gzread(inFile, buffer, length) == length);
assertEqual(content, String(buffer, length));
delete[] buffer;
int err = gzclose(inFile);
t_assert(err == Z_OK);
}
/*
* Copyright (c) 2005, Peter Sommerlad and IFS Institute for Software at HSR Rapperswil, Switzerland
* All rights reserved.
*
* This library/application is free software; you can redistribute and/or modify it under the terms of
* the license that is included with this library/application in the file license.txt.
*/
#ifndef _ZipStreamTest_H
#define _ZipStreamTest_H
//---- baseclass include -------------------------------------------------
#include "ITOString.h"
#include "TestCase.h"
//---- ZipStreamTest ----------------------------------------------------------
//! TestCases description
class ZipStreamTest : public TestCase
{
public:
//--- constructors
//!TestCase constructor
//! \param name name of the test
ZipStreamTest(TString name);
//!destroys the test case
~ZipStreamTest();
//--- public api
//!builds up a suite of testcases for this test
static Test *suite ();
//!sets the environment for this test
void setUp ();
//!deletes the environment for this test
void tearDown ();
//!test the gzip header after init
void GzipHeaderCheck();
//!test the gzip file creation and reading
void GzipSimpleFileCheck();
//!test the gzip file creation and reading for a bigger file
void GzipBigFileCheck();
//!read a long file, zip and unzip it
void GzipLongFileCheck();
//!test with constant output/input buffers
void GzipConstantBufferCheck();
//! Corrupted input for ZipIStream
void GzipCorruptInputCheck();
//!test the gzip file creation
void GzipZlibTest();
//!describe this testcase
void testCase();
private:
void VerifyFile(const char *fileName);
};
#endif
This diff is collapsed.
#!/bin/ksh
## add test specific things before the call to callTest
function prepareTest
{
echo
}
## call to wdtest or whatever you want to call
function callTest
{
WDROOT=. WDPATH=. ${TEST_EXE} $cfg_testparams
# remember return code of wdtest, signals number of failures
return $?;
}
## add test specific things after the call to callTest
# remove generated files ...
function cleanupTest
{
echo
}
/*
* Copyright (c) 2005, Peter Sommerlad and IFS Institute for Software at HSR Rapperswil, Switzerland
* All rights reserved.
*
* This library/application is free software; you can redistribute and/or modify it under the terms of
* the license that is included with this library/application in the file license.txt.
*/
//--- interface include --------------------------------------------------------
#include "ZipStream.h"
//--- standard modules used ----------------------------------------------------
#include "Anything.h"
#include "Dbg.h"
//--- c-modules used -----------------------------------------------------------
// definition og GzHeader see RFC 1952
const unsigned char ZipStreamBuf::fgcGzSimpleHeader[10] = {
0x1f, 0x8b,
fgcZDeflated,
0, // flags
0, 0, 0, 0, // time
0, // xflags
fgcOsCode
}; /* gzip magic header */
const unsigned char ZipStreamBuf::fgcZDeflated = 0x08;
#if defined(WIN32)
// nt os code
const unsigned char ZipOStreamBuf::fgcOsCode = 0x0b;
#else
// unix os code
const unsigned char ZipStreamBuf::fgcOsCode = 0x03;
#endif
const long ZipStreamBuf::fgcStoreSize = 16384; // zlib's Z_BUFSIZE
//---- ZipOStreamBuf ----------------------------------------------------------------
ZipOStreamBuf::ZipOStreamBuf(ostream &os, Allocator *alloc)
: fAllocator(alloc ? alloc : Storage::Current())
, fStore(fgcStoreSize, fAllocator)
, fCompressed(fgcStoreSize, fAllocator)
, fOs(&os)
, fCrc(0)
, isInitialized(false)
{
xinit();
}
ZipOStreamBuf::~ZipOStreamBuf()
{
close();
}
void ZipOStreamBuf::close()
{
StartTrace(ZipOStreamBuf.close);
if (!fOs) {
return;
}
sync();
flushCompressedIfNecessary();
fZip.avail_in = 0;
long err = Z_OK;
do {
err = deflate(&fZip, Z_FINISH);
Trace("deflate finish err=" << err);
if (err == Z_OK || err == Z_STREAM_END) {
flushCompressed();
}
} while (err == Z_OK);
Trace("bytes compressed:" << (long)fZip.total_in << " into : " << (long)fZip.total_out);
Trace("crc is:" << (long)fCrc);
Trace("total_out: " << (long) fZip.total_out);
// now write crc and length
putLong(fCrc);
putLong(fZip.total_in);
err = deflateEnd(&fZip);
if (err != Z_OK) {
</