void TestChoiceFormat::TestSimpleExample( void ) { double limits[] = {1,2,3,4,5,6,7}; UnicodeString monthNames[] = {"Sun","Mon","Tue","Wed","Thur","Fri","Sat"}; ChoiceFormat* form = new ChoiceFormat(limits, monthNames, 7); ParsePosition parse_pos; // TODO Fix this ParsePosition stuff... UnicodeString str; UnicodeString res1, res2; UErrorCode status; FieldPosition fpos(FieldPosition::DONT_CARE); Formattable f; int32_t ix; //for (double i = 0.0; i <= 8.0; ++i) { for (ix = 0; ix <= 8; ++ix) { double i = ix; //nos status = U_ZERO_ERROR; fpos = 0; str = ""; res1 = form->format(i, str, fpos, status ); if (!chkstatus( status, "*** test_simple_example format" )) { delete form; return; } //form->parse(res1, f, parse_pos); res2 = " ??? "; it_logln(UnicodeString("") + ix + UnicodeString(" -> ") + res1 + UnicodeString(" -> ") + res2); } //Testing ==operator const double filelimits[] = {0,1,2}; const UnicodeString filepart[] = {"are no files","is one file","are {2} files"}; ChoiceFormat* formnew=new ChoiceFormat(filelimits, filepart, 3); ChoiceFormat* formequal=new ChoiceFormat(limits, monthNames, 7); if(*formnew == *form){ errln("ERROR: ==operator failed\n"); } if(!(*form == *formequal)){ errln("ERROR: ==operator failed\n"); } delete formequal; delete formnew; //Testing getLimits() int32_t count=0; const double *gotLimits=form->getLimits(count); #if 1 // ICU 4.8 deprecates and disables the ChoiceFormat getters. if(count != 0 || gotLimits != NULL) { errln("getLimits() returns something, should be disabled"); } const UnicodeString *gotFormats=form->getFormats(count); if(count != 0 || gotFormats != NULL) { errln("getFormats() returns something, should be disabled"); } const UBool *gotClosures=form->getClosures(count); if(count != 0 || gotClosures != NULL) { errln("getClosures() returns something, should be disabled"); } #else if(count != 7){ errln("getLimits didn't update the count correctly\n"); } for(ix=0; ix<count; ix++){ if(gotLimits[ix] != limits[ix]){ errln((UnicodeString)"getLimits didn't get the limits correctly. Expected " + limits[ix] + " Got " + gotLimits[ix]); } } //Testing getFormats() count=0; const UnicodeString *gotFormats=form->getFormats(count); if(count != 7){ errln("getFormats didn't update the count correctly\n"); } for(ix=0; ix<count; ix++){ if(gotFormats[ix] != monthNames[ix]){ errln((UnicodeString)"getFormats didn't get the Formats correctly. Expected " + monthNames[ix] + " Got " + gotFormats[ix]); } } #endif delete form; }