summaryrefslogtreecommitdiff
path: root/tools/qa
diff options
context:
space:
mode:
authorSébastien Le Ray <sebastien-libreoffice@orniz.org>2011-02-10 16:53:29 +0100
committerCédric Bosdonnat <cedricbosdo@openoffice.org>2011-02-10 16:56:30 +0100
commitb5d135810fad8e8309a5572159173fd4ffa5c66e (patch)
treebfeb68f0bf1fe6a316fe89dd3fe76b35bfe3d865 /tools/qa
parent298b9df14ba23b43db3691d299191d01f3815fc3 (diff)
Add a CompareToNumeric to ByteString & UniString
Diffstat (limited to 'tools/qa')
-rw-r--r--tools/qa/makefile.mk3
-rw-r--r--tools/qa/test_strings.cxx88
2 files changed, 90 insertions, 1 deletions
diff --git a/tools/qa/makefile.mk b/tools/qa/makefile.mk
index e82b39337ac2..06c2cb1a03e4 100644
--- a/tools/qa/makefile.mk
+++ b/tools/qa/makefile.mk
@@ -39,7 +39,8 @@ SHL1TARGET=test_tools
SHL1OBJS=\
$(SLO)$/pathutils.obj \
$(SLO)$/test_pathutils.obj \
- $(SLO)$/test_reversemap.obj
+ $(SLO)$/test_reversemap.obj \
+ $(SLO)$/test_strings.obj
SHL1STDLIBS = $(TOOLSLIB) $(CPPUNITLIB) $(SALLIB)
SHL1VERSIONMAP = version.map
SHL1IMPLIB = i$(SHL1TARGET)
diff --git a/tools/qa/test_strings.cxx b/tools/qa/test_strings.cxx
new file mode 100644
index 000000000000..b7060f333ae1
--- /dev/null
+++ b/tools/qa/test_strings.cxx
@@ -0,0 +1,88 @@
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+#include <tools/string.hxx>
+
+namespace test {
+ namespace unistring {
+ /**
+ * test::unistring::Compare Perform comparison functions
+ * tests on UniString.
+ */
+ class Compare: public CppUnit::TestFixture
+ {
+ private:
+ /**
+ * Performs tests on natural comparison function
+ */
+ void testCompareToNumeric();
+
+ CPPUNIT_TEST_SUITE(Compare);
+ CPPUNIT_TEST(testCompareToNumeric);
+ CPPUNIT_TEST_SUITE_END();
+
+ };
+ }
+}
+
+#define US_FROM_STRING(STRING) UniString((STRING), RTL_TEXTENCODING_UTF8)
+
+void test::unistring::Compare::testCompareToNumeric()
+{
+// --- Some generic tests to ensure we do not alter original behavior
+// outside what we want
+ CPPUNIT_ASSERT(
+ US_FROM_STRING("ABC").CompareToNumeric(US_FROM_STRING("ABC")) == COMPARE_EQUAL
+ );
+ // Case sensitivity
+ CPPUNIT_ASSERT(
+ US_FROM_STRING("ABC").CompareToNumeric(US_FROM_STRING("abc")) == COMPARE_LESS
+ );
+ // Reverse
+ CPPUNIT_ASSERT(
+ US_FROM_STRING("abc").CompareToNumeric(US_FROM_STRING("ABC")) == COMPARE_GREATER
+ );
+ // First shorter
+ CPPUNIT_ASSERT(
+ US_FROM_STRING("alongstring").CompareToNumeric(US_FROM_STRING("alongerstring")) == COMPARE_GREATER
+ );
+ // Second shorter
+ CPPUNIT_ASSERT(
+ US_FROM_STRING("alongerstring").CompareToNumeric(US_FROM_STRING("alongstring")) == COMPARE_LESS
+ );
+// -- Here we go on natural order, each one is followed by classic compare and the reverse comparison
+ // That's why we originally made the patch
+ CPPUNIT_ASSERT(
+ US_FROM_STRING("Heading 9").CompareToNumeric(US_FROM_STRING("Heading 10")) == COMPARE_LESS
+ );
+ // Original behavior
+ CPPUNIT_ASSERT(
+ US_FROM_STRING("Heading 9").CompareTo(US_FROM_STRING("Heading 10")) == COMPARE_GREATER
+ );
+ CPPUNIT_ASSERT(
+ US_FROM_STRING("Heading 10").CompareToNumeric(US_FROM_STRING("Heading 9")) == COMPARE_GREATER
+ );
+ // Harder
+ CPPUNIT_ASSERT(
+ US_FROM_STRING("July, the 4th").CompareToNumeric(US_FROM_STRING("July, the 10th")) == COMPARE_LESS
+ );
+ CPPUNIT_ASSERT(
+ US_FROM_STRING("July, the 4th").CompareTo(US_FROM_STRING("July, the 10th")) == COMPARE_GREATER
+ );
+ CPPUNIT_ASSERT(
+ US_FROM_STRING("July, the 10th").CompareToNumeric(US_FROM_STRING("July, the 4th")) == COMPARE_GREATER
+ );
+ // Hardest
+ CPPUNIT_ASSERT(
+ US_FROM_STRING("abc08").CompareToNumeric(US_FROM_STRING("abc010")) == COMPARE_LESS
+ );
+ CPPUNIT_ASSERT(
+ US_FROM_STRING("abc08").CompareTo(US_FROM_STRING("abc010")) == COMPARE_GREATER
+ );
+ CPPUNIT_ASSERT(
+ US_FROM_STRING("abc010").CompareToNumeric(US_FROM_STRING("abc08")) == COMPARE_GREATER
+ );
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(test::unistring::Compare);