activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1036203 - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/activemq/commands/ main/cms/ test/ test/activemq/commands/
Date Wed, 17 Nov 2010 20:26:22 GMT
Author: tabish
Date: Wed Nov 17 20:26:22 2010
New Revision: 1036203

URL: http://svn.apache.org/viewvc?rev=1036203&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQCPP-329

Completed unit test and some fixes for problems that the test exposed.  

Added:
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/XATransactionIdTest.cpp
  (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/XATransactionIdTest.h
  (with props)
Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/XATransactionId.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/Xid.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/XATransactionId.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/XATransactionId.cpp?rev=1036203&r1=1036202&r2=1036203&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/XATransactionId.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/commands/XATransactionId.cpp
Wed Nov 17 20:26:22 2010
@@ -40,7 +40,7 @@ using namespace decaf::lang::exceptions;
  */
 
 ////////////////////////////////////////////////////////////////////////////////
-XATransactionId::XATransactionId() 
+XATransactionId::XATransactionId()
     : TransactionId(), cms::Xid(), formatId(0), globalTransactionId(), branchQualifier()
{
 
 }
@@ -329,7 +329,11 @@ bool XATransactionId::equals( const cms:
 int XATransactionId::getBranchQualifier( unsigned char* buffer, int size ) const {
 
     if( size < 0 ) {
-        throw cms::XAException("Invalid negative size value passed to getBranchQualifier()");
+        throw cms::XAException("Error: Negative size value passed to getBranchQualifier()");
+    }
+
+    if( buffer == NULL ) {
+        throw cms::XAException("Error: NULL buffer pointer passed to getBranchQualifier()");
     }
 
     if( size < (int)this->branchQualifier.size() ) {
@@ -349,7 +353,11 @@ int XATransactionId::getBranchQualifier(
 int XATransactionId::getGlobalTransactionId( unsigned char* buffer, int size ) const {
 
     if( size < 0 ) {
-        throw cms::XAException("Invalid negative size value passed to getGlobalTransactionId()");
+        throw cms::XAException("Error: Negative size value passed to getGlobalTransactionId()");
+    }
+
+    if( buffer == NULL ) {
+        throw cms::XAException("Error: NULL buffer pointer passed to getGlobalTransactionId()");
     }
 
     if( size < (int)this->globalTransactionId.size() ) {

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/Xid.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/Xid.h?rev=1036203&r1=1036202&r2=1036203&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/Xid.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/Xid.h Wed Nov 17 20:26:22 2010
@@ -88,7 +88,7 @@ namespace cms {
          * @return the number of bytes copied into the buffer, or -1 if the buffer
          *         provided was not large enough.
          *
-         * @throws CMSException if the size parameter is less than zero or buffer is NULL.
+         * @throws XAException if the size parameter is less than zero or buffer is NULL.
          */
         virtual int getBranchQualifier( unsigned char* buffer, int size ) const = 0;
 
@@ -114,7 +114,7 @@ namespace cms {
          * @return the number of bytes copied into the buffer, or -1 if the buffer
          *         provided was not large enough.
          *
-         * @throws CMSException if the size parameter is less than zero or buffer is NULL.
+         * @throws XAException if the size parameter is less than zero or buffer is NULL.
          */
         virtual int getGlobalTransactionId( unsigned char* buffer, int size ) const = 0;
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am?rev=1036203&r1=1036202&r2=1036203&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am Wed Nov 17 20:26:22 2010
@@ -33,6 +33,7 @@ cc_sources = \
     activemq/commands/ActiveMQTopicTest.cpp \
     activemq/commands/BrokerIdTest.cpp \
     activemq/commands/BrokerInfoTest.cpp \
+    activemq/commands/XATransactionIdTest.cpp \
     activemq/core/ActiveMQConnectionFactoryTest.cpp \
     activemq/core/ActiveMQConnectionTest.cpp \
     activemq/core/ActiveMQSessionTest.cpp \
@@ -244,6 +245,7 @@ h_sources = \
     activemq/commands/ActiveMQTopicTest.h \
     activemq/commands/BrokerIdTest.h \
     activemq/commands/BrokerInfoTest.h \
+    activemq/commands/XATransactionIdTest.h \
     activemq/core/ActiveMQConnectionFactoryTest.h \
     activemq/core/ActiveMQConnectionTest.h \
     activemq/core/ActiveMQSessionTest.h \

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/XATransactionIdTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/XATransactionIdTest.cpp?rev=1036203&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/XATransactionIdTest.cpp
(added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/XATransactionIdTest.cpp
Wed Nov 17 20:26:22 2010
@@ -0,0 +1,298 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "XATransactionIdTest.h"
+
+#include <memory>
+#include <activemq/commands/XATransactionId.h>
+
+#include <cms/Xid.h>
+#include <cms/XAException.h>
+
+using namespace std;
+using namespace cms;
+using namespace activemq;
+using namespace activemq::commands;
+
+////////////////////////////////////////////////////////////////////////////////
+namespace {
+
+    class DummyXid : public cms::Xid {
+    private:
+
+        std::vector<unsigned char> branchQualifier;
+        std::vector<unsigned char> globalTransactionId;
+
+    public:
+
+        DummyXid() {
+
+            for(int i = 0; i < Xid::MAXBQUALSIZE; ++i ) {
+                this->branchQualifier.push_back( (unsigned char)i );
+            }
+
+            for(int i = 0; i < Xid::MAXGTRIDSIZE; ++i ) {
+                this->globalTransactionId.push_back( (unsigned char)i );
+            }
+        }
+
+        virtual ~DummyXid() {
+        }
+
+        virtual Xid* clone() const {
+            return new DummyXid();
+        }
+
+        virtual bool equals( const Xid* other ) const {
+
+            if( (void*)this == other ) {
+                return true;
+            }
+
+            if( other == NULL ) {
+                return false;
+            }
+
+            if( this->getFormatId() != other->getFormatId() ) {
+                return false;
+            }
+
+            std::vector<unsigned char> otherBQual( Xid::MAXBQUALSIZE );
+            std::vector<unsigned char> otherGblTx( Xid::MAXGTRIDSIZE );
+
+            other->getBranchQualifier( &otherBQual[0], Xid::MAXBQUALSIZE );
+            other->getGlobalTransactionId( &otherGblTx[0], Xid::MAXGTRIDSIZE );
+
+            if( this->branchQualifier != otherBQual ) {
+                return false;
+            }
+
+            if( this->globalTransactionId != otherGblTx ) {
+                return false;
+            }
+
+            return true;
+        }
+
+        virtual int getBranchQualifier( unsigned char* buffer, int size ) const {
+
+            if( size < 0 ) {
+                throw XAException("Specified Buffer Size was negative.");
+            }
+
+            if( buffer == 0 ) {
+                throw XAException("The Buffer provided was null.");
+            }
+
+            if( size < Xid::MAXBQUALSIZE ) {
+                return -1;
+            }
+
+            for( int i = 0; i < Xid::MAXBQUALSIZE; ++i ) {
+                buffer[i] = this->branchQualifier[i];
+            }
+
+            return Xid::MAXBQUALSIZE;
+        }
+
+        virtual int getFormatId() const {
+            return 42;
+        }
+
+        virtual int getGlobalTransactionId( unsigned char* buffer, int size ) const {
+            if( size < 0 ) {
+                throw XAException("Specified Buffer Size was negative.");
+            }
+
+            if( buffer == 0 ) {
+                throw XAException("The Buffer provided was null.");
+            }
+
+            if( size < Xid::MAXGTRIDSIZE ) {
+                return -1;
+            }
+
+            for( int i = 0; i < Xid::MAXGTRIDSIZE; ++i ) {
+                buffer[i] = this->globalTransactionId[i];
+            }
+
+            return Xid::MAXGTRIDSIZE;
+        }
+
+    };
+}
+
+////////////////////////////////////////////////////////////////////////////////
+XATransactionIdTest::XATransactionIdTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+XATransactionIdTest::~XATransactionIdTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void XATransactionIdTest::testConstructor() {
+
+    XATransactionId id;
+
+    CPPUNIT_ASSERT_EQUAL( 0, id.getFormatId() );
+    CPPUNIT_ASSERT_EQUAL( 0, (int)id.getBranchQualifier().size() );
+    CPPUNIT_ASSERT_EQUAL( 0, (int)id.getGlobalTransactionId().size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void XATransactionIdTest::testConstructor2() {
+
+    DummyXid myXid;
+    XATransactionId id( &myXid );
+
+    CPPUNIT_ASSERT_EQUAL( 42, id.getFormatId() );
+    CPPUNIT_ASSERT_EQUAL( Xid::MAXBQUALSIZE, (int)id.getBranchQualifier().size() );
+    CPPUNIT_ASSERT_EQUAL( Xid::MAXGTRIDSIZE, (int)id.getGlobalTransactionId().size() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void XATransactionIdTest::testEquals() {
+
+    DummyXid myXid;
+    XATransactionId id( &myXid );
+
+    CPPUNIT_ASSERT_EQUAL( 42, id.getFormatId() );
+    CPPUNIT_ASSERT_EQUAL( Xid::MAXBQUALSIZE, (int)id.getBranchQualifier().size() );
+    CPPUNIT_ASSERT_EQUAL( Xid::MAXGTRIDSIZE, (int)id.getGlobalTransactionId().size() );
+
+    CPPUNIT_ASSERT( id.equals( &myXid ) );
+    CPPUNIT_ASSERT( myXid.equals( &id ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void XATransactionIdTest::testClone() {
+
+    DummyXid myXid;
+    XATransactionId id( &myXid );
+    std::auto_ptr<cms::Xid> cloned( id.clone() );
+
+    CPPUNIT_ASSERT_EQUAL( 42, id.getFormatId() );
+    CPPUNIT_ASSERT_EQUAL( Xid::MAXBQUALSIZE, (int)id.getBranchQualifier().size() );
+    CPPUNIT_ASSERT_EQUAL( Xid::MAXGTRIDSIZE, (int)id.getGlobalTransactionId().size() );
+
+    CPPUNIT_ASSERT_EQUAL( 42, cloned->getFormatId() );
+
+    CPPUNIT_ASSERT( myXid.equals( cloned.get() ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void XATransactionIdTest::testGetFormatId() {
+
+    XATransactionId id;
+
+    CPPUNIT_ASSERT_EQUAL( 0, id.getFormatId() );
+
+    id.setFormatId( 42 );
+
+    CPPUNIT_ASSERT_EQUAL( 42, id.getFormatId() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void XATransactionIdTest::testGetBranchQualifier() {
+
+    XATransactionId id;
+
+    CPPUNIT_ASSERT_EQUAL( 0, (int)id.getBranchQualifier().size() );
+
+    std::vector<unsigned char> bqual;
+    for( int i = 0; i < cms::Xid::MAXBQUALSIZE; ++i ) {
+        bqual.push_back( (unsigned char)(i+1) );
+    }
+    id.setBranchQualifier( bqual );
+
+    CPPUNIT_ASSERT( bqual == id.getBranchQualifier() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void XATransactionIdTest::testGetGlobalTransactionId() {
+
+    XATransactionId id;
+
+    CPPUNIT_ASSERT_EQUAL( 0, (int)id.getGlobalTransactionId().size() );
+
+    std::vector<unsigned char> gtx;
+    for( int i = 0; i < cms::Xid::MAXGTRIDSIZE; ++i ) {
+        gtx.push_back( (unsigned char)(i+1) );
+    }
+    id.setGlobalTransactionId( gtx );
+
+    CPPUNIT_ASSERT( gtx == id.getGlobalTransactionId() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void XATransactionIdTest::testGetBranchQualifier1() {
+
+    XATransactionId id;
+    std::vector<unsigned char> buffer( Xid::MAXBQUALSIZE );
+
+    CPPUNIT_ASSERT_EQUAL( 0, (int)id.getBranchQualifier().size() );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should have thrown an XAException",
+        id.getBranchQualifier( NULL, 1 ),
+        XAException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should have thrown an XAException",
+        id.getBranchQualifier( &buffer[0], -1 ),
+        XAException );
+
+    std::vector<unsigned char> gtx;
+    for( int i = 0; i < cms::Xid::MAXBQUALSIZE; ++i ) {
+        gtx.push_back( (unsigned char)(i+1) );
+    }
+    id.setBranchQualifier( gtx );
+
+    CPPUNIT_ASSERT( id.getBranchQualifier( &buffer[0], 1 ) == -1 );
+    CPPUNIT_ASSERT( id.getBranchQualifier( &buffer[0], Xid::MAXBQUALSIZE ) == Xid::MAXBQUALSIZE
);
+    CPPUNIT_ASSERT( gtx == buffer );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void XATransactionIdTest::testGetGlobalTransactionId1() {
+
+    XATransactionId id;
+    std::vector<unsigned char> buffer( Xid::MAXGTRIDSIZE );
+
+    CPPUNIT_ASSERT_EQUAL( 0, (int)id.getGlobalTransactionId().size() );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should have thrown an XAException",
+        id.getGlobalTransactionId( NULL, 1 ),
+        XAException );
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should have thrown an XAException",
+        id.getGlobalTransactionId( &buffer[0], -1 ),
+        XAException );
+
+    std::vector<unsigned char> gtx;
+    for( int i = 0; i < cms::Xid::MAXGTRIDSIZE; ++i ) {
+        gtx.push_back( (unsigned char)(i+1) );
+    }
+    id.setGlobalTransactionId( gtx );
+
+    CPPUNIT_ASSERT( id.getGlobalTransactionId( &buffer[0], 1 ) == -1 );
+    CPPUNIT_ASSERT( id.getGlobalTransactionId( &buffer[0], Xid::MAXGTRIDSIZE ) == Xid::MAXGTRIDSIZE
);
+    CPPUNIT_ASSERT( gtx == buffer );
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/XATransactionIdTest.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/XATransactionIdTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/XATransactionIdTest.h?rev=1036203&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/XATransactionIdTest.h
(added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/XATransactionIdTest.h
Wed Nov 17 20:26:22 2010
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ACTIVEMQ_COMMANDS_XATRANSACTIONIDTEST_H_
+#define _ACTIVEMQ_COMMANDS_XATRANSACTIONIDTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace activemq {
+namespace commands {
+
+    class XATransactionIdTest : public CppUnit::TestFixture {
+
+        CPPUNIT_TEST_SUITE( XATransactionIdTest );
+        CPPUNIT_TEST( testConstructor );
+        CPPUNIT_TEST( testConstructor2 );
+        CPPUNIT_TEST( testEquals );
+        CPPUNIT_TEST( testClone );
+        CPPUNIT_TEST( testGetFormatId );
+        CPPUNIT_TEST( testGetBranchQualifier );
+        CPPUNIT_TEST( testGetGlobalTransactionId );
+        CPPUNIT_TEST( testGetBranchQualifier1 );
+        CPPUNIT_TEST( testGetGlobalTransactionId1 );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+
+        XATransactionIdTest();
+        virtual ~XATransactionIdTest();
+
+        void testConstructor();
+        void testConstructor2();
+        void testEquals();
+        void testClone();
+        void testGetFormatId();
+        void testGetBranchQualifier();
+        void testGetGlobalTransactionId();
+        void testGetBranchQualifier1();
+        void testGetGlobalTransactionId1();
+
+    };
+
+}}
+
+#endif /* _ACTIVEMQ_COMMANDS_XATRANSACTIONIDTEST_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/commands/XATransactionIdTest.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp?rev=1036203&r1=1036202&r2=1036203&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp Wed Nov 17 20:26:22
2010
@@ -42,6 +42,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION( activem
 CPPUNIT_TEST_SUITE_REGISTRATION( activemq::commands::ActiveMQBytesMessageTest );
 #include <activemq/commands/ActiveMQStreamMessageTest.h>
 CPPUNIT_TEST_SUITE_REGISTRATION( activemq::commands::ActiveMQStreamMessageTest );
+#include <activemq/commands/XATransactionIdTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( activemq::commands::XATransactionIdTest );
 
 #include <activemq/wireformat/openwire/marshal/BaseDataStreamMarshallerTest.h>
 CPPUNIT_TEST_SUITE_REGISTRATION( activemq::wireformat::openwire::marshal::BaseDataStreamMarshallerTest
);



Mime
View raw message