diff --git a/icu4c/source/common/cmemory.c b/icu4c/source/common/cmemory.c index c6d9125d002..45902dc9557 100644 --- a/icu4c/source/common/cmemory.c +++ b/icu4c/source/common/cmemory.c @@ -121,6 +121,3 @@ U_CFUNC UBool cmemory_inUse() { return gHeapInUse; } -U_CFUNC void cmemory_clearInUse() { - gHeapInUse = FALSE; -} diff --git a/icu4c/source/common/cmemory.h b/icu4c/source/common/cmemory.h index 0f4224feb0b..0c1a639ac35 100644 --- a/icu4c/source/common/cmemory.h +++ b/icu4c/source/common/cmemory.h @@ -72,15 +72,6 @@ typedef union { U_CFUNC UBool cmemory_inUse(void); -/** - * Mark the ICU heap as not being in use, even if it is. - * Needed so that we can ignore any allocations triggered by ICU - * static initialization, and still pretend that we are in a pristine state. - * TODO: this is awkward. Think about something cleaner. - */ -U_CFUNC void -cmemory_clearInUse(void); - /** * Heap clean up function, called from u_cleanup() * Clears any user heap functions from u_setMemoryFunctions() diff --git a/icu4c/source/common/ucln_cmn.c b/icu4c/source/common/ucln_cmn.c index 9fd286c1329..94865a4fa03 100644 --- a/icu4c/source/common/ucln_cmn.c +++ b/icu4c/source/common/ucln_cmn.c @@ -137,7 +137,3 @@ u_init(UErrorCode *status) { UTRACE_EXIT_STATUS(*status); } - -U_CFUNC UBool u_isUInit() { - return gICUInitialized; -} diff --git a/icu4c/source/common/ucln_cmn.h b/icu4c/source/common/ucln_cmn.h index aa38c2175c6..22e20e6e26e 100644 --- a/icu4c/source/common/ucln_cmn.h +++ b/icu4c/source/common/ucln_cmn.h @@ -64,10 +64,4 @@ U_CFUNC void ucnv_init(UErrorCode *status); U_CFUNC void ures_init(UErrorCode *status); -/** - * Test whether ICU has been initialized. - * @internal - */ -U_CFUNC UBool u_isUInit(void); - #endif diff --git a/icu4c/source/common/uvectr32.h b/icu4c/source/common/uvectr32.h index 47dbc2d6ac3..643a9a05d82 100644 --- a/icu4c/source/common/uvectr32.h +++ b/icu4c/source/common/uvectr32.h @@ -105,9 +105,9 @@ public: int32_t lastElementi(void) const; - int32_t indexOf(int32_t obj, int32_t startIndex = 0) const; + int32_t indexOf(int32_t elem, int32_t startIndex = 0) const; - UBool contains(int32_t obj) const; + UBool contains(int32_t elem) const; UBool containsAll(const UVector32& other) const; @@ -154,7 +154,7 @@ public: * Insert the given integer into this vector at its sorted position. * The current elements are assumed to be sorted already. */ - void sortedInsert(int32_t obj, UErrorCode& ec); + void sortedInsert(int32_t elem, UErrorCode& ec); /** * Returns a pointer to the internal array holding the vector. @@ -189,7 +189,7 @@ private: // In the original UVector, these were in a separate derived class, UStack. // Here in UVector32, they are all together. public: - UBool empty(void) const; + UBool empty(void) const; // TODO: redundant, same as empty(). Remove it? int32_t peeki(void) const; diff --git a/icu4c/source/test/cintltst/tracetst.c b/icu4c/source/test/cintltst/tracetst.c index 40bdd434802..58ebc11c8d4 100644 --- a/icu4c/source/test/cintltst/tracetst.c +++ b/icu4c/source/test/cintltst/tracetst.c @@ -15,6 +15,7 @@ #include "unicode/uclean.h" #include "unicode/uchar.h" #include "unicode/ures.h" +#include "unicode/ucnv.h" #include "cintltst.h" #include #include @@ -94,15 +95,22 @@ static void test_format(const char *format, int32_t bufCap, int32_t indent, /* * define trace functions for use in this test. */ +static int gTraceEntryCount; +static int gTraceExitCount; +static int gTraceDataCount; + static void testTraceEntry(const void *context, int32_t fnNumber) { + gTraceEntryCount++; } static void testTraceExit(const void *context, int32_t fnNumber, const char *fmt, va_list args) { + gTraceExitCount++; } static void testTraceData(const void *context, int32_t fnNumber, int32_t level, const char *fmt, va_list args) { + gTraceDataCount++; } @@ -165,6 +173,27 @@ static void TestTraceAPI() { utrace_setLevel(UTRACE_INFO); } + /* + * Open and close a converter with tracing enabled. + * Verify that our tracing callback functions get called. + */ + { + UErrorCode status = U_ZERO_ERROR; + UConverter *cnv; + + gTraceEntryCount = 0; + gTraceExitCount = 0; + gTraceDataCount = 0; + utrace_setLevel(UTRACE_OPEN_CLOSE); + cnv = ucnv_open(NULL, &status); + TEST_ASSERT(U_SUCCESS(status)); + ucnv_close(cnv); + TEST_ASSERT(gTraceEntryCount > 0); + TEST_ASSERT(gTraceExitCount > 0); + TEST_ASSERT(gTraceDataCount > 0); + } + + /* * trace data formatter operation. @@ -220,6 +249,32 @@ static void TestTraceAPI() { } + /* + * utrace_format. Only need a minimal test to see that the function works at all. + * Full functionality is tested via utrace_vformat. + */ + { + char buf[100]; + int32_t x; + x = utrace_format(buf, 100, 0, "%s", "Hello, World."); + TEST_ASSERT(strcmp(buf, "Hello, World.") == 0); + TEST_ASSERT(x == 14); + } + + /* + * utrace_functionName. Just spot-check a couple of them. + */ + { + const char *name; + name = utrace_functionName(UTRACE_U_INIT); + TEST_ASSERT(strcmp(name, "u_init") == 0); + name = utrace_functionName(UTRACE_UCNV_OPEN); + TEST_ASSERT(strcmp(name, "ucnv_open") == 0); + name = utrace_functionName(UTRACE_UCOL_GET_SORTKEY); + TEST_ASSERT(strcmp(name, "ucol_getSortKey") == 0); + } + + /* Restore the trace function settings to their original values. */ utrace_setFunctions(originalTContext, originalTEntryFunc, originalTExitFunc, originalTDataFunc); diff --git a/icu4c/source/test/intltest/Makefile.in b/icu4c/source/test/intltest/Makefile.in index 6a7eb8f6c35..981901c81da 100644 --- a/icu4c/source/test/intltest/Makefile.in +++ b/icu4c/source/test/intltest/Makefile.in @@ -41,7 +41,7 @@ ufltlgts.o testutil.o transrt.o trnserr.o normconf.o sfwdchit.o \ jamotest.o srchtest.o reptest.o regextst.o \ itrbnf.o itrbnfrt.o tstdtmod.o testdata.o datamap.o ucaconf.o icusvtst.o \ uobjtest.o idnaref.o nptrans.o punyref.o testidn.o testidna.o incaltst.o \ -calcasts.o +calcasts.o v32test.o DEPS = $(OBJECTS:.o=.d) diff --git a/icu4c/source/test/intltest/intltest.dsp b/icu4c/source/test/intltest/intltest.dsp index 8ec43b34546..8f7b26d89e1 100644 --- a/icu4c/source/test/intltest/intltest.dsp +++ b/icu4c/source/test/intltest/intltest.dsp @@ -432,6 +432,14 @@ SOURCE=.\uobjtest.h # PROP Default_Filter "" # Begin Source File +SOURCE=.\astrotst.cpp +# End Source File +# Begin Source File + +SOURCE=.\astrotst.h +# End Source File +# Begin Source File + SOURCE=.\calcasts.cpp # End Source File # Begin Source File @@ -520,14 +528,6 @@ SOURCE=.\incaltst.h # End Source File # Begin Source File -SOURCE=.\astrotst.cpp -# End Source File -# Begin Source File - -SOURCE=.\astrotst.h -# End Source File -# Begin Source File - SOURCE=.\itformat.cpp # End Source File # Begin Source File @@ -762,6 +762,10 @@ SOURCE=.\testidna.cpp SOURCE=.\testidna.h # End Source File +# Begin Source File + +SOURCE=.\v32test.h +# End Source File # End Group # Begin Group "misc" @@ -1023,5 +1027,9 @@ SOURCE=.\unhxtrts.cpp SOURCE=.\unhxtrts.h # End Source File # End Group +# Begin Source File + +SOURCE=.\v32test.cpp +# End Source File # End Target # End Project diff --git a/icu4c/source/test/intltest/itutil.cpp b/icu4c/source/test/intltest/itutil.cpp index 6980a65c357..2a5d6bd8df6 100644 --- a/icu4c/source/test/intltest/itutil.cpp +++ b/icu4c/source/test/intltest/itutil.cpp @@ -21,6 +21,7 @@ #include "tsmthred.h" #include "tsputil.h" #include "uobjtest.h" +#include "v32test.h" //#include "custrtest.h" //#include "ccitrtst.h" //#include "cloctest.h" @@ -120,6 +121,15 @@ void IntlTestUtilities::runIndexedTest( int32_t index, UBool exec, const char* & } break;; + case 10: + name = "UVector32Test"; + if(exec) { + logln ("UVector32Test---"); logln(""); + UVector32Test test; + callTest( test, par ); + } + break;; + /* case 8: name = "LocaleTest"; diff --git a/icu4c/source/test/intltest/v32test.cpp b/icu4c/source/test/intltest/v32test.cpp new file mode 100644 index 00000000000..9714f2a45e5 --- /dev/null +++ b/icu4c/source/test/intltest/v32test.cpp @@ -0,0 +1,506 @@ +/******************************************************************** + * COPYRIGHT: + * Copyright (c) 2002-2003, International Business Machines Corporation and + * others. All Rights Reserved. + ********************************************************************/ + +// +// regextst.cpp +// +// ICU Regular Expressions test, part of intltest. +// + +#include "intltest.h" + +#include "v32test.h" +#include "uvectr32.h" +#include "uvector.h" +#include "util.h" +#include +#include + + +//--------------------------------------------------------------------------- +// +// Test class boilerplate +// +//--------------------------------------------------------------------------- +UVector32Test::UVector32Test() +{ +}; + + +UVector32Test::~UVector32Test() +{ +}; + + + +void UVector32Test::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ ) +{ + if (exec) logln("TestSuite UVector32Test: "); + switch (index) { + + case 0: name = "UVector32_API"; + if (exec) UVector32_API(); + break; + default: name = ""; + break; //needed to end loop + } +} + + +//--------------------------------------------------------------------------- +// +// Error Checking / Reporting macros used in all of the tests. +// +//--------------------------------------------------------------------------- +#define TEST_CHECK_STATUS {if (U_FAILURE(status)) {errln("UVector32Test failure at line %d. status=%s\n", \ +__LINE__, u_errorName(status)); return;}} + +#define TEST_ASSERT(expr) {if ((expr)==FALSE) {errln("RegexTest failure at line %d.\n", __LINE__);};} + + + + + + + + +//--------------------------------------------------------------------------- +// +// UVector32_API Check for basic functionality of UVector32. +// +//--------------------------------------------------------------------------- +void UVector32Test::UVector32_API() { + + UErrorCode status = U_ZERO_ERROR; + UVector32 *a; + UVector32 *b; + + a = new UVector32(status); + TEST_CHECK_STATUS(status); + delete a; + + status = U_ZERO_ERROR; + a = new UVector32(2000, status); + TEST_CHECK_STATUS(status); + delete a; + + // + // assign() + // + status = U_ZERO_ERROR; + a = new UVector32(status); + a->addElement(10, status); + a->addElement(20, status); + a->addElement(30, status); + b = new UVector32(status); + b->assign(*a, status); + TEST_ASSERT(b->size() == 3); + TEST_ASSERT(b->elementAti(1) == 20); + TEST_CHECK_STATUS(status); + delete a; + delete b; + + // + // operator == and != and equals() + // + status = U_ZERO_ERROR; + a = new UVector32(status); + a->addElement(10, status); + a->addElement(20, status); + a->addElement(30, status); + b = new UVector32(status); + TEST_ASSERT(*b != *a); + TEST_ASSERT(!(*b == *a)); + TEST_ASSERT(!b->equals(*a)); + b->assign(*a, status); + TEST_ASSERT(*b == *a); + TEST_ASSERT(!(*b != *a)); + TEST_ASSERT(b->equals(*a)); + b->addElement(666, status); + TEST_ASSERT(*b != *a); + TEST_ASSERT(!(*b == *a)); + TEST_ASSERT(!b->equals(*a)); + TEST_CHECK_STATUS(status); + delete b; + delete a; + + // + // addElement(). Covered by above tests. + // + + // + // setElementAt() + // + status = U_ZERO_ERROR; + a = new UVector32(status); + a->addElement(10, status); + a->addElement(20, status); + a->addElement(30, status); + a->setElementAt(666, 1); + TEST_ASSERT(a->elementAti(0) == 10); + TEST_ASSERT(a->elementAti(1) == 666); + TEST_ASSERT(a->size() == 3); + TEST_CHECK_STATUS(status); + delete a; + + // + // insertElementAt() + // + status = U_ZERO_ERROR; + a = new UVector32(status); + a->addElement(10, status); + a->addElement(20, status); + a->addElement(30, status); + a->insertElementAt(666, 1, status); + TEST_ASSERT(a->elementAti(0) == 10); + TEST_ASSERT(a->elementAti(1) == 666); + TEST_ASSERT(a->elementAti(2) == 20); + TEST_ASSERT(a->elementAti(3) == 30); + TEST_ASSERT(a->size() == 4); + TEST_CHECK_STATUS(status); + delete a; + + // + // elementAti() covered by above tests + // + + // + // lastElementi + // + status = U_ZERO_ERROR; + a = new UVector32(status); + a->addElement(10, status); + a->addElement(20, status); + a->addElement(30, status); + TEST_ASSERT(a->lastElementi() == 30); + TEST_CHECK_STATUS(status); + delete a; + + + // + // indexOf + // + status = U_ZERO_ERROR; + a = new UVector32(status); + a->addElement(10, status); + a->addElement(20, status); + a->addElement(30, status); + TEST_ASSERT(a->indexOf(30, 0) == 2); + TEST_ASSERT(a->indexOf(40, 0) == -1); + TEST_ASSERT(a->indexOf(10, 0) == 0); + TEST_ASSERT(a->indexOf(10, 1) == -1); + TEST_CHECK_STATUS(status); + delete a; + + + // + // contains + // + status = U_ZERO_ERROR; + a = new UVector32(status); + a->addElement(10, status); + a->addElement(20, status); + a->addElement(30, status); + TEST_ASSERT(a->contains(10) == TRUE); + TEST_ASSERT(a->contains(11) == FALSE); + TEST_ASSERT(a->contains(20) == TRUE); + TEST_ASSERT(a->contains(-10) == FALSE); + TEST_CHECK_STATUS(status); + delete a; + + + // + // containsAll + // + status = U_ZERO_ERROR; + a = new UVector32(status); + a->addElement(10, status); + a->addElement(20, status); + a->addElement(30, status); + b = new UVector32(status); + TEST_ASSERT(a->containsAll(*b) == TRUE); + b->addElement(2, status); + TEST_ASSERT(a->containsAll(*b) == FALSE); + b->setElementAt(10, 0); + TEST_ASSERT(a->containsAll(*b) == TRUE); + TEST_ASSERT(b->containsAll(*a) == FALSE); + b->addElement(30, status); + b->addElement(20, status); + TEST_ASSERT(a->containsAll(*b) == TRUE); + TEST_ASSERT(b->containsAll(*a) == TRUE); + b->addElement(2, status); + TEST_ASSERT(a->containsAll(*b) == FALSE); + TEST_ASSERT(b->containsAll(*a) == TRUE); + TEST_CHECK_STATUS(status); + delete a; + delete b; + + // + // removeAll + // + status = U_ZERO_ERROR; + a = new UVector32(status); + a->addElement(10, status); + a->addElement(20, status); + a->addElement(30, status); + b = new UVector32(status); + a->removeAll(*b); + TEST_ASSERT(a->size() == 3); + b->addElement(20, status); + a->removeAll(*b); + TEST_ASSERT(a->size() == 2); + TEST_ASSERT(a->contains(10)==TRUE); + TEST_ASSERT(a->contains(30)==TRUE); + b->addElement(10, status); + a->removeAll(*b); + TEST_ASSERT(a->size() == 1); + TEST_ASSERT(a->contains(30) == TRUE); + TEST_CHECK_STATUS(status); + delete a; + delete b; + + // + // retainAll + // + status = U_ZERO_ERROR; + a = new UVector32(status); + a->addElement(10, status); + a->addElement(20, status); + a->addElement(30, status); + b = new UVector32(status); + b->addElement(10, status); + b->addElement(20, status); + b->addElement(30, status); + b->addElement(15, status); + a->retainAll(*b); + TEST_ASSERT(a->size() == 3); + b->removeElementAt(1); + a->retainAll(*b); + TEST_ASSERT(a->contains(20) == FALSE); + TEST_ASSERT(a->size() == 2); + b->removeAllElements(); + TEST_ASSERT(b->size() == 0); + a->retainAll(*b); + TEST_ASSERT(a->size() == 0); + TEST_CHECK_STATUS(status); + delete a; + delete b; + + // + // removeElementAt Tested above. + // + + // + // removeAllElments Tested above + // + + // + // size() tested above + // + + // + // isEmpty + // + status = U_ZERO_ERROR; + a = new UVector32(status); + TEST_ASSERT(a->isEmpty() == TRUE); + a->addElement(10, status); + TEST_ASSERT(a->isEmpty() == FALSE); + a->addElement(20, status); + a->removeElementAt(0); + TEST_ASSERT(a->isEmpty() == FALSE); + a->removeElementAt(0); + TEST_ASSERT(a->isEmpty() == TRUE); + TEST_CHECK_STATUS(status); + delete a; + + + // + // ensureCapacity, expandCapacity + // + status = U_ZERO_ERROR; + a = new UVector32(status); + TEST_ASSERT(a->isEmpty() == TRUE); + a->addElement(10, status); + TEST_ASSERT(a->ensureCapacity(5000, status)== TRUE); + TEST_ASSERT(a->expandCapacity(20000, status) == TRUE); + TEST_CHECK_STATUS(status); + delete a; + + // + // setSize + // + status = U_ZERO_ERROR; + a = new UVector32(status); + a->addElement(10, status); + a->addElement(20, status); + a->addElement(30, status); + a->setSize(100); + TEST_ASSERT(a->size() == 100); + TEST_ASSERT(a->elementAti(0) == 10); + TEST_ASSERT(a->elementAti(1) == 20); + TEST_ASSERT(a->elementAti(2) == 30); + TEST_ASSERT(a->elementAti(3) == 0); + a->setElementAt(666, 99); + a->setElementAt(777, 100); + TEST_ASSERT(a->elementAti(99) == 666); + TEST_ASSERT(a->elementAti(100) == 0); + a->setSize(2); + TEST_ASSERT(a->elementAti(1) == 20); + TEST_ASSERT(a->elementAti(2) == 0); + TEST_ASSERT(a->size() == 2); + a->setSize(0); + TEST_ASSERT(a->empty() == TRUE); + TEST_ASSERT(a->size() == 0); + + TEST_CHECK_STATUS(status); + delete a; + + // + // containsNone + // + status = U_ZERO_ERROR; + a = new UVector32(status); + a->addElement(10, status); + a->addElement(20, status); + a->addElement(30, status); + b = new UVector32(status); + TEST_ASSERT(a->containsNone(*b) == TRUE); + b->addElement(5, status); + TEST_ASSERT(a->containsNone(*b) == TRUE); + b->addElement(30, status); + TEST_ASSERT(a->containsNone(*b) == FALSE); + + TEST_CHECK_STATUS(status); + delete a; + delete b; + + // + // sortedInsert + // + status = U_ZERO_ERROR; + a = new UVector32(status); + a->sortedInsert(30, status); + a->sortedInsert(20, status); + a->sortedInsert(10, status); + TEST_ASSERT(a->elementAti(0) == 10); + TEST_ASSERT(a->elementAti(1) == 20); + TEST_ASSERT(a->elementAti(2) == 30); + + TEST_CHECK_STATUS(status); + delete a; + + // + // getBuffer + // + status = U_ZERO_ERROR; + a = new UVector32(status); + a->addElement(10, status); + a->addElement(20, status); + int32_t *buf = a->getBuffer(); + TEST_ASSERT(buf[0] == 10); + TEST_ASSERT(buf[1] == 20); + a->setSize(20000); + int32_t *resizedBuf; + resizedBuf = a->getBuffer(); + TEST_ASSERT(buf != resizedBuf); + TEST_ASSERT(resizedBuf[0] == 10); + TEST_ASSERT(resizedBuf[1] == 20); + + TEST_CHECK_STATUS(status); + delete a; + + + // + // RTTI + // + status = U_ZERO_ERROR; + a = new UVector32(status); + TEST_ASSERT(a->getDynamicClassID() == UVector32::getStaticClassID()); + TEST_ASSERT(a->getDynamicClassID() != UVector::getStaticClassID()); + TEST_CHECK_STATUS(status); + delete a; + + // + // empty + // + status = U_ZERO_ERROR; + a = new UVector32(status); + TEST_ASSERT(a->empty() == TRUE); + a->addElement(10, status); + TEST_ASSERT(a->empty() == FALSE); + a->addElement(20, status); + a->removeElementAt(0); + TEST_ASSERT(a->empty() == FALSE); + a->removeElementAt(0); + TEST_ASSERT(a->empty() == TRUE); + TEST_CHECK_STATUS(status); + delete a; + + + // + // peeki + // + status = U_ZERO_ERROR; + a = new UVector32(status); + a->addElement(10, status); + TEST_ASSERT(a->peeki() == 10); + a->addElement(20, status); + TEST_ASSERT(a->peeki() == 20); + a->addElement(30, status); + TEST_ASSERT(a->peeki() == 30); + TEST_CHECK_STATUS(status); + delete a; + + + // + // popi + // + status = U_ZERO_ERROR; + a = new UVector32(status); + a->addElement(10, status); + a->addElement(20, status); + a->addElement(30, status); + TEST_ASSERT(a->popi() == 30); + TEST_ASSERT(a->popi() == 20); + TEST_ASSERT(a->popi() == 10); + TEST_ASSERT(a->popi() == 0); + TEST_ASSERT(a->isEmpty()); + TEST_CHECK_STATUS(status); + delete a; + + // + // push + // + status = U_ZERO_ERROR; + a = new UVector32(status); + TEST_ASSERT(a->push(10, status) == 10); + TEST_ASSERT(a->push(20, status) == 20); + TEST_ASSERT(a->push(30, status) == 30); + TEST_ASSERT(a->size() == 3); + TEST_ASSERT(a->popi() == 30); + TEST_ASSERT(a->popi() == 20); + TEST_ASSERT(a->popi() == 10); + TEST_ASSERT(a->isEmpty()); + TEST_CHECK_STATUS(status); + delete a; + + + // + // reserveBlock + // + status = U_ZERO_ERROR; + a = new UVector32(status); + a->ensureCapacity(1000, status); + + // TODO: + + TEST_CHECK_STATUS(status); + delete a; + +}; + + diff --git a/icu4c/source/test/intltest/v32test.h b/icu4c/source/test/intltest/v32test.h new file mode 100644 index 00000000000..f364aeb1bcd --- /dev/null +++ b/icu4c/source/test/intltest/v32test.h @@ -0,0 +1,32 @@ +/* +****************************************************************************** +* Copyright (C) 2003, International Business Machines Corporation and * +* others. All Rights Reserved. * +****************************************************************************** +*/ + +// file: v32test.h + + +#ifndef V32TEST_H +#define V32TEST_H + +#include "unicode/utypes.h" + +#include "intltest.h" + + +class UVector32Test: public IntlTest { +public: + + UVector32Test(); + virtual ~UVector32Test(); + + virtual void runIndexedTest(int32_t index, UBool exec, const char* &name, char* par = NULL ); + + // The following are test functions that are visible from the intltest test framework. + virtual void UVector32_API(); + +}; + +#endif