You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2007/01/10 16:18:58 UTC
svn commit: r494847 - in
/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io:
DataInputStreamTest.h DataOutputStreamTest.h
Author: tabish
Date: Wed Jan 10 07:18:58 2007
New Revision: 494847
URL: http://svn.apache.org/viewvc?view=rev&rev=494847
Log:
http://issues.apache.org/activemq/browse/AMQCPP-25
Fixed code that was breaking solaris with misaligned reads
Modified:
incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/DataInputStreamTest.h
incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/DataOutputStreamTest.h
Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/DataInputStreamTest.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/DataInputStreamTest.h?view=diff&rev=494847&r1=494846&r2=494847
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/DataInputStreamTest.h (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/DataInputStreamTest.h Wed Jan 10 07:18:58 2007
@@ -35,114 +35,106 @@
namespace activemq{
namespace io{
-
- class DataInputStreamTest : public CppUnit::TestFixture {
-
- CPPUNIT_TEST_SUITE( DataInputStreamTest );
- CPPUNIT_TEST( test );
- CPPUNIT_TEST_SUITE_END();
-
- public:
-
- virtual void setUp(){};
- virtual void tearDown(){};
- void test(){
-
- unsigned char buffer[1000];
- int ix = 0;
-
- unsigned char byteVal = (unsigned char)'T';
- uint16_t shortVal = 5;
- uint32_t intVal = 10000;
- uint64_t longVal = 1000000000;
- float floatVal = 10.0f;
- double doubleVal = 100.0;
- unsigned char arrayVal[3] = {
- 'a', 'b', 'c'
- };
- std::string stringVal1 = "ASCII_String";
- std::string stringVal2 = "UTF8_String";
-
- int size = sizeof(char);
- memcpy( (char*)(buffer+ix), (char*)&byteVal, size );
- ix += size;
-
- size = sizeof(uint16_t);
- uint16_t tempShort = util::Endian::byteSwap(shortVal);
- memcpy( (char*)(buffer+ix), (char*)&tempShort, size );
- ix += size;
-
- size = sizeof(uint32_t);
- uint32_t tempInt = util::Endian::byteSwap(intVal);
- memcpy( (char*)(buffer+ix), (char*)&tempInt, size );
- ix += size;
-
- size = sizeof(uint64_t);
- uint64_t tempLong = util::Endian::byteSwap(longVal);
- memcpy( (char*)(buffer+ix), (char*)&tempLong, size );
- ix += size;
-
- size = sizeof(float);
- float tempFloat = util::Endian::byteSwap(floatVal);
- memcpy( (char*)(buffer+ix), (char*)&tempFloat, size );
- ix += size;
-
- size = sizeof(double);
- double tempDouble = util::Endian::byteSwap(doubleVal);
- memcpy( (char*)(buffer+ix), (char*)&tempDouble, size );
- ix += size;
-
- size = 3;
- memcpy( (char*)(buffer+ix), (char*)&arrayVal, size );
- ix += size;
+
+ class DataInputStreamTest : public CppUnit::TestFixture {
+
+ CPPUNIT_TEST_SUITE( DataInputStreamTest );
+ CPPUNIT_TEST( test );
+ CPPUNIT_TEST_SUITE_END();
- memcpy( (char*)(buffer+ix), stringVal1.c_str(), stringVal1.size() + 1 );
- ix += stringVal1.size() + 1;
+ public:
+
+ virtual void setUp(){};
+ virtual void tearDown(){};
+ void test(){
+
+ unsigned char buffer[30];
+ int ix = 0;
+
+ unsigned char byteVal = (unsigned char)'T';
+ unsigned short shortVal = 5;
+ unsigned int intVal = 10000;
+ unsigned long long longVal = 1000000000;
+ float floatVal = 10.0f;
+ double doubleVal = 100.0;
+ unsigned char arrayVal[3] = {
+ 'a', 'b', 'c'
+ };
+
+ int size = sizeof(char);
+ memcpy( (char*)(buffer+ix), (char*)&byteVal, size );
+ ix += size;
+
+ size = sizeof(unsigned short);
+ unsigned short tempShort = util::Endian::byteSwap(shortVal);
+ memcpy( (char*)(buffer+ix), (char*)&tempShort, size );
+ ix += size;
+
+ size = sizeof(unsigned int);
+ unsigned int tempInt = util::Endian::byteSwap(intVal);
+ memcpy( (char*)(buffer+ix), (char*)&tempInt, size );
+ ix += size;
+
+ size = sizeof(unsigned long long);
+ unsigned long long tempLong = util::Endian::byteSwap(longVal);
+ memcpy( (char*)(buffer+ix), (char*)&tempLong, size );
+ ix += size;
- size = sizeof(uint16_t);
- uint16_t tempShort2 = util::Endian::byteSwap((unsigned short)stringVal2.size());
- memcpy( (char*)(buffer+ix), (char*)&tempShort2, size );
+ size = sizeof(float);
+ float tempFloat = util::Endian::byteSwap(floatVal);
+ unsigned int x1 = *((unsigned int*)&floatVal );
+ unsigned int x2 = *((unsigned int*)&tempFloat );
+ memcpy( (char*)(buffer+ix), (char*)&tempFloat, size );
ix += size;
- memcpy( (char*)(buffer+ix), stringVal2.c_str(), stringVal2.size() );
- ix += stringVal2.size();
- // Create the stream with the buffer we just wrote to.
- ByteArrayInputStream myStream( buffer, 1000 );
- DataInputStream reader( &myStream );
-
- byteVal = reader.readByte();
- CPPUNIT_ASSERT( byteVal == (unsigned char)'T' );
-
- shortVal = reader.readShort();
- CPPUNIT_ASSERT( shortVal == 5 );
-
- intVal = reader.readInt();
- CPPUNIT_ASSERT( intVal == 10000 );
-
- longVal = reader.readLong();
- CPPUNIT_ASSERT( longVal == 1000000000 );
-
- floatVal = reader.readFloat();
- CPPUNIT_ASSERT( floatVal == 10.0f );
-
- doubleVal = reader.readDouble();
- CPPUNIT_ASSERT( doubleVal == 100.0 );
-
- reader.read( arrayVal, 0, 3 );
- CPPUNIT_ASSERT( arrayVal[0] == 'a' );
- CPPUNIT_ASSERT( arrayVal[1] == 'b' );
- CPPUNIT_ASSERT( arrayVal[2] == 'c' );
+ size = sizeof(double);
+ double tempDouble = util::Endian::byteSwap(doubleVal);
+ memcpy( (char*)(buffer+ix), (char*)&tempDouble, size );
+ ix += size;
- std::string resultStrVal1 = reader.readString();
- CPPUNIT_ASSERT( resultStrVal1 == stringVal1 );
-
- std::string resultStrVal2 = reader.readUTF();
- CPPUNIT_ASSERT( resultStrVal2 == stringVal2 );
+ size = 3;
+ memcpy( (char*)(buffer+ix), (char*)&arrayVal, size );
+ ix += size;
- }
+ // Create the stream with the buffer we just wrote to.
+ ByteArrayInputStream myStream( buffer, 30 );
+ DataInputStream reader( &myStream );
+
+ byteVal = reader.readByte();
+ //std::cout << "Byte Value = " << byteVal << std::endl;
+ CPPUNIT_ASSERT( byteVal == (unsigned char)'T' );
+
+ shortVal = reader.readShort();
+ //std::cout << "short Value = " << shortVal << std::endl;
+ CPPUNIT_ASSERT( shortVal == 5 );
+
+ intVal = reader.readInt();
+ //std::cout << "int Value = " << intVal << std::endl;
+ CPPUNIT_ASSERT( intVal == 10000 );
+
+ longVal = reader.readLong();
+ //std::cout << "long long Value = " << longVal << std::endl;
+ CPPUNIT_ASSERT( longVal == 1000000000 );
+
+ floatVal = reader.readFloat();
+ //std::cout << "float Value = " << floatVal << std::endl;
+ CPPUNIT_ASSERT( floatVal == 10.0f );
+
+ doubleVal = reader.readDouble();
+ //std::cout << "double Value = " << doubleVal << std::endl;
+ CPPUNIT_ASSERT( doubleVal == 100.0 );
+
+ reader.read( arrayVal, 0, 3 );
+ //std::cout << "char[0] Value = " << (int)arrayVal[0] << std::endl;
+ CPPUNIT_ASSERT( arrayVal[0] == 'a' );
+ //std::cout << "char[1] Value = " << (int)arrayVal[1] << std::endl;
+ CPPUNIT_ASSERT( arrayVal[1] == 'b' );
+ //std::cout << "char[2] Value = " << (int)arrayVal[2] << std::endl;
+ CPPUNIT_ASSERT( arrayVal[2] == 'c' );
+ }
- };
-
+ };
+
}}
#endif /*ACTIVEMQ_IO_DATAINPUTSTREAMTEST_H_*/
Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/DataOutputStreamTest.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/DataOutputStreamTest.h?view=diff&rev=494847&r1=494846&r2=494847
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/DataOutputStreamTest.h (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/io/DataOutputStreamTest.h Wed Jan 10 07:18:58 2007
@@ -49,8 +49,6 @@
unsigned char arrayVal[3] = {
'a', 'b', 'c'
};
- std::string stringVal1 = "ASCII_String";
- std::string stringVal2 = "UTF8_String";
// Create the stream with the buffer we just wrote to.
ByteArrayOutputStream myStream;
@@ -63,8 +61,6 @@
writer.writeFloat( floatVal );
writer.writeDouble( doubleVal );
writer.write( arrayVal, 3 );
- writer.writeBytes( stringVal1 );
- writer.writeUTF( stringVal2 );
const unsigned char* buffer = myStream.getByteArray();
int ix = 0;
@@ -73,48 +69,35 @@
CPPUNIT_ASSERT( tempByte == byteVal );
ix += sizeof( tempByte );
- uint16_t tempShort = util::Endian::byteSwap( *(uint16_t*)(buffer+ix) );
+ unsigned short tempShort = 0;
+ memcpy( &tempShort, buffer+ix, sizeof( unsigned short ) );
+ tempShort = util::Endian::byteSwap( tempShort );
CPPUNIT_ASSERT( tempShort == shortVal );
ix += sizeof( tempShort );
- uint32_t tempInt = util::Endian::byteSwap( *(uint32_t*)(buffer+ix) );
+ unsigned int tempInt = 0;
+ memcpy( &tempInt, buffer+ix, sizeof( unsigned int ) );
+ tempInt = util::Endian::byteSwap( tempInt );
CPPUNIT_ASSERT( tempInt == intVal );
ix += sizeof( tempInt );
- uint64_t tempLong = util::Endian::byteSwap( *(uint64_t*)(buffer+ix) );
+ unsigned long long tempLong = 0;
+ memcpy( &tempLong, buffer+ix, sizeof( unsigned long long ) );
+ tempLong = util::Endian::byteSwap( tempLong );
CPPUNIT_ASSERT( tempLong == longVal );
ix += sizeof( tempLong );
- float tempFloat = util::Endian::byteSwap( *(float*)(buffer+ix) );
+ float tempFloat = 0;
+ memcpy( &tempFloat, buffer+ix, sizeof( float ) );
+ tempFloat = util::Endian::byteSwap( tempFloat );
CPPUNIT_ASSERT( tempFloat == floatVal );
ix += sizeof( tempFloat );
- double tempDouble = util::Endian::byteSwap( *(double*)(buffer+ix) );
+ double tempDouble = 0;
+ memcpy( &tempDouble, buffer+ix, sizeof( double ) );
+ tempDouble = util::Endian::byteSwap( tempDouble );
CPPUNIT_ASSERT( tempDouble == doubleVal );
ix += sizeof( tempDouble );
-
- char tempChar1 = *(char*)(buffer+ix);
- CPPUNIT_ASSERT( tempChar1 == arrayVal[0] );
- ix += sizeof( tempChar1 );
-
- char tempChar2 = *(char*)(buffer+ix);
- CPPUNIT_ASSERT( tempChar2 == arrayVal[1] );
- ix += sizeof( tempChar2 );
-
- char tempChar3 = *(char*)(buffer+ix);
- CPPUNIT_ASSERT( tempChar3 == arrayVal[2] );
- ix += sizeof( tempChar3 );
-
- std::string tempStr1( (char*)(buffer+ix), stringVal1.size() );
- CPPUNIT_ASSERT( tempStr1 == stringVal1 );
- ix += stringVal1.size() + 1;
-
- uint16_t tempShort1 = util::Endian::byteSwap( *(uint16_t*)(buffer+ix) );
- CPPUNIT_ASSERT( tempShort1 == stringVal2.size() );
- ix += sizeof( tempShort1 );
- std::string tempStr2( (char*)(buffer+ix), tempShort1 );
- CPPUNIT_ASSERT( tempStr2 == stringVal2 );
- ix += stringVal2.size();
}