activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nmitt...@apache.org
Subject svn commit: r487892 - in /incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq: connector/stomp/StompConnectorTest.h connector/stomp/StompFrameTest.h core/ActiveMQSessionTest.h
Date Sat, 16 Dec 2006 21:28:23 GMT
Author: nmittler
Date: Sat Dec 16 13:28:22 2006
New Revision: 487892

URL: http://svn.apache.org/viewvc?view=rev&rev=487892
Log:
[AMQCPP-27] - Fixed a few memory leaks in unit tests

Modified:
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompConnectorTest.h
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompFrameTest.h
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.h

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompConnectorTest.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompConnectorTest.h?view=diff&rev=487892&r1=487891&r2=487892
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompConnectorTest.h
(original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompConnectorTest.h
Sat Dec 16 13:28:22 2006
@@ -93,30 +93,37 @@
             StompResponseBuilder responseBuilder("testConnectionId");
             transport::DummyTransport transport( &responseBuilder );
             util::SimpleProperties properties;
-            StompConnector connector( &transport, properties );
-            connector.start();
             
-            SessionInfo* info1 = connector.createSession( cms::Session::AUTO_ACKNOWLEDGE
);
+            // Using a pointer for the connector so we ensure the proper destruction
+            // order of objects - connector before the transport.
+            StompConnector* connector = new StompConnector( &transport, properties );
+            
+            connector->start();
+            
+            SessionInfo* info1 = connector->createSession( cms::Session::AUTO_ACKNOWLEDGE
);
             CPPUNIT_ASSERT( info1->getAckMode() == cms::Session::AUTO_ACKNOWLEDGE );
             CPPUNIT_ASSERT( info1->getConnectionId() == connectionId );
             
-            SessionInfo* info2 = connector.createSession( cms::Session::DUPS_OK_ACKNOWLEDGE
);
+            SessionInfo* info2 = connector->createSession( cms::Session::DUPS_OK_ACKNOWLEDGE
);
             CPPUNIT_ASSERT( info2->getAckMode() == cms::Session::DUPS_OK_ACKNOWLEDGE );
             CPPUNIT_ASSERT( info2->getConnectionId() == connectionId );
             
-            SessionInfo* info3 = connector.createSession( cms::Session::CLIENT_ACKNOWLEDGE
);
+            SessionInfo* info3 = connector->createSession( cms::Session::CLIENT_ACKNOWLEDGE
);
             CPPUNIT_ASSERT( info3->getAckMode() == cms::Session::CLIENT_ACKNOWLEDGE );
             CPPUNIT_ASSERT( info3->getConnectionId() == connectionId );
             
-            SessionInfo* info4 = connector.createSession( cms::Session::SESSION_TRANSACTED
);
+            SessionInfo* info4 = connector->createSession( cms::Session::SESSION_TRANSACTED
);
             CPPUNIT_ASSERT( info4->getAckMode() == cms::Session::SESSION_TRANSACTED );
             CPPUNIT_ASSERT( info4->getConnectionId() == connectionId );
             
-            connector.destroyResource( info1 );
-            connector.destroyResource( info2 );
-            connector.destroyResource( info3 );
-            connector.destroyResource( info4 );
-
+            connector->destroyResource( info1 );
+            connector->destroyResource( info2 );
+            connector->destroyResource( info3 );
+            connector->destroyResource( info4 );
+
+            // Delete the connector here - this assures the propery order
+            // of destruction.
+            delete connector;
         }
         
         void testConsumers()
@@ -125,50 +132,58 @@
             StompResponseBuilder responseBuilder("testConnectionId");
             transport::DummyTransport transport( &responseBuilder );
             util::SimpleProperties properties;
-            StompConnector connector( &transport, properties );
-            connector.start();
             
-            SessionInfo* info1 = connector.createSession( cms::Session::AUTO_ACKNOWLEDGE
);
+            // Using a pointer for the connector so we ensure the proper destruction
+            // order of objects - connector before the transport.
+            StompConnector* connector = new StompConnector( &transport, properties );
+            
+            connector->start();
+            
+            SessionInfo* info1 = connector->createSession( cms::Session::AUTO_ACKNOWLEDGE
);
             std::string sel1 = "";
             StompTopic dest1( "dummy.topic.1" );
-            ConsumerInfo* cinfo1 = connector.createConsumer( &dest1, info1, sel1 );
+            ConsumerInfo* cinfo1 = connector->createConsumer( &dest1, info1, sel1
);
             CPPUNIT_ASSERT( cinfo1->getSessionInfo() == info1 );
             CPPUNIT_ASSERT( cinfo1->getDestination().toString() == dest1.toString() );
             CPPUNIT_ASSERT( cinfo1->getMessageSelector() == sel1 );
             
-            SessionInfo* info2 = connector.createSession( cms::Session::DUPS_OK_ACKNOWLEDGE
);
+            SessionInfo* info2 = connector->createSession( cms::Session::DUPS_OK_ACKNOWLEDGE
);
             std::string sel2 = "mysel2";
             StompTopic dest2( "dummy.topic.2" );
-            ConsumerInfo* cinfo2 = connector.createConsumer( &dest2, info2, sel2 );
+            ConsumerInfo* cinfo2 = connector->createConsumer( &dest2, info2, sel2
);
             CPPUNIT_ASSERT( cinfo2->getSessionInfo() == info2 );
             CPPUNIT_ASSERT( cinfo2->getDestination().toString() == dest2.toString() );
             CPPUNIT_ASSERT( cinfo2->getMessageSelector() == sel2 );
             
-            SessionInfo* info3 = connector.createSession( cms::Session::CLIENT_ACKNOWLEDGE
);
+            SessionInfo* info3 = connector->createSession( cms::Session::CLIENT_ACKNOWLEDGE
);
             std::string sel3 = "mysel3";
             StompQueue dest3( "dummy.queue.1" );
-            ConsumerInfo* cinfo3 = connector.createConsumer( &dest3, info3, sel3 );
+            ConsumerInfo* cinfo3 = connector->createConsumer( &dest3, info3, sel3
);
             CPPUNIT_ASSERT( cinfo3->getSessionInfo() == info3 );
             CPPUNIT_ASSERT( cinfo3->getDestination().toString() == dest3.toString() );
             CPPUNIT_ASSERT( cinfo3->getMessageSelector() == sel3 );
             
-            SessionInfo* info4 = connector.createSession( cms::Session::SESSION_TRANSACTED
);
+            SessionInfo* info4 = connector->createSession( cms::Session::SESSION_TRANSACTED
);
             std::string sel4 = "";
             StompTopic dest4( "dummy.queue.2" );
-            ConsumerInfo* cinfo4 = connector.createConsumer( &dest4, info4, sel4 );
+            ConsumerInfo* cinfo4 = connector->createConsumer( &dest4, info4, sel4
);
             CPPUNIT_ASSERT( cinfo4->getSessionInfo() == info4 );
             CPPUNIT_ASSERT( cinfo4->getDestination().toString() == dest4.toString() );
             CPPUNIT_ASSERT( cinfo4->getMessageSelector() == sel4 );
             
-            connector.destroyResource( cinfo1 );
-            connector.destroyResource( cinfo2 );
-            connector.destroyResource( cinfo3 );
-            connector.destroyResource( cinfo4 );
-
-            connector.destroyResource( info1 );
-            connector.destroyResource( info2 );
-            connector.destroyResource( info3 );
-            connector.destroyResource( info4 );
+            connector->destroyResource( cinfo1 );
+            connector->destroyResource( cinfo2 );
+            connector->destroyResource( cinfo3 );
+            connector->destroyResource( cinfo4 );
+
+            connector->destroyResource( info1 );
+            connector->destroyResource( info2 );
+            connector->destroyResource( info3 );
+            connector->destroyResource( info4 );
+            
+            // Delete the connector here - this assures the propery order
+            // of destruction.
+            delete connector;
         }
 
         void testProducers()
@@ -177,42 +192,50 @@
             StompResponseBuilder responseBuilder("testConnectionId");
             transport::DummyTransport transport( &responseBuilder );
             util::SimpleProperties properties;
-            StompConnector connector( &transport, properties );
-            connector.start();
             
-            SessionInfo* info1 = connector.createSession( cms::Session::AUTO_ACKNOWLEDGE
);
+            // Using a pointer for the connector so we ensure the proper destruction
+            // order of objects - connector before the transport.
+            StompConnector* connector = new StompConnector( &transport, properties );
+            
+            connector->start();
+            
+            SessionInfo* info1 = connector->createSession( cms::Session::AUTO_ACKNOWLEDGE
);
             StompTopic dest1( "dummy.topic.1" );
-            ProducerInfo* pinfo1 = connector.createProducer( &dest1, info1 );
+            ProducerInfo* pinfo1 = connector->createProducer( &dest1, info1 );
             CPPUNIT_ASSERT( pinfo1->getSessionInfo() == info1 );
             CPPUNIT_ASSERT( pinfo1->getDestination().toString() == dest1.toString() );
             
-            SessionInfo* info2 = connector.createSession( cms::Session::DUPS_OK_ACKNOWLEDGE
);
+            SessionInfo* info2 = connector->createSession( cms::Session::DUPS_OK_ACKNOWLEDGE
);
             StompTopic dest2( "dummy.topic.2" );
-            ProducerInfo* pinfo2 = connector.createProducer( &dest2, info2 );
+            ProducerInfo* pinfo2 = connector->createProducer( &dest2, info2 );
             CPPUNIT_ASSERT( pinfo2->getSessionInfo() == info2 );
             CPPUNIT_ASSERT( pinfo2->getDestination().toString() == dest2.toString() );
             
-            SessionInfo* info3 = connector.createSession( cms::Session::CLIENT_ACKNOWLEDGE
);
+            SessionInfo* info3 = connector->createSession( cms::Session::CLIENT_ACKNOWLEDGE
);
             StompQueue dest3( "dummy.queue.1" );
-            ProducerInfo* pinfo3 = connector.createProducer( &dest3, info3 );
+            ProducerInfo* pinfo3 = connector->createProducer( &dest3, info3 );
             CPPUNIT_ASSERT( pinfo3->getSessionInfo() == info3 );
             CPPUNIT_ASSERT( pinfo3->getDestination().toString() == dest3.toString() );
             
-            SessionInfo* info4 = connector.createSession( cms::Session::SESSION_TRANSACTED
);
+            SessionInfo* info4 = connector->createSession( cms::Session::SESSION_TRANSACTED
);
             StompTopic dest4( "dummy.queue.2" );
-            ProducerInfo* pinfo4 = connector.createProducer( &dest4, info4 );
+            ProducerInfo* pinfo4 = connector->createProducer( &dest4, info4 );
             CPPUNIT_ASSERT( pinfo4->getSessionInfo() == info4 );
             CPPUNIT_ASSERT( pinfo4->getDestination().toString() == dest4.toString() );
             
-            connector.destroyResource( pinfo1 );
-            connector.destroyResource( pinfo2 );
-            connector.destroyResource( pinfo3 );
-            connector.destroyResource( pinfo4 );
-
-            connector.destroyResource( info1 );
-            connector.destroyResource( info2 );
-            connector.destroyResource( info3 );
-            connector.destroyResource( info4 );
+            connector->destroyResource( pinfo1 );
+            connector->destroyResource( pinfo2 );
+            connector->destroyResource( pinfo3 );
+            connector->destroyResource( pinfo4 );
+
+            connector->destroyResource( info1 );
+            connector->destroyResource( info2 );
+            connector->destroyResource( info3 );
+            connector->destroyResource( info4 );
+            
+            // Delete the connector here - this assures the propery order
+            // of destruction.
+            delete connector;
         }
         
         void testCommand()
@@ -221,36 +244,40 @@
             StompResponseBuilder responseBuilder("testConnectionId");
             transport::DummyTransport transport( &responseBuilder );
             util::SimpleProperties properties;
-            StompConnector connector( &transport, properties );
-            connector.start();
+            
+            // Using a pointer for the connector so we ensure the proper destruction
+            // order of objects - connector before the transport.
+            StompConnector* connector = new StompConnector( &transport, properties );
+            
+            connector->start();
             
             StompTopic dest1( "dummy.topic" );
             StompTopic dest2( "dummy.topic2" );
             
-            SessionInfo* info1 = connector.createSession( cms::Session::AUTO_ACKNOWLEDGE
);
-            ConsumerInfo* cinfo1 = connector.createConsumer( &dest1, info1, "" );
+            SessionInfo* info1 = connector->createSession( cms::Session::AUTO_ACKNOWLEDGE
);
+            ConsumerInfo* cinfo1 = connector->createConsumer( &dest1, info1, "" );
             
-            SessionInfo* info2 = connector.createSession( cms::Session::DUPS_OK_ACKNOWLEDGE
);
-            ConsumerInfo* cinfo2 = connector.createConsumer( &dest1, info2, "" );
+            SessionInfo* info2 = connector->createSession( cms::Session::DUPS_OK_ACKNOWLEDGE
);
+            ConsumerInfo* cinfo2 = connector->createConsumer( &dest1, info2, "" );
             
-            SessionInfo* info3 = connector.createSession( cms::Session::CLIENT_ACKNOWLEDGE
);
-            ConsumerInfo* cinfo3 = connector.createConsumer( &dest2, info3, "" );
+            SessionInfo* info3 = connector->createSession( cms::Session::CLIENT_ACKNOWLEDGE
);
+            ConsumerInfo* cinfo3 = connector->createConsumer( &dest2, info3, "" );
             
-            SessionInfo* info4 = connector.createSession( cms::Session::SESSION_TRANSACTED
);
-            ConsumerInfo* cinfo4 = connector.createConsumer( &dest2, info4, "" );
+            SessionInfo* info4 = connector->createSession( cms::Session::SESSION_TRANSACTED
);
+            ConsumerInfo* cinfo4 = connector->createConsumer( &dest2, info4, "" );
             
             MyMessageListener listener;
-            connector.setConsumerMessageListener( &listener );
+            connector->setConsumerMessageListener( &listener );
             
             StompFrame* frame = new StompFrame();
             frame->setCommand( "MESSAGE" );
             frame->getProperties().setProperty( 
                 "destination", dest1.toProviderString() );
-            const char* buffer = strdup("hello world");
+            const char* buffer = "hello world";
             frame->setBody( (const unsigned char*)buffer, 12 );
 
             commands::TextMessageCommand* msg = 
-                new commands::TextMessageCommand( frame );
+                new commands::TextMessageCommand( frame ); // deleted by listener
             transport.fireCommand( msg );
             
             CPPUNIT_ASSERT( listener.consumers.size() == 2 );
@@ -266,10 +293,10 @@
             frame->setCommand( "MESSAGE" );
             frame->getProperties().setProperty( 
                 "destination", dest2.toProviderString() );
-            buffer = strdup("hello world");
+            buffer = "hello world";
             frame->setBody( (unsigned char*)buffer, 12 );
 
-            msg = new commands::TextMessageCommand( frame );
+            msg = new commands::TextMessageCommand( frame ); // deleted by listener
             transport.fireCommand( msg );
             
             CPPUNIT_ASSERT( listener.consumers.size() == 2 );
@@ -278,15 +305,19 @@
                     listener.consumers[ix] == cinfo4 );
             }
                         
-            connector.destroyResource( cinfo1 );
-            connector.destroyResource( cinfo2 );
-            connector.destroyResource( cinfo3 );
-            connector.destroyResource( cinfo4 );
-
-            connector.destroyResource( info1 );
-            connector.destroyResource( info2 );
-            connector.destroyResource( info3 );
-            connector.destroyResource( info4 );
+            connector->destroyResource( cinfo1 );
+            connector->destroyResource( cinfo2 );
+            connector->destroyResource( cinfo3 );
+            connector->destroyResource( cinfo4 );
+
+            connector->destroyResource( info1 );
+            connector->destroyResource( info2 );
+            connector->destroyResource( info3 );
+            connector->destroyResource( info4 );
+            
+            // Delete the connector here - this assures the propery order
+            // of destruction.
+            delete connector;
         }
         
         void testSendingCommands()

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompFrameTest.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompFrameTest.h?view=diff&rev=487892&r1=487891&r2=487892
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompFrameTest.h
(original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/connector/stomp/StompFrameTest.h
Sat Dec 16 13:28:22 2006
@@ -55,7 +55,7 @@
          CPPUNIT_ASSERT( frame.getBody().size() == 0 );
          CPPUNIT_ASSERT( frame.getBodyLength() == 0 );
          
-         frame.setBody( (unsigned char*)strdup("ABC"), 4 );
+         frame.setBody( (unsigned char*)"ABC", 4 );
          
          CPPUNIT_ASSERT( frame.getBody().size() == 4 );
          CPPUNIT_ASSERT( frame.getBodyLength() == 4 );

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.h?view=diff&rev=487892&r1=487891&r2=487892
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.h
(original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/core/ActiveMQSessionTest.h
Sat Dec 16 13:28:22 2006
@@ -199,7 +199,7 @@
             frame->setCommand( "MESSAGE" );
             frame->getProperties().setProperty( 
                 "destination", destination.toProviderString() );
-            const char* buffer = strdup( message.c_str() );
+            const char* buffer = message.c_str();
             frame->setBody( (unsigned char*)buffer, 12 );
 
             connector::stomp::commands::TextMessageCommand* msg = 



Mime
View raw message