sgraenitz created this revision. sgraenitz added a reviewer: labath. 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?
https://reviews.llvm.org/D50334 Files: unittests/Utility/ConstStringTest.cpp Index: unittests/Utility/ConstStringTest.cpp =================================================================== --- unittests/Utility/ConstStringTest.cpp +++ unittests/Utility/ConstStringTest.cpp @@ -34,6 +34,26 @@ 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);
Index: unittests/Utility/ConstStringTest.cpp =================================================================== --- unittests/Utility/ConstStringTest.cpp +++ unittests/Utility/ConstStringTest.cpp @@ -34,6 +34,26 @@ 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);
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits