summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2016-09-29 23:05:53 +0200
committerMichael Stahl <mstahl@redhat.com>2016-09-29 23:18:09 +0200
commita0687f7e656a137cd0c1661094afc72f466ba629 (patch)
treed2948945cfd9f123597ea9dd48d9336f7a9697b9 /sal
parentd3db7589f14ea1874095a66810e64577a6f004b0 (diff)
tdf#83306 add unit test for compareWithLength and '\0'
Change-Id: Iba48390035c560ea499c7fd793d5dd84d1f63cf0
Diffstat (limited to 'sal')
-rw-r--r--sal/qa/rtl/strings/test_ostring.cxx20
-rw-r--r--sal/qa/rtl/strings/test_oustring_compare.cxx22
2 files changed, 41 insertions, 1 deletions
diff --git a/sal/qa/rtl/strings/test_ostring.cxx b/sal/qa/rtl/strings/test_ostring.cxx
index 2929b78c5b3f..ffdd46821b38 100644
--- a/sal/qa/rtl/strings/test_ostring.cxx
+++ b/sal/qa/rtl/strings/test_ostring.cxx
@@ -19,9 +19,11 @@ namespace {
class Test: public CppUnit::TestFixture {
private:
void testStartsWithIgnoreAsciiCase();
+ void testCompareTo();
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(testStartsWithIgnoreAsciiCase);
+ CPPUNIT_TEST(testCompareTo);
CPPUNIT_TEST_SUITE_END();
};
@@ -85,6 +87,24 @@ void Test::testStartsWithIgnoreAsciiCase() {
}
}
+void Test::testCompareTo()
+{
+ // test that embedded NUL does not stop the compare
+ sal_Char str1[2] = { '\0', 'x' };
+ sal_Char str2[2] = { '\0', 'y' };
+
+ OString s1(str1, 2);
+ OString s2(str2, 2);
+ CPPUNIT_ASSERT(s1.compareTo(s1) == 0);
+ CPPUNIT_ASSERT(s2.compareTo(s2) == 0);
+ CPPUNIT_ASSERT(s1.compareTo(s2) < 0);
+ CPPUNIT_ASSERT(s2.compareTo(s1) > 0);
+ CPPUNIT_ASSERT(s1.compareTo(OString(s2 + "y")) < 0);
+ CPPUNIT_ASSERT(s2.compareTo(OString(s1 + "x")) > 0);
+ CPPUNIT_ASSERT(OString(s1 + "x").compareTo(s2) < 0);
+ CPPUNIT_ASSERT(OString(s2 + "y").compareTo(s1) > 0);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
}
diff --git a/sal/qa/rtl/strings/test_oustring_compare.cxx b/sal/qa/rtl/strings/test_oustring_compare.cxx
index 4f056e12889d..77f2fb7f293f 100644
--- a/sal/qa/rtl/strings/test_oustring_compare.cxx
+++ b/sal/qa/rtl/strings/test_oustring_compare.cxx
@@ -29,12 +29,13 @@ class Compare: public CppUnit::TestFixture
{
private:
void equalsIgnoreAsciiCaseAscii();
-
void compareToIgnoreAsciiCase();
+ void compareTo();
CPPUNIT_TEST_SUITE(Compare);
CPPUNIT_TEST(equalsIgnoreAsciiCaseAscii);
CPPUNIT_TEST(compareToIgnoreAsciiCase);
+CPPUNIT_TEST(compareTo);
CPPUNIT_TEST_SUITE_END();
};
@@ -74,4 +75,23 @@ void test::oustring::Compare::compareToIgnoreAsciiCase()
rtl::OUString("A").compareToIgnoreAsciiCase("_") > 0);
}
+void test::oustring::Compare::compareTo()
+{
+ // test that embedded NUL does not stop the compare
+ // this sort of thing is how we assing shape ids in oox
+ sal_Unicode str1[2] = { '\0', 'x' };
+ sal_Unicode str2[2] = { '\0', 'y' };
+
+ OUString s1(str1, 2);
+ OUString s2(str2, 2);
+ CPPUNIT_ASSERT(s1.compareTo(s1) == 0);
+ CPPUNIT_ASSERT(s2.compareTo(s2) == 0);
+ CPPUNIT_ASSERT(s1.compareTo(s2) < 0);
+ CPPUNIT_ASSERT(s2.compareTo(s1) > 0);
+ CPPUNIT_ASSERT(s1.compareTo(OUString(s2 + "y")) < 0);
+ CPPUNIT_ASSERT(s2.compareTo(OUString(s1 + "x")) > 0);
+ CPPUNIT_ASSERT(OUString(s1 + "x").compareTo(s2) < 0);
+ CPPUNIT_ASSERT(OUString(s2 + "y").compareTo(s1) > 0);
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */