X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/374ca955a76ecab1204ca8bfa63ff9238d998416..729e4ab9bc6618bc3d8a898e575df7f4019e29ca:/icuSources/test/cintltst/cctest.c?ds=sidebyside diff --git a/icuSources/test/cintltst/cctest.c b/icuSources/test/cintltst/cctest.c index c7085a12..4f4db0e6 100644 --- a/icuSources/test/cintltst/cctest.c +++ b/icuSources/test/cintltst/cctest.c @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 1997-2004, International Business Machines Corporation and + * Copyright (c) 1997-2010, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ @@ -9,7 +9,9 @@ #include "cintltst.h" #include "ustr_cnv.h" +#include void TestDefaultConverterError(void); /* keep gcc happy */ +void TestDefaultConverterSet(void); /* keep gcc happy */ /* This makes sure that a converter isn't leaked when an error is passed to @@ -32,5 +34,64 @@ void TestDefaultConverterError(void) { } } +/* Get the default converter. Copy its name. Put it back. */ +static void copyDefaultConverterName(char *out, UErrorCode *status) { + UConverter *defConv; + const char *itsName; + out[0]=0; + if(U_FAILURE(*status)) return; + defConv = u_getDefaultConverter(status); + /* get its name */ + itsName = ucnv_getName(defConv, status); + if(U_FAILURE(*status)) return; + strcpy(out, itsName); + /* put it back. */ + u_releaseDefaultConverter(defConv); +} + +/* + Changing the default name may not affect the actual name from u_getDefaultConverter + ( for example, if UTF-8 is the fixed converter ). + But, if it does cause a change, that change should be reflected when the converter is + set back. +*/ +void TestDefaultConverterSet(void) { + UErrorCode status = U_ZERO_ERROR; + static char defaultName[UCNV_MAX_CONVERTER_NAME_LENGTH + 1]; + static char nameBeforeSet[UCNV_MAX_CONVERTER_NAME_LENGTH + 1]; + static char nameAfterSet[UCNV_MAX_CONVERTER_NAME_LENGTH + 1]; + static char nameAfterRestore[UCNV_MAX_CONVERTER_NAME_LENGTH + 1]; + static const char SET_TO[]="iso-8859-3"; + strcpy(defaultName, ucnv_getDefaultName()); + + log_verbose("getDefaultName returned %s\n", defaultName); + + /* first, flush any extant converter */ + u_flushDefaultConverter(); + copyDefaultConverterName(nameBeforeSet, &status); + log_verbose("name from u_getDefaultConverter() = %s\n", nameBeforeSet); + u_flushDefaultConverter(); + ucnv_setDefaultName(SET_TO); + copyDefaultConverterName(nameAfterSet, &status); + log_verbose("name from u_getDefaultConverter() after set to %s (%s) = %s\n", SET_TO, ucnv_getDefaultName(), nameAfterSet); + ucnv_setDefaultName(defaultName); + copyDefaultConverterName(nameAfterRestore, &status); + log_verbose("name from u_getDefaultConverter() after restore = %s\n", nameAfterRestore); + u_flushDefaultConverter(); + + if(U_FAILURE(status)) { + log_err("Error in test: %s\n", u_errorName(status)); + } else { + if(!strcmp(nameBeforeSet, nameAfterSet)) { /* changing the default didn't affect. */ + log_info("Skipping test: ucnv_setDefaultName() did not affect actual name of %s\n", nameBeforeSet); + } else { + if(strcmp(nameBeforeSet, nameAfterRestore)) { + log_err("Error: u_getDefaultConverter() is still returning %s (expected %s) even though default converter was set back to %s (was %s)\n", nameAfterRestore, nameBeforeSet, defaultName , SET_TO); + } else { + log_verbose("Test passed. \n"); + } + } + } +}