175f15221SOliver Tappe /*
275f15221SOliver Tappe ** Copyright 2009 Adrien Destugues, pulkomandy@gmail.com.
375f15221SOliver Tappe ** Distributed under the terms of the MIT License.
475f15221SOliver Tappe */
575f15221SOliver Tappe
675f15221SOliver Tappe
775f15221SOliver Tappe #include <assert.h>
875f15221SOliver Tappe #include <stdio.h>
975f15221SOliver Tappe #include <stdlib.h>
1075f15221SOliver Tappe #include <typeinfo>
1175f15221SOliver Tappe #include <unistd.h>
1275f15221SOliver Tappe
1375f15221SOliver Tappe #include <Application.h>
1475f15221SOliver Tappe #include <StopWatch.h>
1575f15221SOliver Tappe
1675f15221SOliver Tappe #include <unicode/locid.h>
1775f15221SOliver Tappe #include <unicode/strenum.h>
1875f15221SOliver Tappe
1975f15221SOliver Tappe
TestLocale(const Locale & loc)2075f15221SOliver Tappe void TestLocale(const Locale& loc)
2175f15221SOliver Tappe {
2275f15221SOliver Tappe printf("-- init\n");
2375f15221SOliver Tappe assert(!loc.isBogus());
2475f15221SOliver Tappe printf("-- basic info\n");
2575f15221SOliver Tappe printf("Default locale:\nLanguage: %s\nScript: %s\nVariant: %s\n"
2675f15221SOliver Tappe "Country: %s\nName: %s\nBaseName: %s\n", loc.getLanguage(),
2775f15221SOliver Tappe loc.getScript(), loc.getVariant(),
2875f15221SOliver Tappe loc.getCountry(), loc.getName(),
2975f15221SOliver Tappe loc.getBaseName());
3075f15221SOliver Tappe
3175f15221SOliver Tappe UErrorCode err = U_ZERO_ERROR;
3275f15221SOliver Tappe printf("-- keywords\n");
3375f15221SOliver Tappe StringEnumeration* keywords = loc.createKeywords(err);
3475f15221SOliver Tappe if (err != U_ZERO_ERROR)
3575f15221SOliver Tappe printf("FAILED: getting keywords list\n");
3675f15221SOliver Tappe if (keywords == NULL)
3775f15221SOliver Tappe printf("FAILED: getting keywords list returned NULL\n");
3875f15221SOliver Tappe else {
3975f15221SOliver Tappe printf("Keywords: %d available\n", keywords->count(err));
4075f15221SOliver Tappe assert(err == U_ZERO_ERROR);
4175f15221SOliver Tappe
4275f15221SOliver Tappe char keyvalue[256];
4375f15221SOliver Tappe while (const char* keyname = keywords->next(NULL, err)) {
4475f15221SOliver Tappe loc.getKeywordValue(keyname, keyvalue, 256, err);
4575f15221SOliver Tappe printf("%s > %s\n", keyname, keyvalue);
4675f15221SOliver Tappe }
4775f15221SOliver Tappe
4875f15221SOliver Tappe delete keywords;
4975f15221SOliver Tappe }
5075f15221SOliver Tappe }
5175f15221SOliver Tappe
5275f15221SOliver Tappe
5375f15221SOliver Tappe int
main(int argc,char ** argv)5475f15221SOliver Tappe main(int argc, char **argv)
5575f15221SOliver Tappe {
56*27a2d2c7SAdrien Destugues printf("--------\nDefault Locale\n--------\n");
5775f15221SOliver Tappe Locale defaultLocale;
5875f15221SOliver Tappe TestLocale(defaultLocale);
5975f15221SOliver Tappe printf("--------\nFrench Locale\n--------\n");
6075f15221SOliver Tappe Locale french = Locale::getFrench();
6175f15221SOliver Tappe TestLocale(french);
6275f15221SOliver Tappe printf("--------\nCustom Locale\n--------\n");
6375f15221SOliver Tappe Locale custom("es");
6475f15221SOliver Tappe TestLocale(custom);
6575f15221SOliver Tappe
6675f15221SOliver Tappe printf("--------\nLocale listing\n--------\n");
6775f15221SOliver Tappe int32_t count;
6875f15221SOliver Tappe const Locale* localeList = Locale::getAvailableLocales(count);
6975f15221SOliver Tappe printf("%d locales found\n", count);
7075f15221SOliver Tappe
7175f15221SOliver Tappe for (int i=0; i<count; i++) {
7275f15221SOliver Tappe printf("Locale number %d\n", i);
7375f15221SOliver Tappe TestLocale(localeList[i]);
7475f15221SOliver Tappe }
7575f15221SOliver Tappe
7675f15221SOliver Tappe printf("--------\nLocale country codes\n--------\n");
7775f15221SOliver Tappe const char* const* countryTable = Locale::getISOCountries();
7875f15221SOliver Tappe
79*27a2d2c7SAdrien Destugues for (int i=0; countryTable[i] != NULL; i++) {
80*27a2d2c7SAdrien Destugues if (i % 10 == 0) puts("");
8175f15221SOliver Tappe printf("%s\t", countryTable[i]);
82*27a2d2c7SAdrien Destugues }
8375f15221SOliver Tappe
8475f15221SOliver Tappe printf("\n--------\nNumberFormat\n--------\n");
8575f15221SOliver Tappe printf("--------\nDateFormat\n--------\n");
8675f15221SOliver Tappe printf("--------\nCollator\n--------\n");
8775f15221SOliver Tappe
8875f15221SOliver Tappe return 0;
8975f15221SOliver Tappe }
90