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 2010/09/01 17:39:29 UTC
svn commit: r991574 -
/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/IdGeneratorTest.cpp
Author: tabish
Date: Wed Sep 1 15:39:29 2010
New Revision: 991574
URL: http://svn.apache.org/viewvc?rev=991574&view=rev
Log:
improved test for: https://issues.apache.org/activemq/browse/AMQCPP-314
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/IdGeneratorTest.cpp
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/IdGeneratorTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/IdGeneratorTest.cpp?rev=991574&r1=991573&r2=991574&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/IdGeneratorTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/activemq/util/IdGeneratorTest.cpp Wed Sep 1 15:39:29 2010
@@ -33,27 +33,38 @@ namespace {
class CreateIdThread : public Thread {
public:
+ bool failed;
+
+ CreateIdThread() : failed( false ) {}
+
+ public:
+
virtual void run() {
- IdGenerator idGen;
+ try{
+ IdGenerator idGen;
- CPPUNIT_ASSERT( idGen.generateId() != "" );
- CPPUNIT_ASSERT( idGen.generateId() != "" );
+ CPPUNIT_ASSERT( idGen.generateId() != "" );
+ CPPUNIT_ASSERT( idGen.generateId() != "" );
- std::string id1 = idGen.generateId();
- std::string id2 = idGen.generateId();
+ std::string id1 = idGen.generateId();
+ std::string id2 = idGen.generateId();
- CPPUNIT_ASSERT( id1 != id2 );
+ CPPUNIT_ASSERT( id1 != id2 );
- std::size_t idPos = id1.find("ID:");
+ std::size_t idPos = id1.find("ID:");
- CPPUNIT_ASSERT( idPos == 0 );
+ CPPUNIT_ASSERT( idPos == 0 );
- std::size_t firstColon = id1.find(':');
- std::size_t lastColon = id1.rfind(':');
+ std::size_t firstColon = id1.find(':');
+ std::size_t lastColon = id1.rfind(':');
- CPPUNIT_ASSERT( firstColon != lastColon );
- CPPUNIT_ASSERT( ( lastColon - firstColon ) > 1 );
+ CPPUNIT_ASSERT( firstColon != lastColon );
+ CPPUNIT_ASSERT( ( lastColon - firstColon ) > 1 );
+ }
+ catch(...) {
+ failed = true;
+ }
}
};
@@ -75,21 +86,6 @@ void IdGeneratorTest::testConstructor1()
CPPUNIT_ASSERT( idGen.generateId() != "" );
CPPUNIT_ASSERT( idGen.generateId() != "" );
-
- std::string id1 = idGen.generateId();
- std::string id2 = idGen.generateId();
-
- CPPUNIT_ASSERT( id1 != id2 );
-
- std::size_t idPos = id1.find("ID:");
-
- CPPUNIT_ASSERT( idPos == 0 );
-
- std::size_t firstColon = id1.find(':');
- std::size_t lastColon = id1.rfind(':');
-
- CPPUNIT_ASSERT( firstColon != lastColon );
- CPPUNIT_ASSERT( ( lastColon - firstColon ) > 1 );
}
////////////////////////////////////////////////////////////////////////////////
@@ -119,6 +115,8 @@ void IdGeneratorTest::testCompare() {
////////////////////////////////////////////////////////////////////////////////
void IdGeneratorTest::testThreadSafety() {
+ bool failed = false;
+
static const int COUNT = 50;
std::vector<CreateIdThread*> threads;
@@ -136,6 +134,11 @@ void IdGeneratorTest::testThreadSafety()
}
for( int i = 0; i < COUNT; i++ ) {
+ if( !failed ) {
+ threads[i]->failed ? failed = true : failed = false;
+ }
delete threads[i];
}
+
+ CPPUNIT_ASSERT_MESSAGE( "One of the Thread Tester failed", !failed );
}