aria2/test/ChunkedEncodingTest.cc
Tatsuhiro Tsujikawa 3cc1ed5e09 2007-08-10 Ross Smith II <aria2spam at smithii dot com>
gcc 3.4.4 support:
	* src/DefaultBtContext.cc: int32_t -> int
	* src/main.cc: int -> int32_t, int32_t -> int
	* src/messageDigest.h: uint32_t -> unsigned int
	* src/NameResolver.h: int32_t -> int
	* src/PeerConnection.cc: int -> int32_t
	* src/SpeedCalc.cc: int32_t -> int
	* src/TrackerUpdateCommand.h: int -> int32_t
	* src/Util.cc: int32_t -> int
	* src/Util.h: int32_t -> int
	* src/Xml2MetalinkProcessor.cc: int -> uint32_t, int64_t -> 
uint64_t
	* test/AnnounceListTest.cc: int -> int32_t
	* test/ChunkedEncodingTest.cc: int -> int32_t
	* test/DataTest.cc: int -> int32_t
	* test/DefaultBtRequestFactoryTest.cc: int -> int32_t
	* test/DefaultPeerListProcessorTest.cc: int -> int32_t
	* test/DefaultPieceStorageTest.cc: int -> int32_t
	* test/FeatureConfigTest.cc: int -> int32_t
	* test/MetalinkEntryTest.cc: int -> int32_t
	* test/MockBtRequestFactory.h: int -> int32_t
	* test/MockPieceStorage.h: int -> int32_t
	* test/OptionTest.cc: int -> int32_t
	* test/RequestTest.cc: int -> int32_t
	* test/SegmentManTest.cc: int -> int32_t
	* test/Xml2MetalinkProcessorTest.cc: int -> int32_t
2007-08-15 15:11:01 +00:00

70 lines
1.7 KiB
C++

#include "ChunkedEncoding.h"
#include <fstream>
#include <iostream>
#include <string>
#include <cppunit/extensions/HelperMacros.h>
using namespace std;
class ChunkedEncodingTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(ChunkedEncodingTest);
CPPUNIT_TEST(testInflate1);
CPPUNIT_TEST(testInflateLargeChunk);
CPPUNIT_TEST_SUITE_END();
private:
ChunkedEncoding* enc;
public:
void setUp() {
enc = new ChunkedEncoding();
enc->init();
}
void testInflate1();
void testInflateLargeChunk();
};
CPPUNIT_TEST_SUITE_REGISTRATION( ChunkedEncodingTest );
void ChunkedEncodingTest::testInflate1() {
string msg = "a\r\n1234567890\r\n";
char buf[100];
int32_t len = sizeof(buf);
enc->inflate(buf, len, msg.c_str(), msg.size());
buf[len] = '\0';
CPPUNIT_ASSERT_EQUAL(string("1234567890"), string(buf));
// second pass
len = sizeof(buf);
msg = "3;extensionIgnored\r\n123\r\n0\r\n";
enc->inflate(buf, len, msg.c_str(), msg.size());
buf[len] = '\0';
CPPUNIT_ASSERT_EQUAL(string("123"), string(buf));
// input is over
CPPUNIT_ASSERT(enc->finished());
}
void ChunkedEncodingTest::testInflateLargeChunk() {
// give over 4096 character chunk
fstream is("4096chunk.txt", ios::in);
if(is.fail()) {
CPPUNIT_FAIL("cannot open file 4096chunk.txt");
}
string body;
is >> body;
char buf[4097];
int32_t len = sizeof(buf);
for(int i = 0; i < 2; i++) {
string msg = "1000\r\n"+body+"\r\n";
len = sizeof(buf);
enc->inflate(buf, len, msg.c_str(), msg.size());
buf[len] = '\0';
CPPUNIT_ASSERT_EQUAL(body, string(buf));
}
enc->inflate(buf, len, "0\r\n", 3);
CPPUNIT_ASSERT_EQUAL((int32_t)0, len);
CPPUNIT_ASSERT(enc->finished());
}