]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/genderinfotest.cpp
1 /********************************************************************
3 * Copyright (c) 1997-2012, 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"
18 #define LENGTHOF(array) (int32_t)(sizeof(array) / sizeof((array)[0]))
20 static const UGender kSingleFemale
[] = {UGENDER_FEMALE
};
21 static const UGender kSingleMale
[] = {UGENDER_MALE
};
22 static const UGender kSingleOther
[] = {UGENDER_OTHER
};
24 static const UGender kAllFemale
[] = {UGENDER_FEMALE
, UGENDER_FEMALE
};
25 static const UGender kAllMale
[] = {UGENDER_MALE
, UGENDER_MALE
};
26 static const UGender kAllOther
[] = {UGENDER_OTHER
, UGENDER_OTHER
};
28 static const UGender kFemaleMale
[] = {UGENDER_FEMALE
, UGENDER_MALE
};
29 static const UGender kFemaleOther
[] = {UGENDER_FEMALE
, UGENDER_OTHER
};
30 static const UGender kMaleOther
[] = {UGENDER_MALE
, UGENDER_OTHER
};
33 class GenderInfoTest
: public IntlTest
{
38 void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
=0);
40 void TestGetListGender();
42 void check(UGender expected_neutral
, UGender expected_mixed
, UGender expected_taints
, const UGender
* genderList
, int32_t listLength
);
43 void checkLocale(const Locale
& locale
, UGender expected
, const UGender
* genderList
, int32_t listLength
);
46 void GenderInfoTest::runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char * /* par */) {
48 logln("TestSuite GenderInfoTest: ");
51 TESTCASE_AUTO(TestGetListGender
);
52 TESTCASE_AUTO(TestFallback
);
56 void GenderInfoTest::TestGetListGender() {
57 check(UGENDER_OTHER
, UGENDER_OTHER
, UGENDER_OTHER
, NULL
, 0);
58 check(UGENDER_FEMALE
, UGENDER_FEMALE
, UGENDER_FEMALE
, kSingleFemale
, LENGTHOF(kSingleFemale
));
59 check(UGENDER_MALE
, UGENDER_MALE
, UGENDER_MALE
, kSingleMale
, LENGTHOF(kSingleMale
));
60 check(UGENDER_OTHER
, UGENDER_OTHER
, UGENDER_OTHER
, kSingleOther
, LENGTHOF(kSingleOther
));
62 check(UGENDER_OTHER
, UGENDER_FEMALE
, UGENDER_FEMALE
, kAllFemale
, LENGTHOF(kAllFemale
));
63 check(UGENDER_OTHER
, UGENDER_MALE
, UGENDER_MALE
, kAllMale
, LENGTHOF(kAllMale
));
64 check(UGENDER_OTHER
, UGENDER_OTHER
, UGENDER_MALE
, kAllOther
, LENGTHOF(kAllOther
));
66 check(UGENDER_OTHER
, UGENDER_OTHER
, UGENDER_MALE
, kFemaleMale
, LENGTHOF(kFemaleMale
));
67 check(UGENDER_OTHER
, UGENDER_OTHER
, UGENDER_MALE
, kFemaleOther
, LENGTHOF(kFemaleOther
));
68 check(UGENDER_OTHER
, UGENDER_OTHER
, UGENDER_MALE
, kMaleOther
, LENGTHOF(kMaleOther
));
71 void GenderInfoTest::TestFallback() {
72 UErrorCode status
= U_ZERO_ERROR
;
73 const GenderInfo
* actual
= GenderInfo::getInstance("xx", status
);
74 if (U_FAILURE(status
)) {
75 errcheckln(status
, "Fail to create GenderInfo - %s", u_errorName(status
));
78 const GenderInfo
* expected
= GenderInfo::getNeutralInstance();
79 if (expected
!= actual
) {
80 errln("For Neutral, expected %d got %d", expected
, actual
);
82 actual
= GenderInfo::getInstance("fr_CA", status
);
83 if (U_FAILURE(status
)) {
84 errcheckln(status
, "Fail to create GenderInfo - %s", u_errorName(status
));
87 expected
= GenderInfo::getMaleTaintsInstance();
88 if (expected
!= actual
) {
89 errln("For Male Taints, Expected %d got %d", expected
, actual
);
93 void GenderInfoTest::check(
94 UGender expected_neutral
, UGender expected_mixed
, UGender expected_taints
, const UGender
* genderList
, int32_t listLength
) {
95 checkLocale(Locale::getUS(), expected_neutral
, genderList
, listLength
);
96 checkLocale("is", expected_mixed
, genderList
, listLength
);
97 checkLocale(Locale::getFrench(), expected_taints
, genderList
, listLength
);
100 void GenderInfoTest::checkLocale(
101 const Locale
& locale
, UGender expected
, const UGender
* genderList
, int32_t listLength
) {
102 UErrorCode status
= U_ZERO_ERROR
;
103 const GenderInfo
* gi
= GenderInfo::getInstance(locale
, status
);
104 if (U_FAILURE(status
)) {
105 errcheckln(status
, "Fail to create GenderInfo - %s", u_errorName(status
));
108 UGender actual
= gi
->getListGender(genderList
, listLength
, status
);
109 if (U_FAILURE(status
)) {
110 errcheckln(status
, "Fail to get gender of list - %s", u_errorName(status
));
113 if (actual
!= expected
) {
114 errln("For locale: %s expected: %d got %d", locale
.getName(), expected
, actual
);
118 extern IntlTest
*createGenderInfoTest() {
119 return new GenderInfoTest();
122 #endif /* #if !UCONFIG_NO_FORMATTING */