NO-JIRA: c++: additional tests for type conversion.

Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/41eac741
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/41eac741
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/41eac741

Branch: refs/heads/go1
Commit: 41eac74143f0ca644335d6dd7d5ab9fe9775d987
Parents: 89923cf
Author: Alan Conway <[email protected]>
Authored: Tue Nov 17 16:51:40 2015 -0500
Committer: Alan Conway <[email protected]>
Committed: Tue Nov 17 16:51:40 2015 -0500

----------------------------------------------------------------------
 .../bindings/cpp/src/encode_decode_test.cpp     | 50 ++++++++++++++------
 proton-c/bindings/cpp/src/interop_test.cpp      |  6 ---
 proton-c/bindings/cpp/src/test_bits.hpp         |  4 ++
 3 files changed, 40 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/41eac741/proton-c/bindings/cpp/src/encode_decode_test.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/encode_decode_test.cpp 
b/proton-c/bindings/cpp/src/encode_decode_test.cpp
index 89f2c36..6f5eb88 100644
--- a/proton-c/bindings/cpp/src/encode_decode_test.cpp
+++ b/proton-c/bindings/cpp/src/encode_decode_test.cpp
@@ -42,33 +42,55 @@ template <class T> void value_test(T x, type_id tid, const 
std::string& s, T y)
     ASSERT_EQUAL(x, v2.get<T>());
 
     ASSERT_EQUAL(v, v2);
-    std::ostringstream os;
-    os << v;
-    ASSERT_EQUAL(s, os.str());
+    ASSERT_EQUAL(s, str(v));
     ASSERT(x != y);
     ASSERT(x < y);
     ASSERT(y > x);
 }
 
 void value_tests() {
-    value_test(false, BOOLEAN, "0", true);
+    value_test(false, BOOLEAN, "false", true);
     value_test(amqp_ubyte(42), UBYTE, "42", amqp_ubyte(50));
-    value_test(amqp_byte(-42), BYTE, "42", amqp_byte(-40));
-    value_test(amqp_ushort(-4242), USHORT, "4242", amqp_ushort(5252));
-    value_test(amqp_short(4242), SHORT, "-4242", amqp_short(3));
-    value_test(amqp_uint(-4242), UINT, "4242", amqp_uint(5252));
-    value_test(amqp_int(4242), INT, "-4242", amqp_int(3));
-    value_test(amqp_ulong(-4242), ULONG, "4242", amqp_ulong(5252));
-    value_test(amqp_long(4242), LONG, "-4242", amqp_long(3));
-    value_test(amqp_float(1.234), FLOAT, "4242", amqp_float(2.345));
-    value_test(amqp_double(11.2233), DOUBLE, "-4242", amqp_double(12));
+    value_test(amqp_byte(-42), BYTE, "-42", amqp_byte(-40));
+    value_test(amqp_ushort(4242), USHORT, "4242", amqp_ushort(5252));
+    value_test(amqp_short(-4242), SHORT, "-4242", amqp_short(3));
+    value_test(amqp_uint(4242), UINT, "4242", amqp_uint(5252));
+    value_test(amqp_int(-4242), INT, "-4242", amqp_int(3));
+    value_test(amqp_ulong(4242), ULONG, "4242", amqp_ulong(5252));
+    value_test(amqp_long(-4242), LONG, "-4242", amqp_long(3));
+    value_test(amqp_float(1.234), FLOAT, "1.234", amqp_float(2.345));
+    value_test(amqp_double(11.2233), DOUBLE, "11.2233", amqp_double(12));
     value_test(amqp_string("aaa"), STRING, "aaa", amqp_string("aaaa"));
     value_test(std::string("xxx"), STRING, "xxx", std::string("yyy"));
     value_test(amqp_symbol("aaa"), SYMBOL, "aaa", amqp_symbol("aaaa"));
-    value_test(amqp_binary("aaa"), BINARY, "aaa", amqp_binary("aaaa"));
+    value_test(amqp_binary("aaa"), BINARY, "b\"aaa\"", amqp_binary("aaaa"));
+}
+
+// Map values
+void map_test() {
+    std::map<string, int> m;
+    m["a"] = 1;
+    m["b"] = 2;
+    m["c"] = 3;
+    proton::value v = m;
+    ASSERT_EQUAL("{\"a\"=1, \"b\"=2, \"c\"=3}",  str(v));
+    std::map<value, value> mv;
+    v.get(mv);
+    ASSERT_EQUAL(mv["a"], value(amqp_int(1)));
+    mv["b"] = amqp_binary("xyz");
+    mv.erase("c");
+    v = value(mv);
+    ASSERT_EQUAL("{\"a\"=1, \"b\"=b\"xyz\"}",  str(v));
+    std::vector<std::pair<string, value> > vec;
+    v.decoder() >> to_pairs(vec);       // FIXME aconway 2015-11-17: get 
doesn't work with pairs.
+    ASSERT_EQUAL(2, vec.size());
+    ASSERT_EQUAL(std::make_pair(std::string("a"), value(1)), vec[0]);
+    ASSERT_EQUAL(std::make_pair(std::string("b"), value(amqp_binary("xyz"))), 
vec[1]);
 }
 
 int main(int, char**) {
     int failed = 0;
+    failed += RUN_TEST(map_test);
+    failed += RUN_TEST(value_tests);
     return failed;
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/41eac741/proton-c/bindings/cpp/src/interop_test.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/interop_test.cpp 
b/proton-c/bindings/cpp/src/interop_test.cpp
index 0bac03c..9806dac 100644
--- a/proton-c/bindings/cpp/src/interop_test.cpp
+++ b/proton-c/bindings/cpp/src/interop_test.cpp
@@ -45,12 +45,6 @@ template <class T> T get(decoder& d) {
     return v;
 }
 
-template <class T> std::string str(const T& value) {
-    ostringstream oss;
-    oss << value;
-    return oss.str();
-}
-
 // Test data ostream operator
 void test_data_ostream() {
     value dv;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/41eac741/proton-c/bindings/cpp/src/test_bits.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/test_bits.hpp 
b/proton-c/bindings/cpp/src/test_bits.hpp
index 2c245cd..674ac22 100644
--- a/proton-c/bindings/cpp/src/test_bits.hpp
+++ b/proton-c/bindings/cpp/src/test_bits.hpp
@@ -21,6 +21,7 @@
 
 #include <stdexcept>
 #include <iostream>
+#include <sstream>
 #include "msg.hpp"
 
 namespace {
@@ -44,5 +45,8 @@ int run_test(void (*testfn)(), const char* name) {
 }
 
 #define RUN_TEST(TEST) run_test(TEST, #TEST)
+
+template<class T> std::string str(const T& x) { std::ostringstream s; s << x; 
return s.str(); }
+
 }
 #endif // TEST_BITS_HPP


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to