You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2016/03/17 20:28:24 UTC

qpid-proton git commit: PROTON-1159: Some improvements for qpid-interop-test: Added operator<<() to byte_array and decimal classes. Fixed UUID print bug. [Forced Update!]

Repository: qpid-proton
Updated Branches:
  refs/heads/kvdr-PROTON-1159 e15bcdd09 -> 43cebe18b (forced update)


PROTON-1159: Some improvements for qpid-interop-test: Added operator<<() to byte_array and decimal classes. Fixed UUID print bug.


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

Branch: refs/heads/kvdr-PROTON-1159
Commit: 43cebe18b6aeeedc5dfedf47d30a5383f16887e3
Parents: d70dab5
Author: Kim van der Riet <kp...@apache.org>
Authored: Tue Mar 15 10:36:24 2016 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Thu Mar 17 15:24:08 2016 -0400

----------------------------------------------------------------------
 proton-c/bindings/cpp/CMakeLists.txt            |  1 +
 .../bindings/cpp/include/proton/byte_array.hpp  | 10 +++++
 .../bindings/cpp/include/proton/type_id.hpp     |  1 +
 proton-c/bindings/cpp/src/binary.cpp            | 15 ++++----
 proton-c/bindings/cpp/src/byte_array.cpp        | 39 ++++++++++++++++++++
 proton-c/bindings/cpp/src/decimal.cpp           | 16 ++++++--
 proton-c/bindings/cpp/src/types_internal.hpp    | 14 ++++++-
 proton-c/bindings/cpp/src/uuid.cpp              | 10 ++---
 proton-c/bindings/cpp/src/value_test.cpp        |  6 +--
 9 files changed, 89 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/43cebe18/proton-c/bindings/cpp/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/CMakeLists.txt b/proton-c/bindings/cpp/CMakeLists.txt
index ebd38c1..26a7c94 100644
--- a/proton-c/bindings/cpp/CMakeLists.txt
+++ b/proton-c/bindings/cpp/CMakeLists.txt
@@ -27,6 +27,7 @@ include_directories(
 set(qpid-proton-cpp-source
   src/acceptor.cpp
   src/binary.cpp
+  src/byte_array.cpp
   src/scalar_base.cpp
   src/condition.cpp
   src/connection.cpp

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/43cebe18/proton-c/bindings/cpp/include/proton/byte_array.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/byte_array.hpp b/proton-c/bindings/cpp/include/proton/byte_array.hpp
index fe3f864..d695007 100644
--- a/proton-c/bindings/cpp/include/proton/byte_array.hpp
+++ b/proton-c/bindings/cpp/include/proton/byte_array.hpp
@@ -27,6 +27,10 @@
 
 namespace proton {
 
+namespace internal {
+void print_hex(std::ostream& o, const uint8_t* p, size_t n);
+}
+
 /// Used to represent fixed-sized data types that don't have a natural C++ representation
 /// as an array of bytes.
 template <size_t N> class byte_array : private comparable<byte_array<N> > {
@@ -74,6 +78,12 @@ template <size_t N> class byte_array : private comparable<byte_array<N> > {
   }
     ///@}
 
+    /// Print byte array in hex.
+  friend std::ostream& operator<<(std::ostream& o, const byte_array& b) {
+      internal::print_hex(o, b.begin(), b.size());
+      return o;
+  }
+
   private:
     value_type bytes_[N];
 };

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/43cebe18/proton-c/bindings/cpp/include/proton/type_id.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/type_id.hpp b/proton-c/bindings/cpp/include/proton/type_id.hpp
index 8a6e841..d454bc3 100644
--- a/proton-c/bindings/cpp/include/proton/type_id.hpp
+++ b/proton-c/bindings/cpp/include/proton/type_id.hpp
@@ -79,6 +79,7 @@ inline bool type_id_is_signed(type_id t) { return type_id_is_signed_int(t) || ty
 inline bool type_id_is_string_like(type_id t) { return t == BINARY || t == STRING || t == SYMBOL; }
 inline bool type_id_is_container(type_id t) { return t == LIST || t == MAP || t == ARRAY || t == DESCRIBED; }
 inline bool type_id_is_scalar(type_id t) { return type_id_is_integral(t) || type_id_is_floating_point(t) || type_id_is_decimal(t) || type_id_is_string_like(t) || t == TIMESTAMP || t == UUID; }
+inline bool type_id_is_null(type_id t) { return t == NULL_TYPE; }
 ///}
 
 } // proton

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/43cebe18/proton-c/bindings/cpp/src/binary.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/binary.cpp b/proton-c/bindings/cpp/src/binary.cpp
index e99d83e..f854935 100644
--- a/proton-c/bindings/cpp/src/binary.cpp
+++ b/proton-c/bindings/cpp/src/binary.cpp
@@ -17,6 +17,8 @@
  * under the License.
  */
 
+#include "types_internal.hpp"
+
 #include <proton/binary.hpp>
 
 #include <ostream>
@@ -27,18 +29,15 @@
 namespace proton {
 
 std::ostream& operator<<(std::ostream& o, const binary& x) {
-    std::ios_base::fmtflags flags = o.flags();
-    char fill = o.fill();
-    o << std::setfill('0') << "b\"";
+    ios_guard restore_flags(o);
+    o << std::hex << std::setfill('0') << "b\"";
     for (binary::const_iterator i = x.begin(); i != x.end(); ++i) {
-        if (!isprint(*i) && !isspace(*i)) {
-            o << std::hex << "\\x" << std::setw(2) << static_cast<unsigned>(*i);
-            o.flags(flags);
+        if (!isprint(*i) && !isspace(*i)) { // Non-printables in hex.
+            o << "\\x" << std::setw(2) << printable_byte(*i);
         } else {
-            o << *i;
+            o << char(*i);
         }
     }
-    o.fill(fill);
     return o << '"';
 }
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/43cebe18/proton-c/bindings/cpp/src/byte_array.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/byte_array.cpp b/proton-c/bindings/cpp/src/byte_array.cpp
new file mode 100644
index 0000000..b5ffbac
--- /dev/null
+++ b/proton-c/bindings/cpp/src/byte_array.cpp
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+#include "types_internal.hpp"
+
+#include <proton/byte_array.hpp>
+
+#include <ostream>
+#include <iomanip>
+
+namespace proton {
+namespace internal {
+
+void print_hex(std::ostream& o, const uint8_t* p, size_t n) {
+    ios_guard restore_flags(o);
+    o << "0x" << std::hex << std::setfill('0');
+    for (size_t i = 0; i < n; ++i) {
+        o << std::setw(2) << printable_byte(p[i]);
+    }
+}
+
+}}

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/43cebe18/proton-c/bindings/cpp/src/decimal.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/decimal.cpp b/proton-c/bindings/cpp/src/decimal.cpp
index 93fe84c..0cadb19 100644
--- a/proton-c/bindings/cpp/src/decimal.cpp
+++ b/proton-c/bindings/cpp/src/decimal.cpp
@@ -21,7 +21,17 @@
 #include <iostream>
 
 namespace proton {
-std::ostream& operator<<(std::ostream& o, const decimal32& ) { return o << "<decimal32>"; }
-std::ostream& operator<<(std::ostream& o, const decimal64& ) { return o << "<decimal64>"; }
-std::ostream& operator<<(std::ostream& o, const decimal128& ) { return o << "<decimal128>"; }
+
+std::ostream& operator<<(std::ostream& o, const decimal32& d) {
+    return o << "decimal32(" <<static_cast<byte_array<sizeof(d)> >(d)<< ")";
+}
+
+std::ostream& operator<<(std::ostream& o, const decimal64& d) {
+    return o << "decimal64(" <<static_cast<byte_array<sizeof(d)> >(d)<< ")";
+}
+
+std::ostream& operator<<(std::ostream& o, const decimal128& d) {
+    return o << "decimal128(" <<static_cast<byte_array<sizeof(d)> >(d)<< ")";
+}
+
 }

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/43cebe18/proton-c/bindings/cpp/src/types_internal.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/types_internal.hpp b/proton-c/bindings/cpp/src/types_internal.hpp
index 74427a1..11d2e39 100644
--- a/proton-c/bindings/cpp/src/types_internal.hpp
+++ b/proton-c/bindings/cpp/src/types_internal.hpp
@@ -25,7 +25,7 @@
 #include <sstream>
 
 ///@file
-/// Internal helpers for encode/decode/type conversion.
+/// Inline helpers for encode/decode/type conversion/ostream operators.
 
 namespace proton {
 
@@ -58,6 +58,16 @@ inline pn_bytes_t pn_bytes(const binary& s) {
 inline std::string str(const pn_bytes_t& b) { return std::string(b.start, b.size); }
 inline binary bin(const pn_bytes_t& b) { return binary(b.start, b.start+b.size); }
 
-}
+// Save all stream format state, restore in destructor.
+struct ios_guard {
+    std::ios &guarded;
+    std::ios old;
+    ios_guard(std::ios& x) : guarded(x), old(0) { old.copyfmt(guarded); }
+    ~ios_guard() { guarded.copyfmt(old); }
+};
 
+// Convert a char (signed or unsigned) into an unsigned 1 byte integer that will ostream 
+// as a numeric byte value, not a character and will not get sign-extended.
+inline unsigned int printable_byte(uint8_t byte) { return byte; }
+}
 #endif // CODEC_HPP

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/43cebe18/proton-c/bindings/cpp/src/uuid.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/uuid.cpp b/proton-c/bindings/cpp/src/uuid.cpp
index f224df7..22c4047 100644
--- a/proton-c/bindings/cpp/src/uuid.cpp
+++ b/proton-c/bindings/cpp/src/uuid.cpp
@@ -17,6 +17,8 @@
  * under the License.
  */
 
+#include "types_internal.hpp"
+
 #include <proton/uuid.hpp>
 #include <proton/types_fwd.hpp>
 
@@ -49,12 +51,6 @@ struct seed {
     }
 } seed_;
 
-struct ios_guard {
-    std::ios &guarded;
-    std::ios old;
-    ios_guard(std::ios& x) : guarded(x), old(0) { old.copyfmt(guarded); }
-    ~ios_guard() { guarded.copyfmt(old); }
-};
 }
 
 uuid uuid::copy(const char* bytes) {
@@ -93,7 +89,7 @@ std::ostream& operator<<(std::ostream& o, const uuid& u) {
         if (i > 0)
             o << '-';
         for (int j = 0; j < segments[i]; ++j) {
-            o << std::setw(2) << int(*(p++));
+            o << std::setw(2) << printable_byte(*(p++));
         }
     }
     return o;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/43cebe18/proton-c/bindings/cpp/src/value_test.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/value_test.cpp b/proton-c/bindings/cpp/src/value_test.cpp
index fe7c089..d636ffa 100644
--- a/proton-c/bindings/cpp/src/value_test.cpp
+++ b/proton-c/bindings/cpp/src/value_test.cpp
@@ -162,9 +162,9 @@ int main(int, char**) {
     RUN_TEST(failed, simple_type_test(float(1.234), FLOAT, "1.234", float(2.345)));
     RUN_TEST(failed, simple_type_test(double(11.2233), DOUBLE, "11.2233", double(12)));
     RUN_TEST(failed, simple_type_test(timestamp(1234), TIMESTAMP, "1234", timestamp(12345)));
-    RUN_TEST(failed, simple_type_test(make<decimal32>(0), DECIMAL32, "<decimal32>", make<decimal32>(1)));
-    RUN_TEST(failed, simple_type_test(make<decimal64>(0), DECIMAL64, "<decimal64>", make<decimal64>(1)));
-    RUN_TEST(failed, simple_type_test(make<decimal128>(0), DECIMAL128, "<decimal128>", make<decimal128>(1)));
+    RUN_TEST(failed, simple_type_test(make<decimal32>(1), DECIMAL32, "decimal32(0x01010101)", make<decimal32>(2)));
+    RUN_TEST(failed, simple_type_test(make<decimal64>(3), DECIMAL64, "decimal64(0x0303030303030303)", make<decimal64>(4)));
+    RUN_TEST(failed, simple_type_test(make<decimal128>(5), DECIMAL128, "decimal128(0x05050505050505050505050505050505)", make<decimal128>(6)));
     RUN_TEST(failed, simple_type_test(
                  uuid::copy("\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff"),
                  UUID, "00112233-4455-6677-8899-aabbccddeeff",


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org