activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject git commit: Fixes and more tests
Date Thu, 31 Oct 2013 22:42:51 GMT
Updated Branches:
  refs/heads/trunk b1746b23e -> a19bec7b2


Fixes and more tests

Project: http://git-wip-us.apache.org/repos/asf/activemq-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-cpp/commit/a19bec7b
Tree: http://git-wip-us.apache.org/repos/asf/activemq-cpp/tree/a19bec7b
Diff: http://git-wip-us.apache.org/repos/asf/activemq-cpp/diff/a19bec7b

Branch: refs/heads/trunk
Commit: a19bec7b2c69b5207665deb32f2723a8b47abc52
Parents: b1746b2
Author: Timothy Bish <tabish121@gmai.com>
Authored: Thu Oct 31 18:42:38 2013 -0400
Committer: Timothy Bish <tabish121@gmai.com>
Committed: Thu Oct 31 18:42:38 2013 -0400

----------------------------------------------------------------------
 activemq-cpp/src/main/Makefile.am               |   2 +
 .../internal/net/URLStreamHandlerManager.cpp    |   4 +
 .../decaf/internal/net/file/FileHandler.cpp     |  52 ++++
 .../main/decaf/internal/net/file/FileHandler.h  |  48 ++++
 activemq-cpp/src/main/decaf/net/URL.cpp         |  25 +-
 activemq-cpp/src/main/decaf/net/URL.h           |  18 +-
 .../src/main/decaf/net/URLStreamHandler.cpp     |  18 +-
 .../src/main/decaf/net/URLStreamHandler.h       |   2 +-
 activemq-cpp/src/test/decaf/net/URLTest.cpp     | 252 ++++++++++++++++++-
 activemq-cpp/src/test/decaf/net/URLTest.h       |  10 +-
 activemq-cpp/src/test/testRegistry.cpp          |   4 +-
 11 files changed, 398 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/a19bec7b/activemq-cpp/src/main/Makefile.am
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/Makefile.am b/activemq-cpp/src/main/Makefile.am
index 8ca9b15..a9b043c 100644
--- a/activemq-cpp/src/main/Makefile.am
+++ b/activemq-cpp/src/main/Makefile.am
@@ -354,6 +354,7 @@ cc_sources = \
     decaf/internal/net/URIType.cpp \
     decaf/internal/net/URLStreamHandlerManager.cpp \
     decaf/internal/net/URLType.cpp \
+    decaf/internal/net/file/FileHandler.cpp \
     decaf/internal/net/http/HttpHandler.cpp \
     decaf/internal/net/ssl/DefaultSSLContext.cpp \
     decaf/internal/net/ssl/DefaultSSLServerSocketFactory.cpp \
@@ -1030,6 +1031,7 @@ h_sources = \
     decaf/internal/net/URIType.h \
     decaf/internal/net/URLStreamHandlerManager.h \
     decaf/internal/net/URLType.h \
+    decaf/internal/net/file/FileHandler.h \
     decaf/internal/net/http/HttpHandler.h \
     decaf/internal/net/ssl/DefaultSSLContext.h \
     decaf/internal/net/ssl/DefaultSSLServerSocketFactory.h \

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/a19bec7b/activemq-cpp/src/main/decaf/internal/net/URLStreamHandlerManager.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/internal/net/URLStreamHandlerManager.cpp b/activemq-cpp/src/main/decaf/internal/net/URLStreamHandlerManager.cpp
index 7beea65..faf95b1 100644
--- a/activemq-cpp/src/main/decaf/internal/net/URLStreamHandlerManager.cpp
+++ b/activemq-cpp/src/main/decaf/internal/net/URLStreamHandlerManager.cpp
@@ -25,11 +25,13 @@
 #include <decaf/internal/net/Network.h>
 
 #include <decaf/internal/net/http/HttpHandler.h>
+#include <decaf/internal/net/file/FileHandler.h>
 
 using namespace decaf;
 using namespace decaf::internal;
 using namespace decaf::internal::net;
 using namespace decaf::internal::net::http;
+using namespace decaf::internal::net::file;
 using namespace decaf::net;
 using namespace decaf::lang;
 using namespace decaf::lang::exceptions;
@@ -154,6 +156,8 @@ URLStreamHandler* URLStreamHandlerManager::getURLStreamHandler(const decaf::lang
         // No one else has provided a handler, so try our internal one.
         if (protocol.equalsIgnoreCase("http")) {
             return new HttpHandler;
+        } else if (protocol.equalsIgnoreCase("file")) {
+            return new FileHandler;
         }
 
         // TODO we should cache the stream handlers and return the cached version

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/a19bec7b/activemq-cpp/src/main/decaf/internal/net/file/FileHandler.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/internal/net/file/FileHandler.cpp b/activemq-cpp/src/main/decaf/internal/net/file/FileHandler.cpp
new file mode 100644
index 0000000..774d863
--- /dev/null
+++ b/activemq-cpp/src/main/decaf/internal/net/file/FileHandler.cpp
@@ -0,0 +1,52 @@
+/*
+ * 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 <decaf/internal/net/file/FileHandler.h>
+
+#include <decaf/lang/exceptions/IllegalArgumentException.h>
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::internal;
+using namespace decaf::internal::net;
+using namespace decaf::internal::net::file;
+
+////////////////////////////////////////////////////////////////////////////////
+FileHandler::~FileHandler() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+decaf::net::URLConnection* FileHandler::openConnection(const decaf::net::URL& url) {
+    return NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+decaf::net::URLConnection* FileHandler::openConnection(const decaf::net::URL& url,
+                                                       const decaf::net::Proxy* proxy) {
+
+    if (proxy == NULL) {
+        throw IllegalArgumentException(__FILE__, __LINE__, "proxy object cannot be NULL");
+    }
+
+    return NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int FileHandler::getDefaultPort() const {
+    return 80;
+}

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/a19bec7b/activemq-cpp/src/main/decaf/internal/net/file/FileHandler.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/internal/net/file/FileHandler.h b/activemq-cpp/src/main/decaf/internal/net/file/FileHandler.h
new file mode 100644
index 0000000..3274fe9
--- /dev/null
+++ b/activemq-cpp/src/main/decaf/internal/net/file/FileHandler.h
@@ -0,0 +1,48 @@
+/*
+ * 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_INTERNAL_NET_FILE_FILEHANDLER_H_
+#define _DECAF_INTERNAL_NET_FILE_FILEHANDLER_H_
+
+#include <decaf/util/Config.h>
+
+#include <decaf/net/URLStreamHandler.h>
+
+namespace decaf {
+namespace internal {
+namespace net {
+namespace file {
+
+    class DECAF_API FileHandler : public decaf::net::URLStreamHandler {
+    public:
+
+        virtual ~FileHandler();
+
+    public:
+
+        virtual decaf::net::URLConnection* openConnection(const decaf::net::URL& url);
+
+        virtual decaf::net::URLConnection* openConnection(const decaf::net::URL& url,
+                                                          const decaf::net::Proxy* proxy);
+
+        virtual int getDefaultPort() const;
+
+    };
+
+}}}}
+
+#endif /* _DECAF_INTERNAL_NET_FILE_FILEHANDLER_H_ */

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/a19bec7b/activemq-cpp/src/main/decaf/net/URL.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/net/URL.cpp b/activemq-cpp/src/main/decaf/net/URL.cpp
index 87c7f68..990e767 100644
--- a/activemq-cpp/src/main/decaf/net/URL.cpp
+++ b/activemq-cpp/src/main/decaf/net/URL.cpp
@@ -106,33 +106,33 @@ namespace net {
 }}
 
 ////////////////////////////////////////////////////////////////////////////////
-URL::URL(const std::string& url) : impl(new URLImpl) {
+URL::URL(const String& url) : impl(new URLImpl) {
     initialize(NULL, url, NULL);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-URL::URL(const URL& context, const std::string& spec) : impl(new URLImpl) {
+URL::URL(const URL& context, const String& spec) : impl(new URLImpl) {
     initialize(&context, spec, NULL);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-URL::URL(const URL& context, const std::string& spec, URLStreamHandler* streamHandler)
: impl(new URLImpl) {
+URL::URL(const URL& context, const String& spec, URLStreamHandler* streamHandler)
: impl(new URLImpl) {
     initialize(&context, spec, streamHandler);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-URL::URL(const std::string& protocol, const std::string& host, int port,
-         const std::string& file, URLStreamHandler* handler) : impl(new URLImpl) {
+URL::URL(const String& protocol, const String& host, int port,
+         const String& file, URLStreamHandler* handler) : impl(new URLImpl) {
     initialize(protocol, host, port, file, handler);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-URL::URL(const std::string& protocol, const std::string& host, const std::string&
file) : impl(new URLImpl) {
+URL::URL(const String& protocol, const String& host, const String& file) : impl(new
URLImpl) {
     initialize(protocol, host, -1, file, NULL);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-URL::URL(const std::string& protocol, const std::string& host, int port, const std::string&
file) : impl() {
+URL::URL(const String& protocol, const String& host, int port, const String&
file) : impl(new URLImpl) {
     initialize(protocol, host, port, file, NULL);
 }
 
@@ -289,7 +289,7 @@ void URL::initialize(const String& protocol, const String& host,
int port,
         impl->setupStreamHandler();
         if (impl->streamHandler == NULL) {
             throw MalformedURLException(
-            __FILE__, __LINE__, (std::string("Unknown protocol: ") + protocol.toString()).c_str());
+                __FILE__, __LINE__, (std::string("Unknown protocol: ") + protocol.toString()).c_str());
         }
     } else {
         impl->streamHandler.reset(handler);
@@ -390,6 +390,15 @@ InputStream* URL::openStream() {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+bool URL::sameFile(const URL& other) const {
+    if (impl->streamHandler == NULL) {
+        throw MalformedURLException(
+            __FILE__, __LINE__, (std::string("Unknown protocol: ") + getProtocol().toString()).c_str());
+    }
+    return impl->streamHandler->sameFile(*this, other);
+}
+
+////////////////////////////////////////////////////////////////////////////////
 String URL::toExternalForm() const {
     if (impl->streamHandler == NULL) {
         return String("unknown protocol(").concat(getProtocol()).concat(")://").concat(getHost()).concat(getFile());

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/a19bec7b/activemq-cpp/src/main/decaf/net/URL.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/net/URL.h b/activemq-cpp/src/main/decaf/net/URL.h
index 1013307..17bf81a 100644
--- a/activemq-cpp/src/main/decaf/net/URL.h
+++ b/activemq-cpp/src/main/decaf/net/URL.h
@@ -112,6 +112,8 @@ namespace net {
      *
      * The URLEncoder and URLDecoder classes can also be used, but only for HTML form
      * encoding, which is not the same as the encoding scheme defined in RFC2396.
+     *
+     * @since 1.0
      */
     class DECAF_API URL {
     private:
@@ -131,7 +133,7 @@ namespace net {
          *
          * @throws MalformedURLException If the string specifies an unknown protocol.
          */
-        URL(const std::string& url);
+        URL(const decaf::lang::String& url);
 
         /**
          * Creates a URL by parsing the given spec within a specified context. The new URL
is
@@ -172,7 +174,7 @@ namespace net {
          *      if the given string spec could not be parsed as a URL or an invalid
          *      protocol has been found.
          */
-        URL(const URL& context, const std::string& spec);
+        URL(const URL& context, const decaf::lang::String& spec);
 
         /**
          * Creates a URL object from the specified protocol, host, port number, file, and
@@ -180,7 +182,7 @@ namespace net {
          * default port for the protocol. Specifying a handler of null indicates that the
          * URL should use a default stream handler for the protocol, as outlined for:
          *
-         *    URL(const std::string&, const std::string&, int, const std::string&)
+         *    URL(const String&, const String&, int, const String&)
          *
          * If a URLStreamHandler instance is provided then this class will take ownership
          * of the object and delete at a later time.
@@ -198,8 +200,8 @@ namespace net {
          *
          * @throws MalformedURLException if an unknown protocol is specified.
          */
-        URL(const std::string& protocol, const std::string& host, int port,
-            const std::string& file, URLStreamHandler* handler);
+        URL(const decaf::lang::String& protocol, const decaf::lang::String& host,
int port,
+            const decaf::lang::String& file, URLStreamHandler* handler);
 
         /**
          * Creates a URL from the specified protocol name, host name, and file name. The
default
@@ -220,7 +222,7 @@ namespace net {
          *
          * @throws MalformedURLException if an unknown protocol is specified.
          */
-        URL(const std::string& protocol, const std::string& host, const std::string&
file);
+        URL(const decaf::lang::String& protocol, const decaf::lang::String& host,
const decaf::lang::String& file);
 
         /**
          * Creates a new URL instance using the given arguments. The URL uses the
@@ -240,7 +242,7 @@ namespace net {
          *      if the combination of all arguments do not represent a valid
          *      URL or the protocol is invalid.
          */
-        URL(const std::string& protocol, const std::string& host, int port, const
std::string& file);
+        URL(const decaf::lang::String& protocol, const decaf::lang::String& host,
int port, const decaf::lang::String& file);
 
         /**
          * Creates a URL by parsing the given spec with the specified handler within a
@@ -259,7 +261,7 @@ namespace net {
          *
          * @throws MalformedURLException if an unknown protocol is specified.
          */
-        URL(const URL& context, const std::string& spec, URLStreamHandler* streamHandler);
+        URL(const URL& context, const decaf::lang::String& spec, URLStreamHandler*
streamHandler);
 
         virtual ~URL();
 

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/a19bec7b/activemq-cpp/src/main/decaf/net/URLStreamHandler.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/net/URLStreamHandler.cpp b/activemq-cpp/src/main/decaf/net/URLStreamHandler.cpp
index ba3a508..45dcd90 100644
--- a/activemq-cpp/src/main/decaf/net/URLStreamHandler.cpp
+++ b/activemq-cpp/src/main/decaf/net/URLStreamHandler.cpp
@@ -98,14 +98,14 @@ bool URLStreamHandler::equals(const URL& source, const URL& other)
const {
     String s1 = source.getRef();
     String s2 = other.getRef();
 
-    if (s1.isEmpty() || s1 != s2) {
+    if (s1 != s2) {
         return false;
     }
 
     s1 = source.getQuery();
     s2 = other.getQuery();
 
-    return s1.isEmpty() && s1 != s2;
+    return s1 == s2;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -119,13 +119,13 @@ bool URLStreamHandler::sameFile(const URL& source, const URL&
other) const {
     String s1 = source.getProtocol();
     String s2 = other.getProtocol();
 
-    if (s1.isEmpty() || s1 != s2) {
+    if (s1 != s2) {
         return false;
     }
 
     s1 = source.getFile();
     s2 = other.getFile();
-    if (s1.isEmpty() || s1 != s2) {
+    if (s1 != s2) {
         return false;
     }
 
@@ -167,7 +167,7 @@ bool URLStreamHandler::hostsEqual(const URL& source, const URL&
other) const {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-std::string URLStreamHandler::toExternalForm(const URL& url) const {
+String URLStreamHandler::toExternalForm(const URL& url) const {
     std::string answer;
     answer.append(url.getProtocol().toString());
     answer.append(":");
@@ -189,7 +189,7 @@ std::string URLStreamHandler::toExternalForm(const URL& url) const
{
         answer.append(ref.toString());
     }
 
-    return answer;
+    return String(answer);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -230,6 +230,7 @@ void URLStreamHandler::parseURL(URL& url, const String& spec,
int start, int lim
     String parseString = spec.substring(start, limit);
     limit -= start;
     int fileIdx = 0;
+    bool fileIsRelative = false;
 
     // Default is to use info from context
     String host = url.getHost();
@@ -257,6 +258,7 @@ void URLStreamHandler::parseURL(URL& url, const String& spec,
int start, int lim
             fileIdx = limit;
             // Use default
             file = "";
+            fileIsRelative = true;
         }
         int hostEnd = fileIdx;
         if (refIdx != -1 && refIdx < fileIdx) {
@@ -330,8 +332,8 @@ void URLStreamHandler::parseURL(URL& url, const String& spec,
int start, int lim
         if (fileIdx < limit && parseString.charAt(fileIdx) == '/') {
             file = parseString.substring(fileIdx, fileEnd);
         } else if (fileEnd > fileIdx) {
-            if (file.equals("")) {
-                file = "/"; //$NON-NLS-1$
+            if (file.equals("") && fileIsRelative) {
+                file = "/";
             } else if (file.startsWith("/")) {
                 canonicalize = true;
             }

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/a19bec7b/activemq-cpp/src/main/decaf/net/URLStreamHandler.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/decaf/net/URLStreamHandler.h b/activemq-cpp/src/main/decaf/net/URLStreamHandler.h
index 8630b8f..5b1944a 100644
--- a/activemq-cpp/src/main/decaf/net/URLStreamHandler.h
+++ b/activemq-cpp/src/main/decaf/net/URLStreamHandler.h
@@ -135,7 +135,7 @@ namespace net {
          *
          * @returns string form of the provided URL.
          */
-        virtual std::string toExternalForm(const URL& url) const;
+        virtual decaf::lang::String toExternalForm(const URL& url) const;
 
         /**
          * Attempts to get the IP address of the host.  Based on DNS errors or other conditions

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/a19bec7b/activemq-cpp/src/test/decaf/net/URLTest.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/test/decaf/net/URLTest.cpp b/activemq-cpp/src/test/decaf/net/URLTest.cpp
index 2e047e4..15b53c4 100644
--- a/activemq-cpp/src/test/decaf/net/URLTest.cpp
+++ b/activemq-cpp/src/test/decaf/net/URLTest.cpp
@@ -37,19 +37,255 @@ URLTest::~URLTest() {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void URLTest::testConstructorString() {
+void URLTest::testConstructor1() {
 
-    URL u("http://www.yahoo1.com:8080/dir1/dir2/test.cgi?point1.html#anchor1");
+    // Tests for multiple URL instantiation basic parsing test
+    URL a("http://www.yahoo1.com:8080/dir1/dir2/test.cgi?point1.html#anchor1");
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("a returns a wrong protocol", String("http"), a.getProtocol());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("a returns a wrong host", String("www.yahoo1.com"), a.getHost());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("a returns a wrong port", 8080, a.getPort());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("a returns a wrong file",
+                                 String("/dir1/dir2/test.cgi?point1.html"), a.getFile());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("a returns a wrong anchor", String("anchor1"), a.getRef());
 
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("u returns a wrong protocol", String("http"), u.getProtocol());
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("u returns a wrong host", String("www.yahoo1.com"), u.getHost());
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("u returns a wrong port", 8080, u.getPort());
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("u returns a wrong file",
-                                 String("/dir1/dir2/test.cgi?point1.html"), u.getFile());
-    CPPUNIT_ASSERT_EQUAL_MESSAGE("u returns a wrong anchor", String("anchor1"), u.getRef());
+    // test for no file
+    URL b("http://www.yahoo2.com:9999");
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("b returns a wrong protocol", String("http"), b.getProtocol());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("b returns a wrong host", String("www.yahoo2.com"), b.getHost());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("b returns a wrong port", 9999, b.getPort());
+    CPPUNIT_ASSERT_MESSAGE("b returns a wrong file", b.getFile().equals(""));
+    CPPUNIT_ASSERT_MESSAGE("b returns a wrong anchor", b.getRef().isEmpty());
 
+    // test for no port
+    URL c("http://www.yahoo3.com/dir1/dir2/test.cgi?point1.html#anchor1");
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("c returns a wrong protocol", String("http"), c.getProtocol());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("c returns a wrong host", String("www.yahoo3.com"), c.getHost());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("c returns a wrong port", -1, c.getPort());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("c returns a wrong file",
+                                 String("/dir1/dir2/test.cgi?point1.html"), c.getFile());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("c returns a wrong anchor", String("anchor1"), c.getRef());
+
+    // test for no port
+    URL d("file://www.yahoo3.com/dir1/dir2/test.cgi#anchor1");
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("u2a returns a wrong protocol", String("file"), d.getProtocol());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("u2a returns a wrong host", String("www.yahoo3.com"), d.getHost());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("u2a returns a wrong port", -1, d.getPort());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("u2a returns a wrong file", String("/dir1/dir2/test.cgi"),
d.getFile());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("u2a returns a wrong anchor", String("anchor1"), d.getRef());
+
+    // test for no file, no port
+    URL e("http://www.yahoo4.com/");
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("e returns a wrong protocol", String("http"), e.getProtocol());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("e returns a wrong host", String("www.yahoo4.com"), e.getHost());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("e returns a wrong port", -1, e.getPort());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("e returns a wrong file", String("/"), e.getFile());
+    CPPUNIT_ASSERT_MESSAGE("e returns a wrong anchor", e.getRef().isEmpty());
+
+    // test for no file, no port
+    URL f("file://www.yahoo4.com/");
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("f returns a wrong protocol", String("file"), f.getProtocol());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("f returns a wrong host", String("www.yahoo4.com"), f.getHost());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("f returns a wrong port", -1, f.getPort());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("f returns a wrong file", String("/"), f.getFile());
+    CPPUNIT_ASSERT_MESSAGE("f returns a wrong anchor", f.getRef().isEmpty());
+
+    // test for no file, no port
+    URL g("file://www.yahoo4.com");
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("g returns a wrong protocol", String("file"), g.getProtocol());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("g returns a wrong host", String("www.yahoo4.com"), g.getHost());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("g returns a wrong port", -1, g.getPort());
+    CPPUNIT_ASSERT_MESSAGE("g returns a wrong file", g.getFile().equals(""));
+    CPPUNIT_ASSERT_MESSAGE("g returns a wrong anchor", g.getRef().isEmpty());
+
+    // test for non-port ":" and wierd characters occurrences
+    URL h("http://www.yahoo5.com/di!@$%^&*()_+r1/di:::r2/test.cgi?point1.html#anchor1");
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("h returns a wrong protocol", String("http"), h.getProtocol());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("h returns a wrong host", String("www.yahoo5.com"), h.getHost());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("h returns a wrong port", -1, h.getPort());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("h returns a wrong file",
+                                 String("/di!@$%^&*()_+r1/di:::r2/test.cgi?point1.html"),
h.getFile());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("h returns a wrong anchor", String("anchor1"), h.getRef());
+
+    URL i("file:/testing.tst");
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("i returns a wrong protocol", String("file"), i.getProtocol());
+    CPPUNIT_ASSERT_MESSAGE("i returns a wrong host", i.getHost().equals(""));
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("i returns a wrong port", -1, i.getPort());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("i returns a wrong file", String("/testing.tst"), i.getFile());
+    CPPUNIT_ASSERT_MESSAGE("i returns a wrong anchor", i.getRef().isEmpty());
+
+    URL j("file:testing.tst");
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("j returns a wrong protocol", String("file"), j.getProtocol());
+    CPPUNIT_ASSERT_MESSAGE("j returns a wrong host", j.getHost().equals(""));
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("j returns a wrong port", -1, j.getPort());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("j returns a wrong file", String("testing.tst"), j.getFile());
+    CPPUNIT_ASSERT_MESSAGE("j returns a wrong anchor", j.getRef().isEmpty());
+
+    URL l("http://host:/file");
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("l return a wrong port", -1, l.getPort());
+
+    URL m("file:../../file.txt");
+    CPPUNIT_ASSERT_MESSAGE(std::string("m returns a wrong file: ") + m.getFile().toString(),
+                           m.getFile().equals("../../file.txt"));
+
+    URL n("http://[fec0::1:20d:60ff:fe24:7410]:35/file.txt");
+    CPPUNIT_ASSERT_MESSAGE("n returns a wrong protocol ", n.getProtocol().equals("http"));
+    CPPUNIT_ASSERT_MESSAGE("n returns a wrong host ", n.getHost().equals("[fec0::1:20d:60ff:fe24:7410]"));
+    CPPUNIT_ASSERT_MESSAGE("n returns a wrong port ", n.getPort() == 35);
+    CPPUNIT_ASSERT_MESSAGE("n returns a wrong file ", n.getFile().equals("/file.txt"));
+    CPPUNIT_ASSERT_MESSAGE("n returns a wrong anchor ", n.getRef().isEmpty());
+
+    URL o("file://[fec0::1:20d:60ff:fe24:7410]/file.txt#sogood");
+    CPPUNIT_ASSERT_MESSAGE("o returns a wrong protocol ", o.getProtocol().equals("file"));
+    CPPUNIT_ASSERT_MESSAGE("o returns a wrong host ", o.getHost().equals("[fec0::1:20d:60ff:fe24:7410]"));
+    CPPUNIT_ASSERT_MESSAGE("o returns a wrong port ", o.getPort() == -1);
+    CPPUNIT_ASSERT_MESSAGE("o returns a wrong file ", o.getFile().equals("/file.txt"));
+    CPPUNIT_ASSERT_MESSAGE("o returns a wrong anchor ", o.getRef().equals("sogood"));
+
+    URL p("file://[fec0::1:20d:60ff:fe24:7410]");
+    CPPUNIT_ASSERT_MESSAGE("p returns a wrong protocol ", p.getProtocol().equals("file"));
+    CPPUNIT_ASSERT_MESSAGE("p returns a wrong host ", p.getHost()
+            .equals("[fec0::1:20d:60ff:fe24:7410]"));
+    CPPUNIT_ASSERT_MESSAGE("p returns a wrong port ", p.getPort() == -1);
+
+    URL q("file:////file.txt");
+    CPPUNIT_ASSERT_MESSAGE("q returns a wrong authority ", q.getAuthority().isEmpty());
+    CPPUNIT_ASSERT_MESSAGE("q returns a wrong file ", q.getFile().equals("////file.txt"));
+
+    URL r("file:///file.txt");
+    CPPUNIT_ASSERT_MESSAGE("r returns a wrong authority", r.getAuthority().equals(""));
+    CPPUNIT_ASSERT_MESSAGE("r returns a wrong file ", r.getFile().equals("/file.txt"));
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should have thrown MalformedURLException",
+        URL("http://www.yahoo5.com::22/dir1/di:::r2/test.cgi?point1.html#anchor1"),
+        MalformedURLException);
+
+    // unknown protocol
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should have thrown MalformedURLException",
+        URL("myProtocol://www.yahoo.com:22"),
+        MalformedURLException);
+
+    // no protocol
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should have thrown MalformedURLException",
+        URL("www.yahoo.com"),
+        MalformedURLException);
+
+    try {
+        // No leading or trailing spaces.
+        URL u1("file:/some/path");
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("5 got wrong file length1", 10, u1.getFile().length());
+
+        // Leading spaces.
+        URL u2("  file:/some/path");
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("5 got wrong file length2", 10, u2.getFile().length());
+
+        // Trailing spaces.
+        URL u3("file:/some/path  ");
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("5 got wrong file length3", 10, u3.getFile().length());
+
+        // Leading and trailing.
+        URL u4("  file:/some/path ");
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("5 got wrong file length4", 10, u4.getFile().length());
+
+        // in-place spaces.
+        URL u5("  file:  /some/path ");
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("5 got wrong file length5", 12, u5.getFile().length());
+
+    } catch (MalformedURLException& e) {
+        CPPUNIT_FAIL("5 Did not expect the exception ");
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void URLTest::testConstructor2() {
+
+    URL u("http", "www.yahoo.com", "test.html#foo");
+    CPPUNIT_ASSERT(u.getProtocol().equals("http"));
+    CPPUNIT_ASSERT(u.getHost().equals("www.yahoo.com"));
+    CPPUNIT_ASSERT(-1 == u.getPort());
+    CPPUNIT_ASSERT(u.getFile().equals("test.html"));
+    CPPUNIT_ASSERT(u.getRef().equals("foo"));
+
+    // Strange behavior in reference, the hostname contains a ':' so it gets
+    // wrapped in '[', ']'
+    URL testURL("http", "www.apache.org:8080", "test.html#anch");
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong protocol", String("http"), testURL.getProtocol());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong host", String("[www.apache.org:8080]"), testURL.getHost());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong port", -1, testURL.getPort());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong file", String("test.html"), testURL.getFile());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong anchor", String("anch"), testURL.getRef());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void URLTest::testConstructor3() {
+
+    URL u("http", "www.yahoo.com", 8080, "test.html#foo");
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("SSIS returns a wrong protocol", String("http"), u.getProtocol());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("SSIS returns a wrong host", String("www.yahoo.com"), u.getHost());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("SSIS returns a wrong port", 8080, u.getPort());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("SSIS returns a wrong file", String("test.html"), u.getFile());
+    CPPUNIT_ASSERT_MESSAGE("SSIS returns a wrong anchor: ", u.getRef().equals("foo"));
+
+    CPPUNIT_ASSERT_NO_THROW(URL("http", "apache.org", 123456789, "file"));
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should have thrown MalformedURLException",
+        URL("http", "apache.org", -123, "file"),
+        MalformedURLException);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void URLTest::testEquals() {
+
+    URL u("http://www.apache.org:8080/dir::23??????????test.html");
+    URL u1("http://www.apache.org:8080/dir::23??????????test.html");
+    CPPUNIT_ASSERT_MESSAGE("A) equals returns false for two identical URLs", u.equals(u1));
+
+    URL u2("file://www.apache.org:8080/dir::23??????????test.html");
+    CPPUNIT_ASSERT_MESSAGE("Returned true for non-equal URLs", !u2.equals(u1));
+
+    URL a("file", "", 0, "/test.txt");
+    URL b("file", "", 0, "/test.txt");
+    CPPUNIT_ASSERT(a.equals(b));
+
+    URL c("file", "first.invalid", 0, "/test.txt");
+    URL d("file", "second.invalid", 0, "/test.txt");
+    CPPUNIT_ASSERT(!c.equals(d));
+
+    // TODO
+//    URL e("file", "harmony.apache.org", 0, "/test.txt");
+//    URL f("file", "www.apache.org", 0, "/test.txt");
+//    CPPUNIT_ASSERT(e.equals(f));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void URLTest::testSameFile() {
+
+    URL a("http://www.yahoo.com");
+    URL b("http", "www.yahoo.com", "");
+    CPPUNIT_ASSERT_MESSAGE("Should be the same1", a.sameFile(b));
+
+    URL c("http://www.yahoo.com/dir1/dir2/test.html#anchor1");
+    URL d("http://www.yahoo.com/dir1/dir2/test.html#anchor2");
+    CPPUNIT_ASSERT_MESSAGE("Should be the same ", c.sameFile(d));
+
+    // TODO
+//    URL e("file", "", -1, "/d:/somedir/");
+//    URL f("file:/d:/somedir/");
+//    CPPUNIT_ASSERT(!e.sameFile(f));
+
+    URL g("file:///anyfile");
+    URL h("file://localhost/anyfile");
+    CPPUNIT_ASSERT(g.sameFile(h));
+
+    URL i("http:///anyfile");
+    URL j("http://localhost/anyfile");
+    CPPUNIT_ASSERT(!i.sameFile(j));
+
+    // TODO
+//    URL k("ftp:///anyfile");
+//    URL l("ftp://localhost/anyfile");
+//    CPPUNIT_ASSERT(!k.sameFile(l));
 }

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/a19bec7b/activemq-cpp/src/test/decaf/net/URLTest.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/test/decaf/net/URLTest.h b/activemq-cpp/src/test/decaf/net/URLTest.h
index 8d5c230..f203b2b 100644
--- a/activemq-cpp/src/test/decaf/net/URLTest.h
+++ b/activemq-cpp/src/test/decaf/net/URLTest.h
@@ -27,8 +27,11 @@ namespace net {
     class URLTest : public CppUnit::TestFixture {
 
         CPPUNIT_TEST_SUITE( URLTest );
-        CPPUNIT_TEST( testConstructorString );
+        CPPUNIT_TEST( testConstructor1 );
+        CPPUNIT_TEST( testConstructor2 );
+        CPPUNIT_TEST( testConstructor3 );
         CPPUNIT_TEST( testEquals );
+        CPPUNIT_TEST( testSameFile );
         CPPUNIT_TEST_SUITE_END();
 
     public:
@@ -36,8 +39,11 @@ namespace net {
         URLTest();
         virtual ~URLTest();
 
-        void testConstructorString();
+        void testConstructor1();
+        void testConstructor2();
+        void testConstructor3();
         void testEquals();
+        void testSameFile();
 
     };
 

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/a19bec7b/activemq-cpp/src/test/testRegistry.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/test/testRegistry.cpp b/activemq-cpp/src/test/testRegistry.cpp
index 19f0985..7ec7e1e 100644
--- a/activemq-cpp/src/test/testRegistry.cpp
+++ b/activemq-cpp/src/test/testRegistry.cpp
@@ -265,8 +265,8 @@
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::PointerTest );
 //#include <decaf/lang/ArrayPointerTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::ArrayPointerTest );
-#include <decaf/lang/StringTest.h>
-CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::StringTest );
+//#include <decaf/lang/StringTest.h>
+//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::StringTest );
 //
 //#include <decaf/net/InetAddressTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::net::InetAddressTest );


Mime
View raw message