From 4c01eccba2e61a29b14df9fe0496bceacfbc861d Mon Sep 17 00:00:00 2001 From: Stefan Granitz Date: Wed, 8 Aug 2018 21:57:42 +0000 Subject: [PATCH] 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 llvm-svn: 339292 --- lldb/unittests/Utility/ConstStringTest.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lldb/unittests/Utility/ConstStringTest.cpp b/lldb/unittests/Utility/ConstStringTest.cpp index add76a0..5ad6ea9 100644 --- a/lldb/unittests/Utility/ConstStringTest.cpp +++ b/lldb/unittests/Utility/ConstStringTest.cpp @@ -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); -- 2.7.4