Author: tabish Date: Sat Apr 4 00:31:22 2009 New Revision: 761846 URL: http://svn.apache.org/viewvc?rev=761846&view=rev Log: https://issues.apache.org/activemq/browse/AMQCPP-232 Added the submitted unit test patch to provide more code coverage of the OpenWireStringSupport class. Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/wireformat/openwire/utils/OpenwireStringSupportTest.cpp activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/wireformat/openwire/utils/OpenwireStringSupportTest.h Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/wireformat/openwire/utils/OpenwireStringSupportTest.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/wireformat/openwire/utils/OpenwireStringSupportTest.cpp?rev=761846&r1=761845&r2=761846&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/wireformat/openwire/utils/OpenwireStringSupportTest.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/wireformat/openwire/utils/OpenwireStringSupportTest.cpp Sat Apr 4 00:31:22 2009 @@ -27,11 +27,42 @@ using namespace std; using namespace decaf; using namespace decaf::io; +using namespace decaf::lang; using namespace activemq; using namespace activemq::wireformat; using namespace activemq::wireformat::openwire; using namespace activemq::wireformat::openwire::utils; + +//////////////////////////////////////////////////////////////////////////////// +void OpenwireStringSupportTest::testHelper( unsigned char* input, int inputLength, + unsigned char* output, int outputLength, + bool negative ) { + try { + + ByteArrayInputStream bytesIn; + ByteArrayOutputStream bytesOut; + + DataInputStream dataIn( &bytesIn ); + DataOutputStream dataOut( &bytesOut ); + + bytesIn.setByteArray( input, inputLength ); + + string resultStr = OpenwireStringSupport::readString( dataIn ); + if( !negative ) { + CPPUNIT_ASSERT( resultStr == std::string( (char*)output, outputLength ) ); + + OpenwireStringSupport::writeString( dataOut, &resultStr ); + CPPUNIT_ASSERT( bytesOut.toString() == std::string( (char*)input, inputLength ) ); + } else { + CPPUNIT_ASSERT( 0 ); + } + + } catch( Exception& e ) { + CPPUNIT_ASSERT( negative ); + } +} + //////////////////////////////////////////////////////////////////////////////// void OpenwireStringSupportTest::test() { @@ -51,4 +82,53 @@ string resultStr = OpenwireStringSupport::readString( dataIn ); CPPUNIT_ASSERT( testStr == resultStr ); + + // Test data with 1-byte UTF8 encoding. + { + unsigned char input[] = {0x00, 0x0B, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64}; + unsigned char output[] = {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64}; + + testHelper( input, sizeof(input)/sizeof(unsigned char), + output, sizeof(output)/sizeof(unsigned char), false ); + } + + // Test data with 2-byte UT8 encoding. + { + unsigned char input[] = {0x00, 0x04, 0xC2, 0xA9, 0xC3, 0xA6}; + unsigned char output[] = {0xA9, 0xE6}; + testHelper( input, sizeof(input)/sizeof(unsigned char), + output, sizeof(output)/sizeof(unsigned char), false ); + } + + // Test data with value greater than 255 in 2-byte encoding. + // Expect : IO Exception + { + unsigned char input[] = {0x00, 0x04, 0xC8, 0xA9, 0xC3, 0xA6}; + testHelper( input, sizeof(input)/sizeof(unsigned char), NULL, 0, true ); + } + + // Test data with value greater than 255 in 3-byte encoding. + // Expect : IO Exception + { + unsigned char input[] = {0x00, 0x05, 0xE8, 0xA8, 0xA9, 0xC3, 0xA6}; + testHelper( input, sizeof(input)/sizeof(unsigned char), NULL, 0, true ); + } + + // Test data with 1-byte encoding with embedded NULL's. + { + unsigned char input[] = {0x00, 0x0D, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x00, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x00}; + unsigned char output[] = {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x00, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x00}; + + testHelper( input, sizeof(input)/sizeof(unsigned char), + output, sizeof(output)/sizeof(unsigned char), false ); + } + + // Test data with 1-byte and 2-byte encoding with embedded NULL's. + { + unsigned char input[] = {0x00, 0x11, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x00, 0xC2, 0xA9, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x00, 0xC3, 0xA6}; + unsigned char output[] = {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x00, 0xA9, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x00, 0xE6}; + + testHelper( input, sizeof(input)/sizeof(unsigned char), + output, sizeof(output)/sizeof(unsigned char), false ); + } } Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/wireformat/openwire/utils/OpenwireStringSupportTest.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/wireformat/openwire/utils/OpenwireStringSupportTest.h?rev=761846&r1=761845&r2=761846&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/wireformat/openwire/utils/OpenwireStringSupportTest.h (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/wireformat/openwire/utils/OpenwireStringSupportTest.h Sat Apr 4 00:31:22 2009 @@ -39,6 +39,9 @@ void test(); + void testHelper( unsigned char* input, int inputLength, + unsigned char* output, int outputLength, bool negative ); + }; }}}}