[Lldb-commits] [lldb] r339292 - Add ConstString test FromMidOfBufferStringRef

Stefan Granitz via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 8 14:57:42 PDT 2018


Author: stefan.graenitz
Date: Wed Aug  8 14:57:42 2018
New Revision: 339292

URL: http://llvm.org/viewvc/llvm-project?rev=339292&view=rev
Log:
Add ConstString test FromMidOfBufferStringRef

Summary: It was not immediately clear to me whether or not non-null-terminated StringRef's are supported in ConstString and/or the counterpart mechanism. From this test it seems to be fine. Maybe useful to keep?

Reviewers: labath

Subscribers: lldb-commits

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

Modified:
    lldb/trunk/unittests/Utility/ConstStringTest.cpp

Modified: lldb/trunk/unittests/Utility/ConstStringTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/ConstStringTest.cpp?rev=339292&r1=339291&r2=339292&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/ConstStringTest.cpp (original)
+++ lldb/trunk/unittests/Utility/ConstStringTest.cpp Wed Aug  8 14:57:42 2018
@@ -34,6 +34,26 @@ TEST(ConstStringTest, MangledCounterpart
   EXPECT_EQ("bar", counterpart.GetStringRef());
 }
 
+TEST(ConstStringTest, FromMidOfBufferStringRef) {
+  // StringRef's into bigger buffer: no null termination
+  const char *buffer = "foobarbaz";
+  llvm::StringRef foo_ref(buffer, 3);
+  llvm::StringRef bar_ref(buffer + 3, 3);
+
+  ConstString foo(foo_ref);
+
+  ConstString bar;
+  bar.SetStringWithMangledCounterpart(bar_ref, foo);
+  EXPECT_EQ("bar", bar.GetStringRef());
+
+  ConstString counterpart;
+  EXPECT_TRUE(bar.GetMangledCounterpart(counterpart));
+  EXPECT_EQ("foo", counterpart.GetStringRef());
+
+  EXPECT_TRUE(foo.GetMangledCounterpart(counterpart));
+  EXPECT_EQ("bar", counterpart.GetStringRef());
+}
+
 TEST(ConstStringTest, NullAndEmptyStates) {
   ConstString foo("foo");
   EXPECT_FALSE(!foo);




More information about the lldb-commits mailing list