qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject svn commit: r891636 - in /qpid/trunk/qpid/cpp: include/qpid/messaging/Variant.h src/qpid/messaging/Message.cpp src/qpid/messaging/Variant.cpp src/tests/CMakeLists.txt src/tests/ClientMessage.cpp src/tests/Makefile.am src/tests/Variant.cpp
Date Thu, 17 Dec 2009 11:14:58 GMT
Author: gsim
Date: Thu Dec 17 11:14:57 2009
New Revision: 891636

URL: http://svn.apache.org/viewvc?rev=891636&view=rev
Log:
QPID-2289: Fixed copy constructor in qpid::messaging::Message, added in equality operator
for qpid::messaging::Variant

Added:
    qpid/trunk/qpid/cpp/src/tests/ClientMessage.cpp
Modified:
    qpid/trunk/qpid/cpp/include/qpid/messaging/Variant.h
    qpid/trunk/qpid/cpp/src/qpid/messaging/Message.cpp
    qpid/trunk/qpid/cpp/src/qpid/messaging/Variant.cpp
    qpid/trunk/qpid/cpp/src/tests/CMakeLists.txt
    qpid/trunk/qpid/cpp/src/tests/Makefile.am
    qpid/trunk/qpid/cpp/src/tests/Variant.cpp

Modified: qpid/trunk/qpid/cpp/include/qpid/messaging/Variant.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/include/qpid/messaging/Variant.h?rev=891636&r1=891635&r2=891636&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/include/qpid/messaging/Variant.h (original)
+++ qpid/trunk/qpid/cpp/include/qpid/messaging/Variant.h Thu Dec 17 11:14:57 2009
@@ -149,6 +149,8 @@
     QPID_CLIENT_EXTERN void setEncoding(const std::string&);
     QPID_CLIENT_EXTERN const std::string& getEncoding() const;
 
+    QPID_CLIENT_EXTERN bool isEqualTo(const Variant& a) const;
+
     QPID_CLIENT_EXTERN void reset();    
   private:
     VariantImpl* impl;
@@ -157,6 +159,7 @@
 QPID_CLIENT_EXTERN std::ostream& operator<<(std::ostream& out, const Variant&
value);
 QPID_CLIENT_EXTERN std::ostream& operator<<(std::ostream& out, const Variant::Map&
map);
 QPID_CLIENT_EXTERN std::ostream& operator<<(std::ostream& out, const Variant::List&
list);
+QPID_CLIENT_EXTERN bool operator==(const Variant& a, const Variant& b);
 
 typedef Variant::Map VariantMap;
 

Modified: qpid/trunk/qpid/cpp/src/qpid/messaging/Message.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/messaging/Message.cpp?rev=891636&r1=891635&r2=891636&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/messaging/Message.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/messaging/Message.cpp Thu Dec 17 11:14:57 2009
@@ -27,7 +27,7 @@
 Message::Message(const std::string& bytes) : impl(new MessageImpl(bytes)) {}
 Message::Message(const char* bytes, size_t count) : impl(new MessageImpl(bytes, count)) {}
 
-Message::Message(const Message& m) : impl(new MessageImpl(m.getContent())) {}
+Message::Message(const Message& m) : impl(new MessageImpl(*m.impl)) {}
 Message::~Message() { delete impl; }
 
 Message& Message::operator=(const Message& m) { *impl = *m.impl; return *this; }

Modified: qpid/trunk/qpid/cpp/src/qpid/messaging/Variant.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/messaging/Variant.cpp?rev=891636&r1=891635&r2=891636&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/messaging/Variant.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/messaging/Variant.cpp Thu Dec 17 11:14:57 2009
@@ -21,11 +21,10 @@
 #include "qpid/messaging/Variant.h"
 #include <boost/format.hpp>
 #include <boost/lexical_cast.hpp>
+#include <algorithm>
+#include <sstream>
 
 namespace qpid {
-namespace client {
-}
-
 namespace messaging {
 
 InvalidConversion::InvalidConversion(const std::string& msg) : Exception(msg) {}
@@ -81,6 +80,9 @@
     void setEncoding(const std::string&);
     const std::string& getEncoding() const;
 
+    bool isEqualTo(VariantImpl&) const;
+    bool isEquivalentTo(VariantImpl&) const;
+
     static VariantImpl* create(const Variant&);    
   private:
     const VariantType type;
@@ -170,6 +172,18 @@
     throw InvalidConversion(QPID_MSG("Cannot convert " << s << " to bool"));
   
 }
 
+template <class T> std::string toString(const T& t)
+{
+    std::stringstream out;
+    out << t;
+    return out.str();
+}
+
+template <class T> bool equal(const T& a, const T& b)
+{
+    return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin());
+}
+
 }
 
 bool VariantImpl::asBool() const
@@ -298,10 +312,37 @@
       case VAR_DOUBLE: return boost::lexical_cast<std::string>(value.d);
       case VAR_FLOAT: return boost::lexical_cast<std::string>(value.f);
       case VAR_STRING: return *reinterpret_cast<std::string*>(value.v);
+      case VAR_LIST: return toString(asList());
+      case VAR_MAP: return toString(asMap());
       default: throw InvalidConversion(QPID_MSG("Cannot convert from " << getTypeName(type)
<< " to " << getTypeName(VAR_STRING)));
     }
 }
 
+bool VariantImpl::isEqualTo(VariantImpl& other) const
+{
+    if (type == other.type) {
+        switch(type) {
+          case VAR_VOID: return true;
+          case VAR_BOOL: return value.b == other.value.b;
+          case VAR_UINT8: return value.ui8 == other.value.ui8;
+          case VAR_UINT16: return value.ui16 == other.value.ui16;
+          case VAR_UINT32: return value.ui32 == other.value.ui32;
+          case VAR_UINT64: return value.ui64 == other.value.ui64;
+          case VAR_INT8: return value.i8 == other.value.i8;
+          case VAR_INT16: return value.i16 == other.value.i16;
+          case VAR_INT32: return value.i32 == other.value.i32;
+          case VAR_INT64: return value.i64 == other.value.i64;
+          case VAR_DOUBLE: return value.d == other.value.d;
+          case VAR_FLOAT: return value.f == other.value.f;
+          case VAR_STRING: return *reinterpret_cast<std::string*>(value.v) 
+                == *reinterpret_cast<std::string*>(other.value.v);
+          case VAR_LIST: return equal(asList(), other.asList());
+          case VAR_MAP: return equal(asMap(), other.asMap());
+        }
+    }
+    return false;
+}
+
 const Variant::Map& VariantImpl::asMap() const
 {
     switch(type) {
@@ -605,4 +646,14 @@
     return out;    
 }
 
+bool operator==(const Variant& a, const Variant& b)
+{
+    return a.isEqualTo(b);
+}
+
+bool Variant::isEqualTo(const Variant& other) const
+{
+    return impl->isEqualTo(*other.impl);
+}
+
 }} // namespace qpid::messaging

Modified: qpid/trunk/qpid/cpp/src/tests/CMakeLists.txt
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/CMakeLists.txt?rev=891636&r1=891635&r2=891636&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/CMakeLists.txt (original)
+++ qpid/trunk/qpid/cpp/src/tests/CMakeLists.txt Thu Dec 17 11:14:57 2009
@@ -140,6 +140,7 @@
     ClientMessageTest
     PollableCondition
     Variant
+    ClientMessage
     ${xml_tests}
     CACHE STRING "Which unit tests to build"
    )

Added: qpid/trunk/qpid/cpp/src/tests/ClientMessage.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/ClientMessage.cpp?rev=891636&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/ClientMessage.cpp (added)
+++ qpid/trunk/qpid/cpp/src/tests/ClientMessage.cpp Thu Dec 17 11:14:57 2009
@@ -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.
+ *
+ */
+#include <iostream>
+#include "qpid/messaging/Message.h"
+
+#include "unit_test.h"
+
+using namespace qpid::messaging;
+
+namespace qpid {
+namespace tests {
+
+QPID_AUTO_TEST_SUITE(ClientMessageSuite)
+
+QPID_AUTO_TEST_CASE(testCopyConstructor)
+{
+    Message m("my-data");
+    m.setSubject("my-subject");
+    m.getHeaders()["a"] = "ABC";
+    Message c(m);
+    BOOST_CHECK_EQUAL(m.getContent(), c.getContent());
+    BOOST_CHECK_EQUAL(m.getSubject(), c.getSubject());
+    BOOST_CHECK_EQUAL(m.getHeaders()["a"], c.getHeaders()["a"]);
+}
+
+QPID_AUTO_TEST_SUITE_END()
+
+}} // namespace qpid::tests

Modified: qpid/trunk/qpid/cpp/src/tests/Makefile.am
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/Makefile.am?rev=891636&r1=891635&r2=891636&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/Makefile.am (original)
+++ qpid/trunk/qpid/cpp/src/tests/Makefile.am Thu Dec 17 11:14:57 2009
@@ -116,7 +116,8 @@
 	ClientMessageTest.cpp \
 	PollableCondition.cpp \
 	Variant.cpp \
-	Address.cpp
+	Address.cpp \
+	ClientMessage.cpp
 
 if HAVE_XML
 unit_test_SOURCES+= XmlClientSessionTest.cpp

Modified: qpid/trunk/qpid/cpp/src/tests/Variant.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/Variant.cpp?rev=891636&r1=891635&r2=891636&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/Variant.cpp (original)
+++ qpid/trunk/qpid/cpp/src/tests/Variant.cpp Thu Dec 17 11:14:57 2009
@@ -157,6 +157,22 @@
     BOOST_CHECK_EQUAL(std::string("now it's a string"), value.asMap()["my-key"].asString());
 }
 
+QPID_AUTO_TEST_CASE(testIsEqualTo)
+{
+    BOOST_CHECK_EQUAL(Variant("abc"), Variant("abc"));
+    BOOST_CHECK_EQUAL(Variant(1234), Variant(1234));
+
+    Variant a = Variant::Map();
+    a.asMap()["colour"] = "red";
+    a.asMap()["pi"] = 3.14f;
+    a.asMap()["my-key"] = 1234;
+    Variant b = Variant::Map();
+    b.asMap()["colour"] = "red";
+    b.asMap()["pi"] = 3.14f;
+    b.asMap()["my-key"] = 1234;
+    BOOST_CHECK_EQUAL(a, b);
+}
+
 QPID_AUTO_TEST_SUITE_END()
 
 }} // namespace qpid::tests



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org


Mime
View raw message