teemperor updated this revision to Diff 158126.
teemperor edited the summary of this revision.
teemperor added a comment.

- Reverse patch dependencies that we can add the unit test here (but also means 
this has to wait until the StreamTest is in).


https://reviews.llvm.org/D50025

Files:
  source/Utility/Stream.cpp
  unittests/Utility/StreamTest.cpp


Index: unittests/Utility/StreamTest.cpp
===================================================================
--- unittests/Utility/StreamTest.cpp
+++ unittests/Utility/StreamTest.cpp
@@ -191,6 +191,32 @@
   EXPECT_EQ("1234567890abcdefffffffffffffffff0000000000000000", Value());
 }
 
+TEST_F(StreamTest, PutMaxHex64ByteOrderBig) {
+  std::size_t bytes;
+  bytes = s.PutMaxHex64(0x12U, 1, lldb::eByteOrderBig);
+  EXPECT_EQ(2U, bytes);
+  bytes = s.PutMaxHex64(0x1234U, 2, lldb::eByteOrderBig);
+  EXPECT_EQ(4U, bytes);
+  bytes = s.PutMaxHex64(0x12345678U, 4, lldb::eByteOrderBig);
+  EXPECT_EQ(8U, bytes);
+  bytes = s.PutMaxHex64(0x1234567890ABCDEFU, 8, lldb::eByteOrderBig);
+  EXPECT_EQ(16U, bytes);
+  EXPECT_EQ("121234123456781234567890abcdef", Value());
+}
+
+TEST_F(StreamTest, PutMaxHex64ByteOrderLittle) {
+  std::size_t bytes;
+  bytes = s.PutMaxHex64(0x12U, 1, lldb::eByteOrderLittle);
+  EXPECT_EQ(2U, bytes);
+  bytes = s.PutMaxHex64(0x1234U, 2, lldb::eByteOrderLittle);
+  EXPECT_EQ(4U, bytes);
+  bytes = s.PutMaxHex64(0x12345678U, 4, lldb::eByteOrderLittle);
+  EXPECT_EQ(8U, bytes);
+  bytes = s.PutMaxHex64(0x1234567890ABCDEFU, 8, lldb::eByteOrderLittle);
+  EXPECT_EQ(16U, bytes);
+  EXPECT_EQ("12341278563412efcdab9078563412", Value());
+}
+
 
//------------------------------------------------------------------------------
 // Shift operator tests.
 
//------------------------------------------------------------------------------
Index: source/Utility/Stream.cpp
===================================================================
--- source/Utility/Stream.cpp
+++ source/Utility/Stream.cpp
@@ -427,11 +427,11 @@
   case 1:
     return PutHex8((uint8_t)uvalue);
   case 2:
-    return PutHex16((uint16_t)uvalue);
+    return PutHex16((uint16_t)uvalue, byte_order);
   case 4:
-    return PutHex32((uint32_t)uvalue);
+    return PutHex32((uint32_t)uvalue, byte_order);
   case 8:
-    return PutHex64(uvalue);
+    return PutHex64(uvalue, byte_order);
   }
   return 0;
 }


Index: unittests/Utility/StreamTest.cpp
===================================================================
--- unittests/Utility/StreamTest.cpp
+++ unittests/Utility/StreamTest.cpp
@@ -191,6 +191,32 @@
   EXPECT_EQ("1234567890abcdefffffffffffffffff0000000000000000", Value());
 }
 
+TEST_F(StreamTest, PutMaxHex64ByteOrderBig) {
+  std::size_t bytes;
+  bytes = s.PutMaxHex64(0x12U, 1, lldb::eByteOrderBig);
+  EXPECT_EQ(2U, bytes);
+  bytes = s.PutMaxHex64(0x1234U, 2, lldb::eByteOrderBig);
+  EXPECT_EQ(4U, bytes);
+  bytes = s.PutMaxHex64(0x12345678U, 4, lldb::eByteOrderBig);
+  EXPECT_EQ(8U, bytes);
+  bytes = s.PutMaxHex64(0x1234567890ABCDEFU, 8, lldb::eByteOrderBig);
+  EXPECT_EQ(16U, bytes);
+  EXPECT_EQ("121234123456781234567890abcdef", Value());
+}
+
+TEST_F(StreamTest, PutMaxHex64ByteOrderLittle) {
+  std::size_t bytes;
+  bytes = s.PutMaxHex64(0x12U, 1, lldb::eByteOrderLittle);
+  EXPECT_EQ(2U, bytes);
+  bytes = s.PutMaxHex64(0x1234U, 2, lldb::eByteOrderLittle);
+  EXPECT_EQ(4U, bytes);
+  bytes = s.PutMaxHex64(0x12345678U, 4, lldb::eByteOrderLittle);
+  EXPECT_EQ(8U, bytes);
+  bytes = s.PutMaxHex64(0x1234567890ABCDEFU, 8, lldb::eByteOrderLittle);
+  EXPECT_EQ(16U, bytes);
+  EXPECT_EQ("12341278563412efcdab9078563412", Value());
+}
+
 //------------------------------------------------------------------------------
 // Shift operator tests.
 //------------------------------------------------------------------------------
Index: source/Utility/Stream.cpp
===================================================================
--- source/Utility/Stream.cpp
+++ source/Utility/Stream.cpp
@@ -427,11 +427,11 @@
   case 1:
     return PutHex8((uint8_t)uvalue);
   case 2:
-    return PutHex16((uint16_t)uvalue);
+    return PutHex16((uint16_t)uvalue, byte_order);
   case 4:
-    return PutHex32((uint32_t)uvalue);
+    return PutHex32((uint32_t)uvalue, byte_order);
   case 8:
-    return PutHex64(uvalue);
+    return PutHex64(uvalue, byte_order);
   }
   return 0;
 }
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to