hrev47928 adds 6 changesets to branch 'master' old head: 9ddea57b38f3cd93dfcacb023403651b45e52eb0 new head: d7f449e9bc4dc2d89a15cfd99dbe3e3c031c2bbd overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=d7f449e+%5E9ddea57 ---------------------------------------------------------------------------- 9d1cbc6: localeTest: fix build. 27a2d2c: ICUTest: style and output formatting fixes bd06441: localeTest: fix corrupted characters. This file used to hold iso-8859-15 encoded bytes for testing our char conversion ability. However something went wrong and they all got replaced by unicode "invalid character" mark. Use \x notation to escape the actual bytes we want to test. af59f5c: Convert BUnicodeChar tests to cppunit. 706f3f5: Convert collator test to cppunit. d7f449e: Convert language tests to cppunit. [ Adrien Destugues <pulkomandy@xxxxxxxxx> ] ---------------------------------------------------------------------------- 11 files changed, 434 insertions(+), 123 deletions(-) src/tests/kits/locale/CollatorTest.cpp | 80 +++++++++++ src/tests/kits/locale/CollatorTest.h | 24 ++++ src/tests/kits/locale/ICUTest.cpp | 26 ++-- src/tests/kits/locale/Jamfile | 15 ++- src/tests/kits/locale/LanguageTest.cpp | 46 +++++++ src/tests/kits/locale/LanguageTest.h | 24 ++++ src/tests/kits/locale/LocaleKitTestAddon.cpp | 25 ++++ src/tests/kits/locale/UnicodeCharTest.cpp | 161 +++++++++++++++++++++++ src/tests/kits/locale/UnicodeCharTest.h | 41 ++++++ src/tests/kits/locale/collatorTest.cpp | 11 +- src/tests/kits/locale/localeTest.cpp | 104 --------------- ############################################################################ Commit: 9d1cbc67a64de1894e922a22a030a690669123b2 URL: http://cgit.haiku-os.org/haiku/commit/?id=9d1cbc6 Author: Adrien Destugues <pulkomandy@xxxxxxxxx> Date: Mon Sep 29 12:18:59 2014 UTC localeTest: fix build. ---------------------------------------------------------------------------- diff --git a/src/tests/kits/locale/localeTest.cpp b/src/tests/kits/locale/localeTest.cpp index e4fbc9a..c40bb97 100644 --- a/src/tests/kits/locale/localeTest.cpp +++ b/src/tests/kits/locale/localeTest.cpp @@ -1,9 +1,10 @@ -#include <UnicodeChar.h> #include <Collator.h> #include <Language.h> #include <Locale.h> +#include <LocaleRoster.h> #include <String.h> +#include <UnicodeChar.h> #include <stdio.h> @@ -46,7 +47,8 @@ main() } const char *utf8chars[] = {"à", "ß", "ñ", "é", "ç", "ä", NULL}; - for (int32 j = 0, i; (i = BUnicodeChar::FromUTF8(utf8chars[j])) != 0; j++) { + for (int32 j = 0; utf8chars[j] != 0; j++) { + int32 i = BUnicodeChar::FromUTF8(utf8chars[j]); unicode_char_to_string(i, text); printf("%s: alpha == %d, alNum == %d, lower == %d, upper == %d, defined == %d, charType == %d\n", text, @@ -62,20 +64,21 @@ main() // Test BCollator class - BCollator *collator = be_locale->Collator(); + BCollator collator; + BLocaleRoster::Default()->GetDefaultLocale()->GetCollator(&collator); const char *strings[] = {"gehen", "géhen", "aus", "äUß", "auss", "äUß", "WO", "wÖ", "SO", "so", "açñ", "acn", NULL}; const char *strengths[] = {"primary: ", "secondary:", "tertiary: "}; for (int32 i = 0; strings[i]; i += 2) { for (int32 strength = B_COLLATE_PRIMARY; strength < 4; strength++) { BString a, b; - collator->GetSortKey(strings[i], &a, strength); - collator->GetSortKey(strings[i + 1], &b, strength); + collator.GetSortKey(strings[i], &a, strength); + collator.GetSortKey(strings[i + 1], &b, strength); printf("%s sort keys: \"%s\" -> \"%s\", \"%s\" -> \"%s\"\n", strengths[strength-1], strings[i], a.String(), strings[i+1], b.String()); printf("\tcmp = %d (key compare = %d)\n", - collator->Compare(strings[i], strings[i + 1], -1, strength), + collator.Compare(strings[i], strings[i + 1], strength), strcmp(a.String(), b.String())); } putchar('\n'); @@ -83,12 +86,15 @@ main() // Tests the BLanguage class - BLanguage *language = be_locale->Language(); - printf("Language name = \"%s\", code = \"%s\", family = \"%s\"\n", language->Name(), - language->Code(), language->Family()); + BLanguage language; + BLocaleRoster::Default()->GetDefaultLocale()->GetLanguage(&language); + BString name; + language.GetName(name); + printf("Language name = \"%s\", code = \"%s\"\n", name.String(), + language.Code()); printf("\tdirection = %s\n", - language->Direction() == B_LEFT_TO_RIGHT ? "left-to-right" : - language->Direction() == B_RIGHT_TO_LEFT ? "right-to-left" : + language.Direction() == B_LEFT_TO_RIGHT ? "left-to-right" : + language.Direction() == B_RIGHT_TO_LEFT ? "right-to-left" : "top-to-bottom"); //for (int32 i = 0; i < 200; i++) { @@ -98,7 +104,7 @@ main() //} printf("First month = %s (%s)\n", - language->GetString(B_MON_1), - language->GetString(B_AB_MON_1)); + language.GetString(B_MON_1), + language.GetString(B_AB_MON_1)); } ############################################################################ Commit: 27a2d2c7ef0320209af512df13920a69f255630f URL: http://cgit.haiku-os.org/haiku/commit/?id=27a2d2c Author: Adrien Destugues <pulkomandy@xxxxxxxxx> Date: Mon Sep 29 12:33:00 2014 UTC ICUTest: style and output formatting fixes ---------------------------------------------------------------------------- diff --git a/src/tests/kits/locale/ICUTest.cpp b/src/tests/kits/locale/ICUTest.cpp index 629dbaf..55363dd 100644 --- a/src/tests/kits/locale/ICUTest.cpp +++ b/src/tests/kits/locale/ICUTest.cpp @@ -23,9 +23,9 @@ void TestLocale(const Locale& loc) assert(!loc.isBogus()); printf("-- basic info\n"); printf("Default locale:\nLanguage: %s\nScript: %s\nVariant: %s\n" - "Country: %s\nName: %s\nBaseName: %s\n", loc.getLanguage(), - loc.getScript(), loc.getVariant(), - loc.getCountry(), loc.getName(), + "Country: %s\nName: %s\nBaseName: %s\n", loc.getLanguage(), + loc.getScript(), loc.getVariant(), + loc.getCountry(), loc.getName(), loc.getBaseName()); UErrorCode err = U_ZERO_ERROR; @@ -36,13 +36,13 @@ void TestLocale(const Locale& loc) if (keywords == NULL) printf("FAILED: getting keywords list returned NULL\n"); else { - printf("Keywords: %d available\n",keywords->count(err)); + printf("Keywords: %d available\n", keywords->count(err)); assert(err == U_ZERO_ERROR); char keyvalue[256]; - while (const char* keyname = keywords->next(NULL,err)) { - loc.getKeywordValue(keyname,keyvalue,256,err); - printf("%s > %s\n",keyname,keyvalue); + while (const char* keyname = keywords->next(NULL, err)) { + loc.getKeywordValue(keyname, keyvalue, 256, err); + printf("%s > %s\n", keyname, keyvalue); } delete keywords; @@ -53,7 +53,7 @@ void TestLocale(const Locale& loc) int main(int argc, char **argv) { - printf("--------\niDefault Locale\n--------\n"); + printf("--------\nDefault Locale\n--------\n"); Locale defaultLocale; TestLocale(defaultLocale); printf("--------\nFrench Locale\n--------\n"); @@ -66,18 +66,20 @@ main(int argc, char **argv) printf("--------\nLocale listing\n--------\n"); int32_t count; const Locale* localeList = Locale::getAvailableLocales(count); - printf("%d locales found\n",count); + printf("%d locales found\n", count); for (int i=0; i<count; i++) { - printf("Locale number %d\n",i); + printf("Locale number %d\n", i); TestLocale(localeList[i]); } printf("--------\nLocale country codes\n--------\n"); const char* const* countryTable = Locale::getISOCountries(); - for (int i=0; countryTable[i] != NULL; i++) - printf("%s\t",countryTable[i]); + for (int i=0; countryTable[i] != NULL; i++) { + if (i % 10 == 0) puts(""); + printf("%s\t", countryTable[i]); + } printf("\n--------\nNumberFormat\n--------\n"); printf("--------\nDateFormat\n--------\n"); ############################################################################ Commit: bd0644183c84d8bb2c8f0f6b2f4b406da7a825e0 URL: http://cgit.haiku-os.org/haiku/commit/?id=bd06441 Author: Adrien Destugues <pulkomandy@xxxxxxxxx> Date: Mon Sep 29 12:56:02 2014 UTC localeTest: fix corrupted characters. This file used to hold iso-8859-15 encoded bytes for testing our char conversion ability. However something went wrong and they all got replaced by unicode "invalid character" mark. Use \x notation to escape the actual bytes we want to test. ---------------------------------------------------------------------------- diff --git a/src/tests/kits/locale/localeTest.cpp b/src/tests/kits/locale/localeTest.cpp index c40bb97..02f0e50 100644 --- a/src/tests/kits/locale/localeTest.cpp +++ b/src/tests/kits/locale/localeTest.cpp @@ -26,19 +26,22 @@ main() for (int32 i = 30; i < 70; i++) { unicode_char_to_string(i, text); - printf("%s: alpha == %d, alNum == %d, lower == %d, upper == %d, defined == %d, charType == %d\n", - text, - BUnicodeChar::IsAlpha(i), BUnicodeChar::IsAlNum(i), BUnicodeChar::IsLower(i), - BUnicodeChar::IsUpper(i), BUnicodeChar::IsDefined(i), BUnicodeChar::Type(i)); + printf("%s: alpha == %d, alNum == %d, lower == %d, upper == %d, " + "defined == %d, charType == %d\n", text, + BUnicodeChar::IsAlpha(i), BUnicodeChar::IsAlNum(i), + BUnicodeChar::IsLower(i), BUnicodeChar::IsUpper(i), + BUnicodeChar::IsDefined(i), BUnicodeChar::Type(i)); } - uint32 chars[] = {(uint8)'�', (uint8)'�', (uint8)'�', (uint8)'�', (uint8)'�', (uint8)'�', 0}; + uint32 chars[] = {(uint8)'\xe4', (uint8)'\xd6', (uint8)'\xdf', + (uint8)'\xe8', (uint8)'\xe1', (uint8)'\xe9', 0}; for (int32 j = 0, i; (i = chars[j]) != 0; j++) { unicode_char_to_string(i, text); - printf("%s: alpha == %d, alNum == %d, lower == %d, upper == %d, defined == %d, charType == %d\n", - text, - BUnicodeChar::IsAlpha(i), BUnicodeChar::IsAlNum(i), BUnicodeChar::IsLower(i), - BUnicodeChar::IsUpper(i), BUnicodeChar::IsDefined(i), BUnicodeChar::Type(i)); + printf("%s: alpha == %d, alNum == %d, lower == %d, upper == %d, " + "defined == %d, charType == %d\n", text, + BUnicodeChar::IsAlpha(i), BUnicodeChar::IsAlNum(i), + BUnicodeChar::IsLower(i), BUnicodeChar::IsUpper(i), + BUnicodeChar::IsDefined(i), BUnicodeChar::Type(i)); unicode_char_to_string(BUnicodeChar::ToUpper(i), text); printf("toUpper == %s, ", text); @@ -50,10 +53,11 @@ main() for (int32 j = 0; utf8chars[j] != 0; j++) { int32 i = BUnicodeChar::FromUTF8(utf8chars[j]); unicode_char_to_string(i, text); - printf("%s: alpha == %d, alNum == %d, lower == %d, upper == %d, defined == %d, charType == %d\n", - text, - BUnicodeChar::IsAlpha(i), BUnicodeChar::IsAlNum(i), BUnicodeChar::IsLower(i), - BUnicodeChar::IsUpper(i), BUnicodeChar::IsDefined(i), BUnicodeChar::Type(i)); + printf("%s: alpha == %d, alNum == %d, lower == %d, upper == %d, " + "defined == %d, charType == %d\n", text, + BUnicodeChar::IsAlpha(i), BUnicodeChar::IsAlNum(i), + BUnicodeChar::IsLower(i), BUnicodeChar::IsUpper(i), + BUnicodeChar::IsDefined(i), BUnicodeChar::Type(i)); unicode_char_to_string(BUnicodeChar::ToUpper(i), text); printf("toUpper == %s, ", text); @@ -66,8 +70,8 @@ main() BCollator collator; BLocaleRoster::Default()->GetDefaultLocale()->GetCollator(&collator); - const char *strings[] = {"gehen", "géhen", "aus", "äUß", "auss", "äUß", "WO", - "wÖ", "SO", "so", "açñ", "acn", NULL}; + const char *strings[] = {"gehen", "géhen", "aus", "äUß", "auss", "äUß", + "WO", "wÖ", "SO", "so", "açñ", "acn", NULL}; const char *strengths[] = {"primary: ", "secondary:", "tertiary: "}; for (int32 i = 0; strings[i]; i += 2) { for (int32 strength = B_COLLATE_PRIMARY; strength < 4; strength++) { @@ -76,7 +80,8 @@ main() collator.GetSortKey(strings[i + 1], &b, strength); printf("%s sort keys: \"%s\" -> \"%s\", \"%s\" -> \"%s\"\n", - strengths[strength-1], strings[i], a.String(), strings[i+1], b.String()); + strengths[strength-1], strings[i], a.String(), strings[i+1], + b.String()); printf("\tcmp = %d (key compare = %d)\n", collator.Compare(strings[i], strings[i + 1], strength), strcmp(a.String(), b.String())); ############################################################################ Commit: af59f5ca42e5107e22da9a9abd67826e6028ccf0 URL: http://cgit.haiku-os.org/haiku/commit/?id=af59f5c Author: Adrien Destugues <pulkomandy@xxxxxxxxx> Date: Mon Sep 29 14:08:45 2014 UTC Convert BUnicodeChar tests to cppunit. ---------------------------------------------------------------------------- diff --git a/src/tests/kits/locale/Jamfile b/src/tests/kits/locale/Jamfile index a3752b2..f22aa9d 100644 --- a/src/tests/kits/locale/Jamfile +++ b/src/tests/kits/locale/Jamfile @@ -15,7 +15,8 @@ Depends LocaleKitTests collatorTest localeTest ICUTest - libNumberFormatTests.so +# libNumberFormatTests.so + localekittest.so ; rule LocaleTest @@ -47,4 +48,12 @@ Addon catalogTestAddOn : be ; +UnitTestLib localekittest.so : + LocaleKitTestAddon.cpp + + UnicodeCharTest.cpp + + : be [ TargetLibstdc++ ] + ; + # SubInclude HAIKU_TOP src tests kits locale number_format ; diff --git a/src/tests/kits/locale/LocaleKitTestAddon.cpp b/src/tests/kits/locale/LocaleKitTestAddon.cpp new file mode 100644 index 0000000..81adfd6 --- /dev/null +++ b/src/tests/kits/locale/LocaleKitTestAddon.cpp @@ -0,0 +1,21 @@ +/* + * Copyright 2014 Haiku, Inc. + * Distributed under the terms of the MIT License. + */ + + +#include <TestSuite.h> +#include <TestSuiteAddon.h> + +#include "UnicodeCharTest.h" + + +BTestSuite* +getTestSuite() +{ + BTestSuite* suite = new BTestSuite("LocaleKit"); + + UnicodeCharTest::AddTests(*suite); + + return suite; +} diff --git a/src/tests/kits/locale/UnicodeCharTest.cpp b/src/tests/kits/locale/UnicodeCharTest.cpp new file mode 100644 index 0000000..a65d7dc --- /dev/null +++ b/src/tests/kits/locale/UnicodeCharTest.cpp @@ -0,0 +1,161 @@ +/* + * Copyright 2014 Haiku, Inc. + * Distributed under the terms of the MIT License. + */ + + +#include "UnicodeCharTest.h" + +#include <String.h> +#include <UnicodeChar.h> + +#include <cppunit/TestCaller.h> +#include <cppunit/TestSuite.h> + + +UnicodeCharTest::UnicodeCharTest() +{ +} + + +UnicodeCharTest::~UnicodeCharTest() +{ +} + + +void +UnicodeCharTest::TestAscii() +{ + Result results[] = { + {"\x1e", 0, 0, 0, 0, 1, 15, '\x1e', '\x1e'}, + {"\x1f", 0, 0, 0, 0, 1, 15, '\x1f', '\x1f'}, + {" ", 0, 0, 0, 0, 1, 12, ' ', ' '}, + {"!", 0, 0, 0, 0, 1, 23, '!', '!'}, + {"\"", 0, 0, 0, 0, 1, 23, '"', '"'}, + {"#", 0, 0, 0, 0, 1, 23, '#', '#'}, + {"$", 0, 0, 0, 0, 1, 25, '$', '$'}, + {"%", 0, 0, 0, 0, 1, 23, '%', '%'}, + {"&", 0, 0, 0, 0, 1, 23, '&', '&'}, + {"'", 0, 0, 0, 0, 1, 23, '\'', '\''}, + {"(", 0, 0, 0, 0, 1, 20, '(', '('}, + {")", 0, 0, 0, 0, 1, 21, ')', ')'}, + {"*", 0, 0, 0, 0, 1, 23, '*', '*'}, + {"+", 0, 0, 0, 0, 1, 24, '+', '+'}, + {",", 0, 0, 0, 0, 1, 23, ',', ','}, + {"-", 0, 0, 0, 0, 1, 19, '-', '-'}, + {".", 0, 0, 0, 0, 1, 23, '.', '.'}, + {"/", 0, 0, 0, 0, 1, 23, '/', '/'}, + {"0", 0, 1, 0, 0, 1, 9, '0', '0'}, + {"1", 0, 1, 0, 0, 1, 9, '1', '1'}, + {"2", 0, 1, 0, 0, 1, 9, '2', '2'}, + {"3", 0, 1, 0, 0, 1, 9, '3', '3'}, + {"4", 0, 1, 0, 0, 1, 9, '4', '4'}, + {"5", 0, 1, 0, 0, 1, 9, '5', '5'}, + {"6", 0, 1, 0, 0, 1, 9, '6', '6'}, + {"7", 0, 1, 0, 0, 1, 9, '7', '7'}, + {"8", 0, 1, 0, 0, 1, 9, '8', '8'}, + {"9", 0, 1, 0, 0, 1, 9, '9', '9'}, + {":", 0, 0, 0, 0, 1, 23, ':', ':'}, + {";", 0, 0, 0, 0, 1, 23, ';', ';'}, + {"<", 0, 0, 0, 0, 1, 24, '<', '<'}, + {"=", 0, 0, 0, 0, 1, 24, '=', '='}, + {">", 0, 0, 0, 0, 1, 24, '>', '>'}, + {"?", 0, 0, 0, 0, 1, 23, '?', '?'}, + {"@", 0, 0, 0, 0, 1, 23, '@', '@'}, + {"A", 1, 1, 0, 1, 1, 1, 'A', 'a'}, + {"B", 1, 1, 0, 1, 1, 1, 'B', 'b'}, + {"C", 1, 1, 0, 1, 1, 1, 'C', 'c'}, + {"D", 1, 1, 0, 1, 1, 1, 'D', 'd'}, + {"E", 1, 1, 0, 1, 1, 1, 'E', 'e'} + }; + + for (int32 i = 30; i < 70; i++) { + NextSubTest(); + _TestChar(i, results[i - 30]); + } +} + + +void +UnicodeCharTest::TestISO8859() +{ + uint32 chars[] = {(uint8)'\xe4', (uint8)'\xd6', (uint8)'\xdf', + (uint8)'\xe8', (uint8)'\xe1', (uint8)'\xe9', 0}; + + Result results[] = { + {"ä", 1, 1, 1, 0, 1, 2, 196, 228}, + {"Ö", 1, 1, 0, 1, 1, 1, 214, 246}, + {"ß", 1, 1, 1, 0, 1, 2, 223, 223}, + {"è", 1, 1, 1, 0, 1, 2, 200, 232}, + {"á", 1, 1, 1, 0, 1, 2, 193, 225}, + {"é", 1, 1, 1, 0, 1, 2, 201, 233} + }; + + for(int i = 0; chars[i] != 0; i++) { + NextSubTest(); + _TestChar(chars[i], results[i]); + } +} + + +void +UnicodeCharTest::TestUTF8() +{ + const char *utf8chars[] = {"à", "ß", "ñ", "é", "ç", "ä", NULL}; + + Result results[] = { + {"à", 1, 1, 1, 0, 1, 2, 192, 224}, + {"ß", 1, 1, 1, 0, 1, 2, 223, 223}, + {"ñ", 1, 1, 1, 0, 1, 2, 209, 241}, + {"é", 1, 1, 1, 0, 1, 2, 201, 233}, + {"ç", 1, 1, 1, 0, 1, 2, 199, 231}, + {"ä", 1, 1, 1, 0, 1, 2, 196, 228} + }; + + for(int i = 0; utf8chars[i] != 0; i++) { + NextSubTest(); + _TestChar(BUnicodeChar::FromUTF8(utf8chars[i]), results[i]); + } +} + + +/*static*/ void +UnicodeCharTest::AddTests(BTestSuite& parent) +{ + CppUnit::TestSuite& suite = *new CppUnit::TestSuite("UnicodeCharTest"); + + suite.addTest(new CppUnit::TestCaller<UnicodeCharTest>( + "UnicodeCharTest::TestAscii", &UnicodeCharTest::TestAscii)); + suite.addTest(new CppUnit::TestCaller<UnicodeCharTest>( + "UnicodeCharTest::TestISO8859", &UnicodeCharTest::TestISO8859)); + suite.addTest(new CppUnit::TestCaller<UnicodeCharTest>( + "UnicodeCharTest::TestUTF8", &UnicodeCharTest::TestUTF8)); + + parent.addTest("UnicodeCharTest", &suite); +} + + +void +UnicodeCharTest::_ToString(uint32 c, char *text) +{ + BUnicodeChar::ToUTF8(c, &text); + text[0] = '\0'; +} + + +void +UnicodeCharTest::_TestChar(uint32 i, Result result) +{ + char text[16]; + + _ToString(i, text); + CPPUNIT_ASSERT_EQUAL(BString(result.value), text); + CPPUNIT_ASSERT_EQUAL(result.isAlpha, BUnicodeChar::IsAlpha(i)); + CPPUNIT_ASSERT_EQUAL(result.isAlNum, BUnicodeChar::IsAlNum(i)); + CPPUNIT_ASSERT_EQUAL(result.isLower, BUnicodeChar::IsLower(i)); + CPPUNIT_ASSERT_EQUAL(result.isUpper, BUnicodeChar::IsUpper(i)); + CPPUNIT_ASSERT_EQUAL(result.isDefined, BUnicodeChar::IsDefined(i)); + CPPUNIT_ASSERT_EQUAL(result.type, BUnicodeChar::Type(i)); + CPPUNIT_ASSERT_EQUAL(result.toUpper, BUnicodeChar::ToUpper(i)); + CPPUNIT_ASSERT_EQUAL(result.toLower, BUnicodeChar::ToLower(i)); +} diff --git a/src/tests/kits/locale/UnicodeCharTest.h b/src/tests/kits/locale/UnicodeCharTest.h new file mode 100644 index 0000000..31fa795 --- /dev/null +++ b/src/tests/kits/locale/UnicodeCharTest.h @@ -0,0 +1,41 @@ +/* + * Copyright 2014 Haiku, Inc. + * Distributed under the terms of the MIT License. + */ +#ifndef UNICODE_CHAR_TEST_H +#define UNICODE_CHAR_TEST_H + + +#include <TestCase.h> +#include <TestSuite.h> + + +class UnicodeCharTest: public BTestCase { +public: + UnicodeCharTest(); + virtual ~UnicodeCharTest(); + + void TestAscii(); + void TestISO8859(); + void TestUTF8(); + + static void AddTests(BTestSuite& suite); + +private: + struct Result { + const char* value; + bool isAlpha; + bool isAlNum; + bool isLower; + bool isUpper; + bool isDefined; + int type; + int32 toUpper; + int32 toLower; + }; + + void _ToString(uint32 c, char* text); + void _TestChar(uint32 c, Result result); +}; + +#endif diff --git a/src/tests/kits/locale/localeTest.cpp b/src/tests/kits/locale/localeTest.cpp index 02f0e50..f24d985 100644 --- a/src/tests/kits/locale/localeTest.cpp +++ b/src/tests/kits/locale/localeTest.cpp @@ -9,63 +9,9 @@ #include <stdio.h> -void -unicode_char_to_string(uint32 c, char *text) -{ - BUnicodeChar::ToUTF8(c, &text); - text[0] = '\0'; -} - - int main() { - // Test BUnicodeChar class - - char text[16]; - - for (int32 i = 30; i < 70; i++) { - unicode_char_to_string(i, text); - printf("%s: alpha == %d, alNum == %d, lower == %d, upper == %d, " - "defined == %d, charType == %d\n", text, - BUnicodeChar::IsAlpha(i), BUnicodeChar::IsAlNum(i), - BUnicodeChar::IsLower(i), BUnicodeChar::IsUpper(i), - BUnicodeChar::IsDefined(i), BUnicodeChar::Type(i)); - } - - uint32 chars[] = {(uint8)'\xe4', (uint8)'\xd6', (uint8)'\xdf', - (uint8)'\xe8', (uint8)'\xe1', (uint8)'\xe9', 0}; - for (int32 j = 0, i; (i = chars[j]) != 0; j++) { - unicode_char_to_string(i, text); - printf("%s: alpha == %d, alNum == %d, lower == %d, upper == %d, " - "defined == %d, charType == %d\n", text, - BUnicodeChar::IsAlpha(i), BUnicodeChar::IsAlNum(i), - BUnicodeChar::IsLower(i), BUnicodeChar::IsUpper(i), - BUnicodeChar::IsDefined(i), BUnicodeChar::Type(i)); - - unicode_char_to_string(BUnicodeChar::ToUpper(i), text); - printf("toUpper == %s, ", text); - unicode_char_to_string(BUnicodeChar::ToLower(i), text); - printf("toLower == %s\n", text); - } - - const char *utf8chars[] = {"à", "ß", "ñ", "é", "ç", "ä", NULL}; - for (int32 j = 0; utf8chars[j] != 0; j++) { - int32 i = BUnicodeChar::FromUTF8(utf8chars[j]); - unicode_char_to_string(i, text); - printf("%s: alpha == %d, alNum == %d, lower == %d, upper == %d, " - "defined == %d, charType == %d\n", text, - BUnicodeChar::IsAlpha(i), BUnicodeChar::IsAlNum(i), - BUnicodeChar::IsLower(i), BUnicodeChar::IsUpper(i), - BUnicodeChar::IsDefined(i), BUnicodeChar::Type(i)); - - unicode_char_to_string(BUnicodeChar::ToUpper(i), text); - printf("toUpper == %s, ", text); - unicode_char_to_string(BUnicodeChar::ToLower(i), text); - printf("toLower == %s\n", text); - } - printf("%c: digitValue == %ld\n", '8', BUnicodeChar::DigitValue('8')); - // Test BCollator class BCollator collator; ############################################################################ Commit: 706f3f5396f5579fffda9a78107f99e8ac92c02a URL: http://cgit.haiku-os.org/haiku/commit/?id=706f3f5 Author: Adrien Destugues <pulkomandy@xxxxxxxxx> Date: Mon Sep 29 15:28:49 2014 UTC Convert collator test to cppunit. ---------------------------------------------------------------------------- diff --git a/src/tests/kits/locale/CollatorTest.cpp b/src/tests/kits/locale/CollatorTest.cpp new file mode 100644 index 0000000..3dee2ac --- /dev/null +++ b/src/tests/kits/locale/CollatorTest.cpp @@ -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); +} diff --git a/src/tests/kits/locale/CollatorTest.h b/src/tests/kits/locale/CollatorTest.h new file mode 100644 index 0000000..4a1765a --- /dev/null +++ b/src/tests/kits/locale/CollatorTest.h @@ -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 diff --git a/src/tests/kits/locale/Jamfile b/src/tests/kits/locale/Jamfile index f22aa9d..caa88e5 100644 --- a/src/tests/kits/locale/Jamfile +++ b/src/tests/kits/locale/Jamfile @@ -51,6 +51,7 @@ Addon catalogTestAddOn UnitTestLib localekittest.so : LocaleKitTestAddon.cpp + CollatorTest.cpp UnicodeCharTest.cpp : be [ TargetLibstdc++ ] diff --git a/src/tests/kits/locale/LocaleKitTestAddon.cpp b/src/tests/kits/locale/LocaleKitTestAddon.cpp index 81adfd6..33811e2 100644 --- a/src/tests/kits/locale/LocaleKitTestAddon.cpp +++ b/src/tests/kits/locale/LocaleKitTestAddon.cpp @@ -7,6 +7,7 @@ #include <TestSuite.h> #include <TestSuiteAddon.h> +#include "CollatorTest.h" #include "UnicodeCharTest.h" @@ -15,6 +16,7 @@ getTestSuite() { BTestSuite* suite = new BTestSuite("LocaleKit"); + CollatorTest::AddTests(*suite); UnicodeCharTest::AddTests(*suite); return suite; diff --git a/src/tests/kits/locale/collatorTest.cpp b/src/tests/kits/locale/collatorTest.cpp index a9b9606..a49fb4c 100644 --- a/src/tests/kits/locale/collatorTest.cpp +++ b/src/tests/kits/locale/collatorTest.cpp @@ -6,6 +6,7 @@ #include <Collator.h> #include <Locale.h> +#include <LocaleRoster.h> #include <Message.h> #include <stdio.h> @@ -126,6 +127,9 @@ main(int argc, char **argv) bool ignorePunctuation = false; char *addon = NULL; + BCollator defaultCollator; + BLocaleRoster::Default()->GetDefaultLocale()->GetCollator(&defaultCollator); + while ((++argv)[0]) { if (argv[0][0] == '-' && argv[0][1] != '-') { char *arg = argv[0] + 1; @@ -155,13 +159,12 @@ main(int argc, char **argv) // load the collator add-on if necessary - if (addon != NULL) { + if (addon != NULL) gCollator = new BCollator(addon, strength, true); - } if (gCollator == NULL) { printf("--------- Use standard collator! -----------\n"); - gCollator = be_locale->Collator(); + gCollator = &defaultCollator; } printf("test archiving/unarchiving collator\n"); @@ -176,7 +179,7 @@ main(int argc, char **argv) fprintf(stderr, "Unarchiving failed!\n"); delete unarchived; - gCollator = be_locale->Collator(); + gCollator = &defaultCollator; } } diff --git a/src/tests/kits/locale/localeTest.cpp b/src/tests/kits/locale/localeTest.cpp index f24d985..4360027 100644 --- a/src/tests/kits/locale/localeTest.cpp +++ b/src/tests/kits/locale/localeTest.cpp @@ -12,29 +12,6 @@ int main() { - // Test BCollator class - - BCollator collator; - BLocaleRoster::Default()->GetDefaultLocale()->GetCollator(&collator); - const char *strings[] = {"gehen", "géhen", "aus", "äUß", "auss", "äUß", - "WO", "wÖ", "SO", "so", "açñ", "acn", NULL}; - const char *strengths[] = {"primary: ", "secondary:", "tertiary: "}; - for (int32 i = 0; strings[i]; i += 2) { - for (int32 strength = B_COLLATE_PRIMARY; strength < 4; strength++) { - BString a, b; - collator.GetSortKey(strings[i], &a, strength); - collator.GetSortKey(strings[i + 1], &b, strength); - - printf("%s sort keys: \"%s\" -> \"%s\", \"%s\" -> \"%s\"\n", - strengths[strength-1], strings[i], a.String(), strings[i+1], - b.String()); - printf("\tcmp = %d (key compare = %d)\n", - collator.Compare(strings[i], strings[i + 1], strength), - strcmp(a.String(), b.String())); - } - putchar('\n'); - } - // Tests the BLanguage class BLanguage language; ############################################################################ Revision: hrev47928 Commit: d7f449e9bc4dc2d89a15cfd99dbe3e3c031c2bbd URL: http://cgit.haiku-os.org/haiku/commit/?id=d7f449e Author: Adrien Destugues <pulkomandy@xxxxxxxxx> Date: Mon Sep 29 15:50:29 2014 UTC Convert language tests to cppunit. ---------------------------------------------------------------------------- diff --git a/src/tests/kits/locale/Jamfile b/src/tests/kits/locale/Jamfile index caa88e5..8caf5c0 100644 --- a/src/tests/kits/locale/Jamfile +++ b/src/tests/kits/locale/Jamfile @@ -13,7 +13,6 @@ Depends LocaleKitTests catalogTestAddOn collatorSpeed collatorTest - localeTest ICUTest # libNumberFormatTests.so localekittest.so @@ -32,7 +31,6 @@ LocaleTest catalogTest.cpp ; LocaleTest collatorSpeed.cpp ; LocaleTest collatorTest.cpp ; LocaleTest genericNumberFormatTest.cpp ; -LocaleTest localeTest.cpp ; LocaleTest formatTest.cpp ; Includes [ FGristFiles ICUTest.cpp ] : [ BuildFeatureAttribute icu : headers ] ; @@ -52,6 +50,7 @@ UnitTestLib localekittest.so : LocaleKitTestAddon.cpp CollatorTest.cpp + LanguageTest.cpp UnicodeCharTest.cpp : be [ TargetLibstdc++ ] diff --git a/src/tests/kits/locale/LanguageTest.cpp b/src/tests/kits/locale/LanguageTest.cpp new file mode 100644 index 0000000..48cabe1 --- /dev/null +++ b/src/tests/kits/locale/LanguageTest.cpp @@ -0,0 +1,46 @@ +/* + * Copyright 2014 Haiku, Inc. + * Distributed under the terms of the MIT License. + */ + + +#include "LanguageTest.h" + +#include "Language.h" + +#include <cppunit/TestCaller.h> +#include <cppunit/TestSuite.h> + + +LanguageTest::LanguageTest() +{ +} + + +LanguageTest::~LanguageTest() +{ +} + + +void +LanguageTest::TestLanguage() +{ + BLanguage language("fr_FR"); + BString name; + language.GetName(name); + CPPUNIT_ASSERT_EQUAL(BString("français (France)"), name); + CPPUNIT_ASSERT_EQUAL(BString("fr"), language.Code()); + CPPUNIT_ASSERT(language.Direction() == B_LEFT_TO_RIGHT); +} + + +/*static*/ void +LanguageTest::AddTests(BTestSuite& parent) +{ + CppUnit::TestSuite& suite = *new CppUnit::TestSuite("LanguageTest"); + + suite.addTest(new CppUnit::TestCaller<LanguageTest>( + "LanguageTest::TestLanguage", &LanguageTest::TestLanguage)); + + parent.addTest("LanguageTest", &suite); +} diff --git a/src/tests/kits/locale/LanguageTest.h b/src/tests/kits/locale/LanguageTest.h new file mode 100644 index 0000000..5cdf408 --- /dev/null +++ b/src/tests/kits/locale/LanguageTest.h @@ -0,0 +1,24 @@ +/* + * Copyright 2014 Haiku, Inc. + * Distributed under the terms of the MIT License. + */ +#ifndef LANGUAGE_TEST_H +#define LANGUAGE_TEST_H + + +#include <TestCase.h> +#include <TestSuite.h> + + +class LanguageTest: public BTestCase { +public: + LanguageTest(); + virtual ~LanguageTest(); + + void TestLanguage(); + + static void AddTests(BTestSuite& suite); +}; + + +#endif diff --git a/src/tests/kits/locale/LocaleKitTestAddon.cpp b/src/tests/kits/locale/LocaleKitTestAddon.cpp index 33811e2..0877206 100644 --- a/src/tests/kits/locale/LocaleKitTestAddon.cpp +++ b/src/tests/kits/locale/LocaleKitTestAddon.cpp @@ -8,6 +8,7 @@ #include <TestSuiteAddon.h> #include "CollatorTest.h" +#include "LanguageTest.h" #include "UnicodeCharTest.h" @@ -17,6 +18,7 @@ getTestSuite() BTestSuite* suite = new BTestSuite("LocaleKit"); CollatorTest::AddTests(*suite); + LanguageTest::AddTests(*suite); UnicodeCharTest::AddTests(*suite); return suite; diff --git a/src/tests/kits/locale/localeTest.cpp b/src/tests/kits/locale/localeTest.cpp deleted file mode 100644 index 4360027..0000000 --- a/src/tests/kits/locale/localeTest.cpp +++ /dev/null @@ -1,38 +0,0 @@ - -#include <Collator.h> -#include <Language.h> -#include <Locale.h> -#include <LocaleRoster.h> -#include <String.h> -#include <UnicodeChar.h> - -#include <stdio.h> - - -int -main() -{ - // Tests the BLanguage class - - BLanguage language; - BLocaleRoster::Default()->GetDefaultLocale()->GetLanguage(&language); - BString name; - language.GetName(name); - printf("Language name = \"%s\", code = \"%s\"\n", name.String(), - language.Code()); - printf("\tdirection = %s\n", - language.Direction() == B_LEFT_TO_RIGHT ? "left-to-right" : - language.Direction() == B_RIGHT_TO_LEFT ? "right-to-left" : - "top-to-bottom"); - - //for (int32 i = 0; i < 200; i++) { - // const char *string = language.GetString(i); - // if (string != NULL) - // printf("%ld: %s\n", i, string); - //} - - printf("First month = %s (%s)\n", - language.GetString(B_MON_1), - language.GetString(B_AB_MON_1)); -} -