-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af59f5c
commit 706f3f5
Showing
6 changed files
with
114 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright 2014 Haiku, Inc. | ||
* Distributed under the terms of the MIT License. | ||
*/ | ||
|
||
|
||
#include "CollatorTest.h" | ||
|
||
#include <Collator.h> | ||
#include <Locale.h> | ||
#include <LocaleRoster.h> | ||
|
||
#include <cppunit/TestCaller.h> | ||
#include <cppunit/TestSuite.h> | ||
|
||
|
||
CollatorTest::CollatorTest() | ||
{ | ||
} | ||
|
||
|
||
CollatorTest::~CollatorTest() | ||
{ | ||
} | ||
|
||
|
||
void | ||
CollatorTest::TestSortKeys() | ||
{ | ||
struct Test { | ||
char* first; | ||
char* second; | ||
int sign[3]; | ||
}; | ||
|
||
BCollator collator; | ||
BLocaleRoster::Default()->GetDefaultLocale()->GetCollator(&collator); | ||
const Test tests[] = { | ||
{"gehen", "géhen", {0, -1, -1}}, | ||
{"aus", "äUß", {-1, -1, -1}}, | ||
{"auss", "äUß", {0, -1, -1}}, | ||
{"WO", "wÖ", {0, -1, -1}}, | ||
{"SO", "so", {0, 0, 1}}, | ||
{"açñ", "acn", {0, 1, 1}}, | ||
{NULL, NULL, {0, 0, 0}} | ||
}; | ||
|
||
for (int32 i = 0; tests[i].first != NULL; i++) { | ||
NextSubTest(); | ||
|
||
for (int32 strength = B_COLLATE_PRIMARY; strength < 4; strength++) { | ||
BString a, b; | ||
collator.GetSortKey(tests[i].first, &a, strength); | ||
collator.GetSortKey(tests[i].second, &b, strength); | ||
|
||
int difference = collator.Compare(tests[i].first, tests[i].second, | ||
strength); | ||
CPPUNIT_ASSERT_EQUAL(tests[i].sign[strength - 1], difference); | ||
int keydiff = strcmp(a.String(), b.String()); | ||
// Check that the keys compare the same as the strings. Either both | ||
// are 0, or both have the same sign. | ||
if (difference == 0) | ||
CPPUNIT_ASSERT_EQUAL(0, keydiff); | ||
else | ||
CPPUNIT_ASSERT(keydiff * difference > 0); | ||
} | ||
} | ||
} | ||
|
||
|
||
/*static*/ void | ||
CollatorTest::AddTests(BTestSuite& parent) | ||
{ | ||
CppUnit::TestSuite& suite = *new CppUnit::TestSuite("CollatorTest"); | ||
|
||
suite.addTest(new CppUnit::TestCaller<CollatorTest>( | ||
"CollatorTest::TestSortKeys", &CollatorTest::TestSortKeys)); | ||
|
||
parent.addTest("CollatorTest", &suite); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2014 Haiku, Inc. | ||
* Distributed under the terms of the MIT License. | ||
*/ | ||
#ifndef COLLATOR_TEST_H | ||
#define COLLATOR_TEST_H | ||
|
||
|
||
#include <TestCase.h> | ||
#include <TestSuite.h> | ||
|
||
|
||
class CollatorTest: public BTestCase { | ||
public: | ||
CollatorTest(); | ||
virtual ~CollatorTest(); | ||
|
||
void TestSortKeys(); | ||
|
||
static void AddTests(BTestSuite& suite); | ||
}; | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters