[Lldb-commits] [PATCH] D50473: [Demangle] Add another test for ItaniumPartialDemangler

Phabricator via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 8 15:38:53 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL339297: [Demangle] Add another test for ItaniumPartialDemangler (authored by stefan.graenitz, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D50473

Files:
  llvm/trunk/unittests/Demangle/PartialDemangleTest.cpp


Index: llvm/trunk/unittests/Demangle/PartialDemangleTest.cpp
===================================================================
--- llvm/trunk/unittests/Demangle/PartialDemangleTest.cpp
+++ llvm/trunk/unittests/Demangle/PartialDemangleTest.cpp
@@ -145,5 +145,50 @@
   EXPECT_TRUE(D2.isFunction());
 
   EXPECT_TRUE(D1.partialDemangle("Not a mangled name!"));
+}
+
+TEST(PartialDemanglerTest, TestPrintCases) {
+  llvm::ItaniumPartialDemangler D;
+
+  const size_t OriginalSize = 4;
+  char *Buf = static_cast<char *>(std::malloc(OriginalSize));
+  const char *OriginalBuf = Buf;
+
+  // Default success case: Result fits into the given buffer.
+  // Res points to Buf. N returns string size including null termination.
+  {
+    EXPECT_FALSE(D.partialDemangle("_ZN1a1bEv"));
+
+    size_t N = OriginalSize;
+    char *Res = D.getFunctionDeclContextName(Buf, &N);
+    EXPECT_STREQ("a", Res);
+    EXPECT_EQ(OriginalBuf, Res);
+    EXPECT_EQ(strlen(Res) + 1, N);
+  }
 
+  // Realloc success case: Result does not fit into the given buffer.
+  // Res points to the new or extended buffer. N returns string size
+  // including null termination. Buf was extended or freed.
+  {
+    EXPECT_FALSE(D.partialDemangle("_ZN1a1b1cIiiiEEvm"));
+
+    size_t N = OriginalSize;
+    char *Res = D.finishDemangle(Buf, &N);
+    EXPECT_STREQ("void a::b::c<int, int, int>(unsigned long)", Res);
+    EXPECT_EQ(strlen(Res) + 1, N);
+    Buf = Res;
+  }
+
+  // Failure case: a::c is not a function.
+  // Res is nullptr. N remains unchanged.
+  {
+    EXPECT_FALSE(D.partialDemangle("_ZN1a1cE"));
+
+    size_t N = OriginalSize;
+    char *Res = D.getFunctionName(Buf, &N);
+    EXPECT_EQ(nullptr, Res);
+    EXPECT_EQ(OriginalSize, N);
+  }
+
+  std::free(Buf);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50473.159818.patch
Type: text/x-patch
Size: 1752 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180808/9eb3090c/attachment.bin>


More information about the lldb-commits mailing list