[Demangle] Add another test for ItaniumPartialDemangler
authorStefan Granitz <stefan.graenitz@gmail.com>
Wed, 8 Aug 2018 22:38:23 +0000 (22:38 +0000)
committerStefan Granitz <stefan.graenitz@gmail.com>
Wed, 8 Aug 2018 22:38:23 +0000 (22:38 +0000)
Summary: Show the behavior of print operations in the ItaniumPartialDemangler. It's a summary of what the current integration in LLDB assumes. For new users this may be a useful example.

Reviewers: erik.pilkington

Subscribers: llvm-commits, lldb-commits

Differential Revision: https://reviews.llvm.org/D50473

llvm-svn: 339297

llvm/unittests/Demangle/PartialDemangleTest.cpp

index 49d5016..98d9f86 100644 (file)
@@ -145,5 +145,50 @@ TEST(PartialDemanglerTest, TestMisc) {
   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);
 }