-
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/***********************************************************************
- * COPYRIGHT:
- * Copyright (c) 1997-2004, International Business Machines Corporation
+ * COPYRIGHT:
+ * Copyright (c) 1997-2016, International Business Machines Corporation
* and others. All Rights Reserved.
***********************************************************************/
#include "intltest.h"
#include "tfsmalls.h"
+#include "cmemory.h"
#include "unicode/msgfmt.h"
#include "unicode/choicfmt.h"
#include "unicode/fieldpos.h"
#include "unicode/fmtable.h"
-#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
-
/*static UBool chkstatus( UErrorCode &status, char* msg = NULL )
{
UBool ok = (status == U_ZERO_ERROR);
//***** this test is for compiler checks and visual verification only.
double doubleNum[] = { 123456789.0, -12345678.9, 1234567.89, -123456.789,
12345.6789, -1234.56789, 123.456789, -12.3456789, 1.23456789};
- int32_t dNumSize = (int32_t)(sizeof(doubleNum)/sizeof(double));
+ int32_t dNumSize = UPRV_LENGTHOF(doubleNum);
UErrorCode status = U_ZERO_ERROR;
DecimalFormat* fmt = (DecimalFormat*) NumberFormat::createInstance(status);
+ if (U_FAILURE(status)) {
+ it_dataerrln("NumberFormat::createInstance() error");
+ return;
+ }
fmt->setDecimalSeparatorAlwaysShown(TRUE);
const int32_t tempLen = 20;
void test_Formattable( void )
{
+ UErrorCode status = U_ZERO_ERROR;
Formattable* ftp = new Formattable();
if (!ftp || !(ftp->getType() == Formattable::kLong) || !(ftp->getLong() == 0)) {
it_errln("*** Formattable constructor or getType or getLong");
fta.setLong(1); ftb.setLong(2);
if ((fta != ftb) || !(fta == ftb)) {
it_logln("FT setLong, operator== and operator!= tested.");
+ status = U_ZERO_ERROR;
+ fta.getLong(&status);
+ if ( status == U_INVALID_FORMAT_ERROR){
+ it_errln("*** FT getLong(UErrorCode* status) failed on real Long");
+ } else {
+ it_logln("FT getLong(UErrorCode* status) tested.");
+ }
}else{
it_errln("*** Formattable setLong or operator== or !=");
}
}else{
it_errln("*** FT set- or getDouble");
}
-
+
+ fta.getDate(status = U_ZERO_ERROR);
+ if (status != U_INVALID_FORMAT_ERROR){
+ it_errln("*** FT getDate with status should fail on non-Date");
+ }
fta.setDate( 4.0 );
if ((fta.getType() == Formattable::kDate) && (fta.getDate() == 4.0)) {
- it_logln("FT set- and getDate tested.");
+ it_logln("FT set- and getDate tested.");
+ status = U_ZERO_ERROR;
+ fta.getDate(status);
+ if ( status == U_INVALID_FORMAT_ERROR){
+ it_errln("*** FT getDate with status failed on real Date");
+ } else {
+ it_logln("FT getDate with status tested.");
+ }
}else{
it_errln("*** FT set- or getDate");
}
+ status = U_ZERO_ERROR;
+ fta.getLong(&status);
+ if (status != U_INVALID_FORMAT_ERROR){
+ it_errln("*** FT getLong(UErrorCode* status) should fail on non-Long");
+ }
+
fta.setString("abc");
+ const Formattable ftc(fta);
UnicodeString res;
- if ((fta.getType() == Formattable::kString) && (fta.getString(res) == "abc")) {
- it_logln("FT set- and getString tested.");
- }else{
- it_errln("*** FT set- or getString");
- }
+ {
+ UBool t;
+ t = (fta.getType() == Formattable::kString)
+ && (fta.getString(res) == "abc")
+ && (fta.getString() == "abc");
+ res = fta.getString(status = U_ZERO_ERROR);
+ t = t && (status != U_INVALID_FORMAT_ERROR && res == "abc");
+ res = ftc.getString(status = U_ZERO_ERROR);
+ t = t && (status != U_INVALID_FORMAT_ERROR && res == "abc");
+ ftc.getString(res,status = U_ZERO_ERROR);
+ t = t && (status != U_INVALID_FORMAT_ERROR && res == "abc");
+ if (t) {
+ it_logln("FT set- and getString tested.");
+ }else{
+ it_errln("*** FT set- or getString");
+ }
+ }
UnicodeString ucs = "unicode-string";
UnicodeString* ucs_ptr = new UnicodeString("pointed-to-unicode-string");
ucs,
ucs_ptr
};
- const int32_t ft_cnt = LENGTHOF(ftarray);
+ const int32_t ft_cnt = UPRV_LENGTHOF(ftarray);
Formattable ft_arr( ftarray, ft_cnt );
UnicodeString temp;
if ((ft_arr[0].getType() == Formattable::kDate) && (ft_arr[0].getDate() == 1.0)
}
if (same) {
it_logln("FT getArray tested");
+ res_array = ft_arr.getArray( res_cnt, status = U_ZERO_ERROR);
+ if (status == U_INVALID_FORMAT_ERROR){
+ it_errln("*** FT getArray with status failed on real array");
+ } else {
+ it_logln("FT getArray with status tested on real array");
+ }
}else{
it_errln("*** FT getArray comparison");
}
}else{
it_errln(UnicodeString("*** FT getArray count res_cnt=") + res_cnt + UnicodeString("ft_cnt=") + ft_cnt);
}
+
+ res_array = fta.getArray(res_cnt, status = U_ZERO_ERROR);
+ if (status == U_INVALID_FORMAT_ERROR){
+ if (res_cnt == 0 && res_array == NULL){
+ it_logln("FT getArray with status tested on non array");
+ } else {
+ it_errln("*** FT getArray with status return values are not consistent");
+ }
+ } else {
+ it_errln("*** FT getArray with status should fail on non-array");
+ }
Formattable *pf;
for(i = 0; i < ft_cnt; ++i) {
pf = ftarray[i].clone();
if(pf == (ftarray + i) || *pf != ftarray[i]) {
- it_errln("Formattable.clone() failed for item %d" + i);
+ it_errln(UnicodeString("Formattable.clone() failed for item ") + i);
}
delete pf;
}
const Formattable ftarr1[] = { Formattable( (int32_t)1 ), Formattable( (int32_t)2 ) };
const Formattable ftarr2[] = { Formattable( (int32_t)3 ), Formattable( (int32_t)4 ) };
- const int32_t ftarr1_cnt = (int32_t)(sizeof(ftarr1) / sizeof(Formattable));
- const int32_t ftarr2_cnt = (int32_t)(sizeof(ftarr2) / sizeof(Formattable));
+ const int32_t ftarr1_cnt = UPRV_LENGTHOF(ftarr1);
+ const int32_t ftarr2_cnt = UPRV_LENGTHOF(ftarr2);
ft_arr.setArray( ftarr1, ftarr1_cnt );
if ((ft_arr[0].getType() == Formattable::kLong) && (ft_arr[0].getLong() == (int32_t)1)) {