+void NumberFormatTest::TestExplicitParents() {
+
+ /* Test that number formats are properly inherited from es_419 */
+ /* These could be subject to change if the CLDR data changes */
+ static const char* parentLocaleTests[][2]= {
+ /* locale ID */ /* expected */
+ {"es_CO", "1.250,75" },
+ {"es_CR", "1.250,75" },
+ {"es_ES", "1.250,75" },
+ {"es_GQ", "1.250,75" },
+ {"es_MX", "1,250.75" },
+ {"es_US", "1,250.75" },
+ {"es_VE", "1.250,75" },
+ };
+
+ UnicodeString s;
+
+ for(int i=0; i < (int)(sizeof(parentLocaleTests)/sizeof(parentLocaleTests[i])); i++){
+ UErrorCode status = U_ZERO_ERROR;
+ const char *localeID = parentLocaleTests[i][0];
+ UnicodeString expected(parentLocaleTests[i][1], -1, US_INV);
+ expected = expected.unescape();
+ char loc[256]={0};
+ uloc_canonicalize(localeID, loc, 256, &status);
+ NumberFormat *fmt= NumberFormat::createInstance(Locale(loc), status);
+ if(U_FAILURE(status)){
+ dataerrln("Could not create number formatter for locale %s - %s",localeID, u_errorName(status));
+ continue;
+ }
+ s.remove();
+ fmt->format(1250.75, s);
+ if(s!=expected){
+ errln(UnicodeString("FAIL: Expected: ")+expected
+ + UnicodeString(" Got: ") + s
+ + UnicodeString( " for locale: ")+ UnicodeString(localeID) );
+ }
+ if (U_FAILURE(status)){
+ errln((UnicodeString)"FAIL: Status " + (int32_t)status);
+ }
+ delete fmt;
+ }
+
+}
+
+/**
+ * Test available numbering systems API.
+ */
+void NumberFormatTest::TestAvailableNumberingSystems() {
+ UErrorCode status = U_ZERO_ERROR;
+ StringEnumeration *availableNumberingSystems = NumberingSystem::getAvailableNames(status);
+ CHECK_DATA(status, "NumberingSystem::getAvailableNames()")
+
+ int32_t nsCount = availableNumberingSystems->count(status);
+ if ( nsCount < 36 ) {
+ errln("FAIL: Didn't get as many numbering systems as we had hoped for. Need at least 36, got %d",nsCount);
+ }
+
+ /* A relatively simple test of the API. We call getAvailableNames() and cycle through */
+ /* each name returned, attempting to create a numbering system based on that name and */
+ /* verifying that the name returned from the resulting numbering system is the same */
+ /* one that we initially thought. */
+
+ int32_t len;
+ for ( int32_t i = 0 ; i < nsCount ; i++ ) {
+ const char *nsname = availableNumberingSystems->next(&len,status);
+ NumberingSystem* ns = NumberingSystem::createInstanceByName(nsname,status);
+ if ( uprv_strcmp(nsname,ns->getName()) ) {
+ errln("FAIL: Numbering system name didn't match for name = %s\n",nsname);
+ }
+
+ delete ns;
+ }
+
+ delete availableNumberingSystems;
+}
+
+void
+NumberFormatTest::Test9087(void)
+{
+ U_STRING_DECL(pattern,"#",1);
+ U_STRING_INIT(pattern,"#",1);
+
+ U_STRING_DECL(infstr,"INF",3);
+ U_STRING_INIT(infstr,"INF",3);
+
+ U_STRING_DECL(nanstr,"NAN",3);
+ U_STRING_INIT(nanstr,"NAN",3);
+
+ UChar outputbuf[50] = {0};
+ UErrorCode status = U_ZERO_ERROR;
+ UNumberFormat* fmt = unum_open(UNUM_PATTERN_DECIMAL,pattern,1,NULL,NULL,&status);
+ if ( U_FAILURE(status) ) {
+ dataerrln("FAIL: error in unum_open() - %s", u_errorName(status));
+ return;
+ }
+
+ unum_setSymbol(fmt,UNUM_INFINITY_SYMBOL,infstr,3,&status);
+ unum_setSymbol(fmt,UNUM_NAN_SYMBOL,nanstr,3,&status);
+ if ( U_FAILURE(status) ) {
+ errln("FAIL: error setting symbols");
+ }
+
+ double inf = uprv_getInfinity();
+
+ unum_setAttribute(fmt,UNUM_ROUNDING_MODE,UNUM_ROUND_HALFEVEN);
+ unum_setDoubleAttribute(fmt,UNUM_ROUNDING_INCREMENT,0);
+
+ UFieldPosition position = { 0, 0, 0};
+ unum_formatDouble(fmt,inf,outputbuf,50,&position,&status);
+
+ if ( u_strcmp(infstr, outputbuf)) {
+ errln((UnicodeString)"FAIL: unexpected result for infinity - expected " + infstr + " got " + outputbuf);
+ }
+
+ unum_close(fmt);
+}