Fix TestBreakpointSerialization on windows
authorPavel Labath <labath@google.com>
Thu, 22 Sep 2016 15:26:43 +0000 (15:26 +0000)
committerPavel Labath <labath@google.com>
Thu, 22 Sep 2016 15:26:43 +0000 (15:26 +0000)
The test exposed a bug in the StructuredData Serialization code, which did not
escape the backslash properly. This manifested itself as windows breakpoint
serialization roundtrip test not succeeding (as windows paths included
backslashes).

llvm-svn: 282167

lldb/source/Core/StructuredData.cpp
lldb/unittests/Core/CMakeLists.txt
lldb/unittests/Core/StructuredDataTest.cpp [new file with mode: 0644]

index 3866861..46be782 100644 (file)
@@ -264,7 +264,7 @@ void StructuredData::String::Dump(Stream &s, bool pretty_print) const {
   const size_t strsize = m_value.size();
   for (size_t i = 0; i < strsize; ++i) {
     char ch = m_value[i];
-    if (ch == '"')
+    if (ch == '"' || ch == '\\')
       quoted.push_back('\\');
     quoted.push_back(ch);
   }
index 8ab43d6..9ec5175 100644 (file)
@@ -3,4 +3,5 @@ add_lldb_unittest(LLDBCoreTests
   BroadcasterTest.cpp
   DataExtractorTest.cpp
   ScalarTest.cpp
+  StructuredDataTest.cpp
   )
diff --git a/lldb/unittests/Core/StructuredDataTest.cpp b/lldb/unittests/Core/StructuredDataTest.cpp
new file mode 100644 (file)
index 0000000..8e10d57
--- /dev/null
@@ -0,0 +1,32 @@
+//===-- StructuredDataTest.cpp ----------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+
+#include "lldb/Core/StructuredData.h"
+#include "lldb/Core/StreamString.h"
+
+#include "llvm/Support/MachO.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+TEST(StructuredDataTest, StringDump) {
+  std::pair<llvm::StringRef, llvm::StringRef> TestCases[] = {
+    { R"(asdfg)", R"("asdfg")" },
+    { R"(as"df)", R"("as\"df")" },
+    { R"(as\df)", R"("as\\df")" },
+  };
+  for(auto P : TestCases) {
+    StreamString S;
+    const bool pretty_print = false;
+    StructuredData::String(P.first).Dump(S, pretty_print);
+    EXPECT_EQ(P.second, S.GetString());
+  }
+}