activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r943604 - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/decaf/net/ test/ test/decaf/net/
Date Wed, 12 May 2010 18:09:35 GMT
Author: tabish
Date: Wed May 12 18:09:34 2010
New Revision: 943604

URL: http://svn.apache.org/viewvc?rev=943604&view=rev
Log:
Implement and test more of the InetAddress API

Added:
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet4AddressTest.cpp   (with
props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet4AddressTest.h   (with
props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet6AddressTest.cpp   (with
props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet6AddressTest.h   (with
props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/InetAddressTest.cpp   (with
props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/InetAddressTest.h   (with
props)
Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet4Address.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet4Address.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet6Address.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet6Address.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/InetAddress.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/InetAddress.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/decaf/net/Inet4Address.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet4Address.cpp?rev=943604&r1=943603&r2=943604&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet4Address.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet4Address.cpp Wed May 12
18:09:34 2010
@@ -25,5 +25,98 @@ Inet4Address::Inet4Address() {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+Inet4Address::Inet4Address( const unsigned char* ipAddress, int numBytes ) :
+    InetAddress( ipAddress, numBytes ) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Inet4Address::Inet4Address( const std::string& hostname, const unsigned char* ipAddress,
int numBytes ) :
+    InetAddress( hostname, ipAddress, numBytes ) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
 Inet4Address::~Inet4Address() {
 }
+
+////////////////////////////////////////////////////////////////////////////////
+bool Inet4Address::isAnyLocalAddress() const {
+
+    for( int ix = 0; ix < 4; ix++ ) {
+        if( this->addressBytes[ix] != 0 ) {
+            return false;
+        }
+    }
+
+    return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Inet4Address::isLoopbackAddress() const {
+    return this->addressBytes[0] == 127;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Inet4Address::isMulticastAddress() const {
+    return ( this->addressBytes[0] & 0xF0 ) == 0xE0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Inet4Address::isLinkLocalAddress() const {
+    return ( ( this->addressBytes[0] == 169 ) && ( this->addressBytes[1] ==
254 ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Inet4Address::isSiteLocalAddress() const {
+    return ( this->addressBytes[0] == 10 ) ||
+           ( ( this->addressBytes[0] == 172 ) && ( ( this->addressBytes[1]
> 15 ) && ( this->addressBytes[1] < 32 ) ) ) ||
+           ( ( this->addressBytes[0] == 192 ) && ( this->addressBytes[1] ==
168 ) );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Inet4Address::isMCGlobal() const {
+
+    // Check if we have a prefix of 1110
+    if( !isMulticastAddress() ) {
+        return false;
+    }
+
+    unsigned int address = InetAddress::bytesToInt( addressBytes.get(), 0 );
+
+    // Now check the boundaries of the global space if we have an address
+    // that is prefixed by something less than 111000000000000000000001
+    // it is not multicast. ( < 224.0.1.0)
+    if( ( address >> 8 ) < 0xE00001 ) {
+        return false;
+    }
+
+    // Now check the high boundary which is prefixed by 11101110 = 0xEE. If
+    // the value is higher than this than it is not MCGlobal ( > 238.255.255.255 )
+    if( ( address >> 24 ) > 0xEE ) {
+        return false;
+    }
+
+    return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Inet4Address::isMCNodeLocal() const {
+
+    // Never true for IPV4
+    return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Inet4Address::isMCLinkLocal() const {
+    return ( InetAddress::bytesToInt( addressBytes.get(), 0 ) >> 8 ) == 0xE00000;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Inet4Address::isMCSiteLocal() const {
+    return ( InetAddress::bytesToInt( addressBytes.get(), 0 ) >> 16 ) == 0xEFFF;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Inet4Address::isMCOrgLocal() const {
+    unsigned int prefix = InetAddress::bytesToInt( addressBytes.get(), 0 ) >> 16;
+    return prefix >= 0xEFC0 && prefix <= 0xEFC3;
+}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet4Address.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet4Address.h?rev=943604&r1=943603&r2=943604&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet4Address.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet4Address.h Wed May 12
18:09:34 2010
@@ -26,12 +26,90 @@ namespace decaf {
 namespace net {
 
     class DECAF_API Inet4Address : public InetAddress {
-    public:
+    private:
+
+        friend class InetAddress;
+
+    protected:
 
         Inet4Address();
+        Inet4Address( const unsigned char* ipAddress, int numBytes );
+        Inet4Address( const std::string& hostname, const unsigned char* ipAddress, int
numBytes );
+
+    public:
 
         virtual ~Inet4Address();
 
+        /**
+         * Check if this InetAddress is a valid wildcard address.
+         *
+         * @return true if the address is a wildcard address.
+         */
+        virtual bool isAnyLocalAddress() const;
+
+        /**
+         * Check if this InetAddress is a valid loopback address.
+         *
+         * @return true if the address is a loopback address.
+         */
+        virtual bool isLoopbackAddress() const;
+
+        /**
+         * Check if this InetAddress is a valid Multicast address.
+         *
+         * @return true if the address is a Multicast address.
+         */
+        virtual bool isMulticastAddress() const;
+
+        /**
+         * Check if this InetAddress is a valid link local address.
+         *
+         * @return true if the address is a link local address.
+         */
+        virtual bool isLinkLocalAddress() const;
+
+        /**
+         * Check if this InetAddress is a valid site local address.
+         *
+         * @return true if the address is a site local address.
+         */
+        virtual bool isSiteLocalAddress() const;
+
+        /**
+         * Check if this InetAddress is Multicast and has Global scope.
+         *
+         * @return true if the address is Multicast and has Global scope.
+         */
+        virtual bool isMCGlobal() const;
+
+        /**
+         * Check if this InetAddress is Multicast and has Node Local scope.
+         *
+         * @return true if the address is Multicast and has Node Local scope.
+         */
+        virtual bool isMCNodeLocal() const;
+
+        /**
+         * Check if this InetAddress is Multicast and has Link Local scope.
+         *
+         * @return true if the address is Multicast and has Link Local scope.
+         */
+        virtual bool isMCLinkLocal() const;
+
+        /**
+         * Check if this InetAddress is Multicast and has Site Local scope.
+         *
+         * @return true if the address is Multicast and has Site Local scope.
+         */
+        virtual bool isMCSiteLocal() const;
+
+        /**
+         * Check if this InetAddress is Multicast and has Organization scope.
+         *
+         * @return true if the address is Multicast and has Organization scope.
+         */
+        virtual bool isMCOrgLocal() const;
+
     };
 
 }}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet6Address.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet6Address.cpp?rev=943604&r1=943603&r2=943604&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet6Address.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet6Address.cpp Wed May 12
18:09:34 2010
@@ -25,5 +25,15 @@ Inet6Address::Inet6Address() {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+Inet6Address::Inet6Address( const unsigned char* ipAddress, int numBytes ) :
+    InetAddress( ipAddress, numBytes ) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Inet6Address::Inet6Address( const std::string& hostname, const unsigned char* ipAddress,
int numBytes ) :
+    InetAddress( hostname, ipAddress, numBytes ) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
 Inet6Address::~Inet6Address() {
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet6Address.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet6Address.h?rev=943604&r1=943603&r2=943604&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet6Address.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Inet6Address.h Wed May 12
18:09:34 2010
@@ -26,9 +26,17 @@ namespace decaf {
 namespace net {
 
     class DECAF_API Inet6Address : public InetAddress {
-    public:
+    private:
+
+        friend class InetAddress;
+
+    protected:
 
         Inet6Address();
+        Inet6Address( const unsigned char* ipAddress, int numBytes );
+        Inet6Address( const std::string& hostname, const unsigned char* ipAddress, int
numBytes );
+
+    public:
 
         virtual ~Inet6Address();
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/InetAddress.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/InetAddress.cpp?rev=943604&r1=943603&r2=943604&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/InetAddress.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/InetAddress.cpp Wed May 12
18:09:34 2010
@@ -17,6 +17,12 @@
 
 #include "InetAddress.h"
 
+#include <decaf/lang/System.h>
+#include <decaf/lang/Byte.h>
+#include <decaf/net/Inet4Address.h>
+#include <decaf/net/Inet6Address.h>
+#include <decaf/net/UnknownHostException.h>
+
 using namespace decaf;
 using namespace decaf::net;
 using namespace decaf::lang;
@@ -26,12 +32,15 @@ using namespace decaf::lang::exceptions;
 const unsigned char InetAddress::loopbackBytes[4] = { 127, 0, 0, 1 };
 const unsigned char InetAddress::anyBytes[4] = { 0, 0, 0, 0 };
 
+const InetAddress InetAddress::LOOPBACK( Inet4Address( "localhost", InetAddress::loopbackBytes,
4 ) );
+const InetAddress InetAddress::ANY( Inet4Address( InetAddress::anyBytes, 4 ) );
+
 ////////////////////////////////////////////////////////////////////////////////
 InetAddress::InetAddress() {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-InetAddress::InetAddress( unsigned char* ipAddress DECAF_UNUSED, int numBytes DECAF_UNUSED
) {
+InetAddress::InetAddress( const unsigned char* ipAddress, int numBytes ) {
 
     if( ipAddress == NULL ) {
         throw NullPointerException(
@@ -43,12 +52,28 @@ InetAddress::InetAddress( unsigned char*
             __FILE__, __LINE__, "Number of bytes value is invalid: %d", numBytes );
     }
 
-
+    unsigned char* copy = new unsigned char[numBytes];
+    System::arraycopy( ipAddress, 0, copy, 0, numBytes );
+    this->addressBytes.reset( copy, numBytes );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-InetAddress::InetAddress( const std::string& hostname DECAF_UNUSED, unsigned char* ipAddress
DECAF_UNUSED, int numBytes DECAF_UNUSED ) {
+InetAddress::InetAddress( const std::string& hostname, const unsigned char* ipAddress,
int numBytes ) {
+
+    if( ipAddress == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "InetAddress constructor called with null address array."
);
+    }
+
+    if( numBytes < 0 ) {
+        throw IllegalArgumentException(
+            __FILE__, __LINE__, "Number of bytes value is invalid: %d", numBytes );
+    }
 
+    unsigned char* copy = new unsigned char[numBytes];
+    System::arraycopy( ipAddress, 0, copy, 0, numBytes );
+    this->addressBytes.reset( copy, numBytes );
+    this->hostname = hostname;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -57,12 +82,83 @@ InetAddress::~InetAddress() {
 
 ////////////////////////////////////////////////////////////////////////////////
 ArrayPointer<unsigned char> InetAddress::getAddress() const {
-
-    return ArrayPointer<unsigned char>();
+    return this->addressBytes.clone();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 std::string InetAddress::getHostAddress() const {
 
-    return "";
+    std::string address;
+
+    for( int ix = 0; ix < this->addressBytes.length(); ix++ ) {
+        address.append( Byte::toString( addressBytes[ix] ) );
+
+        if( ix < this->addressBytes.length() - 1 ) {
+            address.append(".");
+        }
+    }
+    return address;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string InetAddress::getHostname() const {
+
+    if( !this->hostname.empty() ) {
+        return this->hostname;
+    }
+
+    return this->getHostAddress();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string InetAddress::toString() const {
+    return getHostname() + " / " + getHostAddress();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+InetAddress InetAddress::getByAddress( const std::string& hostname, const unsigned char*
bytes, int numBytes ) {
+
+    if( numBytes == 4 ) {
+        return Inet4Address( hostname, bytes, numBytes );
+    } else if( numBytes == 16 ) {
+        return Inet6Address( hostname, bytes, numBytes );
+    } else {
+        throw UnknownHostException(
+            __FILE__, __LINE__, "Number of Bytes passed was invalid: %d", numBytes );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+InetAddress InetAddress::getByAddress( const unsigned char* bytes, int numBytes ) {
+
+    if( numBytes == 4 ) {
+        return Inet4Address( bytes, numBytes );
+    } else if( numBytes == 16 ) {
+        return Inet6Address( bytes, numBytes );
+    } else {
+        throw UnknownHostException(
+            __FILE__, __LINE__, "Number of Bytes passed was invalid: %d", numBytes );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+InetAddress InetAddress::getLocalHost() {
+    return InetAddress::LOOPBACK;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned int InetAddress::bytesToInt( const unsigned char* bytes, int start ) {
+
+    // First mask the byte with 255, as when a negative
+    // signed byte converts to an integer, it has bits
+    // on in the first 3 bytes, we are only concerned
+    // about the right-most 8 bits.
+    // Then shift the rightmost byte to align with its
+    // position in the integer.
+    int value = ( ( bytes[start + 3] & 255 ) ) |
+                ( ( bytes[start + 2] & 255 ) << 8 ) |
+                ( ( bytes[start + 1] & 255 ) << 16 ) |
+                ( ( bytes[start] & 255 ) << 24 );
+
+    return value;
 }

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/InetAddress.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/InetAddress.h?rev=943604&r1=943603&r2=943604&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/InetAddress.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/InetAddress.h Wed May 12 18:09:34
2010
@@ -39,26 +39,17 @@ namespace net {
         static const InetAddress ANY;
         static const InetAddress LOOPBACK;
 
-    private:
-
-        std::string hostname;
-        bool reached;
-        decaf::lang::ArrayPointer<unsigned char> addressBytes;
-
     protected:
 
-        int family;
+        mutable std::string hostname;
+        mutable bool reached;
+        mutable decaf::lang::ArrayPointer<unsigned char> addressBytes;
 
     protected:
 
         InetAddress();
-        InetAddress( unsigned char* ipAddress, int numBytes );
-        InetAddress( const std::string& hostname, unsigned char* ipAddress, int numBytes
);
-
-    private:
-
-        InetAddress( const InetAddress& );
-        InetAddress& operator= ( const InetAddress& );
+        InetAddress( const unsigned char* ipAddress, int numBytes );
+        InetAddress( const std::string& hostname, const unsigned char* ipAddress, int
numBytes );
 
     public:
 
@@ -70,14 +61,178 @@ namespace net {
          *
          * @returns and ArrayPointer containing the raw bytes of the network address.
          */
-        decaf::lang::ArrayPointer<unsigned char> getAddress() const;
+        virtual decaf::lang::ArrayPointer<unsigned char> getAddress() const;
 
         /**
          * Returns a textual representation of the IP Address.
          *
-         * @returns the string form of the IP Adrress.
+         * @returns the string form of the IP Address.
+         */
+        virtual std::string getHostAddress() const;
+
+        /**
+         * Get the host name associated with this InetAddress instance.
+         *
+         * If a host name was set upon construction then that value is returned, otherwise
a
+         * reverse name lookup with be performed to attempt to get the host name associated
+         * with the set IP Address.  If the host name cannot be resolved the textual representation
+         * of the IP Address is returned instead.
+         *
+         * @returns the name of the host associated with this set IP Address.
+         */
+        virtual std::string getHostname() const;
+
+        /**
+         * Returns a string representation of the InetAddress in the form 'hostname / ipaddress'
+         *
+         * If the hostname is not resolved than it appears as empty.
+         *
+         * @returns string value of this InetAddress.
+         */
+        virtual std::string toString() const;
+
+    public:  // Address Property Tests, override in the subclasses for correct results
+
+        /**
+         * Check if this InetAddress is a valid wildcard address.
+         *
+         * @return true if the address is a wildcard address.
+         */
+        virtual bool isAnyLocalAddress() const {
+            return false;
+        }
+
+        /**
+         * Check if this InetAddress is a valid loopback address.
+         *
+         * @return true if the address is a loopback address.
+         */
+        virtual bool isLoopbackAddress() const {
+            return false;
+        }
+
+        /**
+         * Check if this InetAddress is a valid Multicast address.
+         *
+         * @return true if the address is a Multicast address.
+         */
+        virtual bool isMulticastAddress() const {
+            return false;
+        }
+
+        /**
+         * Check if this InetAddress is a valid link local address.
+         *
+         * @return true if the address is a link local address.
+         */
+        virtual bool isLinkLocalAddress() const {
+            return false;
+        }
+
+        /**
+         * Check if this InetAddress is a valid site local address.
+         *
+         * @return true if the address is a site local address.
+         */
+        virtual bool isSiteLocalAddress() const {
+            return false;
+        }
+
+        /**
+         * Check if this InetAddress is Multicast and has Global scope.
+         *
+         * @return true if the address is Multicast and has Global scope.
+         */
+        virtual bool isMCGlobal() const {
+            return false;
+        }
+
+        /**
+         * Check if this InetAddress is Multicast and has Node Local scope.
+         *
+         * @return true if the address is Multicast and has Node Local scope.
+         */
+        virtual bool isMCNodeLocal() const {
+            return false;
+        }
+
+        /**
+         * Check if this InetAddress is Multicast and has Link Local scope.
+         *
+         * @return true if the address is Multicast and has Link Local scope.
+         */
+        virtual bool isMCLinkLocal() const {
+            return false;
+        }
+
+        /**
+         * Check if this InetAddress is Multicast and has Site Local scope.
+         *
+         * @return true if the address is Multicast and has Site Local scope.
+         */
+        virtual bool isMCSiteLocal() const {
+            return false;
+        }
+
+        /**
+         * Check if this InetAddress is Multicast and has Organization scope.
+         *
+         * @return true if the address is Multicast and has Organization scope.
+         */
+        virtual bool isMCOrgLocal() const {
+            return false;
+        }
+
+    public:  // Static Create methods.
+
+        /**
+         * Given a raw IP Address in byte array form, create and return a new InetAddress
instance.
+         *
+         * An IPV4 address must be only four bytes in length and an IPV6 address must be
16 bytes in length.
+         *
+         * @return a copy of an InetAddress that represents the given byte array address.
+         *
+         * @throws UnknownHostException if the address array length is invalid.
+         */
+        static InetAddress getByAddress( const unsigned char* bytes, int numBytes );
+
+        /**
+         * Given a host name and IPAddress return a new InetAddress.  There is no name service
checking or
+         * address validation done on the provided host name.  The host name can either be
machine name or
+         * the text based representation of the IP Address.
+         *
+         * An IPV4 address must be only four bytes in length and an IPV6 address must be
16 bytes in length.
+         *
+         * @return a copy of an InetAddress that represents the given byte array address.
+         *
+         * @throws UnknownHostException if the address array length is invalid.
+         */
+        static InetAddress getByAddress( const std::string& hostname, const unsigned
char* bytes, int numBytes );
+
+        /**
+         * Gets an InetAddress that is the local host address.  If the localhost value cannot
+         * be resolved than the InetAddress for Loopback is returned.
+         *
+         * @returns a new InetAddress object that contains the local host address.
+         *
+         * @throws UnknownHostException if the address for local host is not found.
+         */
+        static InetAddress getLocalHost();
+
+    protected:
+
+        /**
+         * Converts the bytes in an address array to an int starting from the value start
+         * treating the start value as the high order byte.
+         *
+         * @param bytes
+         *      The array of bytes to convert to an int.
+         * @param start
+         *      The index in the array to treat as the high order byte.
+         *
+         * @return an unsigned int that represents the address value.
          */
-        std::string getHostAddress() const;
+        static unsigned int bytesToInt( const unsigned char* bytes, int start );
 
     };
 

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=943604&r1=943603&r2=943604&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am Wed May 12 18:09:34 2010
@@ -111,6 +111,9 @@ cc_sources = \
     decaf/lang/StringTest.cpp \
     decaf/lang/SystemTest.cpp \
     decaf/lang/ThreadTest.cpp \
+    decaf/net/Inet4AddressTest.cpp \
+    decaf/net/Inet6AddressTest.cpp \
+    decaf/net/InetAddressTest.cpp \
     decaf/net/ServerSocketTest.cpp \
     decaf/net/SocketFactoryTest.cpp \
     decaf/net/SocketTest.cpp \
@@ -258,6 +261,9 @@ h_sources = \
     decaf/lang/StringTest.h \
     decaf/lang/SystemTest.h \
     decaf/lang/ThreadTest.h \
+    decaf/net/Inet4AddressTest.h \
+    decaf/net/Inet6AddressTest.h \
+    decaf/net/InetAddressTest.h \
     decaf/net/ServerSocketTest.h \
     decaf/net/SocketFactoryTest.h \
     decaf/net/SocketTest.h \

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet4AddressTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet4AddressTest.cpp?rev=943604&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet4AddressTest.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet4AddressTest.cpp Wed May
12 18:09:34 2010
@@ -0,0 +1,36 @@
+/*
+ * 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 "Inet4AddressTest.h"
+
+#include <decaf/net/Inet6Address.h>
+
+using namespace decaf;
+using namespace decaf::net;
+
+////////////////////////////////////////////////////////////////////////////////
+Inet4AddressTest::Inet4AddressTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Inet4AddressTest::~Inet4AddressTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Inet4AddressTest::testGetByAddress() {
+
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet4AddressTest.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet4AddressTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet4AddressTest.h?rev=943604&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet4AddressTest.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet4AddressTest.h Wed May
12 18:09:34 2010
@@ -0,0 +1,44 @@
+/*
+ * 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_NET_INET4ADDRESSTEST_H_
+#define _DECAF_NET_INET4ADDRESSTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace decaf {
+namespace net {
+
+    class Inet4AddressTest : public CppUnit::TestFixture {
+
+        CPPUNIT_TEST_SUITE( Inet4AddressTest );
+        CPPUNIT_TEST( testGetByAddress );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+
+        Inet4AddressTest();
+        virtual ~Inet4AddressTest();
+
+        void testGetByAddress();
+
+    };
+
+}}
+
+#endif /* _DECAF_NET_INET4ADDRESSTEST_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet4AddressTest.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet6AddressTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet6AddressTest.cpp?rev=943604&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet6AddressTest.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet6AddressTest.cpp Wed May
12 18:09:34 2010
@@ -0,0 +1,36 @@
+/*
+ * 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 "Inet6AddressTest.h"
+
+#include <decaf/net/Inet4Address.h>
+
+using namespace decaf;
+using namespace decaf::net;
+
+////////////////////////////////////////////////////////////////////////////////
+Inet6AddressTest::Inet6AddressTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Inet6AddressTest::~Inet6AddressTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Inet6AddressTest::testGetByAddress() {
+
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet6AddressTest.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet6AddressTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet6AddressTest.h?rev=943604&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet6AddressTest.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet6AddressTest.h Wed May
12 18:09:34 2010
@@ -0,0 +1,44 @@
+/*
+ * 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_NET_INET6ADDRESSTEST_H_
+#define _DECAF_NET_INET6ADDRESSTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace decaf {
+namespace net {
+
+    class Inet6AddressTest : public CppUnit::TestFixture {
+
+        CPPUNIT_TEST_SUITE( Inet6AddressTest );
+        CPPUNIT_TEST( testGetByAddress );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+
+        Inet6AddressTest();
+        virtual ~Inet6AddressTest();
+
+        void testGetByAddress();
+
+    };
+
+}}
+
+#endif /* _DECAF_NET_INET6ADDRESSTEST_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/Inet6AddressTest.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/InetAddressTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/InetAddressTest.cpp?rev=943604&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/InetAddressTest.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/InetAddressTest.cpp Wed May
12 18:09:34 2010
@@ -0,0 +1,63 @@
+/*
+ * 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 "InetAddressTest.h"
+
+#include <decaf/net/InetAddress.h>
+#include <decaf/net/UnknownHostException.h>
+
+using namespace decaf;
+using namespace decaf::net;
+using namespace decaf::lang;
+
+////////////////////////////////////////////////////////////////////////////////
+InetAddressTest::InetAddressTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+InetAddressTest::~InetAddressTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void InetAddressTest::testGetByAddress() {
+
+    const unsigned char bytes[] = { 127, 0, 0, 1 };
+    InetAddress address = InetAddress::getByAddress( bytes, 4 );
+
+    ArrayPointer<unsigned char> value = address.getAddress();
+
+    CPPUNIT_ASSERT( value.get() != NULL );
+    CPPUNIT_ASSERT_EQUAL( bytes[0], value[0] );
+    CPPUNIT_ASSERT_EQUAL( bytes[1], value[1] );
+    CPPUNIT_ASSERT_EQUAL( bytes[2], value[2] );
+    CPPUNIT_ASSERT_EQUAL( bytes[3], value[3] );
+
+    const unsigned char invalid[] = { 1 };
+
+    CPPUNIT_ASSERT_THROW_MESSAGE(
+        "Should throw an UnknownHostException",
+        InetAddress::getByAddress( invalid, 1 ),
+        UnknownHostException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void InetAddressTest::testGetHostAddress() {
+
+    const unsigned char bytes[] = { 127, 0, 0, 1 };
+    InetAddress address = InetAddress::getByAddress( bytes, 4 );
+    CPPUNIT_ASSERT_EQUAL( std::string( "127.0.0.1" ), address.getHostAddress() );
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/InetAddressTest.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/InetAddressTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/InetAddressTest.h?rev=943604&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/InetAddressTest.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/InetAddressTest.h Wed May
12 18:09:34 2010
@@ -0,0 +1,46 @@
+/*
+ * 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_NET_INETADDRESSTEST_H_
+#define _DECAF_NET_INETADDRESSTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace decaf {
+namespace net {
+
+    class InetAddressTest : public CppUnit::TestFixture {
+
+        CPPUNIT_TEST_SUITE( InetAddressTest );
+        CPPUNIT_TEST( testGetByAddress );
+        CPPUNIT_TEST( testGetHostAddress );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+
+        InetAddressTest();
+        virtual ~InetAddressTest();
+
+        void testGetByAddress();
+        void testGetHostAddress();
+
+    };
+
+}}
+
+#endif /* _DECAF_NET_INETADDRESSTEST_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/net/InetAddressTest.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=943604&r1=943603&r2=943604&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp Wed May 12 18:09:34
2010
@@ -223,11 +223,17 @@
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::SystemTest );
 //#include <decaf/lang/PointerTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::PointerTest );
-//#include <decaf/lang/ArrayPointerTest.h>
-//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::ArrayPointerTest );
+#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/net/InetAddressTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::net::InetAddressTest );
+#include <decaf/net/Inet4AddressTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::net::InetAddressTest );
+#include <decaf/net/Inet6AddressTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::net::InetAddressTest );
 //#include <decaf/net/SocketFactoryTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::net::SocketFactoryTest );
 //#include <decaf/net/ServerSocketTest.h>



Mime
View raw message