1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*********************************************************************** 3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * COPYRIGHT: 48393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius * Copyright (c) 1997-2012, International Business Machines Corporation 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * and others. All Rights Reserved. 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ***********************************************************************/ 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h" 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_FORMATTING 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "intltest.h" 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "tfsmalls.h" 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/msgfmt.h" 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/choicfmt.h" 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/parsepos.h" 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/fieldpos.h" 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/fmtable.h" 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*static UBool chkstatus( UErrorCode &status, char* msg = NULL ) 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool ok = (status == U_ZERO_ERROR); 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (!ok) it_errln( msg ); 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return ok; 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}*/ 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid test_ParsePosition( void ) 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ParsePosition* pp1 = new ParsePosition(); 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (pp1 && (pp1->getIndex() == 0)) { 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("PP constructor() tested."); 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** PP getIndex or constructor() result"); 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete pp1; 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t to = 5; 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ParsePosition pp2( to ); 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (pp2.getIndex() == 5) { 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("PP getIndex and constructor(int32_t) tested."); 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** PP getIndex or constructor(int32_t) result"); 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pp2.setIndex( 3 ); 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (pp2.getIndex() == 3) { 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("PP setIndex tested."); 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** PP getIndex or setIndex result"); 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ParsePosition pp2, pp3; 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pp2 = 3; 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pp3 = 5; 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ParsePosition pp4( pp3 ); 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if ((pp2 != pp3) && (pp3 == pp4)) { 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("PP copy contructor, operator== and operator != tested."); 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** PP operator== or operator != result"); 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ParsePosition pp5; 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pp5 = pp4; 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if ((pp4 == pp5) && (!(pp4 != pp5))) { 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("PP operator= tested."); 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** PP operator= operator== or operator != result"); 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/decimfmt.h" 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid test_FieldPosition_example( void ) 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru //***** no error detection yet !!!!!!! 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru //***** this test is for compiler checks and visual verification only. 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru double doubleNum[] = { 123456789.0, -12345678.9, 1234567.89, -123456.789, 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 12345.6789, -1234.56789, 123.456789, -12.3456789, 1.23456789}; 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t dNumSize = (int32_t)(sizeof(doubleNum)/sizeof(double)); 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru DecimalFormat* fmt = (DecimalFormat*) NumberFormat::createInstance(status); 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)) { 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_dataerrln("NumberFormat::createInstance() error"); 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return; 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fmt->setDecimalSeparatorAlwaysShown(TRUE); 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const int32_t tempLen = 20; 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru char temp[tempLen]; 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (int32_t i=0; i<dNumSize; i++) { 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru FieldPosition pos(NumberFormat::INTEGER_FIELD); 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString buf; 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru //char fmtText[tempLen]; 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru //ToCharString(fmt->format(doubleNum[i], buf, pos), fmtText); 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString res = fmt->format(doubleNum[i], buf, pos); 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (int32_t j=0; j<tempLen; j++) temp[j] = '='; // clear with spaces 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t tempOffset = (tempLen <= (tempLen - pos.getEndIndex())) ? 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru tempLen : (tempLen - pos.getEndIndex()); 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru temp[tempOffset] = '\0'; 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln(UnicodeString("FP ") + UnicodeString(temp) + res); 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete fmt; 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln(""); 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid test_FieldPosition( void ) 119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru FieldPosition fp( 7 ); 122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (fp.getField() == 7) { 124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("FP constructor(int32_t) and getField tested."); 125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** FP constructor(int32_t) or getField"); 127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru FieldPosition* fph = new FieldPosition( 3 ); 130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if ( fph->getField() != 3) it_errln("*** FP getField or heap constr."); 131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete fph; 132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool err1 = FALSE; 134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool err2 = FALSE; 135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool err3 = FALSE; 136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (int32_t i = -50; i < 50; i++ ) { 137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fp.setField( i+8 ); 138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fp.setBeginIndex( i+6 ); 139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fp.setEndIndex( i+7 ); 140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (fp.getField() != i+8) err1 = TRUE; 141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (fp.getBeginIndex() != i+6) err2 = TRUE; 142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (fp.getEndIndex() != i+7) err3 = TRUE; 143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 144ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (!err1) { 145ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("FP setField and getField tested."); 146ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 147ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** FP setField or getField"); 148ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 149ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (!err2) { 150ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("FP setBeginIndex and getBeginIndex tested."); 151ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 152ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** FP setBeginIndex or getBeginIndex"); 153ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 154ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (!err3) { 155ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("FP setEndIndex and getEndIndex tested."); 156ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 157ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** FP setEndIndex or getEndIndex"); 158ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 159ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 160ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln(""); 161ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 162ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 163ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 164ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid test_Formattable( void ) 165ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 166ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 167ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Formattable* ftp = new Formattable(); 168ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (!ftp || !(ftp->getType() == Formattable::kLong) || !(ftp->getLong() == 0)) { 169ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** Formattable constructor or getType or getLong"); 170ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 171ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete ftp; 172ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 173ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Formattable fta, ftb; 174ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fta.setLong(1); ftb.setLong(2); 175ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if ((fta != ftb) || !(fta == ftb)) { 176ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("FT setLong, operator== and operator!= tested."); 177ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 178ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fta.getLong(&status); 179ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if ( status == U_INVALID_FORMAT_ERROR){ 180ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** FT getLong(UErrorCode* status) failed on real Long"); 181ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 182ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("FT getLong(UErrorCode* status) tested."); 183ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 184ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 185ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** Formattable setLong or operator== or !="); 186ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 187ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fta = ftb; 188ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if ((fta == ftb) || !(fta != ftb)) { 189ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("FT operator= tested."); 190ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 191ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** FT operator= or operator== or operator!="); 192ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 193ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 194ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fta.setDouble( 3.0 ); 195ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if ((fta.getType() == Formattable::kDouble) && (fta.getDouble() == 3.0)) { 196ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("FT set- and getDouble tested."); 197ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 198ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** FT set- or getDouble"); 199ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 200ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 201ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fta.getDate(status = U_ZERO_ERROR); 202ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (status != U_INVALID_FORMAT_ERROR){ 203ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** FT getDate with status should fail on non-Date"); 204ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 205ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fta.setDate( 4.0 ); 206ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if ((fta.getType() == Formattable::kDate) && (fta.getDate() == 4.0)) { 207ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("FT set- and getDate tested."); 208ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 209ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fta.getDate(status); 210ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if ( status == U_INVALID_FORMAT_ERROR){ 211ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** FT getDate with status failed on real Date"); 212ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 213ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("FT getDate with status tested."); 214ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 215ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 216ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** FT set- or getDate"); 217ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 218ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 219ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru status = U_ZERO_ERROR; 220ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fta.getLong(&status); 221ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (status != U_INVALID_FORMAT_ERROR){ 222ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** FT getLong(UErrorCode* status) should fail on non-Long"); 223ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 224ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 225ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fta.setString("abc"); 226ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const Formattable ftc(fta); 227ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString res; 228ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 229ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 230ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool t; 231ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t = (fta.getType() == Formattable::kString) 232ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru && (fta.getString(res) == "abc") 233ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru && (fta.getString() == "abc"); 234ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru res = fta.getString(status = U_ZERO_ERROR); 235ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t = t && (status != U_INVALID_FORMAT_ERROR && res == "abc"); 236ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru res = ftc.getString(status = U_ZERO_ERROR); 237ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t = t && (status != U_INVALID_FORMAT_ERROR && res == "abc"); 238ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ftc.getString(res,status = U_ZERO_ERROR); 239ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru t = t && (status != U_INVALID_FORMAT_ERROR && res == "abc"); 240ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (t) { 241ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("FT set- and getString tested."); 242ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 243ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** FT set- or getString"); 244ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 245ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 246ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 247ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString ucs = "unicode-string"; 248ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString* ucs_ptr = new UnicodeString("pointed-to-unicode-string"); 249ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 250ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const Formattable ftarray[] = 251ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru { 252ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Formattable( 1.0, Formattable::kIsDate ), 253ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 2.0, 254ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (int32_t)3, 255ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucs, 256ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ucs_ptr 257ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }; 258ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const int32_t ft_cnt = LENGTHOF(ftarray); 259ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Formattable ft_arr( ftarray, ft_cnt ); 260ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString temp; 261ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if ((ft_arr[0].getType() == Formattable::kDate) && (ft_arr[0].getDate() == 1.0) 262ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru && (ft_arr[1].getType() == Formattable::kDouble) && (ft_arr[1].getDouble() == 2.0) 263ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru && (ft_arr[2].getType() == Formattable::kLong) && (ft_arr[2].getLong() == (int32_t)3) 264ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru && (ft_arr[3].getType() == Formattable::kString) && (ft_arr[3].getString(temp) == ucs) 265ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru && (ft_arr[4].getType() == Formattable::kString) && (ft_arr[4].getString(temp) == *ucs_ptr) ) { 266ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("FT constr. for date, double, long, ustring, ustring* and array tested"); 267ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 268ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** FT constr. for date, double, long, ustring, ustring* or array"); 269ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 270ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 271ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t i, res_cnt; 272ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const Formattable* res_array = ft_arr.getArray( res_cnt ); 273ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (res_cnt == ft_cnt) { 274ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool same = TRUE; 275ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (i = 0; i < res_cnt; i++ ) { 276ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (res_array[i] != ftarray[i]) { 277ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru same = FALSE; 278ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 279ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 280ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (same) { 281ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("FT getArray tested"); 282ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru res_array = ft_arr.getArray( res_cnt, status = U_ZERO_ERROR); 283ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (status == U_INVALID_FORMAT_ERROR){ 284ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** FT getArray with status failed on real array"); 285ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 286ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("FT getArray with status tested on real array"); 287ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 288ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 289ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** FT getArray comparison"); 290ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 291ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 292ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln(UnicodeString("*** FT getArray count res_cnt=") + res_cnt + UnicodeString("ft_cnt=") + ft_cnt); 293ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 294ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 295ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru res_array = fta.getArray(res_cnt, status = U_ZERO_ERROR); 296ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (status == U_INVALID_FORMAT_ERROR){ 297ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (res_cnt == 0 && res_array == NULL){ 298ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("FT getArray with status tested on non array"); 299ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 300ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** FT getArray with status return values are not consistent"); 301ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 302ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } else { 303ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** FT getArray with status should fail on non-array"); 304ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 305ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 306ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 307ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Formattable *pf; 308ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for(i = 0; i < ft_cnt; ++i) { 309ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru pf = ftarray[i].clone(); 310ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if(pf == (ftarray + i) || *pf != ftarray[i]) { 3118393335b955da7340c9f19b1b4b2d6c0c2c04be7Craig Cornelius it_errln(UnicodeString("Formattable.clone() failed for item ") + i); 312ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 313ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru delete pf; 314ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 315ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 316ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const Formattable ftarr1[] = { Formattable( (int32_t)1 ), Formattable( (int32_t)2 ) }; 317ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const Formattable ftarr2[] = { Formattable( (int32_t)3 ), Formattable( (int32_t)4 ) }; 318ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 319ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const int32_t ftarr1_cnt = (int32_t)(sizeof(ftarr1) / sizeof(Formattable)); 320ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const int32_t ftarr2_cnt = (int32_t)(sizeof(ftarr2) / sizeof(Formattable)); 321ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 322ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ft_arr.setArray( ftarr1, ftarr1_cnt ); 323ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if ((ft_arr[0].getType() == Formattable::kLong) && (ft_arr[0].getLong() == (int32_t)1)) { 324ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("FT setArray tested"); 325ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 326ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** FT setArray"); 327ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 328ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 329ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru Formattable* ft_dynarr = new Formattable[ftarr2_cnt]; 330ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (i = 0; i < ftarr2_cnt; i++ ) { 331ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ft_dynarr[i] = ftarr2[i]; 332ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 333ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if ((ft_dynarr[0].getType() == Formattable::kLong) && (ft_dynarr[0].getLong() == (int32_t)3) 334ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru && (ft_dynarr[1].getType() == Formattable::kLong) && (ft_dynarr[1].getLong() == (int32_t)4)) { 335ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("FT operator= and array operations tested"); 336ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 337ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** FT operator= or array operations"); 338ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 339ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 340ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ft_arr.adoptArray( ft_dynarr, ftarr2_cnt ); 341ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if ((ft_arr[0].getType() == Formattable::kLong) && (ft_arr[0].getLong() == (int32_t)3) 342ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru && (ft_arr[1].getType() == Formattable::kLong) && (ft_arr[1].getLong() == (int32_t)4)) { 343ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("FT adoptArray tested"); 344ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 345ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** FT adoptArray or operator[]"); 346ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 347ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 348ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ft_arr.setLong(0); // calls 'dispose' and deletes adopted array ! 349ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 350ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString* ucs_dyn = new UnicodeString("ttt"); 351ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString tmp2; 352ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 353ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fta.adoptString( ucs_dyn ); 354ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if ((fta.getType() == Formattable::kString) && (fta.getString(tmp2) == "ttt")) { 355ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln("FT adoptString tested"); 356ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru }else{ 357ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_errln("*** FT adoptString or getString"); 358ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 359ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fta.setLong(0); // calls 'dispose' and deletes adopted string ! 360ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 361ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru it_logln(); 362ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 363ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 364ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid TestFormatSmallClasses::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ ) 365ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 366ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru switch (index) { 367ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 0: name = "pp"; 368ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (exec) logln("TestSuite Format/SmallClasses/ParsePosition (f/chc/sma/pp): "); 369ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (exec) test_ParsePosition(); 370ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 371ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 1: name = "fp"; 372ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (exec) logln("TestSuite Format/SmallClasses/FieldPosition (f/chc/sma/fp): "); 373ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (exec) test_FieldPosition(); 374ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 375ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 2: name = "fpe"; 376ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (exec) logln("TestSuite Format/SmallClasses/FieldPositionExample (f/chc/sma/fpe): "); 377ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (exec) test_FieldPosition_example(); 378ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 379ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 3: name = "ft"; 380ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (exec) logln("TestSuite Format/SmallClasses/Formattable (f/chc/sma/ft): "); 381ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (exec) test_Formattable(); 382ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru break; 383ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru default: name = ""; break; //needed to end loop 384ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 385ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 386ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 387ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif /* #if !UCONFIG_NO_FORMATTING */ 388