aria2/test/DataTest.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.5 KiB
C++

#include "Data.h"
#include <string>
#include <cppunit/extensions/HelperMacros.h>
using namespace std;
class DataTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(DataTest);
CPPUNIT_TEST(testToString);
CPPUNIT_TEST(testGetData);
CPPUNIT_TEST(testToInt);
CPPUNIT_TEST(testToLLInt);
CPPUNIT_TEST_SUITE_END();
private:
public:
void setUp() {
}
void testToString();
void testGetData();
void testToInt();
void testToLLInt();
};
CPPUNIT_TEST_SUITE_REGISTRATION( DataTest );
void DataTest::testToString() {
Data data("aria2", 5);
CPPUNIT_ASSERT_EQUAL(string("aria2"), data.toString());
Data null(NULL, 0);
CPPUNIT_ASSERT_EQUAL(string(""), null.toString());
}
void DataTest::testGetData() {
Data data("aria2", 5);
int len;
CPPUNIT_ASSERT_EQUAL(0, memcmp("aria2", data.getData(), 5));
CPPUNIT_ASSERT_EQUAL((int32_t)5, data.getLen());
Data null(NULL, 0);
CPPUNIT_ASSERT_EQUAL((const char*)NULL, null.getData());
CPPUNIT_ASSERT_EQUAL((int32_t)0, null.getLen());
}
void DataTest::testToInt() {
Data data("1000", 4);
CPPUNIT_ASSERT_EQUAL((int32_t)1000, data.toInt());
Data null(NULL, 0);
CPPUNIT_ASSERT_EQUAL((int32_t)0, null.toInt());
Data alpha("abc", 3);
CPPUNIT_ASSERT_EQUAL((int32_t)0, alpha.toInt());
}
void DataTest::testToLLInt() {
Data data("1000", 4);
CPPUNIT_ASSERT_EQUAL(1000, (int)data.toLLInt());
Data null(NULL, 0);
CPPUNIT_ASSERT_EQUAL(0, (int)null.toLLInt());
Data alpha("abc", 3);
CPPUNIT_ASSERT_EQUAL(0, (int)alpha.toLLInt());
}