2 * Copyright 2014 Haiku, Inc.
3 * Distributed under the terms of the MIT License.
7 #include "CollatorTest.h"
11 #include <LocaleRoster.h>
13 #include <cppunit/TestCaller.h>
14 #include <cppunit/TestSuite.h>
17 CollatorTest::CollatorTest()
22 CollatorTest::~CollatorTest()
28 CollatorTest::TestSortKeys()
37 BLocaleRoster::Default()->GetDefaultLocale()->GetCollator(&collator
);
38 const Test tests
[] = {
39 {"gehen", "géhen", {0, -1, -1}},
40 {"aus", "äUß", {-1, -1, -1}},
41 {"auss", "äUß", {0, -1, -1}},
42 {"WO", "wÖ", {0, -1, -1}},
43 {"SO", "so", {0, 0, 1}},
44 {"açñ", "acn", {0, 1, 1}},
45 {NULL
, NULL
, {0, 0, 0}}
48 for (int32 i
= 0; tests
[i
].first
!= NULL
; i
++) {
51 for (int32 strength
= B_COLLATE_PRIMARY
; strength
< 4; strength
++) {
53 collator
.SetStrength(strength
);
54 collator
.GetSortKey(tests
[i
].first
, &a
);
55 collator
.GetSortKey(tests
[i
].second
, &b
);
57 int difference
= collator
.Compare(tests
[i
].first
, tests
[i
].second
);
58 CPPUNIT_ASSERT_EQUAL(tests
[i
].sign
[strength
- 1], difference
);
59 int keydiff
= strcmp(a
.String(), b
.String());
60 // Check that the keys compare the same as the strings. Either both
61 // are 0, or both have the same sign.
63 CPPUNIT_ASSERT_EQUAL(0, keydiff
);
65 CPPUNIT_ASSERT(keydiff
* difference
> 0);
72 CollatorTest::AddTests(BTestSuite
& parent
)
74 CppUnit::TestSuite
& suite
= *new CppUnit::TestSuite("CollatorTest");
76 suite
.addTest(new CppUnit::TestCaller
<CollatorTest
>(
77 "CollatorTest::TestSortKeys", &CollatorTest::TestSortKeys
));
79 parent
.addTest("CollatorTest", &suite
);