]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/genderinfotest.cpp
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
5 * Copyright (c) 1997-2014, International Business Machines Corporation and
6 * others. All Rights Reserved.
7 ********************************************************************/
8 /* Modification History:
11 #include "unicode/utypes.h"
13 #if !UCONFIG_NO_FORMATTING
16 #include "unicode/gender.h"
17 #include "unicode/unum.h"
21 static const UGender kSingleFemale
[] = {UGENDER_FEMALE
};
22 static const UGender kSingleMale
[] = {UGENDER_MALE
};
23 static const UGender kSingleOther
[] = {UGENDER_OTHER
};
25 static const UGender kAllFemale
[] = {UGENDER_FEMALE
, UGENDER_FEMALE
};
26 static const UGender kAllMale
[] = {UGENDER_MALE
, UGENDER_MALE
};
27 static const UGender kAllOther
[] = {UGENDER_OTHER
, UGENDER_OTHER
};
29 static const UGender kFemaleMale
[] = {UGENDER_FEMALE
, UGENDER_MALE
};
30 static const UGender kFemaleOther
[] = {UGENDER_FEMALE
, UGENDER_OTHER
};
31 static const UGender kMaleOther
[] = {UGENDER_MALE
, UGENDER_OTHER
};
34 class GenderInfoTest
: public IntlTest
{
39 void runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char *par
=0);
41 void TestGetListGender();
43 void check(UGender expected_neutral
, UGender expected_mixed
, UGender expected_taints
, const UGender
* genderList
, int32_t listLength
);
44 void checkLocale(const Locale
& locale
, UGender expected
, const UGender
* genderList
, int32_t listLength
);
47 void GenderInfoTest::runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char * /* par */) {
49 logln("TestSuite GenderInfoTest: ");
52 TESTCASE_AUTO(TestGetListGender
);
53 TESTCASE_AUTO(TestFallback
);
57 void GenderInfoTest::TestGetListGender() {
58 check(UGENDER_OTHER
, UGENDER_OTHER
, UGENDER_OTHER
, NULL
, 0);
59 check(UGENDER_FEMALE
, UGENDER_FEMALE
, UGENDER_FEMALE
, kSingleFemale
, UPRV_LENGTHOF(kSingleFemale
));
60 check(UGENDER_MALE
, UGENDER_MALE
, UGENDER_MALE
, kSingleMale
, UPRV_LENGTHOF(kSingleMale
));
61 check(UGENDER_OTHER
, UGENDER_OTHER
, UGENDER_OTHER
, kSingleOther
, UPRV_LENGTHOF(kSingleOther
));
63 check(UGENDER_OTHER
, UGENDER_FEMALE
, UGENDER_FEMALE
, kAllFemale
, UPRV_LENGTHOF(kAllFemale
));
64 check(UGENDER_OTHER
, UGENDER_MALE
, UGENDER_MALE
, kAllMale
, UPRV_LENGTHOF(kAllMale
));
65 check(UGENDER_OTHER
, UGENDER_OTHER
, UGENDER_MALE
, kAllOther
, UPRV_LENGTHOF(kAllOther
));
67 check(UGENDER_OTHER
, UGENDER_OTHER
, UGENDER_MALE
, kFemaleMale
, UPRV_LENGTHOF(kFemaleMale
));
68 check(UGENDER_OTHER
, UGENDER_OTHER
, UGENDER_MALE
, kFemaleOther
, UPRV_LENGTHOF(kFemaleOther
));
69 check(UGENDER_OTHER
, UGENDER_OTHER
, UGENDER_MALE
, kMaleOther
, UPRV_LENGTHOF(kMaleOther
));
72 void GenderInfoTest::TestFallback() {
73 UErrorCode status
= U_ZERO_ERROR
;
74 const GenderInfo
* actual
= GenderInfo::getInstance("xx", status
);
75 if (U_FAILURE(status
)) {
76 errcheckln(status
, "Fail to create GenderInfo - %s", u_errorName(status
));
79 const GenderInfo
* expected
= GenderInfo::getNeutralInstance();
80 if (expected
!= actual
) {
81 errln("For Neutral, expected %d got %d", expected
, actual
);
83 actual
= GenderInfo::getInstance("fr_CA", status
);
84 if (U_FAILURE(status
)) {
85 errcheckln(status
, "Fail to create GenderInfo - %s", u_errorName(status
));
88 expected
= GenderInfo::getMaleTaintsInstance();
89 if (expected
!= actual
) {
90 errln("For Male Taints, Expected %d got %d", expected
, actual
);
94 void GenderInfoTest::check(
95 UGender expected_neutral
, UGender expected_mixed
, UGender expected_taints
, const UGender
* genderList
, int32_t listLength
) {
96 checkLocale(Locale::getUS(), expected_neutral
, genderList
, listLength
);
97 checkLocale("is", expected_mixed
, genderList
, listLength
);
98 checkLocale(Locale::getFrench(), expected_taints
, genderList
, listLength
);
101 void GenderInfoTest::checkLocale(
102 const Locale
& locale
, UGender expected
, const UGender
* genderList
, int32_t listLength
) {
103 UErrorCode status
= U_ZERO_ERROR
;
104 const GenderInfo
* gi
= GenderInfo::getInstance(locale
, status
);
105 if (U_FAILURE(status
)) {
106 errcheckln(status
, "Fail to create GenderInfo - %s", u_errorName(status
));
109 UGender actual
= gi
->getListGender(genderList
, listLength
, status
);
110 if (U_FAILURE(status
)) {
111 errcheckln(status
, "Fail to get gender of list - %s", u_errorName(status
));
114 if (actual
!= expected
) {
115 errln("For locale: %s expected: %d got %d", locale
.getName(), expected
, actual
);
119 extern IntlTest
*createGenderInfoTest() {
120 return new GenderInfoTest();
123 #endif /* #if !UCONFIG_NO_FORMATTING */