/******************************************************************** * COPYRIGHT: * Copyright (c) 2002-2003, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ #include "uobjtest.h" #include "cmemory.h" // UAlignedMemory #include #include /** * * Test for UObject, currently only the classID. * * Usage * TESTCLASSID_ABSTRACT(Bar) * -- Bar is expected to be abstract. Only the static ID will be tested. * * TESTCLASSID_DEFAULT(Foo) * -- Foo will be default-constructed. * * TESTCLASSID_CTOR(Foo, (1, 2, 3, status)) * -- Second argument is (parenthesized) constructor argument. * Will be called as: new Foo ( 1, 2, 3, status) [status is tested] * * TESTCLASSID_FACTORY(Foo, fooCreateFunction(status) ) * -- call fooCreateFunction. 'status' will be tested & reset */ #define TESTCLASSID_FACTORY(c, f) { delete testClass(f, #c, #f, c ::getStaticClassID()); if(U_FAILURE(status)) { errln(UnicodeString(#c " - " #f " - got err status ") + UnicodeString(u_errorName(status))); status = U_ZERO_ERROR; } } #define TESTCLASSID_TRANSLIT(c, t) { delete testClass(Transliterator::createInstance(UnicodeString(t), UTRANS_FORWARD,parseError,status), #c, "Transliterator: " #t, c ::getStaticClassID()); if(U_FAILURE(status)) { errln(UnicodeString(#c " - Transliterator: " #t " - got err status ") + UnicodeString(u_errorName(status))); status = U_ZERO_ERROR; } } #define TESTCLASSID_CTOR(c, x) { delete testClass(new c x, #c, "new " #c #x, c ::getStaticClassID()); if(U_FAILURE(status)) { errln(UnicodeString(#c " - new " #x " - got err status ") + UnicodeString(u_errorName(status))); status = U_ZERO_ERROR; } } #define TESTCLASSID_DEFAULT(c) delete testClass(new c, #c, "new " #c , c::getStaticClassID()) //#define TESTCLASSID_ABSTRACT(c) testClass(NULL, #c, NULL, c::getStaticClassID()) #define MAX_CLASS_ID 200 UClassID ids[MAX_CLASS_ID]; const char *ids_factory[MAX_CLASS_ID]; const char *ids_class[MAX_CLASS_ID]; uint32_t ids_count = 0; UObject *UObjectTest::testClass(UObject *obj, const char *className, const char *factory, UClassID staticID) { uint32_t i; UnicodeString what = UnicodeString(className) + " * x= " + UnicodeString(factory?factory:" ABSTRACT ") + "; "; UClassID dynamicID = NULL; if(ids_count >= MAX_CLASS_ID) { char count[100]; sprintf(count, " (currently %d) ", MAX_CLASS_ID); errln("FAIL: Fatal: Ran out of IDs! Increase MAX_CLASS_ID." + UnicodeString(count) + what); return obj; } if(obj) { dynamicID = obj->getDynamicClassID(); } { char tmp[500]; sprintf(tmp, " [static=%p, dynamic=%p] ", staticID, dynamicID); logln(what + tmp); } if(staticID == NULL) { errln( "FAIL: staticID == NULL!" + what); } if(factory != NULL) { /* NULL factory means: abstract */ if(!obj) { errln( "FAIL: ==NULL!" + what); return obj; } if(dynamicID == NULL) { errln("FAIL: dynamicID == NULL!" + what); } if(dynamicID != staticID) { errln("FAIL: dynamicID != staticID!" + what ); } } // Bail out if static ID is null if(staticID == NULL) { return obj; } for(i=0;ib;"), status)); TESTCLASSID_TRANSLIT(TitlecaseTransliterator, "Title"); TESTCLASSID_TRANSLIT(UnescapeTransliterator, "Hex-Any"); TESTCLASSID_TRANSLIT(UnicodeNameTransliterator, "Any-Name"); TESTCLASSID_TRANSLIT(UppercaseTransliterator, "Upper"); #endif TESTCLASSID_FACTORY(Locale, new Locale("123")); //TESTCLASSID_DEFAULT(Normalizer); //TESTCLASSID_DEFAULT(NumeratorSubstitution); #if !UCONFIG_NO_TRANSLITERATION TESTCLASSID_DEFAULT(ParsePosition); //TESTCLASSID_DEFAULT(Quantifier); #endif // NO_REG_EX //TESTCLASSID_DEFAULT(RegexCompile); //TESTCLASSID_DEFAULT(RegexMatcher); //TESTCLASSID_DEFAULT(RegexPattern); //TESTCLASSID_DEFAULT(ReplaceableGlue); TESTCLASSID_FACTORY(ResourceBundle, new ResourceBundle(UnicodeString(), status) ); //TESTCLASSID_DEFAULT(RuleBasedTransliterator); //TESTCLASSID_DEFAULT(SimpleFwdCharIterator); //TESTCLASSID_DEFAULT(StringReplacer); //TESTCLASSID_DEFAULT(StringSearch); //TESTCLASSID_DEFAULT(TempSearch); //TESTCLASSID_DEFAULT(TestMultipleKeyStringFactory); //TESTCLASSID_DEFAULT(TestReplaceable); //#if !UCONFIG_NO_FORMATTING //TESTCLASSID_ABSTRACT(TimeZone); //#endif #if !UCONFIG_NO_TRANSLITERATION TESTCLASSID_FACTORY(TitlecaseTransliterator, Transliterator::createInstance(UnicodeString("Any-Title"), UTRANS_FORWARD, parseError, status)); //TESTCLASSID_ABSTRACT(Transliterator); #if UOBJTEST_TEST_INTERNALS TESTCLASSID_CTOR(StringMatcher, (UnicodeString("x"), 0,0,0,TransliterationRuleData(status))); TESTCLASSID_CTOR(StringReplacer,(UnicodeString(),new TransliterationRuleData(status))); #endif #endif TESTCLASSID_DEFAULT(UnicodeString); TESTCLASSID_CTOR(UnicodeSet, (0, 1)); //TESTCLASSID_ABSTRACT(UnicodeFilter); //TESTCLASSID_ABSTRACT(UnicodeFunctor); TESTCLASSID_CTOR(UnicodeSetIterator,(UnicodeSet(0,1))); TESTCLASSID_CTOR(UStack, (status)); TESTCLASSID_CTOR(UVector, (status)); #if !UCONFIG_NO_SERVICE TESTCLASSID_CTOR(SimpleFactory, (NULL, UnicodeString("foo"))); TESTCLASSID_DEFAULT(EventListener); #if UOBJTEST_TEST_INTERNALS TESTCLASSID_DEFAULT(ICUResourceBundleFactory); //TESTCLASSID_DEFAULT(Key); // does ont exist? TESTCLASSID_CTOR(LocaleKey, (UnicodeString("baz"), UnicodeString("bat"), NULL, 92)); TESTCLASSID_CTOR(LocaleKeyFactory, (42)); TESTCLASSID_CTOR(SimpleLocaleKeyFactory, (NULL, UnicodeString("bar"), 8, 12) ); #endif #endif #if UOBJTEST_DUMP_IDS int i; for(i=0;ilength()!=len || p->charAt(0)!=0x20ac || p->charAt(len-1)!=0x20ac) { errln("constructor used with placement new did not work right"); } /* * It is not possible to simply say * delete(p, stackMemory); * which results in a call to the normal, non-placement delete operator. * * Via a search on google.com for "c++ placement delete" I found * http://cpptips.hyperformix.com/cpptips/placement_del3 * which says: * * TITLE: using placement delete * * (Newsgroups: comp.std.c++, 27 Aug 97) * * ISJ: isj@image.dk * * > I do not completely understand how placement works on operator delete. * > ... * There is no delete-expression which will invoke a placement * form of operator delete. You can still call the function * explicitly. Example: * ... * // destroy object and delete space manually * p->~T(); * operator delete(p, 12); * * ... so that's what I am doing here. * markus 20031216 */ // destroy object and delete space manually p->~UnicodeString(); UnicodeString::operator delete(p, stackMemory); #endif // try to call the compiler-generated UMemory::operator=(class UMemory const &) UMemory m, n; m=n; } /* --------------- */ #define CASE(id,test) case id: name = #test; if (exec) { logln(#test "---"); logln((UnicodeString)""); test(); } break; void UObjectTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /* par */ ) { switch (index) { CASE(0, testIDs); CASE(1, testUMemory); default: name = ""; break; //needed to end loop } }