[Cppunit-cvs] cppunit2/src/opentesttest main.cpp,1.3,1.4 packetstest.cpp,1.3,1.4 serializertest.cpp,
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-09-06 07:31:52
|
Update of /cvsroot/cppunit/cppunit2/src/opentesttest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16321/src/opentesttest Modified Files: main.cpp packetstest.cpp serializertest.cpp Log Message: * fixed compilation without RTTI * revised stringize implementation to allow an additional customization point by overloading toString(). * added test and corrected bug in serialization/packets implementation. Index: packetstest.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/opentesttest/packetstest.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** packetstest.cpp 8 Aug 2005 22:12:37 -0000 1.3 --- packetstest.cpp 6 Sep 2005 07:31:42 -0000 1.4 *************** *** 2,5 **** --- 2,6 ---- #include <cpput/assert.h> #include <cpput/assertstring.h> + #include <cpput/registry.h> #include <cpptl/scopedptr.h> #include <memory.h> // memcmp, memset *************** *** 33,37 **** namespace CppUT { // converter for assert equal ! inline std::string convertToString( const BinaryData &value ) { return value.toString().str(); --- 34,38 ---- namespace CppUT { // converter for assert equal ! inline std::string toString( const BinaryData &value ) { return value.toString().str(); *************** *** 40,43 **** --- 41,46 ---- + CPPUT_REGISTER_SUITE_TO_DEFAULT( PacketsTest ); + PacketsTest::PacketsTest() { *************** *** 75,92 **** { 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_.reset( new OpenTest::Packets( 4 ) ); // notes: test fails if using the same packets... ! 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 ) ); } } --- 78,101 ---- { static const char *testData[] = { "1", "12", "123", "12345", "1234abcd" }; + static int packetSizes[] = { 1, 2, 3, 4, 5, 16384 }; const int numberOfTestData = sizeof(testData) / sizeof(const Byte *); ! for ( int size = 0; size < sizeof(packetSizes)/sizeof(int); ++size ) { ! int packetSize = packetSizes[size]; ! CppUT::log( "Using packet size: " + CppTL::toString( packetSize ) ); ! packets_.reset( new OpenTest::Packets( packetSize ) ); ! for ( int index1 = 0; index1 < numberOfTestData; ++index1 ) ! { ! Pos testDataLength = strlen(testData[index1]); ! packets_->beginWriteMessage(); ! packets_->write( testData[index1], testDataLength ); ! packets_->endWriteMessage(); ! CPPUT_ASSERT_EXPR( packets_->hasPendingMessage()); ! CppTL::ScopedArray<Byte> actual( new Byte[ testDataLength ] ); ! memset( actual.get(), 0, testDataLength ); ! Pos actualLength = packets_->read( 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.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** main.cpp 4 Jul 2005 08:12:34 -0000 1.3 --- main.cpp 6 Sep 2005 07:31:42 -0000 1.4 *************** *** 2,5 **** --- 2,6 ---- #include <cpput/testsuite.h> #include <cpput/lighttestrunner.h> + #include <cpput/registry.h> #include <stdio.h> #include "packetstest.h" *************** *** 65,70 **** printf( "All bootstrap tests passed successfuly...\n" ); ! CppUT::TestSuitePtr allSuite = CppUT::makeTestSuite( "All tests" ); ! allSuite->add( PacketsTest::suite() ); //allSuite->add( SerializerTest::suite() ); --- 66,71 ---- printf( "All bootstrap tests passed successfuly...\n" ); ! CppUT::TestSuitePtr allSuite = CppUT::Registry::instance().createDefaultTests(); ! // allSuite->add( PacketsTest::suite() ); //allSuite->add( SerializerTest::suite() ); Index: serializertest.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/opentesttest/serializertest.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** serializertest.cpp 2 Jul 2005 20:27:37 -0000 1.3 --- serializertest.cpp 6 Sep 2005 07:31:42 -0000 1.4 *************** *** 2,9 **** #include <cpput/assert.h> #include <cpput/assertstring.h> namespace CppUT { // converter for assert equal ! inline std::string convertToString( const OpenTest::Value &value ) { return value.toString().c_str(); --- 2,15 ---- #include <cpput/assert.h> #include <cpput/assertstring.h> + #include <cpput/registry.h> namespace CppUT { // converter for assert equal ! inline std::string toString( const OpenTest::Properties &value ) ! { ! return value.toString().c_str(); ! } ! ! inline std::string toString( const OpenTest::Value &value ) { return value.toString().c_str(); *************** *** 13,16 **** --- 19,25 ---- + CPPUT_REGISTER_SUITE_TO_DEFAULT( SerializerTest ); + + SerializerTest::SerializerTest() { *************** *** 39,43 **** SerializerTest::prepareSerialize() { ! streamOut_.packets().beginMessage(); } --- 48,52 ---- SerializerTest::prepareSerialize() { ! streamOut_.packets().beginWriteMessage(); } *************** *** 46,58 **** SerializerTest::prepareUnserialize() { ! streamOut_.packets().endSerializeMessage(); int length = streamOut_.packets().getFirstMessageLength(); void *buffer = new char[length]; ! streamOut_.packets().send( buffer, length ); streamOut_.packets().discardFirstMessage(); ! streamIn_.packets().beginMessage(); ! streamIn_.packets().received( buffer, length ); ! streamIn_.packets().endExternalMessage(); delete [] buffer; } --- 55,70 ---- SerializerTest::prepareUnserialize() { ! streamOut_.packets().endWriteMessage(); ! ! // Read the serialized message in 'streamOut_' int length = streamOut_.packets().getFirstMessageLength(); void *buffer = new char[length]; ! streamOut_.packets().read( buffer, length ); streamOut_.packets().discardFirstMessage(); ! // and write the serialized message back in 'streamIn_' ! streamIn_.packets().beginWriteMessage(); ! streamIn_.packets().write( buffer, length ); ! streamIn_.packets().endWriteMessage(); delete [] buffer; } |