diff options
author | David Kalnischkies <david@kalnischkies.de> | 2016-08-12 11:27:19 +0200 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2016-08-12 11:56:21 +0200 |
commit | 5404685b66b92f93da7ded5f8fe44fbabea38ba4 (patch) | |
tree | 1d44fd80ba156da23516710b31417ff0d0b19585 /test/libapt | |
parent | 379a36f43d3f4db4afa5ad4fb6f79b89824c999c (diff) | |
download | apt-5404685b66b92f93da7ded5f8fe44fbabea38ba4.tar.gz |
tests: don't do boundless string compares with data()
Git-Dch: Ignore
Diffstat (limited to 'test/libapt')
-rw-r--r-- | test/libapt/stringview_test.cc | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/test/libapt/stringview_test.cc b/test/libapt/stringview_test.cc index a4b7d77e3..f215287d9 100644 --- a/test/libapt/stringview_test.cc +++ b/test/libapt/stringview_test.cc @@ -34,26 +34,28 @@ TEST(StringViewTest,EmptyString) TEST(StringViewTest,FooString) { - constexpr APT::StringView defString("foo", 3); + constexpr APT::StringView defString("fooGARBAGE", 3); static_assert( 3 == defString.length(), "def right size"); - EXPECT_EQ(defString.to_string(), defString.data()); + EXPECT_EQ(0, defString.to_string().compare(0, defString.length(), defString.data(), 3)); APT::StringView strString{std::string{"foo"}}; EXPECT_EQ(3, strString.length()); - EXPECT_EQ(strString.to_string(), strString.data()); + EXPECT_EQ(0, strString.to_string().compare(0, strString.length(), strString.data(), 3)); - constexpr char const * const charp = "foo"; + constexpr char const * const charp = "fooGARBAGE"; constexpr APT::StringView charpString{charp, 3}; - EXPECT_EQ( 3, charpString.length()); - EXPECT_EQ(charpString.to_string(), charpString.data()); + EXPECT_EQ(3, charpString.length()); + EXPECT_EQ(0, charpString.to_string().compare(0, charpString.length(), charpString.data(), 3)); - APT::StringView charp2String{charp}; + char * charp2 = strdup("foo"); + APT::StringView charp2String{charp2}; EXPECT_EQ(3, charp2String.length()); - EXPECT_EQ(charp2String.to_string(), charp2String.data()); + EXPECT_EQ(0, charp2String.to_string().compare(0, charp2String.length(), charp2String.data(), 3)); + free(charp2); const APT::StringView charaString{"foo"}; EXPECT_EQ(3, charaString.length()); - EXPECT_EQ(charaString.to_string(), charaString.data()); + EXPECT_EQ(0, charaString.to_string().compare(0, charaString.length(), charaString.data(), 3)); EXPECT_TRUE(APT::StringView("foo") == "foo"); EXPECT_FALSE(APT::StringView("foo") != "foo"); |