]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/genderinfotest.cpp
1 /********************************************************************
3 * Copyright (c) 1997-2014, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /* Modification History:
9 #include "unicode/utypes.h"
11 #if !UCONFIG_NO_FORMATTING
14 #include "unicode/gender.h"
15 #include "unicode/unum.h"
19 static const UGender kSingleFemale
[] = {UGENDER_FEMALE
};
20 static const UGender kSingleMale
[] = {UGENDER_MALE
};
21 static const UGender kSingleOther
[] = {UGENDER_OTHER
};
23 static const UGender kAllFemale
[] = {UGENDER_FEMALE
, UGENDER_FEMALE
};
24 static const UGender kAllMale
[] = {UGENDER_MALE
, UGENDER_MALE
};
25 static const UGender kAllOther
[] = {UGENDER_OTHER
, UGENDER_OTHER
};
27 static const UGender kFemaleMale
[] = {UGENDER_FEMALE
, UGENDER_MALE
};
28 static const UGender kFemaleOther
[] = {UGENDER_FEMALE
, UGENDER_OTHER
};
29 static const UGender kMaleOther
[] = {UGENDER_MALE
, UGENDER_OTHER
};
32 class GenderInfoTest
: public IntlTest
{
37 void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
=0);
39 void TestGetListGender();
41 void check(UGender expected_neutral
, UGender expected_mixed
, UGender expected_taints
, const UGender
* genderList
, int32_t listLength
);
42 void checkLocale(const Locale
& locale
, UGender expected
, const UGender
* genderList
, int32_t listLength
);
45 void GenderInfoTest::runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char * /* par */) {
47 logln("TestSuite GenderInfoTest: ");
50 TESTCASE_AUTO(TestGetListGender
);
51 TESTCASE_AUTO(TestFallback
);
55 void GenderInfoTest::TestGetListGender() {
56 check(UGENDER_OTHER
, UGENDER_OTHER
, UGENDER_OTHER
, NULL
, 0);
57 check(UGENDER_FEMALE
, UGENDER_FEMALE
, UGENDER_FEMALE
, kSingleFemale
, UPRV_LENGTHOF(kSingleFemale
));
58 check(UGENDER_MALE
, UGENDER_MALE
, UGENDER_MALE
, kSingleMale
, UPRV_LENGTHOF(kSingleMale
));
59 check(UGENDER_OTHER
, UGENDER_OTHER
, UGENDER_OTHER
, kSingleOther
, UPRV_LENGTHOF(kSingleOther
));
61 check(UGENDER_OTHER
, UGENDER_FEMALE
, UGENDER_FEMALE
, kAllFemale
, UPRV_LENGTHOF(kAllFemale
));
62 check(UGENDER_OTHER
, UGENDER_MALE
, UGENDER_MALE
, kAllMale
, UPRV_LENGTHOF(kAllMale
));
63 check(UGENDER_OTHER
, UGENDER_OTHER
, UGENDER_MALE
, kAllOther
, UPRV_LENGTHOF(kAllOther
));
65 check(UGENDER_OTHER
, UGENDER_OTHER
, UGENDER_MALE
, kFemaleMale
, UPRV_LENGTHOF(kFemaleMale
));
66 check(UGENDER_OTHER
, UGENDER_OTHER
, UGENDER_MALE
, kFemaleOther
, UPRV_LENGTHOF(kFemaleOther
));
67 check(UGENDER_OTHER
, UGENDER_OTHER
, UGENDER_MALE
, kMaleOther
, UPRV_LENGTHOF(kMaleOther
));
70 void GenderInfoTest::TestFallback() {
71 UErrorCode status
= U_ZERO_ERROR
;
72 const GenderInfo
* actual
= GenderInfo::getInstance("xx", status
);
73 if (U_FAILURE(status
)) {
74 errcheckln(status
, "Fail to create GenderInfo - %s", u_errorName(status
));
77 const GenderInfo
* expected
= GenderInfo::getNeutralInstance();
78 if (expected
!= actual
) {
79 errln("For Neutral, expected %d got %d", expected
, actual
);
81 actual
= GenderInfo::getInstance("fr_CA", status
);
82 if (U_FAILURE(status
)) {
83 errcheckln(status
, "Fail to create GenderInfo - %s", u_errorName(status
));
86 expected
= GenderInfo::getMaleTaintsInstance();
87 if (expected
!= actual
) {
88 errln("For Male Taints, Expected %d got %d", expected
, actual
);
92 void GenderInfoTest::check(
93 UGender expected_neutral
, UGender expected_mixed
, UGender expected_taints
, const UGender
* genderList
, int32_t listLength
) {
94 checkLocale(Locale::getUS(), expected_neutral
, genderList
, listLength
);
95 checkLocale("is", expected_mixed
, genderList
, listLength
);
96 checkLocale(Locale::getFrench(), expected_taints
, genderList
, listLength
);
99 void GenderInfoTest::checkLocale(
100 const Locale
& locale
, UGender expected
, const UGender
* genderList
, int32_t listLength
) {
101 UErrorCode status
= U_ZERO_ERROR
;
102 const GenderInfo
* gi
= GenderInfo::getInstance(locale
, status
);
103 if (U_FAILURE(status
)) {
104 errcheckln(status
, "Fail to create GenderInfo - %s", u_errorName(status
));
107 UGender actual
= gi
->getListGender(genderList
, listLength
, status
);
108 if (U_FAILURE(status
)) {
109 errcheckln(status
, "Fail to get gender of list - %s", u_errorName(status
));
112 if (actual
!= expected
) {
113 errln("For locale: %s expected: %d got %d", locale
.getName(), expected
, actual
);
117 extern IntlTest
*createGenderInfoTest() {
118 return new GenderInfoTest();
121 #endif /* #if !UCONFIG_NO_FORMATTING */