void ResourceBundleTest::TestGetSize(void) { const struct { const char* key; int32_t size; } test[] = { { "zerotest", 1}, { "one", 1}, { "importtest", 1}, { "integerarray", 1}, { "emptyarray", 0}, { "emptytable", 0}, { "emptystring", 1}, /* empty string is still a string */ { "emptyint", 1}, { "emptybin", 1}, { "testinclude", 1}, { "collations", 1}, /* not 2 - there is hidden %%CollationBin */ }; UErrorCode status = U_ZERO_ERROR; const char* testdatapath = loadTestData(status); int32_t i = 0, j = 0; int32_t size = 0; if(U_FAILURE(status)) { dataerrln("Could not load testdata.dat %s\n", u_errorName(status)); return; } ResourceBundle rb(testdatapath, "testtypes", status); if(U_FAILURE(status)) { err("Could not testtypes resource bundle %s\n", u_errorName(status)); return; } for(i = 0; i < (int32_t)(sizeof(test)/sizeof(test[0])); i++) { ResourceBundle res = rb.get(test[i].key, status); if(U_FAILURE(status)) { err("Couldn't find the key %s. Error: %s\n", u_errorName(status)); return; } size = res.getSize(); if(size != test[i].size) { err("Expected size %i, got size %i for key %s\n", test[i].size, size, test[i].key); for(j = 0; j < size; j++) { ResourceBundle helper = res.get(j, status); err("%s\n", helper.getKey()); } } } }
void NewResourceBundleTest::TestIteration() { UErrorCode err = U_ZERO_ERROR; const char* testdatapath; const char* data[]={ "string_in_Root_te_te_IN", "1", "array_in_Root_te_te_IN", "5", "array_2d_in_Root_te_te_IN", "4", }; Locale *locale=new Locale("te_IN"); testdatapath=loadTestData(err); if(U_FAILURE(err)) { dataerrln("Could not load testdata.dat %s " + UnicodeString(u_errorName(err))); return; } ResourceBundle test1(testdatapath, *locale, err); if(U_FAILURE(err)){ errln("Construction failed"); } uint32_t i; int32_t count, row=0, col=0; char buf[5]; UnicodeString expected; UnicodeString element("TE_IN"); UnicodeString action; for(i=0; i<UPRV_LENGTHOF(data); i=i+2){ action = "te_IN"; action +=".get("; action += data[i]; action +=", err)"; err=U_ZERO_ERROR; ResourceBundle bundle = test1.get(data[i], err); if(!U_FAILURE(err)){ action = "te_IN"; action +=".getKey()"; CONFIRM_EQ((UnicodeString)bundle.getKey(), (UnicodeString)data[i]); count=0; row=0; while(bundle.hasNext()){ action = data[i]; action +=".getNextString(err)"; row=count; UnicodeString got=bundle.getNextString(err); if(U_SUCCESS(err)){ expected=element; if(bundle.getSize() > 1){ CONFIRM_EQ(bundle.getType(), URES_ARRAY); expected+=itoa(row, buf); ResourceBundle rowbundle=bundle.get(row, err); if(!U_FAILURE(err) && rowbundle.getSize()>1){ col=0; while(rowbundle.hasNext()){ expected=element; got=rowbundle.getNextString(err); if(!U_FAILURE(err)){ expected+=itoa(row, buf); expected+=itoa(col, buf); col++; CONFIRM_EQ(got, expected); } } CONFIRM_EQ(col, rowbundle.getSize()); } } else{ CONFIRM_EQ(bundle.getType(), (int32_t)URES_STRING); } } CONFIRM_EQ(got, expected); count++; } action = data[i]; action +=".getSize()"; CONFIRM_EQ(bundle.getSize(), count); CONFIRM_EQ(count, atoi(data[i+1])); //after reaching the end err=U_ZERO_ERROR; ResourceBundle errbundle=bundle.getNext(err); action = "After reaching the end of the Iterator:- "; action +=data[i]; action +=".getNext()"; CONFIRM_NE(err, (int32_t)U_ZERO_ERROR); CONFIRM_EQ(u_errorName(err), u_errorName(U_INDEX_OUTOFBOUNDS_ERROR)); //reset the iterator err = U_ZERO_ERROR; bundle.resetIterator(); /* The following code is causing a crash ****CRASH****** */ bundle.getNext(err); if(U_FAILURE(err)){ errln("ERROR: getNext() throw an error"); } } } delete locale; }