[Cppunit-cvs] cppunit2/src/opentesttest packetstest.cpp,NONE,1.1 packetstest.h,NONE,1.1 SConscript,1
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-07-04 08:12:55
|
Update of /cvsroot/cppunit/cppunit2/src/opentesttest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23595/src/opentesttest Modified Files: SConscript main.cpp opentest.vcproj Added Files: packetstest.cpp packetstest.h Log Message: * Started adding unit tests for Packets. --- NEW FILE: packetstest.h --- #ifndef OPENTEST_PACKETSTEST_H # define OPENTEST_PACKETSTEST_H # include <cpput/testfixture.h> # include <opentest/serializer.h> # include <cpptl/scopedptr.h> class PacketsTest : public CppUT::TestFixture { CPPUT_TESTSUITE_BEGIN( PacketsTest ); CPPUT_TEST( testDefaultConstructor ); CPPUT_TEST( testSerializeMessage ); CPPUT_TESTSUITE_END(); public: PacketsTest(); virtual ~PacketsTest(); void setUp(); void tearDown(); void testDefaultConstructor(); void testSerializeMessage(); private: typedef OpenTest::Packets::Byte Byte; typedef OpenTest::Packets::Pos Pos; CppTL::ScopedPtr<OpenTest::Packets> packets_; }; #endif // OPENTEST_PACKETSTEST_H --- NEW FILE: packetstest.cpp --- #include "packetstest.h" #include <cpput/assert.h> #include <cpput/assertstring.h> #include <cpptl/scopedptr.h> #include <memory.h> // memcmp, memset class BinaryData { public: BinaryData( const void *data, unsigned int length ) : data_( data ) , length_( length ) { } bool operator ==( const BinaryData &other ) const { return length_ == other.length_ && memcmp( data_, other.data_, length_ ) == 0; } CppTL::ConstString toString() const { const char *begin = static_cast<const char *>( data_ ); return "length = " + CppTL::toString( length_ ) + "\ndata = " + quoteString( CppTL::ConstString( begin, begin + length_ ) ); } const void *data_; unsigned int length_; }; namespace CppUT { // converter for assert equal inline std::string convertToString( const BinaryData &value ) { return value.toString().str(); } } PacketsTest::PacketsTest() { } PacketsTest::~PacketsTest() { } void PacketsTest::setUp() { packets_.reset( new OpenTest::Packets( 4 ) ); } void PacketsTest::tearDown() { packets_.reset(); } void PacketsTest::testDefaultConstructor() { CPPUT_ASSERT_EXPR_FALSE( packets_->hasPendingMessage() ); } void PacketsTest::testSerializeMessage() { static const char *testData[] = { "1", "12", "123", "12345", "1234abcd" }; const int numberOfTestData = sizeof(testData) / sizeof(const Byte *); for ( int index1 = 0; index1 < numberOfTestData; ++index1 ) { Pos testDataLength = strlen(testData[index1]); packets_->beginMessage(); packets_->serializationWrite( testData[index1], testDataLength ); packets_->endSerializeMessage(); CPPUT_ASSERT_EXPR( packets_->hasPendingMessage() ); CppTL::ScopedArray<Byte> actual( new Byte[ testDataLength ] ); memset( actual.get(), 0, testDataLength ); Pos actualLength = packets_->send( actual.get(), testDataLength ); CPPUT_ASSERT_EQUAL( BinaryData( testData[index1], testDataLength ), BinaryData( actual.get(), actualLength ) ); } } Index: main.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/opentesttest/main.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** main.cpp 2 Jul 2005 20:27:37 -0000 1.2 --- main.cpp 4 Jul 2005 08:12:34 -0000 1.3 *************** *** 3,6 **** --- 3,7 ---- #include <cpput/lighttestrunner.h> #include <stdio.h> + #include "packetstest.h" #include "serializertest.h" *************** *** 65,69 **** CppUT::TestSuitePtr allSuite = CppUT::makeTestSuite( "All tests" ); ! allSuite->add( SerializerTest::suite() ); CppUT::LightTestRunner runner; --- 66,71 ---- CppUT::TestSuitePtr allSuite = CppUT::makeTestSuite( "All tests" ); ! allSuite->add( PacketsTest::suite() ); ! //allSuite->add( SerializerTest::suite() ); CppUT::LightTestRunner runner; Index: SConscript =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/opentesttest/SConscript,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SConscript 1 Jul 2005 08:19:37 -0000 1.1 --- SConscript 4 Jul 2005 08:12:34 -0000 1.2 *************** *** 2,17 **** buildLibraryUnitTest( env_testing, Split( """ ! assertenumtest.cpp ! assertstringtest.cpp ! enumeratortest.cpp main.cpp - registrytest.cpp - testbasicassertion.cpp - testexceptionguard.cpp - testfunctor.cpp - testfixturetest.cpp - testtestcase.cpp - testtestsuite.cpp - reflectiontest.cpp """ ), ! 'cpputtest' ) --- 2,8 ---- buildLibraryUnitTest( env_testing, Split( """ ! packetstest.cpp ! serializertest.cpp main.cpp """ ), ! 'opentesttest' ) Index: opentest.vcproj =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/opentesttest/opentest.vcproj,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** opentest.vcproj 1 Jul 2005 08:19:37 -0000 1.1 --- opentest.vcproj 4 Jul 2005 08:12:34 -0000 1.2 *************** *** 55,59 **** <Tool Name="VCPostBuildEventTool" ! Description="Testing cpput library..." CommandLine="$(TargetPath)"/> <Tool --- 55,59 ---- <Tool Name="VCPostBuildEventTool" ! Description="Testing opentest library..." CommandLine="$(TargetPath)"/> <Tool *************** *** 126,130 **** <Tool Name="VCPostBuildEventTool" ! Description="Testing cpput library..." CommandLine="$(TargetPath)"/> <Tool --- 126,130 ---- <Tool Name="VCPostBuildEventTool" ! Description="Testing opentest library..." CommandLine="$(TargetPath)"/> <Tool *************** *** 155,158 **** --- 155,164 ---- </File> <File + RelativePath=".\packetstest.cpp"> + </File> + <File + RelativePath=".\packetstest.h"> + </File> + <File RelativePath=".\serializertest.cpp"> </File> |