activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r559061 - in /activemq/activemq-cpp/trunk/src/decaf/src: main/decaf/lang/Exception.cpp test/Makefile.am test/decaf/lang/ExceptionTest.cpp test/decaf/lang/ExceptionTest.h
Date Tue, 24 Jul 2007 14:31:19 GMT
Author: tabish
Date: Tue Jul 24 07:31:18 2007
New Revision: 559061

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

APR'ified Exception Class, with Unit Test

Added:
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/ExceptionTest.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/ExceptionTest.h
Modified:
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Exception.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/test/Makefile.am

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Exception.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Exception.cpp?view=diff&rev=559061&r1=559060&r2=559061
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Exception.cpp (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Exception.cpp Tue Jul 24 07:31:18
2007
@@ -19,16 +19,14 @@
 #include <decaf/util/logging/LoggerDefines.h>
 #include <sstream>
 
+#include <apr_pools.h>
+#include <apr_strings.h>
+
 using namespace std;
 using namespace decaf;
 using namespace decaf::lang;
 using namespace decaf::util::logging;
 
-// For supporting older versions of msvc (<=2003)
-#if defined(_MSC_VER) && (_MSC_VER < 1400)
-    #define vsnprintf _vsnprintf
-#endif
-
 ////////////////////////////////////////////////////////////////////////////////
 Exception::Exception() throw(){
 }
@@ -40,7 +38,7 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 Exception::Exception( const char* file, const int lineNumber,
-                   const char* msg, ... ) throw() {
+                      const char* msg, ... ) throw() {
     va_list vargs;
     va_start( vargs, msg ) ;
     buildMessage( msg, vargs );
@@ -56,42 +54,28 @@
 ////////////////////////////////////////////////////////////////////////////////
 void Exception::setMessage( const char* msg, ... ){
     va_list vargs;
-    va_start(vargs, msg);
-    buildMessage(msg, vargs);
+    va_start( vargs, msg );
+    buildMessage( msg, vargs );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void Exception::buildMessage(const char* format, va_list& vargs) {
+void Exception::buildMessage( const char* format, va_list& vargs ) {
 
     // Allocate buffer with a guess of it's size
-    int size = 128;
-
-    // Format string
-    while( true ){
-
-        // Allocate a buffer of the specified size.
-        char* buffer = new char[size];
-
-        int written = vsnprintf(buffer, size, format, vargs);
-        if (written > -1 && written < size-1) {
-
-            // Guessed size was enough. Assign the string.
-            message.assign (buffer, written);
+    apr_pool_t* pool = NULL;
+    apr_pool_create( &pool, NULL );
 
-            // assign isn't passing ownership, just copying, delete
-            // the allocated buffer.
-            delete [] buffer;
+    // Allocate a buffer of the specified size.
+    char* buffer = apr_pvsprintf( pool, format, vargs );
 
-            break;
-        }
+    // Guessed size was enough. Assign the string.
+    message.assign( buffer, strlen( buffer ) );
 
-        // Our buffer wasn't big enough - destroy the old buffer,
-        // double the size and try again.
-        delete [] buffer;
-        size *= 2;
-    }
+    // assign isn't passing ownership, just copying, delete
+    // the allocated buffer.
+    apr_pool_destroy( pool );
 
-    //activemq::logger::SimpleLogger logger("com.yadda1");
+    //decaf::util::logger::SimpleLogger logger("com.yadda1");
     //logger.log( message );
 }
 
@@ -105,7 +89,7 @@
     stream << "\tFILE: " << stackTrace[stackTrace.size()-1].first;
     stream << ", LINE: " << stackTrace[stackTrace.size()-1].second;
 
-    //activemq::logger::SimpleLogger logger("com.yadda2");
+    //decaf::util::logger::SimpleLogger logger("com.yadda2");
     //logger.log( stream.str() );
 }
 

Modified: activemq/activemq-cpp/trunk/src/decaf/src/test/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/Makefile.am?view=diff&rev=559061&r1=559060&r2=559061
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/Makefile.am Tue Jul 24 07:31:18 2007
@@ -20,6 +20,7 @@
   decaf/lang/IntegerTest.cpp \
   decaf/lang/LongTest.cpp \
   decaf/lang/ThreadTest.cpp \
+  decaf/lang/ExceptionTest.cpp \
   decaf/io/BufferedInputStreamTest.cpp \
   decaf/io/BufferedOutputStreamTest.cpp \
   decaf/io/ByteArrayInputStreamTest.cpp \
@@ -46,6 +47,7 @@
   decaf/lang/IntegerTest.h \
   decaf/lang/LongTest.h \
   decaf/lang/ThreadTest.h \
+  decaf/lang/ExceptionTest.h \
   decaf/io/BufferedInputStreamTest.h \
   decaf/io/BufferedOutputStreamTest.h \
   decaf/io/ByteArrayInputStreamTest.h \

Added: activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/ExceptionTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/ExceptionTest.cpp?view=auto&rev=559061
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/ExceptionTest.cpp (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/ExceptionTest.cpp Tue Jul 24
07:31:18 2007
@@ -0,0 +1,39 @@
+/*
+ * 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 "ExceptionTest.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::ExceptionTest );
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+
+////////////////////////////////////////////////////////////////////////////////
+void ExceptionTest::testMessage0(){
+      char* text = "This is a test";
+      Exception ex( __FILE__, __LINE__, text );
+      CPPUNIT_ASSERT( strcmp( ex.getMessage().c_str(), text ) == 0 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ExceptionTest::testMessage3(){
+    Exception ex( __FILE__, __LINE__,
+        "This is a test %d %d %d", 1, 100, 1000 );
+    CPPUNIT_ASSERT( strcmp( ex.getMessage().c_str(),
+                    "This is a test 1 100 1000" ) == 0 );
+}

Added: activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/ExceptionTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/ExceptionTest.h?view=auto&rev=559061
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/ExceptionTest.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/ExceptionTest.h Tue Jul 24 07:31:18
2007
@@ -0,0 +1,51 @@
+/*
+ * 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 _DECAF_LANG_EXCEPTIONTEST_H_
+#define _DECAF_LANG_EXCEPTIONTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <decaf/lang/Exception.h>
+#include <string.h>
+
+namespace decaf{
+namespace lang{
+
+    class ExceptionTest : public CppUnit::TestFixture {
+
+        CPPUNIT_TEST_SUITE( ExceptionTest );
+        CPPUNIT_TEST( testMessage0 );
+        CPPUNIT_TEST( testMessage3 );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+
+        virtual ~ExceptionTest(){}
+
+        virtual void setUp(){}
+        virtual void tearDown(){}
+
+        void testMessage0();
+        void testMessage3();
+
+    };
+
+}}
+
+#endif /*_DECAF_LANG_EXCEPTIONTEST_H_*/



Mime
View raw message