blob: 90a2ce8b6c95ace6b673d0ec83c35684f499d0af (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#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);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|