[sword-cvs] icu-sword/source/test/cintltst cucdapi.h,NONE,1.1 hpmufn.c,NONE,1.1 idnatest.c,NONE,1.1 nfsprep.c,NONE,1.1 nfsprep.h,NONE,1.1 sorttest.c,NONE,1.1 spreptst.c,NONE,1.1 sprpdata.c,NONE,1.1 tracetst.c,NONE,1.1 Makefile.in,1.4,1.5 bocu1tst.c,1.1,1.2 callcoll.c,1.4,1.5 callcoll.h,1.3,1.4 calltest.c,1.3,1.4 capitst.c,1.4,1.5 cbididat.c,1.3,1.4 cbiditst.c,1.4,1.5 ccaltst.c,1.3,1.4 ccapitst.c,1.4,1.5 cctest.c,1.1,1.2 cdantst.c,1.3,1.4 cdattst.c,1.3,1.4 cdtdptst.c,1.3,1.4 cdtrgtst.c,1.3,1.4 cintltst.c,1.4,1.5 cintltst.dsp,1.3,1.4 cintltst.h,1.3,1.4 cintltst.vcproj,1.1,1.2 citertst.c,1.4,1.5 citertst.h,1.3,1.4 cloctst.c,1.4,1.5 cloctst.h,1.3,1.4 cmsccoll.c,1.6,1.7 cmsgtst.c,1.3,1.4 cnmdptst.c,1.4,1.5 cnmdptst.h,1.3,1.4 cnumtst.c,1.4,1.5 cnumtst.h,1.3,1.4 crestst.c,1.4,1.5 crestst.h,1.3,1.4 creststn.c,1.4,1.5 cstrtest.c,1.3,1.4 cucdapi.c,1.1,1.2 cucdtst.c,1.5,1.6 custrtrn.c,1.4,1.5 cutiltst.c,1.3,1.4 encoll.c,1.3,1.4 nccbtst.c,1.4,1.5 ncnvfbts.c,1.3,1.4 ncnvtst.c,1.3,1.4 nucnvtst.c,1.4,1.5 stdnmtst.c,1.4,1.5 trietest.c,1.1,1.2 udatatst.c,1.5,1.6 usettest.c,1.1,1.2 usrchdat.c,1.3,1.4 utransts.c,1.4,1.5

sword@www.crosswire.org sword@www.crosswire.org
Tue, 6 Apr 2004 03:11:14 -0700


Update of /cvs/core/icu-sword/source/test/cintltst
In directory www:/tmp/cvs-serv8911/source/test/cintltst

Modified Files:
	Makefile.in bocu1tst.c callcoll.c callcoll.h calltest.c 
	capitst.c cbididat.c cbiditst.c ccaltst.c ccapitst.c cctest.c 
	cdantst.c cdattst.c cdtdptst.c cdtrgtst.c cintltst.c 
	cintltst.dsp cintltst.h cintltst.vcproj citertst.c citertst.h 
	cloctst.c cloctst.h cmsccoll.c cmsgtst.c cnmdptst.c cnmdptst.h 
	cnumtst.c cnumtst.h crestst.c crestst.h creststn.c cstrtest.c 
	cucdapi.c cucdtst.c custrtrn.c cutiltst.c encoll.c nccbtst.c 
	ncnvfbts.c ncnvtst.c nucnvtst.c stdnmtst.c trietest.c 
	udatatst.c usettest.c usrchdat.c utransts.c 
Added Files:
	cucdapi.h hpmufn.c idnatest.c nfsprep.c nfsprep.h sorttest.c 
	spreptst.c sprpdata.c tracetst.c 
Log Message:
ICU 2.8 sync

--- NEW FILE: cucdapi.h ---
/********************************************************************
 * COPYRIGHT:
 * Copyright (c) 2003-2003, International Business Machines Corporation and
 * others. All Rights Reserved.
 ********************************************************************/

void TestUScriptCodeAPI(void);



--- NEW FILE: hpmufn.c ---
/********************************************************************
 * COPYRIGHT: 
 * Copyright (c) 2003, International Business Machines Corporation and
 * others. All Rights Reserved.
 ********************************************************************/
/*
* File hpmufn.c
*
*/

#include "unicode/utypes.h"
#include "unicode/uclean.h"
#include "unicode/uchar.h"
#include "unicode/ures.h"
#include "cintltst.h"
#include "umutex.h"
#include "unicode/utrace.h"
#include <stdlib.h>
#include <string.h>

/**
 * This should align the memory properly on any machine.
 */
typedef union {
    long    t1;
    double  t2;
    void   *t3;
} ctest_AlignedMemory;

static void TestHeapFunctions(void);
static void TestMutexFunctions(void);
static void TestIncDecFunctions(void);

void addHeapMutexTest(TestNode **root);


void
addHeapMutexTest(TestNode** root)
{
    addTest(root, &TestHeapFunctions,       "tsutil/hpmufn/TestHeapFunctions"  );
    addTest(root, &TestMutexFunctions,      "tsutil/hpmufn/TestMutexFunctions" );
    addTest(root, &TestIncDecFunctions,     "tsutil/hpmufn/TestIncDecFunctions");
}


#define TEST_STATUS(status, expected) \
if (status != expected) { \
log_err("FAIL at  %s:%d. Actual status = \"%s\";  Expected status = \"%s\"\n", \
__FILE__, __LINE__, u_errorName(status), u_errorName(expected)); }


#define TEST_ASSERT(expr) \
if (!(expr)) { \
    log_err("FAILED Assertion \"" #expr "\" at  %s:%d.\n", __FILE__, __LINE__); \
}


/*  These tests do cleanup and reinitialize ICU in the course of their operation.
 *    The ICU data directory must be preserved across these operations.
 *    Here is a helper function to assist with that.
 */
static char *safeGetICUDataDirectory() {
    const char *dataDir = u_getDataDirectory();  /* Returned string vanashes with u_cleanup */
    char *retStr = NULL;
    if (dataDir != NULL) {
        retStr = (char *)malloc(strlen(dataDir)+1);
        strcpy(retStr, dataDir);
    }
    return retStr;
}


    
/*
 *  Test Heap Functions.
 *    Implemented on top of the standard malloc heap.
 *    All blocks increased in size by 8 to 16 bytes, and the poiner returned to ICU is
 *       offset up by 8 to 16, which should cause a good heap corruption if one of our "blocks"
 *       ends up being freed directly, without coming through us.
 *    Allocations are counted, to check that ICU actually does call back to us.
 */
int    gBlockCount = 0;
const void  *gContext;

static void   *myMemAlloc(const void *context, size_t size) {
    char *retPtr = (char *)malloc(size+sizeof(ctest_AlignedMemory));
    if (retPtr != NULL) {
        retPtr += sizeof(ctest_AlignedMemory);
    }
    gBlockCount ++;
    return retPtr;
}

static void  myMemFree(const void *context, void *mem) {
    char *freePtr = (char *)mem;
    if (freePtr != NULL) {
        freePtr -= sizeof(ctest_AlignedMemory);
    }
    free(freePtr);
}



static void  *myMemRealloc(const void *context, void *mem, size_t size) {
    char *p = (char *)mem;
    char *retPtr;

    if (p!=NULL) {
        p -= sizeof(ctest_AlignedMemory);
    }
    retPtr = realloc(p, size+sizeof(ctest_AlignedMemory));
    if (retPtr != NULL) {
        p += sizeof(ctest_AlignedMemory);
    }
    return retPtr;
}


static void TestHeapFunctions() {
    UErrorCode       status = U_ZERO_ERROR;
    UResourceBundle *rb     = NULL;
    char            *icuDataDir;

    UTraceEntry   *traceEntryFunc;           /* Tracing function ptrs.  We need to save    */
    UTraceExit    *traceExitFunc;            /*  and restore them across calls to          */
    UTraceData    *traceDataFunc;            /*  u_cleanup() that we make in this test.    */
    const void    *traceContext;
    int32_t        traceLevel;

    icuDataDir = safeGetICUDataDirectory();   /* save icu data dir, so we can put it back
                                               *  after doing u_cleanup().                */

    utrace_getFunctions(&traceContext, &traceEntryFunc, &traceExitFunc, &traceDataFunc);
    traceLevel = utrace_getLevel();

    /* Can not set memory functions if ICU is already initialized */
    u_setMemoryFunctions(&gContext, myMemAlloc, myMemRealloc, myMemFree, &status);
    TEST_STATUS(status, U_INVALID_STATE_ERROR);

    /* Un-initialize ICU */
    u_cleanup();
    utrace_setFunctions(traceContext, traceEntryFunc, traceExitFunc, traceDataFunc);
    utrace_setLevel(traceLevel);

    /* Can not set memory functions with NULL values */
    status = U_ZERO_ERROR;
    u_setMemoryFunctions(&gContext, NULL, myMemRealloc, myMemFree, &status);
    TEST_STATUS(status, U_ILLEGAL_ARGUMENT_ERROR);
    status = U_ZERO_ERROR;
    u_setMemoryFunctions(&gContext, myMemAlloc, NULL, myMemFree, &status);
    TEST_STATUS(status, U_ILLEGAL_ARGUMENT_ERROR);
    status = U_ZERO_ERROR;
    u_setMemoryFunctions(&gContext, myMemAlloc, myMemRealloc, NULL, &status);
    TEST_STATUS(status, U_ILLEGAL_ARGUMENT_ERROR);

    /* u_setMemoryFunctions() should work with null or non-null context pointer */
    status = U_ZERO_ERROR;
    u_setMemoryFunctions(NULL, myMemAlloc, myMemRealloc, myMemFree, &status);
    TEST_STATUS(status, U_ZERO_ERROR);
    u_setMemoryFunctions(&gContext, myMemAlloc, myMemRealloc, myMemFree, &status);
    TEST_STATUS(status, U_ZERO_ERROR);


    /* After reinitializing ICU, we should not be able to set the memory funcs again. */
    status = U_ZERO_ERROR;
    u_setDataDirectory(icuDataDir);
    u_init(&status);
    TEST_STATUS(status, U_ZERO_ERROR);
    u_setMemoryFunctions(NULL, myMemAlloc, myMemRealloc, myMemFree, &status);
    TEST_STATUS(status, U_INVALID_STATE_ERROR);

    /* Doing ICU operations should cause allocations to come through our test heap */
    gBlockCount = 0;
    status = U_ZERO_ERROR;
    rb = ures_open(NULL, "es", &status);
    TEST_STATUS(status, U_ZERO_ERROR);
    if (gBlockCount == 0) {
        log_err("Heap functions are not being called from ICU.\n");
    }
    ures_close(rb);

    /* Cleanup should put the heap back to its default implementation. */
    u_cleanup();
    utrace_setFunctions(traceContext, traceEntryFunc, traceExitFunc, traceDataFunc);
    utrace_setLevel(traceLevel);
    u_setDataDirectory(icuDataDir);
    status = U_ZERO_ERROR;
    u_init(&status);
    TEST_STATUS(status, U_ZERO_ERROR);

    /* ICU operations should no longer cause allocations to come through our test heap */
    gBlockCount = 0;
    status = U_ZERO_ERROR;
    rb = ures_open(NULL, "fr", &status);
    TEST_STATUS(status, U_ZERO_ERROR);
    if (gBlockCount != 0) {
        log_err("Heap functions did not reset after u_cleanup.\n");
    }
    ures_close(rb);
    free(icuDataDir);
}


/*
 *  Test u_setMutexFunctions()
 */

int         gTotalMutexesInitialized = 0;         /* Total number of mutexes created */
int         gTotalMutexesActive      = 0;         /* Total mutexes created, but not destroyed  */
int         gAccumulatedLocks        = 0;
const void *gMutexContext;

typedef struct DummyMutex {
    int  fLockCount;
    int  fMagic;
} DummyMutex;


static void myMutexInit(const void *context, UMTX *mutex, UErrorCode *status) {
    DummyMutex *theMutex;

    TEST_STATUS(*status, U_ZERO_ERROR);
    theMutex = (DummyMutex *)malloc(sizeof(DummyMutex));
    theMutex->fLockCount = 0;
    theMutex->fMagic     = 123456;
    gTotalMutexesInitialized++;
    gTotalMutexesActive++;
    gMutexContext = context;
    *mutex = theMutex;
}


static void myMutexDestroy(const void *context, UMTX  *mutex) {
    DummyMutex *This = *(DummyMutex **)mutex;

    gTotalMutexesActive--;
    TEST_ASSERT(This->fLockCount == 0);
    TEST_ASSERT(This->fMagic == 123456);
    This->fMagic = 0;
    This->fLockCount = 0;
    free(This);
}

static void  myMutexLock(const void *context, UMTX *mutex) {
    DummyMutex *This = *(DummyMutex **)mutex;

    TEST_ASSERT(This->fMagic == 123456);
    This->fLockCount++;
    gAccumulatedLocks++;
}

static void  myMutexUnlock(const void *context, UMTX *mutex) {
    DummyMutex *This = *(DummyMutex **)mutex;

    TEST_ASSERT(This->fMagic == 123456);
    This->fLockCount--;
    TEST_ASSERT(This->fLockCount >= 0);
}



static void TestMutexFunctions() {
    UErrorCode       status = U_ZERO_ERROR;
    UResourceBundle *rb     = NULL;
    char            *icuDataDir;

    UTraceEntry     *traceEntryFunc;           /* Tracing function ptrs.  We need to save    */
    UTraceExit      *traceExitFunc;            /*  and restore them across calls to          */
    UTraceData      *traceDataFunc;            /*  u_cleanup() that we make in this test.    */
    const void      *traceContext;
    int32_t          traceLevel;

    /*  Save initial ICU state so that it can be restored later.
     *  u_cleanup(), which is called in this test, resets ICU's state.
     */
    icuDataDir = safeGetICUDataDirectory();
    utrace_getFunctions(&traceContext, &traceEntryFunc, &traceExitFunc, &traceDataFunc);
    traceLevel = utrace_getLevel();

    /* Can not set mutex functions if ICU is already initialized */
    u_setMutexFunctions(&gContext, myMutexInit, myMutexDestroy, myMutexLock, myMutexUnlock, &status);
    TEST_STATUS(status, U_INVALID_STATE_ERROR);

    /* Un-initialize ICU */
    u_cleanup();
    utrace_setFunctions(traceContext, traceEntryFunc, traceExitFunc, traceDataFunc);
    utrace_setLevel(traceLevel);

    /* Can not set Mutex functions with NULL values */
    status = U_ZERO_ERROR;
    u_setMutexFunctions(&gContext, NULL, myMutexDestroy, myMutexLock, myMutexUnlock, &status);
    TEST_STATUS(status, U_ILLEGAL_ARGUMENT_ERROR);
    status = U_ZERO_ERROR;
    u_setMutexFunctions(&gContext, myMutexInit, NULL, myMutexLock, myMutexUnlock, &status);
    TEST_STATUS(status, U_ILLEGAL_ARGUMENT_ERROR);
    status = U_ZERO_ERROR;
    u_setMutexFunctions(&gContext, myMutexInit, myMutexDestroy, NULL, myMutexUnlock, &status);
    TEST_STATUS(status, U_ILLEGAL_ARGUMENT_ERROR);
    status = U_ZERO_ERROR;
    u_setMutexFunctions(&gContext, myMutexInit, myMutexDestroy, myMutexLock, NULL, &status);
    TEST_STATUS(status, U_ILLEGAL_ARGUMENT_ERROR);

    /* u_setMutexFunctions() should work with null or non-null context pointer */
    status = U_ZERO_ERROR;
    u_setMutexFunctions(&gContext, myMutexInit, myMutexDestroy, myMutexLock, myMutexUnlock, &status);
    TEST_STATUS(status, U_ZERO_ERROR);
    u_setMutexFunctions(&gContext, myMutexInit, myMutexDestroy, myMutexLock, myMutexUnlock, &status);
    TEST_STATUS(status, U_ZERO_ERROR);


    /* After reinitializing ICU, we should not be able to set the mutex funcs again. */
    status = U_ZERO_ERROR;
    u_setDataDirectory(icuDataDir);
    u_init(&status);
    TEST_STATUS(status, U_ZERO_ERROR);
    u_setMutexFunctions(&gContext, myMutexInit, myMutexDestroy, myMutexLock, myMutexUnlock, &status);
    TEST_STATUS(status, U_INVALID_STATE_ERROR);

    /* Doing ICU operations should cause allocations to come through our test mutexes */
    gBlockCount = 0;
    status = U_ZERO_ERROR;
    rb = ures_open(NULL, "es", &status);
    TEST_STATUS(status, U_ZERO_ERROR);
    TEST_ASSERT(gTotalMutexesInitialized > 0);
    TEST_ASSERT(gTotalMutexesActive > 0);

    ures_close(rb);

    /* Cleanup should destroy all of the mutexes. */
    u_cleanup();
    u_setDataDirectory(icuDataDir);
    utrace_setFunctions(traceContext, traceEntryFunc, traceExitFunc, traceDataFunc);
    utrace_setLevel(traceLevel);
    status = U_ZERO_ERROR;
    TEST_ASSERT(gTotalMutexesInitialized > 0);
    TEST_ASSERT(gTotalMutexesActive == 0);


    /* Additional ICU operations should no longer use our dummy test mutexes */
    gTotalMutexesInitialized = 0;
    gTotalMutexesActive      = 0;
    u_init(&status);
    TEST_STATUS(status, U_ZERO_ERROR);

    status = U_ZERO_ERROR;
    rb = ures_open(NULL, "fr", &status);
    TEST_STATUS(status, U_ZERO_ERROR);
    TEST_ASSERT(gTotalMutexesInitialized == 0);
    TEST_ASSERT(gTotalMutexesActive == 0);

    ures_close(rb);
    free(icuDataDir);
}




/*
 *  Test Atomic Increment & Decrement Functions
 */

int         gIncCount             = 0;
int         gDecCount             = 0;
const void *gIncDecContext;


static int32_t myIncFunc(const void *context, int32_t *p) {
    int32_t  retVal;
    TEST_ASSERT(context == gIncDecContext);
    gIncCount++;
    retVal = ++(*p);
    return retVal;
}

static int32_t myDecFunc(const void *context, int32_t *p) {
    int32_t  retVal;
    TEST_ASSERT(context == gIncDecContext);
    gDecCount++;
    retVal = --(*p);
    return retVal;
}




static void TestIncDecFunctions() {
    UErrorCode   status = U_ZERO_ERROR;
    int32_t      t = 1; /* random value to make sure that Inc/dec works */
    char         *dataDir;

    UTraceEntry     *traceEntryFunc;           /* Tracing function ptrs.  We need to save    */
    UTraceExit      *traceExitFunc;            /*  and restore them across calls to          */
    UTraceData      *traceDataFunc;            /*  u_cleanup() that we make in this test.    */
    const void      *traceContext;
    int32_t          traceLevel;

    /* Can not set mutex functions if ICU is already initialized */
    u_setAtomicIncDecFunctions(&gIncDecContext, myIncFunc, myDecFunc,  &status);
    TEST_STATUS(status, U_INVALID_STATE_ERROR);

    /* Un-initialize ICU */
    dataDir = safeGetICUDataDirectory();
    utrace_getFunctions(&traceContext, &traceEntryFunc, &traceExitFunc, &traceDataFunc);
    traceLevel = utrace_getLevel();
    u_cleanup();
    utrace_setFunctions(traceContext, traceEntryFunc, traceExitFunc, traceDataFunc);
    utrace_setLevel(traceLevel);

    /* Can not set functions with NULL values */
    status = U_ZERO_ERROR;
    u_setAtomicIncDecFunctions(&gIncDecContext, NULL, myDecFunc,  &status);
    TEST_STATUS(status, U_ILLEGAL_ARGUMENT_ERROR);
    status = U_ZERO_ERROR;
    u_setAtomicIncDecFunctions(&gIncDecContext, myIncFunc, NULL,  &status);
    TEST_STATUS(status, U_ILLEGAL_ARGUMENT_ERROR);

    /* u_setIncDecFunctions() should work with null or non-null context pointer */
    status = U_ZERO_ERROR;
    u_setAtomicIncDecFunctions(NULL, myIncFunc, myDecFunc,  &status);
    TEST_STATUS(status, U_ZERO_ERROR);
    u_setAtomicIncDecFunctions(&gIncDecContext, myIncFunc, myDecFunc,  &status);
    TEST_STATUS(status, U_ZERO_ERROR);


    /* After reinitializing ICU, we should not be able to set the inc/dec funcs again. */
    status = U_ZERO_ERROR;
    u_setDataDirectory(dataDir);
    u_init(&status);
    TEST_STATUS(status, U_ZERO_ERROR);
    u_setAtomicIncDecFunctions(&gIncDecContext, myIncFunc, myDecFunc,  &status);
    TEST_STATUS(status, U_INVALID_STATE_ERROR);

    /* Doing ICU operations should cause our functions to be called */
    gIncCount = 0;
    gDecCount = 0;
    umtx_atomic_inc(&t);
    TEST_ASSERT(t == 2);
    umtx_atomic_dec(&t);
    TEST_ASSERT(t == 1);
    TEST_ASSERT(gIncCount > 0);
    TEST_ASSERT(gDecCount > 0);


    /* Cleanup should cancel use of our inc/dec functions. */
    /* Additional ICU operations should not use them */
    u_cleanup();
    utrace_setFunctions(traceContext, traceEntryFunc, traceExitFunc, traceDataFunc);
    utrace_setLevel(traceLevel);
    gIncCount = 0;
    gDecCount = 0;
    status = U_ZERO_ERROR;
    u_setDataDirectory(dataDir);
    u_init(&status);
    TEST_ASSERT(gIncCount == 0);
    TEST_ASSERT(gDecCount == 0);

    status = U_ZERO_ERROR;
    umtx_atomic_inc(&t);
    umtx_atomic_dec(&t);
    TEST_STATUS(status, U_ZERO_ERROR);
    TEST_ASSERT(gIncCount == 0);
    TEST_ASSERT(gDecCount == 0);

    free(dataDir);
}


--- NEW FILE: idnatest.c ---
/*
 *******************************************************************************
 *
 *   Copyright (C) 2003, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
 *   file name:  idnatest.c
 *   encoding:   US-ASCII
 *   tab size:   8 (not used)
 *   indentation:4
 *
 *   created on: 2003jul11
 *   created by: Ram Viswanadha
 */
#include <stdlib.h>
#include <string.h>
#include "unicode/utypes.h"

#if !UCONFIG_NO_IDNA

#include "unicode/ustring.h"
#include "unicode/uidna.h"
#include "cintltst.h"



#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
#define MAX_DEST_SIZE 1000

static void TestToUnicode(void);
static void TestToASCII(void);
static void TestIDNToUnicode(void);
static void TestIDNToASCII(void);
static void TestCompare(void);

void addIDNATest(TestNode** root);


typedef int32_t
(*TestFunc) (   const UChar *src, int32_t srcLength,
                UChar *dest, int32_t destCapacity,
                int32_t options, UParseError *parseError,
                UErrorCode *status);
typedef int32_t
(*CompareFunc) (const UChar *s1, int32_t s1Len,
                const UChar *s2, int32_t s2Len,
                int32_t options,
                UErrorCode *status);


void
addIDNATest(TestNode** root)
{
   addTest(root, &TestToUnicode,    "idna/TestToUnicode");
   addTest(root, &TestToASCII,      "idna/TestToASCII");
   addTest(root, &TestIDNToUnicode, "idna/TestIDNToUnicode");
   addTest(root, &TestIDNToASCII,   "idna/TestIDNToASCII");
   addTest(root, &TestCompare,      "idna/TestCompare");
}

static void
testAPI(const UChar* src, const UChar* expected, const char* testName,
            UBool useSTD3ASCIIRules,UErrorCode expectedStatus,
            UBool doCompare, UBool testUnassigned,  TestFunc func){

    UErrorCode status = U_ZERO_ERROR;
    UChar destStack[MAX_DEST_SIZE];
    int32_t destLen = 0;
    UChar* dest = NULL;
    int32_t expectedLen = (expected != NULL) ? u_strlen(expected) : 0;
    int32_t options = (useSTD3ASCIIRules == TRUE) ? UIDNA_USE_STD3_RULES : UIDNA_DEFAULT;
    UParseError parseError;
    int32_t tSrcLen = 0;
    UChar* tSrc = NULL;

    if(src != NULL){
        tSrcLen = u_strlen(src);
        tSrc  =(UChar*) malloc( U_SIZEOF_UCHAR * tSrcLen );
        memcpy(tSrc,src,tSrcLen * U_SIZEOF_UCHAR);
    }

    /* test null-terminated source and return value of number of UChars required */
    if( expectedStatus != U_IDNA_STD3_ASCII_RULES_ERROR ){
        destLen = func(src,-1,NULL,0,options, &parseError , &status);
        if(status == U_BUFFER_OVERFLOW_ERROR){
            status = U_ZERO_ERROR; /* reset error code */
            if(destLen+1 < MAX_DEST_SIZE){
                dest = destStack;
                destLen = func(src,-1,dest,destLen+1,options, &parseError, &status);
                /* TODO : compare output with expected */
                if(U_SUCCESS(status) && expectedStatus != U_IDNA_STD3_ASCII_RULES_ERROR&& (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){
                    log_err("Did not get the expected result for  null terminated source.\n" );
                }
            }else{
                log_err( "%s null terminated source failed. Requires destCapacity > 300\n",testName);
            }
        }

        if(status != expectedStatus){
            log_err( "Did not get the expected error for %s null terminated source failed. Expected: %s Got: %s\n",testName, u_errorName(expectedStatus), u_errorName(status));
            free(tSrc);
            return;
        }
        if(testUnassigned ){
            status = U_ZERO_ERROR;
            destLen = func(src,-1,NULL,0,options | UIDNA_ALLOW_UNASSIGNED, &parseError, &status);
            if(status == U_BUFFER_OVERFLOW_ERROR){
                status = U_ZERO_ERROR; /* reset error code */
                if(destLen+1 < MAX_DEST_SIZE){
                    dest = destStack;
                    destLen = func(src,-1,dest,destLen+1,options | UIDNA_ALLOW_UNASSIGNED, &parseError, &status);
                    /* TODO : compare output with expected */
                    if(U_SUCCESS(status) && (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){
                        log_err("Did not get the expected result for %s null terminated source with both options set.\n",testName);

                    }
                }else{
                    log_err( "%s null terminated source failed. Requires destCapacity > 300\n",testName);
                }
            }
            /*testing query string*/
            if(status != expectedStatus && expectedStatus != U_IDNA_UNASSIGNED_ERROR){
                log_err( "Did not get the expected error for %s null terminated source with options set. Expected: %s Got: %s\n",testName, u_errorName(expectedStatus), u_errorName(status));
            }
        }

        status = U_ZERO_ERROR;

        /* test source with lengthand return value of number of UChars required*/
        destLen = func(tSrc, tSrcLen, NULL,0,options, &parseError, &status);
        if(status == U_BUFFER_OVERFLOW_ERROR){
            status = U_ZERO_ERROR; /* reset error code */
            if(destLen+1 < MAX_DEST_SIZE){
                dest = destStack;
                destLen = func(src,u_strlen(src),dest,destLen+1,options, &parseError, &status);
                /* TODO : compare output with expected */
                if(U_SUCCESS(status) && (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){
                    log_err("Did not get the expected result for %s with source length.\n",testName);
                }
            }else{
                log_err( "%s with source length  failed. Requires destCapacity > 300\n",testName);
            }
        }

        if(status != expectedStatus){
            log_err( "Did not get the expected error for %s with source length. Expected: %s Got: %s\n",testName, u_errorName(expectedStatus), u_errorName(status));
        }
        if(testUnassigned){
            status = U_ZERO_ERROR;

            destLen = func(tSrc,tSrcLen,NULL,0,options | UIDNA_ALLOW_UNASSIGNED, &parseError, &status);

            if(status == U_BUFFER_OVERFLOW_ERROR){
                status = U_ZERO_ERROR; /* reset error code */
                if(destLen+1 < MAX_DEST_SIZE){
                    dest = destStack;
                    destLen = func(src,u_strlen(src),dest,destLen+1,options | UIDNA_ALLOW_UNASSIGNED, &parseError, &status);
                    /* TODO : compare output with expected */
                    if(U_SUCCESS(status) && (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){
                        log_err("Did not get the expected result for %s with source length and both options set.\n",testName);
                    }
                }else{
                    log_err( "%s with source length  failed. Requires destCapacity > 300\n",testName);
                }
            }
            /*testing query string*/
            if(status != expectedStatus && expectedStatus != U_IDNA_UNASSIGNED_ERROR){
                log_err( "Did not get the expected error for %s with source length and options set. Expected: %s Got: %s\n",testName, u_errorName(expectedStatus), u_errorName(status));
            }
        }
    }else{

        status = U_ZERO_ERROR;
        destLen = func(src,-1,NULL,0,options | UIDNA_USE_STD3_RULES, &parseError, &status);
        if(status == U_BUFFER_OVERFLOW_ERROR){
            status = U_ZERO_ERROR; /* reset error code*/
            if(destLen+1 < MAX_DEST_SIZE){
                dest = destStack;
                destLen = func(src,-1,dest,destLen+1,options | UIDNA_USE_STD3_RULES, &parseError, &status);
                /* TODO : compare output with expected*/
                if(U_SUCCESS(status) && (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){
                    log_err("Did not get the expected result for %s null terminated source with both options set.\n",testName);

                }
            }else{
                log_err( "%s null terminated source failed. Requires destCapacity > 300\n",testName);
            }
        }
        /*testing query string*/
        if(status != expectedStatus){
            log_err( "Did not get the expected error for %s null terminated source with options set. Expected: %s Got: %s\n",testName, u_errorName(expectedStatus), u_errorName(status));
        }

        status = U_ZERO_ERROR;

        destLen = func(tSrc,tSrcLen,NULL,0,options | UIDNA_USE_STD3_RULES, &parseError, &status);

        if(status == U_BUFFER_OVERFLOW_ERROR){
            status = U_ZERO_ERROR; /* reset error code*/
            if(destLen+1 < MAX_DEST_SIZE){
                dest = destStack;
                destLen = func(src,u_strlen(src),dest,destLen+1,options | UIDNA_USE_STD3_RULES, &parseError, &status);
                /* TODO : compare output with expected*/
                if(U_SUCCESS(status) && (doCompare==TRUE) && u_strCaseCompare(dest,destLen, expected,expectedLen,0,&status)!=0){
                    log_err("Did not get the expected result for %s with source length and both options set.\n",testName);
                }
            }else{
                log_err( "%s with source length  failed. Requires destCapacity > 300\n",testName);
            }
        }
        /*testing query string*/
        if(status != expectedStatus && expectedStatus != U_IDNA_UNASSIGNED_ERROR){
            log_err( "Did not get the expected error for %s with source length and options set. Expected: %s Got: %s\n",testName, u_errorName(expectedStatus), u_errorName(status));
        }
    }
    free(tSrc);
}

static UChar unicodeIn[][41] ={
    {
        0x0644, 0x064A, 0x0647, 0x0645, 0x0627, 0x0628, 0x062A, 0x0643, 0x0644,
        0x0645, 0x0648, 0x0634, 0x0639, 0x0631, 0x0628, 0x064A, 0x061F, 0x0000
    },
    {
        0x4ED6, 0x4EEC, 0x4E3A, 0x4EC0, 0x4E48, 0x4E0D, 0x8BF4, 0x4E2D, 0x6587,
        0x0000
    },
    {
        0x0050, 0x0072, 0x006F, 0x010D, 0x0070, 0x0072, 0x006F, 0x0073, 0x0074,
        0x011B, 0x006E, 0x0065, 0x006D, 0x006C, 0x0075, 0x0076, 0x00ED, 0x010D,
        0x0065, 0x0073, 0x006B, 0x0079, 0x0000
    },
    {
        0x05DC, 0x05DE, 0x05D4, 0x05D4, 0x05DD, 0x05E4, 0x05E9, 0x05D5, 0x05D8,
        0x05DC, 0x05D0, 0x05DE, 0x05D3, 0x05D1, 0x05E8, 0x05D9, 0x05DD, 0x05E2,
        0x05D1, 0x05E8, 0x05D9, 0x05EA, 0x0000
    },
    {
        0x092F, 0x0939, 0x0932, 0x094B, 0x0917, 0x0939, 0x093F, 0x0928, 0x094D,
        0x0926, 0x0940, 0x0915, 0x094D, 0x092F, 0x094B, 0x0902, 0x0928, 0x0939,
        0x0940, 0x0902, 0x092C, 0x094B, 0x0932, 0x0938, 0x0915, 0x0924, 0x0947,
        0x0939, 0x0948, 0x0902, 0x0000
    },
    {
        0x306A, 0x305C, 0x307F, 0x3093, 0x306A, 0x65E5, 0x672C, 0x8A9E, 0x3092,
        0x8A71, 0x3057, 0x3066, 0x304F, 0x308C, 0x306A, 0x3044, 0x306E, 0x304B,
        0x0000
    },
/*
    {
        0xC138, 0xACC4, 0xC758, 0xBAA8, 0xB4E0, 0xC0AC, 0xB78C, 0xB4E4, 0xC774,
        0xD55C, 0xAD6D, 0xC5B4, 0xB97C, 0xC774, 0xD574, 0xD55C, 0xB2E4, 0xBA74,
        0xC5BC, 0xB9C8, 0xB098, 0xC88B, 0xC744, 0xAE4C, 0x0000
    },
*/
    {
        0x043F, 0x043E, 0x0447, 0x0435, 0x043C, 0x0443, 0x0436, 0x0435, 0x043E,
        0x043D, 0x0438, 0x043D, 0x0435, 0x0433, 0x043E, 0x0432, 0x043E, 0x0440,
        0x044F, 0x0442, 0x043F, 0x043E, 0x0440, 0x0443, 0x0441, 0x0441, 0x043A,
        0x0438, 0x0000
    },
    {
        0x0050, 0x006F, 0x0072, 0x0071, 0x0075, 0x00E9, 0x006E, 0x006F, 0x0070,
        0x0075, 0x0065, 0x0064, 0x0065, 0x006E, 0x0073, 0x0069, 0x006D, 0x0070,
        0x006C, 0x0065, 0x006D, 0x0065, 0x006E, 0x0074, 0x0065, 0x0068, 0x0061,
        0x0062, 0x006C, 0x0061, 0x0072, 0x0065, 0x006E, 0x0045, 0x0073, 0x0070,
        0x0061, 0x00F1, 0x006F, 0x006C, 0x0000
    },
    {
        0x4ED6, 0x5011, 0x7232, 0x4EC0, 0x9EBD, 0x4E0D, 0x8AAA, 0x4E2D, 0x6587,
        0x0000
    },
    {
        0x0054, 0x1EA1, 0x0069, 0x0073, 0x0061, 0x006F, 0x0068, 0x1ECD, 0x006B,
        0x0068, 0x00F4, 0x006E, 0x0067, 0x0074, 0x0068, 0x1EC3, 0x0063, 0x0068,
        0x1EC9, 0x006E, 0x00F3, 0x0069, 0x0074, 0x0069, 0x1EBF, 0x006E, 0x0067,
        0x0056, 0x0069, 0x1EC7, 0x0074, 0x0000
    },
    {
        0x0033, 0x5E74, 0x0042, 0x7D44, 0x91D1, 0x516B, 0x5148, 0x751F, 0x0000
    },
    {
        0x5B89, 0x5BA4, 0x5948, 0x7F8E, 0x6075, 0x002D, 0x0077, 0x0069, 0x0074,
        0x0068, 0x002D, 0x0053, 0x0055, 0x0050, 0x0045, 0x0052, 0x002D, 0x004D,
        0x004F, 0x004E, 0x004B, 0x0045, 0x0059, 0x0053, 0x0000
    },
    {
        0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x002D, 0x0041, 0x006E, 0x006F,
        0x0074, 0x0068, 0x0065, 0x0072, 0x002D, 0x0057, 0x0061, 0x0079, 0x002D,
        0x305D, 0x308C, 0x305E, 0x308C, 0x306E, 0x5834, 0x6240, 0x0000
    },
    {
        0x3072, 0x3068, 0x3064, 0x5C4B, 0x6839, 0x306E, 0x4E0B, 0x0032, 0x0000
    },
    {
        0x004D, 0x0061, 0x006A, 0x0069, 0x3067, 0x004B, 0x006F, 0x0069, 0x3059,
        0x308B, 0x0035, 0x79D2, 0x524D, 0x0000
    },
    {
        0x30D1, 0x30D5, 0x30A3, 0x30FC, 0x0064, 0x0065, 0x30EB, 0x30F3, 0x30D0,
        0x0000
    },
    {
        0x305D, 0x306E, 0x30B9, 0x30D4, 0x30FC, 0x30C9, 0x3067, 0x0000
    },
    /* test non-BMP code points */
    {
        0xD800, 0xDF00, 0xD800, 0xDF01, 0xD800, 0xDF02, 0xD800, 0xDF03, 0xD800, 0xDF05,
        0xD800, 0xDF06, 0xD800, 0xDF07, 0xD800, 0xDF09, 0xD800, 0xDF0A, 0xD800, 0xDF0B,
        0x0000
    },
    {
        0xD800, 0xDF0D, 0xD800, 0xDF0C, 0xD800, 0xDF1E, 0xD800, 0xDF0F, 0xD800, 0xDF16,
        0xD800, 0xDF15, 0xD800, 0xDF14, 0xD800, 0xDF12, 0xD800, 0xDF10, 0xD800, 0xDF20,
        0xD800, 0xDF21,
        0x0000
    },
    /* Greek  */
    {
        0x03b5, 0x03bb, 0x03bb, 0x03b7, 0x03bd, 0x03b9, 0x03ba, 0x03ac
    },
    /* Maltese */
    {
        0x0062, 0x006f, 0x006e, 0x0121, 0x0075, 0x0073, 0x0061, 0x0127,
        0x0127, 0x0061
    },
    /* Russian */
    {
        0x043f, 0x043e, 0x0447, 0x0435, 0x043c, 0x0443, 0x0436, 0x0435,
        0x043e, 0x043d, 0x0438, 0x043d, 0x0435, 0x0433, 0x043e, 0x0432,
        0x043e, 0x0440, 0x044f, 0x0442, 0x043f, 0x043e, 0x0440, 0x0443,
        0x0441, 0x0441, 0x043a, 0x0438
    }

};

static const char *asciiIn[] = {
    "xn--egbpdaj6bu4bxfgehfvwxn",
    "xn--ihqwcrb4cv8a8dqg056pqjye",
    "xn--Proprostnemluvesky-uyb24dma41a",
    "xn--4dbcagdahymbxekheh6e0a7fei0b",
    "xn--i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd",
    "xn--n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa",
/*  "xn--989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5jpsd879ccm6fea98c",*/
    "xn--b1abfaaepdrnnbgefbaDotcwatmq2g4l",
    "xn--PorqunopuedensimplementehablarenEspaol-fmd56a",
    "xn--ihqwctvzc91f659drss3x8bo0yb",
    "xn--TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g",
    "xn--3B-ww4c5e180e575a65lsy2b",
    "xn---with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n",
    "xn--Hello-Another-Way--fc4qua05auwb3674vfr0b",
    "xn--2-u9tlzr9756bt3uc0v",
    "xn--MajiKoi5-783gue6qz075azm5e",
    "xn--de-jg4avhby1noc0d",
    "xn--d9juau41awczczp",
    "XN--097CCDEKGHQJK",
    "XN--db8CBHEJLGH4E0AL",
    "xn--hxargifdar",                       /* Greek */
    "xn--bonusaa-5bb1da",                   /* Maltese */
    "xn--b1abfaaepdrnnbgefbadotcwatmq2g4l", /* Russian (Cyrillic)*/

};

static const char *domainNames[] = {
    "slip129-37-118-146.nc.us.ibm.net",
    "saratoga.pe.utexas.edu",
    "dial-120-45.ots.utexas.edu",
    "woo-085.dorms.waller.net",
    "hd30-049.hil.compuserve.com",
    "pem203-31.pe.ttu.edu",
    "56K-227.MaxTNT3.pdq.net",
    "dial-36-2.ots.utexas.edu",
    "slip129-37-23-152.ga.us.ibm.net",
    "ts45ip119.cadvision.com",
    "sdn-ts-004txaustP05.dialsprint.net",
    "bar-tnt1s66.erols.com",
    "101.st-louis-15.mo.dial-access.att.net",
    "h92-245.Arco.COM",
    "dial-13-2.ots.utexas.edu",
    "net-redynet29.datamarkets.com.ar",
    "ccs-shiva28.reacciun.net.ve",
    "7.houston-11.tx.dial-access.att.net",
    "ingw129-37-120-26.mo.us.ibm.net",
    "dialup6.austintx.com",
    "dns2.tpao.gov.tr",
    "slip129-37-119-194.nc.us.ibm.net",
    "cs7.dillons.co.uk.203.119.193.in-addr.arpa",
    "swprd1.innovplace.saskatoon.sk.ca",
    "bikini.bologna.maraut.it",
    "node91.subnet159-198-79.baxter.com",
    "cust19.max5.new-york.ny.ms.uu.net",
    "balexander.slip.andrew.cmu.edu",
    "pool029.max2.denver.co.dynip.alter.net",
    "cust49.max9.new-york.ny.ms.uu.net",
    "s61.abq-dialin2.hollyberry.com",
    "http://\\u0917\\u0928\\u0947\\u0936.sanjose.ibm.com",
    "www.xn--vea.com",
    "www.\\u00E0\\u00B3\\u00AF.com",
    "www.\\u00C2\\u00A4.com",
    "www.\\u00C2\\u00A3.com",
    "\\u0025",
    "\\u005C\\u005C",
    "@",
    "\\u002F",
    "www.\\u0021.com",
    "www.\\u0024.com",
    "\\u003f",
    /* These yeild U_IDNA_PROHIBITED_ERROR
    //"\\u00CF\\u0082.com",
    //"\\u00CE\\u00B2\\u00C3\\u009Fss.com",
    //"\\u00E2\\u0098\\u00BA.com",*/
    "\\u00C3\\u00BC.com",

};

static void
TestToASCII(){

    int32_t i;
    UChar buf[MAX_DEST_SIZE];
    const char* testName = "uidna_toASCII";
    TestFunc func = uidna_toASCII;
    for(i=0;i< (int32_t)(sizeof(unicodeIn)/sizeof(unicodeIn[0])); i++){
        u_charsToUChars(asciiIn[i],buf, (int32_t)strlen(asciiIn[i])+1);
        testAPI(unicodeIn[i], buf,testName, FALSE,U_ZERO_ERROR, TRUE, TRUE, func);

    }
}

static void
TestToUnicode(){

    int32_t i;
    UChar buf[MAX_DEST_SIZE];
    const char* testName = "uidna_toUnicode";
    TestFunc func = uidna_toUnicode;
    for(i=0;i< (int32_t)(sizeof(asciiIn)/sizeof(asciiIn[0])); i++){
        u_charsToUChars(asciiIn[i],buf, (int32_t)strlen(asciiIn[i])+1);
        testAPI(buf,unicodeIn[i],testName,FALSE,U_ZERO_ERROR, TRUE, TRUE, func);
    }
}


static void
TestIDNToUnicode(){
    int32_t i;
    UChar buf[MAX_DEST_SIZE];
    UChar expected[MAX_DEST_SIZE];
    UErrorCode status = U_ZERO_ERROR;
    int32_t bufLen = 0;
    UParseError parseError;
    const char* testName="uidna_IDNToUnicode";
    TestFunc func = uidna_IDNToUnicode;
    for(i=0;i< (int32_t)(sizeof(domainNames)/sizeof(domainNames[0])); i++){
        bufLen = (int32_t)strlen(domainNames[i]);
        bufLen = u_unescape(domainNames[i],buf, bufLen+1);
        func(buf,bufLen,expected,MAX_DEST_SIZE, UIDNA_ALLOW_UNASSIGNED, &parseError,&status);
        if(U_FAILURE(status)){
            log_err( "%s failed to convert domainNames[%i].Error: %s \n",testName, i, u_errorName(status));
            break;
        }
        testAPI(buf,expected,testName,FALSE,U_ZERO_ERROR, TRUE, TRUE, func);
         /*test toUnicode with all labels in the string*/
        testAPI(buf,expected,testName, FALSE,U_ZERO_ERROR, TRUE, TRUE, func);
        if(U_FAILURE(status)){
            log_err( "%s failed to convert domainNames[%i].Error: %s \n",testName,i, u_errorName(status));
            break;
        }
    }

}

static void
TestIDNToASCII(){
    int32_t i;
    UChar buf[MAX_DEST_SIZE];
    UChar expected[MAX_DEST_SIZE];
    UErrorCode status = U_ZERO_ERROR;
    int32_t bufLen = 0;
    UParseError parseError;
    const char* testName="udina_IDNToASCII";
    TestFunc func=uidna_IDNToASCII;

    for(i=0;i< (int32_t)(sizeof(domainNames)/sizeof(domainNames[0])); i++){
        bufLen = (int32_t)strlen(domainNames[i]);
        bufLen = u_unescape(domainNames[i],buf, bufLen+1);
        func(buf,bufLen,expected,MAX_DEST_SIZE, UIDNA_ALLOW_UNASSIGNED, &parseError,&status);
        if(U_FAILURE(status)){
            log_err( "%s failed to convert domainNames[%i].Error: %s \n",testName,i, u_errorName(status));
            break;
        }
        testAPI(buf,expected,testName, FALSE,U_ZERO_ERROR, TRUE, TRUE, func);
        /*test toASCII with all labels in the string*/
        testAPI(buf,expected,testName, FALSE,U_ZERO_ERROR, FALSE, TRUE, func);
        if(U_FAILURE(status)){
            log_err( "%s failed to convert domainNames[%i].Error: %s \n",testName,i, u_errorName(status));
            break;
        }
    }

}


static void
testCompareWithSrc(const UChar* s1, int32_t s1Len,
            const UChar* s2, int32_t s2Len,
            const char* testName, CompareFunc func,
            UBool isEqual){

    UErrorCode status = U_ZERO_ERROR;
    int32_t retVal = func(s1,-1,s2,-1,UIDNA_DEFAULT,&status);

    if(isEqual==TRUE &&  retVal !=0){
        log_err("Did not get the expected result for %s with null termniated strings.\n",testName);
    }
    if(U_FAILURE(status)){
        log_err( "%s null terminated source failed. Error: %s\n", testName,u_errorName(status));
    }

    status = U_ZERO_ERROR;
    retVal = func(s1,-1,s2,-1,UIDNA_ALLOW_UNASSIGNED,&status);

    if(isEqual==TRUE &&  retVal !=0){
        log_err("Did not get the expected result for %s with null termniated strings with options set.\n", testName);
    }
    if(U_FAILURE(status)){
        log_err( "%s null terminated source and options set failed. Error: %s\n",testName, u_errorName(status));
    }

    status = U_ZERO_ERROR;
    retVal = func(s1,s1Len,s2,s2Len,UIDNA_DEFAULT,&status);

    if(isEqual==TRUE &&  retVal !=0){
        log_err("Did not get the expected result for %s with string length.\n",testName);
    }
    if(U_FAILURE(status)){
        log_err( "%s with string length. Error: %s\n",testName, u_errorName(status));
    }

    status = U_ZERO_ERROR;
    retVal = func(s1,s1Len,s2,s2Len,UIDNA_ALLOW_UNASSIGNED,&status);

    if(isEqual==TRUE &&  retVal !=0){
        log_err("Did not get the expected result for %s with string length and options set.\n",testName);
    }
    if(U_FAILURE(status)){
        log_err( "%s with string length and options set. Error: %s\n", u_errorName(status), testName);
    }
}


static void
TestCompare(){
    int32_t i;

    const char* testName ="uidna_compare";
    CompareFunc func = uidna_compare;

    UChar www[] = {0x0057, 0x0057, 0x0057, 0x002E, 0x0000};
    UChar com[] = {0x002E, 0x0043, 0x004F, 0x004D, 0x0000};
    UChar buf[MAX_DEST_SIZE]={0x0057, 0x0057, 0x0057, 0x002E, 0x0000};
    UChar source[MAX_DEST_SIZE]={0},
          uni0[MAX_DEST_SIZE]={0},
          uni1[MAX_DEST_SIZE]={0},
          ascii0[MAX_DEST_SIZE]={0},
          ascii1[MAX_DEST_SIZE]={0},
          temp[MAX_DEST_SIZE] ={0};


    u_strcat(uni0,unicodeIn[0]);
    u_strcat(uni0,com);

    u_strcat(uni1,unicodeIn[1]);
    u_strcat(uni1,com);

    u_charsToUChars(asciiIn[0], temp, (int32_t)strlen(asciiIn[0]));
    u_strcat(ascii0,temp);
    u_strcat(ascii0,com);

    memset(temp, 0, U_SIZEOF_UCHAR * MAX_DEST_SIZE);

    u_charsToUChars(asciiIn[1], temp, (int32_t)strlen(asciiIn[1]));
    u_strcat(ascii1,temp);
    u_strcat(ascii1,com);

    /* prepend www. */
    u_strcat(source, www);

    for(i=0;i< (int32_t)(sizeof(unicodeIn)/sizeof(unicodeIn[0])); i++){
        UChar* src;
        int32_t srcLen;

        memset(buf+4, 0, (MAX_DEST_SIZE-4) * U_SIZEOF_UCHAR);

        u_charsToUChars(asciiIn[i],buf+4, (int32_t)strlen(asciiIn[i]));
        u_strcat(buf,com);


        /* for every entry in unicodeIn array
           prepend www. and append .com*/
        source[4]=0;
        u_strncat(source,unicodeIn[i], u_strlen(unicodeIn[i]));
        u_strcat(source,com);

        /* a) compare it with itself*/
        src = source;
        srcLen = u_strlen(src);

        testCompareWithSrc(src,srcLen,src,srcLen,testName, func, TRUE);

        /* b) compare it with asciiIn equivalent */
        testCompareWithSrc(src,srcLen,buf,u_strlen(buf),testName, func,TRUE);

        /* c) compare it with unicodeIn not equivalent*/
        if(i==0){
            testCompareWithSrc(src,srcLen,uni1,u_strlen(uni1),testName, func,FALSE);
        }else{
            testCompareWithSrc(src,srcLen,uni0,u_strlen(uni0),testName, func,FALSE);
        }
        /* d) compare it with asciiIn not equivalent */
        if(i==0){
            testCompareWithSrc(src,srcLen,ascii1,u_strlen(ascii1),testName, func,FALSE);
        }else{
            testCompareWithSrc(src,srcLen,ascii0,u_strlen(ascii0),testName, func,FALSE);
        }

    }
}

#endif

/*
 * Hey, Emacs, please set the following:
 *
 * Local Variables:
 * indent-tabs-mode: nil
 * End:
 *
 */


--- NEW FILE: nfsprep.c ---
/*
 *******************************************************************************
 *
 *   Copyright (C) 2003, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
 *   file name:  nfsprep.c
 *   encoding:   US-ASCII
 *   tab size:   8 (not used)
 *   indentation:4
 *
 *   created on: 2003jul11
 *   created by: Ram Viswanadha
 */

#include "unicode/utypes.h"

#if !UCONFIG_NO_IDNA

#include "nfsprep.h"
#include "ustr_imp.h"
#include "cintltst.h"

#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
#define NFS4_MAX_BUFFER_SIZE 1000
#define PREFIX_SUFFIX_SEPARATOR 0x0040 /* '@' */


const char* NFS4DataFileNames[5] ={
    "nfscss",
    "nfscsi",
    "nfscis",
    "nfsmxp",
    "nfsmxs"
};


int32_t
nfs4_prepare( const char* src, int32_t srcLength,
              char* dest, int32_t destCapacity,
              NFS4ProfileState state,
              UParseError* parseError,
              UErrorCode*  status){
    
    UChar b1Stack[NFS4_MAX_BUFFER_SIZE], 
          b2Stack[NFS4_MAX_BUFFER_SIZE]; 
    char  b3Stack[NFS4_MAX_BUFFER_SIZE];

    /* initialize pointers to stack buffers */
    UChar *b1 = b1Stack, *b2 = b2Stack;
    char  *b3=b3Stack;
    int32_t b1Len=0, b2Len=0, b3Len=0,
            b1Capacity = NFS4_MAX_BUFFER_SIZE, 
            b2Capacity = NFS4_MAX_BUFFER_SIZE,
            b3Capacity = NFS4_MAX_BUFFER_SIZE,
            reqLength=0;
    
    UStringPrepProfile* profile = NULL;
    /* get the test data path */
    const char *testdatapath = NULL;

    if(status==NULL || U_FAILURE(*status)){
        return 0;
    }
    if((src==NULL) || (srcLength < -1) || (destCapacity<0) || (!dest && destCapacity > 0)){
        *status = U_ILLEGAL_ARGUMENT_ERROR;
        return 0;
    }
    testdatapath = loadTestData(status);

    /* convert the string from UTF-8 to UTF-16 */
    u_strFromUTF8(b1,b1Capacity,&b1Len,src,srcLength,status);
    if(*status == U_BUFFER_OVERFLOW_ERROR){

        /* reset the status */
        *status = U_ZERO_ERROR;
        
        b1 = (UChar*) malloc(b1Len * U_SIZEOF_UCHAR);
        if(b1==NULL){
            *status = U_MEMORY_ALLOCATION_ERROR;
            goto CLEANUP;
        }

        b1Capacity = b1Len;
        u_strFromUTF8(b1, b1Capacity, &b1Len, src, srcLength, status);
    }

    /* open the profile */
    profile = usprep_open(testdatapath, NFS4DataFileNames[state],  status);
    /* prepare the string */
    b2Len = usprep_prepare(profile, b1, b1Len, b2, b2Capacity, USPREP_DEFAULT, parseError, status);
    if(*status == U_BUFFER_OVERFLOW_ERROR){
        *status = U_ZERO_ERROR;
        b2 = (UChar*) malloc(b2Len * U_SIZEOF_UCHAR);
        if(b2== NULL){
            *status = U_MEMORY_ALLOCATION_ERROR;
            goto CLEANUP;
        }
        b2Len = usprep_prepare(profile, b1, b1Len, b2, b2Len, USPREP_DEFAULT, parseError, status);
    }
    
    /* convert the string back to UTF-8 */
    u_strToUTF8(b3,b3Capacity, &b3Len, b2, b2Len, status);
    if(*status == U_BUFFER_OVERFLOW_ERROR){
        *status = U_ZERO_ERROR;
        b3 = (char*) malloc(b3Len);
        if(b3== NULL){
            *status = U_MEMORY_ALLOCATION_ERROR;
            goto CLEANUP;
        }
        b3Capacity = b3Len;
        u_strToUTF8(b3,b3Capacity, &b3Len, b2, b2Len, status);
    }

    reqLength = b3Len;
    if(dest!=NULL && reqLength <= destCapacity){
        memmove(dest, b3, reqLength);
    }

CLEANUP:
    if(b1!=b1Stack){
        free(b1);
    }
    if(b2!=b2Stack){
        free(b2);
    }
    if(b3!=b3Stack){
        free(b3);
    }

    return u_terminateChars(dest, destCapacity, reqLength, status);
}

static void
syntaxError( const UChar* rules, 
             int32_t pos,
             int32_t rulesLen,
             UParseError* parseError){
    int32_t start, stop;
    if(parseError == NULL){
        return;
    }
    if(pos == rulesLen && rulesLen >0){
        pos--;
    }
    parseError->offset = pos;
    parseError->line = 0 ; /* we are not using line numbers */
    
    /* for pre-context */
    start = (pos <=U_PARSE_CONTEXT_LEN)? 0 : (pos - (U_PARSE_CONTEXT_LEN-1));
    stop  = pos;
    
    u_memcpy(parseError->preContext,rules+start,stop-start);
    /* null terminate the buffer */
    parseError->preContext[stop-start] = 0;
    
    /* for post-context */
    start = pos;
    if(start<rulesLen) {
        U16_FWD_1(rules, start, rulesLen);
    }

    stop  = ((pos+U_PARSE_CONTEXT_LEN)<= rulesLen )? (pos+(U_PARSE_CONTEXT_LEN)) : 
                                                            rulesLen;
    if(start < stop){
        u_memcpy(parseError->postContext,rules+start,stop-start);
        /* null terminate the buffer */
        parseError->postContext[stop-start]= 0;
    }
    
}


/* sorted array for binary search*/
static const char* special_prefixes[]={
    "\x0041\x004e\x004f\x004e\x0059\x004d\x004f\x0055\x0053",    
    "\x0041\x0055\x0054\x0048\x0045\x004e\x0054\x0049\x0043\x0041\x0054\x0045\x0044",
    "\x0042\x0041\x0054\x0043\x0048", 
    "\x0044\x0049\x0041\x004c\x0055\x0050", 
    "\x0045\x0056\x0045\x0052\x0059\x004f\x004e\x0045", 
    "\x0047\x0052\x004f\x0055\x0050",
    "\x0049\x004e\x0054\x0045\x0052\x0041\x0043\x0054\x0049\x0056\x0045",  
    "\x004e\x0045\x0054\x0057\x004f\x0052\x004b", 
    "\x004f\x0057\x004e\x0045\x0052",
};


/* binary search the sorted array */
static int 
findStringIndex(const char* const *sortedArr, int32_t sortedArrLen, const char* target, int32_t targetLen){

    int left, middle, right,rc;

    left =0;
    right= sortedArrLen-1;

    while(left <= right){
        middle = (left+right)/2;
        rc=strncmp(sortedArr[middle],target, targetLen);
    
        if(rc<0){
            left = middle+1;
        }else if(rc >0){
            right = middle -1;
        }else{
            return middle;
        }
    }
    return -1;
}

static void 
getPrefixSuffix(const char *src, int32_t srcLength, 
                const char **prefix, int32_t *prefixLen,
                const char **suffix, int32_t *suffixLen,
                UErrorCode *status){

    int32_t i=0;
    *prefix = src;
    while(i<srcLength){
        if(src[i] == PREFIX_SUFFIX_SEPARATOR){
            if((i+1) == srcLength){
                /* we reached the end of the string */
                *suffix = NULL;
                i++;
                break;
            }
            i++;/* the prefix contains the separator */
            *suffix = src + i;
            break;
        }
        i++;
    }
    *prefixLen = i;
    *suffixLen = srcLength - i;
    /* special prefixes must not be followed by suffixes! */
    if((findStringIndex(special_prefixes,LENGTHOF(special_prefixes), *prefix, *prefixLen-1) != -1) && (*suffix != NULL)){
        *status = U_PARSE_ERROR;
        return;
    }
            
}

int32_t
nfs4_mixed_prepare( const char* src, int32_t srcLength,
                    char* dest, int32_t destCapacity,
                    UParseError* parseError,
                    UErrorCode*  status){

    const char *prefix = NULL, *suffix = NULL;
    int32_t prefixLen=0, suffixLen=0;
    char  pStack[NFS4_MAX_BUFFER_SIZE], 
          sStack[NFS4_MAX_BUFFER_SIZE]; 
    char *p=pStack, *s=sStack;
    int32_t pLen=0, sLen=0, reqLen=0,
            pCapacity = NFS4_MAX_BUFFER_SIZE,
            sCapacity = NFS4_MAX_BUFFER_SIZE;


    if(status==NULL || U_FAILURE(*status)){
        return 0;
    }
    if((src==NULL) || (srcLength < -1) || (destCapacity<0) || (!dest && destCapacity > 0)){
        *status = U_ILLEGAL_ARGUMENT_ERROR;
        return 0;
    }
    if(srcLength == -1){
        srcLength = (int32_t)strlen(src);
    }
    getPrefixSuffix(src, srcLength, &prefix, &prefixLen, &suffix, &suffixLen, status); 

    /* prepare the prefix */
    pLen = nfs4_prepare(prefix, prefixLen, p, pCapacity, NFS4_MIXED_PREP_PREFIX, parseError, status);
    if(*status == U_BUFFER_OVERFLOW_ERROR){
        *status = U_ZERO_ERROR;
        p = (char*) malloc(pLen);
        if(p == NULL){
           *status = U_MEMORY_ALLOCATION_ERROR;
           goto CLEANUP;
        }
        pLen = nfs4_prepare(prefix, prefixLen, p, pLen, NFS4_MIXED_PREP_PREFIX, parseError, status);
    }

    /* prepare the suffix */
    if(suffix != NULL){
        sLen = nfs4_prepare(suffix, suffixLen, s, sCapacity, NFS4_MIXED_PREP_SUFFIX, parseError, status);
        if(*status == U_BUFFER_OVERFLOW_ERROR){
            *status = U_ZERO_ERROR;
            s = (char*) malloc(pLen);
            if(s == NULL){
               *status = U_MEMORY_ALLOCATION_ERROR;
               goto CLEANUP;
            }
            sLen = nfs4_prepare(suffix, suffixLen, s, sLen, NFS4_MIXED_PREP_SUFFIX, parseError, status);
        }
    }
    reqLen = pLen+sLen+1 /* for the delimiter */;
    if(dest != NULL && reqLen <= destCapacity){
        memmove(dest, p, pLen);
        /* add the suffix */
        if(suffix!=NULL){
            dest[pLen++] = PREFIX_SUFFIX_SEPARATOR;
            memmove(dest+pLen, s, sLen);
        }
    }

CLEANUP:
    if(p != pStack){
        free(p);
    }
    if(s != sStack){
        free(s);
    }
    
    return u_terminateChars(dest, destCapacity, reqLen, status);
}

int32_t
nfs4_cis_prepare(   const char* src, int32_t srcLength,
                    char* dest, int32_t destCapacity,
                    UParseError* parseError,
                    UErrorCode*  status){
    return nfs4_prepare(src, srcLength, dest, destCapacity, NFS4_CIS_PREP, parseError, status);
}


int32_t
nfs4_cs_prepare(    const char* src, int32_t srcLength,
                    char* dest, int32_t destCapacity,
                    UBool isCaseSensitive,
                    UParseError* parseError,
                    UErrorCode*  status){
    if(isCaseSensitive){
        return nfs4_prepare(src, srcLength, dest, destCapacity, NFS4_CS_PREP_CS, parseError, status);
    }else{
        return nfs4_prepare(src, srcLength, dest, destCapacity, NFS4_CS_PREP_CI, parseError, status);
    }
}

#endif
/*
 * Hey, Emacs, please set the following:
 *
 * Local Variables:
 * indent-tabs-mode: nil
 * End:
 *
 */


--- NEW FILE: nfsprep.h ---
/*
 *******************************************************************************
 *
 *   Copyright (C) 2003, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
 *   file name:  nfsprep.h
 *   encoding:   US-ASCII
 *   tab size:   8 (not used)
 *   indentation:4
 *
 *   created on: 2003jul11
 *   created by: Ram Viswanadha
 */
#ifndef _NFSPREP_H
#define _NFSPREP_H

#include "unicode/utypes.h"

#if !UCONFIG_NO_IDNA

#include "unicode/ustring.h"
#include "unicode/usprep.h"
#include <stdlib.h>
#include <string.h>


/* this enum must be kept in syn with NFS4DataFileNames array in nfsprep.c */
enum NFS4ProfileState{
    NFS4_CS_PREP_CS,
    NFS4_CS_PREP_CI,
    NFS4_CIS_PREP,
    NFS4_MIXED_PREP_PREFIX,
    NFS4_MIXED_PREP_SUFFIX
};

typedef enum NFS4ProfileState NFS4ProfileState;

/**
 * Prepares the source UTF-8 string for use in file names and 
 * returns UTF-8 string on output.
 * @param src
 * @param srcLen
 * @param dest
 * @param destCapacity
 * @param state
 * @param parseError
 * @param status
 */
int32_t
nfs4_prepare(const char* src, int32_t srcLength,
                  char* dest, int32_t destCapacity,
                  NFS4ProfileState state,
                  UParseError* parseError,
                  UErrorCode*  status);

/**
 * @param dest
 * @param destCapacity
 * @param src
 * @param srcLen
 * @param state
 * @param parseError
 * @param status
 */
int32_t
nfs4_mixed_prepare( const char* src, int32_t srcLength,
                    char* dest, int32_t destCapacity,
                    UParseError* parseError,
                    UErrorCode*  status);

/**
 * @param dest
 * @param destCapacity
 * @param src
 * @param srcLen
 * @param state
 * @param parseError
 * @param status
 */
int32_t
nfs4_cis_prepare(   const char* src, int32_t srcLength,
                    char* dest, int32_t destCapacity,
                    UParseError* parseError,
                    UErrorCode*  status);

/**
 * @param dest
 * @param destCapacity
 * @param src
 * @param srcLen
 * @param state
 * @param parseError
 * @param status
 */
int32_t
nfs4_cs_prepare(    const char* src, int32_t srcLength,
                    char* dest, int32_t destCapacity,
                    UBool isCaseSensitive,
                    UParseError* parseError,
                    UErrorCode*  status);
#endif

#endif
/*
 * Hey, Emacs, please set the following:
 *
 * Local Variables:
 * indent-tabs-mode: nil
 * End:
 *
 */

--- NEW FILE: sorttest.c ---
/*
*******************************************************************************
*
*   Copyright (C) 2003, International Business Machines
*   Corporation and others.  All Rights Reserved.
*
*******************************************************************************
*   file name:  csorttst.c
*   encoding:   US-ASCII
*   tab size:   8 (not used)
*   indentation:4
*
*   created on: 2003aug04
*   created by: Markus W. Scherer
*
*   Test internal sorting functions.
*/

#include "unicode/utypes.h"
#include "cmemory.h"
#include "cintltst.h"
#include "uarrsort.h"

#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))

/* compare only the top 28 bits of int32_t items (bits 3..0 contain the original index) */
static int32_t U_CALLCONV
_int32Top28Comparator(const void *context, const void *left, const void *right) {
    return (*(const int32_t *)left>>4) - (*(const int32_t *)right>>4);
}

static void
SortTest(void) {
    uint16_t small[]={ 8, 1, 2, 5, 4, 3, 7, 6 };
    int32_t medium[]={ 10, 8, 1, 2, 5, 5, 6, 4, 3, 9, 7, 5 };
    uint32_t large[]={ 21, 10, 20, 19, 11, 12, 13, 10, 10, 10, 10,
                       8, 1, 2, 5, 10, 10, 4, 17, 18, 3, 9, 10, 7, 6, 14, 15, 16 };

    int32_t i;
    UErrorCode errorCode;

    /* sort small array (stable) */
    errorCode=U_ZERO_ERROR;
    uprv_sortArray(small, LENGTHOF(small), sizeof(small[0]), uprv_uint16Comparator, NULL, TRUE, &errorCode);
    if(U_FAILURE(errorCode)) {
        log_err("uprv_sortArray(small) failed - %s\n", u_errorName(errorCode));
        return;
    }
    for(i=1; i<LENGTHOF(small); ++i) {
        if(small[i-1]>small[i]) {
            log_err("uprv_sortArray(small) mis-sorted [%d]=%u > [%d]=%u\n", i-1, small[i-1], i, small[i]);
            return;
        }
    }

    /* for medium, add bits that will not be compared, to test stability */
    for(i=0; i<LENGTHOF(medium); ++i) {
        medium[i]=(medium[i]<<4)|i;
    }

    /* sort medium array (stable) */
    uprv_sortArray(medium, LENGTHOF(medium), sizeof(medium[0]), _int32Top28Comparator, NULL, TRUE, &errorCode);
    if(U_FAILURE(errorCode)) {
        log_err("uprv_sortArray(medium) failed - %s\n", u_errorName(errorCode));
        return;
    }
    for(i=1; i<LENGTHOF(medium); ++i) {
        if(medium[i-1]>=medium[i]) {
            log_err("uprv_sortArray(medium) mis-sorted [%d]=%u > [%d]=%u\n", i-1, medium[i-1], i, medium[i]);
            return;
        }
    }

    /* sort large array (not stable) */
    errorCode=U_ZERO_ERROR;
    uprv_sortArray(large, LENGTHOF(large), sizeof(large[0]), uprv_uint32Comparator, NULL, FALSE, &errorCode);
    if(U_FAILURE(errorCode)) {
        log_err("uprv_sortArray(large) failed - %s\n", u_errorName(errorCode));
        return;
    }
    for(i=1; i<LENGTHOF(large); ++i) {
        if(large[i-1]>large[i]) {
            log_err("uprv_sortArray(large) mis-sorted [%d]=%u > [%d]=%u\n", i-1, large[i-1], i, large[i]);
            return;
        }
    }
}

void
addSortTest(TestNode** root);

void
addSortTest(TestNode** root) {
    addTest(root, &SortTest, "tsutil/sorttest/SortTest");
}

--- NEW FILE: spreptst.c ---
/*
 *******************************************************************************
 *
 *   Copyright (C) 2003, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
 *   file name:  spreptst.c
 *   encoding:   US-ASCII
 *   tab size:   8 (not used)
 *   indentation:4
 *
 *   created on: 2003jul11
 *   created by: Ram Viswanadha
 */
#include <stdlib.h>
#include <string.h>
#include "unicode/utypes.h"

#if !UCONFIG_NO_IDNA

#include "unicode/ustring.h"
#include "unicode/usprep.h"
#include "cintltst.h"
#include "nfsprep.h"


#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))

void addUStringPrepTest(TestNode** root);
void doStringPrepTest(const char* binFileName, const char* txtFileName, 
                 int32_t options, UErrorCode* errorCode);

static void Test_nfs4_cs_prep_data(void);
static void Test_nfs4_cis_prep_data(void);
static void Test_nfs4_mixed_prep_data(void);
static void Test_nfs4_cs_prep(void);
static void Test_nfs4_cis_prep(void);
static void Test_nfs4_mixed_prep(void);

void 
addUStringPrepTest(TestNode** root)
{
   addTest(root, &Test_nfs4_cs_prep_data,    "spreptst/Test_nfs4_cs_prep_data");
   addTest(root, &Test_nfs4_cis_prep_data,   "spreptst/Test_nfs4_cis_prep_data");
   addTest(root, &Test_nfs4_mixed_prep_data, "spreptst/Test_nfs4_mixed_prep_data");
   addTest(root, &Test_nfs4_cs_prep,         "spreptst/Test_nfs4_cs_prep");
   addTest(root, &Test_nfs4_cis_prep,        "spreptst/Test_nfs4_cis_prep");
   addTest(root, &Test_nfs4_mixed_prep,      "spreptst/Test_nfs4_mixed_prep");
}

static void 
Test_nfs4_cs_prep_data(void){
    UErrorCode errorCode = U_ZERO_ERROR;
    log_verbose("Testing nfs4_cs_prep_ci.txt\n");
    doStringPrepTest("nfscsi","nfs4_cs_prep_ci.txt", USPREP_DEFAULT, &errorCode);

    log_verbose("Testing nfs4_cs_prep_cs.txt\n");
    errorCode = U_ZERO_ERROR;
    doStringPrepTest("nfscss","nfs4_cs_prep_cs.txt", USPREP_DEFAULT, &errorCode);
    

}
static void 
Test_nfs4_cis_prep_data(void){
    UErrorCode errorCode = U_ZERO_ERROR;
    log_verbose("Testing nfs4_cis_prep.txt\n");
    doStringPrepTest("nfscis","nfs4_cis_prep.txt", USPREP_DEFAULT, &errorCode);
}
static void 
Test_nfs4_mixed_prep_data(void){
    UErrorCode errorCode = U_ZERO_ERROR;
    log_verbose("Testing nfs4_mixed_prep_s.txt\n");
    doStringPrepTest("nfsmxs","nfs4_mixed_prep_s.txt", USPREP_DEFAULT, &errorCode);

    errorCode = U_ZERO_ERROR;
    log_verbose("Testing nfs4_mixed_prep_p.txt\n");
    doStringPrepTest("nfsmxp","nfs4_mixed_prep_p.txt", USPREP_DEFAULT, &errorCode);

}

static struct ConformanceTestCases
   {
     const char *comment;
     const char *in;
     const char *out;
     const char *profile;
     UErrorCode expectedStatus;
   }
   conformanceTestCases[] =
   {
  
     {/*0*/
       "Case folding ASCII U+0043 U+0041 U+0046 U+0045",
       "\x43\x41\x46\x45", "\x63\x61\x66\x65",
       "nfs4_cis_prep", 
       U_ZERO_ERROR

     },
     {/*1*/
       "Case folding 8bit U+00DF (german sharp s)",
       "\xC3\x9F", "\x73\x73", 
       "nfs4_cis_prep", 
       U_ZERO_ERROR  
     },
     {/*2*/
       "Non-ASCII multibyte space character U+1680",
       "\xE1\x9A\x80", NULL, 
       "nfs4_cis_prep", 
       U_STRINGPREP_PROHIBITED_ERROR
     },
     {/*3*/
       "Non-ASCII 8bit control character U+0085",
       "\xC2\x85", NULL, 
       "nfs4_cis_prep",
       U_STRINGPREP_PROHIBITED_ERROR
     },
     {/*4*/
       "Non-ASCII multibyte control character U+180E",
       "\xE1\xA0\x8E", NULL, 
       "nfs4_cis_prep", 
       U_STRINGPREP_PROHIBITED_ERROR
     },
     {/*5*/
       "Non-ASCII control character U+1D175",
       "\xF0\x9D\x85\xB5", NULL, 
       "nfs4_cis_prep",
       U_STRINGPREP_PROHIBITED_ERROR
     },
     {/*6*/
       "Plane 0 private use character U+F123",
       "\xEF\x84\xA3", NULL, 
       "nfs4_cis_prep", 
       U_STRINGPREP_PROHIBITED_ERROR
     },
     {/*7*/
       "Plane 15 private use character U+F1234",
       "\xF3\xB1\x88\xB4", NULL, 
       "nfs4_cis_prep",
       U_STRINGPREP_PROHIBITED_ERROR
     },
     {/*8*/
       "Plane 16 private use character U+10F234",
       "\xF4\x8F\x88\xB4", NULL, 
       "nfs4_cis_prep",
       U_STRINGPREP_PROHIBITED_ERROR
     },
     {/*9*/
       "Non-character code point U+8FFFE",
       "\xF2\x8F\xBF\xBE", NULL, 
       "nfs4_cis_prep",
       U_STRINGPREP_PROHIBITED_ERROR
     },
     {/*10*/
       "Non-character code point U+10FFFF",
       "\xF4\x8F\xBF\xBF", NULL,
       "nfs4_cis_prep", 
       U_STRINGPREP_PROHIBITED_ERROR 
     },
 /* 
     {
       "Surrogate code U+DF42",
       "\xED\xBD\x82", NULL, "nfs4_cis_prep", UIDNA_DEFAULT,
       U_STRINGPREP_PROHIBITED_ERROR
     },
*/
     {/*11*/
       "Non-plain text character U+FFFD",
       "\xEF\xBF\xBD", NULL, 
       "nfs4_cis_prep",
       U_STRINGPREP_PROHIBITED_ERROR
     },
     {/*12*/
       "Ideographic description character U+2FF5",
       "\xE2\xBF\xB5", NULL, 
       "nfs4_cis_prep", 
       U_STRINGPREP_PROHIBITED_ERROR
     },
     {/*13*/
       "Display property character U+0341",
       "\xCD\x81", "\xCC\x81",
       "nfs4_cis_prep", U_ZERO_ERROR

     },

     {/*14*/
       "Left-to-right mark U+200E",
       "\xE2\x80\x8E", "\xCC\x81", 
       "nfs4_cis_prep",
       U_STRINGPREP_PROHIBITED_ERROR
     },
     {/*15*/

       "Deprecated U+202A",
       "\xE2\x80\xAA", "\xCC\x81", 
       "nfs4_cis_prep", 
       U_STRINGPREP_PROHIBITED_ERROR
     },
     {/*16*/
       "Language tagging character U+E0001",
       "\xF3\xA0\x80\x81", "\xCC\x81", 
       "nfs4_cis_prep", 
       U_STRINGPREP_PROHIBITED_ERROR
     },
     {/*17*/
       "Language tagging character U+E0042",
       "\xF3\xA0\x81\x82", NULL, 
       "nfs4_cis_prep", 
       U_STRINGPREP_PROHIBITED_ERROR
     },
     {/*18*/
       "Bidi: RandALCat character U+05BE and LCat characters",
       "\x66\x6F\x6F\xD6\xBE\x62\x61\x72", NULL, 
       "nfs4_cis_prep", 
       U_STRINGPREP_CHECK_BIDI_ERROR
     },
     {/*19*/
       "Bidi: RandALCat character U+FD50 and LCat characters",
       "\x66\x6F\x6F\xEF\xB5\x90\x62\x61\x72", NULL,
       "nfs4_cis_prep",
       U_STRINGPREP_CHECK_BIDI_ERROR
     },
     {/*20*/
       "Bidi: RandALCat character U+FB38 and LCat characters",
       "\x66\x6F\x6F\xEF\xB9\xB6\x62\x61\x72", "\x66\x6F\x6F\x20\xd9\x8e\x62\x61\x72",
       "nfs4_cis_prep", 
       U_ZERO_ERROR
     },
     {/*21*/
       "Bidi: RandALCat without trailing RandALCat U+0627 U+0031",
       "\xD8\xA7\x31", NULL, 
       "nfs4_cis_prep", 
       U_STRINGPREP_CHECK_BIDI_ERROR
     },
     {/*22*/
       "Bidi: RandALCat character U+0627 U+0031 U+0628",
       "\xD8\xA7\x31\xD8\xA8", "\xD8\xA7\x31\xD8\xA8",
       "nfs4_cis_prep", 
       U_ZERO_ERROR
     },
     {/*23*/
       "Unassigned code point U+E0002",
       "\xF3\xA0\x80\x82", NULL, 
       "nfs4_cis_prep", 
       U_STRINGPREP_UNASSIGNED_ERROR
     },

/*  // Invalid UTF-8
     {
       "Larger test (shrinking)",
       "X\xC2\xAD\xC3\xDF\xC4\xB0\xE2\x84\xA1\x6a\xcc\x8c\xc2\xa0\xc2"
       "\xaa\xce\xb0\xe2\x80\x80", "xssi\xcc\x87""tel\xc7\xb0 a\xce\xb0 ",
       "nfs4_cis_prep",
        U_ZERO_ERROR
     },
    {

       "Larger test (expanding)",
       "X\xC3\xDF\xe3\x8c\x96\xC4\xB0\xE2\x84\xA1\xE2\x92\x9F\xE3\x8c\x80",
       "xss\xe3\x82\xad\xe3\x83\xad\xe3\x83\xa1\xe3\x83\xbc\xe3\x83\x88"
       "\xe3\x83\xab""i\xcc\x87""tel\x28""d\x29\xe3\x82\xa2\xe3\x83\x91"
       "\xe3\x83\xbc\xe3\x83\x88"
       "nfs4_cis_prep",
        U_ZERO_ERROR
     },
  */
};

#define MAX_BUFFER_SIZE  1000

static int32_t 
unescapeData(const char* src, int32_t srcLen, 
             char* dest, int32_t destCapacity, 
             UErrorCode* status){

    UChar b1Stack[MAX_BUFFER_SIZE];
    int32_t b1Capacity = MAX_BUFFER_SIZE,
            b1Len      = 0,
            destLen    = 0;

    UChar* b1 = b1Stack;

    b1Len = u_unescape(src,b1,b1Capacity);

    u_strToUTF8(dest, destCapacity, &destLen, b1, b1Len, status);

    return destLen;
}


static void Test_nfs4_cis_prep(void){
    int32_t i=0;

    for(i=0;i< (int32_t)(sizeof(conformanceTestCases)/sizeof(conformanceTestCases[0]));i++){
        const char* src = conformanceTestCases[i].in;
        UErrorCode status = U_ZERO_ERROR;
        UParseError parseError;
        UErrorCode expectedStatus = conformanceTestCases[i].expectedStatus;
        const char* expectedDest = conformanceTestCases[i].out;
        char* dest = NULL;
        int32_t destLen = 0;

        destLen = nfs4_cis_prepare(src , (int32_t)strlen(src), dest, destLen, &parseError, &status); 
        if(status == U_BUFFER_OVERFLOW_ERROR){
            status = U_ZERO_ERROR;
            dest = (char*) malloc(++destLen);
            destLen = nfs4_cis_prepare( src , (int32_t)strlen(src), dest, destLen, &parseError, &status); 
        }

        if(expectedStatus != status){
            log_err("Did not get the expected status for nfs4_cis_prep at index %i. Expected: %s Got: %s\n",i, u_errorName(expectedStatus), u_errorName(status));
        }
        if(U_SUCCESS(status) && (strcmp(expectedDest,dest) !=0)){
              log_err("Did not get the expected output for nfs4_cis_prep at index %i.\n", i);
        }
        free(dest);
    }
}



/*
   There are several special identifiers ("who") which need to be
   understood universally, rather than in the context of a particular
   DNS domain.  Some of these identifiers cannot be understood when an
   NFS client accesses the server, but have meaning when a local process
   accesses the file.  The ability to display and modify these
   permissions is permitted over NFS, even if none of the access methods
   on the server understands the identifiers.

    Who                    Description
   _______________________________________________________________

   "OWNER"                The owner of the file.
   "GROUP"                The group associated with the file.
   "EVERYONE"             The world.
   "INTERACTIVE"          Accessed from an interactive terminal.
   "NETWORK"              Accessed via the network.
   "DIALUP"               Accessed as a dialup user to the server.
   "BATCH"                Accessed from a batch job.
   "ANONYMOUS"            Accessed without any authentication.
   "AUTHENTICATED"        Any authenticated user (opposite of
                          ANONYMOUS)
   "SERVICE"              Access from a system service.

   To avoid conflict, these special identifiers are distinguish by an
   appended "@" and should appear in the form "xxxx@" (note: no domain
   name after the "@").  For example: ANONYMOUS@.
*/
static const char* mixed_prep_data[] ={
    "OWNER@",
    "GROUP@",        
    "EVERYONE@",     
    "INTERACTIVE@",  
    "NETWORK@",      
    "DIALUP@",       
    "BATCH@",        
    "ANONYMOUS@",    
    "AUTHENTICATED@",
    "\\u0930\\u094D\\u092E\\u094D\\u0915\\u094D\\u0937\\u0947\\u0924\\u094D@slip129-37-118-146.nc.us.ibm.net",
    "\\u0936\\u094d\\u0930\\u0940\\u092e\\u0926\\u094d@saratoga.pe.utexas.edu",
    "\\u092d\\u0917\\u0935\\u0926\\u094d\\u0917\\u0940\\u0924\\u093e@dial-120-45.ots.utexas.edu",
    "\\u0905\\u0927\\u094d\\u092f\\u093e\\u092f@woo-085.dorms.waller.net",
    "\\u0905\\u0930\\u094d\\u091c\\u0941\\u0928@hd30-049.hil.compuserve.com",
    "\\u0935\\u093f\\u0937\\u093e\\u0926@pem203-31.pe.ttu.edu",
    "\\u092f\\u094b\\u0917@56K-227.MaxTNT3.pdq.net",
    "\\u0927\\u0943\\u0924\\u0930\\u093e\\u0937\\u094d\\u091f\\u094d\\u0930@dial-36-2.ots.utexas.edu",
    "\\u0909\\u0935\\u093E\\u091A\\u0943@slip129-37-23-152.ga.us.ibm.net",
    "\\u0927\\u0930\\u094d\\u092e\\u0915\\u094d\\u0937\\u0947\\u0924\\u094d\\u0930\\u0947@ts45ip119.cadvision.com",
    "\\u0915\\u0941\\u0930\\u0941\\u0915\\u094d\\u0937\\u0947\\u0924\\u094d\\u0930\\u0947@sdn-ts-004txaustP05.dialsprint.net",
    "\\u0938\\u092e\\u0935\\u0947\\u0924\\u093e@bar-tnt1s66.erols.com",
    "\\u092f\\u0941\\u092f\\u0941\\u0924\\u094d\\u0938\\u0935\\u0903@101.st-louis-15.mo.dial-access.att.net",
    "\\u092e\\u093e\\u092e\\u0915\\u093e\\u0903@h92-245.Arco.COM",
    "\\u092a\\u093e\\u0923\\u094d\\u0921\\u0935\\u093e\\u0936\\u094d\\u091a\\u0948\\u0935@dial-13-2.ots.utexas.edu",
    "\\u0915\\u093f\\u092e\\u0915\\u0941\\u0930\\u094d\\u0935\\u0924@net-redynet29.datamarkets.com.ar",
    "\\u0938\\u0902\\u091c\\u0935@ccs-shiva28.reacciun.net.ve",
    "\\u0c30\\u0c18\\u0c41\\u0c30\\u0c3e\\u0c2e\\u0c4d@7.houston-11.tx.dial-access.att.net",
    "\\u0c35\\u0c3f\\u0c36\\u0c4d\\u0c35\\u0c28\\u0c3e\\u0c27@ingw129-37-120-26.mo.us.ibm.net",
    "\\u0c06\\u0c28\\u0c02\\u0c26\\u0c4d@dialup6.austintx.com",
    "\\u0C35\\u0C26\\u0C4D\\u0C26\\u0C3F\\u0C30\\u0C3E\\u0C1C\\u0C41@dns2.tpao.gov.tr",
    "\\u0c30\\u0c3e\\u0c1c\\u0c40\\u0c35\\u0c4d@slip129-37-119-194.nc.us.ibm.net",
    "\\u0c15\\u0c36\\u0c30\\u0c2c\\u0c3e\\u0c26@cs7.dillons.co.uk.203.119.193.in-addr.arpa",
    "\\u0c38\\u0c02\\u0c1c\\u0c40\\u0c35\\u0c4d@swprd1.innovplace.saskatoon.sk.ca",
    "\\u0c15\\u0c36\\u0c30\\u0c2c\\u0c3e\\u0c26@bikini.bologna.maraut.it",
    "\\u0c38\\u0c02\\u0c1c\\u0c40\\u0c2c\\u0c4d@node91.subnet159-198-79.baxter.com",
    "\\u0c38\\u0c46\\u0c28\\u0c4d\\u0c17\\u0c41\\u0c2a\\u0c4d\\u0c24@cust19.max5.new-york.ny.ms.uu.net",
    "\\u0c05\\u0c2e\\u0c30\\u0c47\\u0c02\\u0c26\\u0c4d\\u0c30@balexander.slip.andrew.cmu.edu",
    "\\u0c39\\u0c28\\u0c41\\u0c2e\\u0c3e\\u0c28\\u0c41\\u0c32@pool029.max2.denver.co.dynip.alter.net",
    "\\u0c30\\u0c35\\u0c3f@cust49.max9.new-york.ny.ms.uu.net",
    "\\u0c15\\u0c41\\u0c2e\\u0c3e\\u0c30\\u0c4d@s61.abq-dialin2.hollyberry.com",
    "\\u0c35\\u0c3f\\u0c36\\u0c4d\\u0c35\\u0c28\\u0c3e\\u0c27@\\u0917\\u0928\\u0947\\u0936.sanjose.ibm.com",
    "\\u0c06\\u0c26\\u0c3f\\u0c24\\u0c4d\\u0c2f@www.\\u00E0\\u00B3\\u00AF.com",
    "\\u0C15\\u0C02\\u0C26\\u0C4D\\u0C30\\u0C47\\u0C17\\u0C41\\u0c32@www.\\u00C2\\u00A4.com",
    "\\u0c36\\u0c4d\\u0c30\\u0c40\\u0C27\\u0C30\\u0C4D@www.\\u00C2\\u00A3.com",
    "\\u0c15\\u0c02\\u0c1f\\u0c2e\\u0c36\\u0c46\\u0c1f\\u0c4d\\u0c1f\\u0c3f@\\u0025",
    "\\u0c2e\\u0c3e\\u0c27\\u0c35\\u0c4d@\\u005C\\u005C",
    "\\u0c26\\u0c46\\u0c36\\u0c46\\u0c1f\\u0c4d\\u0c1f\\u0c3f@www.\\u0021.com",
    "test@www.\\u0024.com",
    "help@\\u00C3\\u00BC.com",

};


static void 
Test_nfs4_mixed_prep(void){
    {
        int32_t i=0;
        char src[MAX_BUFFER_SIZE];
        int32_t srcLen;

        for(i=0; i< LENGTHOF(mixed_prep_data); i++){
            int32_t destLen=0;
            char* dest = NULL;
            UErrorCode status = U_ZERO_ERROR;
            UParseError parseError;
            srcLen = unescapeData(mixed_prep_data[i], (int32_t)strlen(mixed_prep_data[i]), src, MAX_BUFFER_SIZE, &status);
            if(U_FAILURE(status)){
                log_err("Conversion of data at index %i failed. Error: %s\n", i, u_errorName(status));
                continue;
            }
            destLen = nfs4_mixed_prepare(src, srcLen, NULL, 0, &parseError, &status);
            if(status == U_BUFFER_OVERFLOW_ERROR){
                status = U_ZERO_ERROR;
                dest = (char*)malloc(++destLen);
                destLen = nfs4_mixed_prepare(src, srcLen, dest, destLen, &parseError, &status);
            }
            free(dest);
            if(U_FAILURE(status)){
                log_err("Preparation of string at index %i failed. Error: %s\n", i, u_errorName(status));
                continue;
            }
        } 
    }
    /* test the error condition */
    {
        const char* source = "OWNER@oss.software.ibm.com";
        char dest[MAX_BUFFER_SIZE];
        char src[MAX_BUFFER_SIZE] = {0};
        UErrorCode status = U_ZERO_ERROR;
        UParseError parseError;
        
        int32_t srcLen = unescapeData(source, (int32_t)strlen(source), src, MAX_BUFFER_SIZE, &status);

        nfs4_mixed_prepare(src, srcLen, dest, MAX_BUFFER_SIZE, &parseError, &status);

        if(status != U_PARSE_ERROR){
            log_err("Did not get the expected error.Expected: %s Got: %s\n", u_errorName(U_PARSE_ERROR), u_errorName(status));
        }
    }


}

static void 
Test_nfs4_cs_prep(void){
    {
        /* BiDi checking is turned off */
        const char *source = "\\uC138\\uACC4\\uC758\\uBAA8\\uB4E0\\uC0AC\\uB78C\\uB4E4\\uC774\\u0644\\u064A\\u0647\\uD55C\\uAD6D\\uC5B4\\uB97C\\uC774\\uD574\\uD55C\\uB2E4\\uBA74";
        UErrorCode status = U_ZERO_ERROR;
        char src[MAX_BUFFER_SIZE]={'\0'};
        UParseError parseError;
        int32_t srcLen = unescapeData(source, (int32_t)strlen(source), src, MAX_BUFFER_SIZE, &status);
        if(U_SUCCESS(status)){
            char dest[MAX_BUFFER_SIZE] = {'\0'};
            int32_t destLen = nfs4_cs_prepare(src, srcLen, dest, MAX_BUFFER_SIZE, FALSE, &parseError, &status);
            if(U_FAILURE(status)){
                log_err("StringPrep failed for case: BiDi Checking Turned OFF with error: %s\n", u_errorName(status));
            }
            if(strcmp(dest,src)!=0){
                log_err("Did not get the expected output for case: BiDi Checking Turned OFF\n");
            }
            if(destLen != srcLen){
                log_err("Did not get the expected length for the output for case: BiDi Checking Turned OFF. Expected: %i Got: %i\n", srcLen, destLen);
            }
        }else{
            log_err("Conversion failed for case: BiDi Checking Turned OFF with error: %s\n", u_errorName(status));
        }
    }
    {
        /* Normalization turned off */
        const char *source = "www.\\u00E0\\u00B3\\u00AF.com";
        UErrorCode status = U_ZERO_ERROR;
        char src[MAX_BUFFER_SIZE]={'\0'};
        UParseError parseError;
        int32_t srcLen = unescapeData(source, (int32_t)strlen(source), src, MAX_BUFFER_SIZE, &status);
        if(U_SUCCESS(status)){
            char dest[MAX_BUFFER_SIZE] = {'\0'};
            int32_t destLen = nfs4_cs_prepare(src, srcLen, dest, MAX_BUFFER_SIZE, FALSE, &parseError, &status);
            if(U_FAILURE(status)){
                log_err("StringPrep failed for case: Normalization Turned OFF with error: %s\n", u_errorName(status));
            }
            if(strcmp(dest,src)!=0){
                log_err("Did not get the expected output for case: Normalization Turned OFF\n");
            }
            if(destLen != srcLen){
                log_err("Did not get the expected length for the output for case: Normalization Turned OFF. Expected: %i Got: %i\n", srcLen, destLen);
            }
        }else{
            log_err("Conversion failed for case: Normalization Turned OFF with error: %s\n", u_errorName(status));
        }
    }
    {
        /* case mapping turned off */
        const char *source = "THISISATEST";
        UErrorCode status = U_ZERO_ERROR;
        char src[MAX_BUFFER_SIZE]={'\0'};
        UParseError parseError;
        int32_t srcLen = unescapeData(source, (int32_t)strlen(source), src, MAX_BUFFER_SIZE, &status);
        if(U_SUCCESS(status)){
            char dest[MAX_BUFFER_SIZE] = {'\0'};
            int32_t destLen = nfs4_cs_prepare(src, srcLen, dest, MAX_BUFFER_SIZE, TRUE, &parseError, &status);
            if(U_FAILURE(status)){
                log_err("StringPrep failed for case: Case Mapping Turned OFF with error: %s\n", u_errorName(status));
            }
            if(strcmp(dest,src)!=0){
                log_err("Did not get the expected output for case: Case Mapping Turned OFF\n");
            }
            if(destLen != srcLen){
                log_err("Did not get the expected length for the output for case: Case Mapping Turned OFF. Expected: %i Got: %i\n", srcLen, destLen);
            }
        }else{
            log_err("Conversion failed for case: Case Mapping Turned OFF with error: %s\n", u_errorName(status));
        }
    }
    {
        /* case mapping turned on */
        const char *source = "THISISATEST";
        const char *expected = "thisisatest";
        UErrorCode status = U_ZERO_ERROR;
        char src[MAX_BUFFER_SIZE]={'\0'};
        char exp[MAX_BUFFER_SIZE]={'\0'};
        UParseError parseError;
        int32_t srcLen = unescapeData(source, (int32_t)strlen(source), src, MAX_BUFFER_SIZE, &status);
        int32_t expLen = unescapeData(expected, (int32_t)strlen(expected), exp, MAX_BUFFER_SIZE, &status);
        if(U_SUCCESS(status)){
            char dest[MAX_BUFFER_SIZE] = {'\0'};
            int32_t destLen = nfs4_cs_prepare(src, srcLen, dest, MAX_BUFFER_SIZE, FALSE, &parseError, &status);
            if(U_FAILURE(status)){
                log_err("StringPrep failed for case: Case Mapping Turned On with error: %s\n", u_errorName(status));
            }
            if(strcmp(exp, dest)!=0){
                log_err("Did not get the expected output for case: Case Mapping Turned On!\n");
            }
            if(destLen != expLen){
                log_err("Did not get the expected length for the outputfor case: Case Mapping Turned On. Expected: %i Got: %i\n", strlen(expected), destLen);
            }
        }else{
            log_err("Conversion failed for case: Case Mapping Turned ON with error: %s\n", u_errorName(status));
        }
    }
}

#endif

/*
 * Hey, Emacs, please set the following:
 *
 * Local Variables:
 * indent-tabs-mode: nil
 * End:
 *
 */

--- NEW FILE: sprpdata.c ---
/*
 *******************************************************************************
 *
 *   Copyright (C) 2003, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
 *   file name:  spreptst.c
 *   encoding:   US-ASCII
 *   tab size:   8 (not used)
 *   indentation:4
 *
 *   created on: 2003jul11
 *   created by: Ram Viswanadha
 */
#define USPREP_TYPE_NAMES_ARRAY

#include "unicode/utypes.h"

#if !UCONFIG_NO_IDNA

#include "unicode/ustring.h"
#include "cintltst.h"
#include "unicode/usprep.h"
#include "sprpimpl.h"
#include "uparse.h"
#include "cmemory.h"
#include "ustr_imp.h"
#include "cstring.h"

static void
parseMappings(const char *filename, UStringPrepProfile* data, UBool reportError, UErrorCode *pErrorCode);

static void
compareMapping(UStringPrepProfile* data, uint32_t codepoint, uint32_t* mapping, int32_t mapLength,
               UStringPrepType option);

static void
compareFlagsForRange(UStringPrepProfile* data, uint32_t start, uint32_t end,UStringPrepType option);

void
doStringPrepTest(const char* binFileName, const char* txtFileName, int32_t options, UErrorCode* errorCode);

static void U_CALLCONV
strprepProfileLineFn(void *context,
              char *fields[][2], int32_t fieldCount,
              UErrorCode *pErrorCode) {
    uint32_t mapping[40];
    char *end, *map;
    uint32_t code;
    int32_t length;
    UStringPrepProfile* data = (UStringPrepProfile*) context;
    const char* typeName;
    uint32_t rangeStart=0,rangeEnd =0;

    typeName = fields[2][0];
    map = fields[1][0];

    if(strstr(typeName, usprepTypeNames[USPREP_UNASSIGNED])!=NULL){

        u_parseCodePointRange(fields[0][0], &rangeStart,&rangeEnd, pErrorCode);

        /* store the range */
        compareFlagsForRange(data, rangeStart,rangeEnd,USPREP_UNASSIGNED);

    }else if(strstr(typeName, usprepTypeNames[USPREP_PROHIBITED])!=NULL){

        u_parseCodePointRange(fields[0][0], &rangeStart,&rangeEnd, pErrorCode);

        /* store the range */
        compareFlagsForRange(data, rangeStart,rangeEnd,USPREP_PROHIBITED);

    }else if(strstr(typeName, usprepTypeNames[USPREP_MAP])!=NULL){
        /* get the character code, field 0 */
        code=(uint32_t)uprv_strtoul(fields[0][0], &end, 16);

        /* parse the mapping string */
        length=u_parseCodePoints(map, mapping, sizeof(mapping)/4, pErrorCode);

        /* compare the mapping */
        compareMapping(data, code,mapping, length,USPREP_MAP);
    }else{
        *pErrorCode = U_INVALID_FORMAT_ERROR;
    }

}



static void
parseMappings(const char *filename, UStringPrepProfile* data, UBool reportError, UErrorCode *pErrorCode) {
    char *fields[3][2];

    if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
        return;
    }

    u_parseDelimitedFile(filename, ';', fields, 3, strprepProfileLineFn, (void*)data, pErrorCode);

    /*fprintf(stdout,"Number of code points that have mappings with length >1 : %i\n",len);*/

    if(U_FAILURE(*pErrorCode) && (reportError || *pErrorCode!=U_FILE_ACCESS_ERROR)) {
        log_err( "testidn error: u_parseDelimitedFile(\"%s\") failed - %s\n", filename, u_errorName(*pErrorCode));
    }
}


static UStringPrepType
getValues(uint32_t result, int32_t* value, UBool* isIndex){

    UStringPrepType type;
    if(result == 0){
        /*
         * Initial value stored in the mapping table
         * just return USPREP_TYPE_LIMIT .. so that
         * the source codepoint is copied to the destination
         */
        type = USPREP_TYPE_LIMIT;
    }else if(result >= _SPREP_TYPE_THRESHOLD){
        type = (UStringPrepType) (result - _SPREP_TYPE_THRESHOLD);
    }else{
        /* get the type */
        type = USPREP_MAP;
        /* ascertain if the value is index or delta */
        if(result & 0x02){
            *isIndex = TRUE;
            *value = result  >> 2;

        }else{
            *isIndex = FALSE;
            *value = (int16_t)result;
            *value =  (*value >> 2);

        }
        if((result>>2) == _SPREP_MAX_INDEX_VALUE){
            type = USPREP_DELETE;
            isIndex =FALSE;
            value = 0;
        }
    }
    return type;
}

static void
compareMapping(UStringPrepProfile* data, uint32_t codepoint, uint32_t* mapping,int32_t mapLength,
               UStringPrepType type){
    uint32_t result = 0;
    int32_t length=0;
    UBool isIndex = FALSE;
    UStringPrepType retType;
    int32_t value=0, index=0, delta=0;
    int32_t* indexes = data->indexes;
    UTrie trie = data->sprepTrie;
    const uint16_t* mappingData = data->mappingData;
    int32_t realLength =0;
    int32_t j=0;
    int8_t i=0;

    UTRIE_GET16(&trie, codepoint, result);
    retType = getValues(result,&value,&isIndex);


    if(type != retType && retType != USPREP_DELETE){

        log_err( "Did not get the assigned type for codepoint 0x%08X. Expected: %i Got: %i\n",codepoint, USPREP_MAP, type);

    }

    if(isIndex){
        index = value;
        if(index >= indexes[_SPREP_ONE_UCHAR_MAPPING_INDEX_START] &&
                 index < indexes[_SPREP_TWO_UCHARS_MAPPING_INDEX_START]){
            length = 1;
        }else if(index >= indexes[_SPREP_TWO_UCHARS_MAPPING_INDEX_START] &&
                 index < indexes[_SPREP_THREE_UCHARS_MAPPING_INDEX_START]){
            length = 2;
        }else if(index >= indexes[_SPREP_THREE_UCHARS_MAPPING_INDEX_START] &&
                 index < indexes[_SPREP_FOUR_UCHARS_MAPPING_INDEX_START]){
            length = 3;
        }else{
            length = mappingData[index++];
        }
    }else{
        delta = value;
        length = (retType == USPREP_DELETE)? 0 :  1;
    }

    /* figure out the real length */
    for(j=0; j<mapLength; j++){
        if(mapping[j] > 0xFFFF){
            realLength +=2;
        }else{
            realLength++;
        }
    }

    if(realLength != length){
        log_err( "Did not get the expected length. Expected: %i Got: %i\n", mapLength, length);
    }

    if(isIndex){
        for(i =0; i< mapLength; i++){
            if(mapping[i] <= 0xFFFF){
                if(mappingData[index+i] != (uint16_t)mapping[i]){
                    log_err("Did not get the expected result. Expected: 0x%04X Got: 0x%04X \n", mapping[i], mappingData[index+i]);
                }
            }else{
                UChar lead  = UTF16_LEAD(mapping[i]);
                UChar trail = UTF16_TRAIL(mapping[i]);
                if(mappingData[index+i] != lead ||
                    mappingData[index+i+1] != trail){
                    log_err( "Did not get the expected result. Expected: 0x%04X 0x%04X  Got: 0x%04X 0x%04X\n", lead, trail, mappingData[index+i], mappingData[index+i+1]);
                }
            }
        }
    }else{
        if(retType!=USPREP_DELETE && (codepoint-delta) != (uint16_t)mapping[0]){
           log_err("Did not get the expected result. Expected: 0x%04X Got: 0x%04X \n", mapping[0],(codepoint-delta));
        }
    }

}

static void
compareFlagsForRange(UStringPrepProfile* data,
                     uint32_t start, uint32_t end,
                     UStringPrepType type){

    uint32_t result =0 ;
    UStringPrepType retType;
    UBool isIndex=FALSE;
    int32_t value=0;
    UTrie trie = data->sprepTrie;
/*
    // supplementary code point
    UChar __lead16=UTF16_LEAD(0x2323E);
    int32_t __offset;

    // get data for lead surrogate
    (result)=_UTRIE_GET_RAW((&idnTrie), index, 0, (__lead16));
    __offset=(&idnTrie)->getFoldingOffset(result);

    // get the real data from the folded lead/trail units
    if(__offset>0) {
        (result)=_UTRIE_GET_RAW((&idnTrie), index, __offset, (0x2323E)&0x3ff);
    } else {
        (result)=(uint32_t)((&idnTrie)->initialValue);
    }

    UTRIE_GET16(&idnTrie,0x2323E, result);
*/
    while(start < end+1){
        UTRIE_GET16(&trie,start, result);
        retType = getValues(result, &value, &isIndex);
        if(result > _SPREP_TYPE_THRESHOLD){
            if(retType != type){
                log_err( "FAIL: Did not get the expected type for 0x%06X. Expected: %s Got: %s\n",start,usprepTypeNames[type], usprepTypeNames[retType]);
            }
        }else{
            if(type == USPREP_PROHIBITED && ((result & 0x01) != 0x01)){
                log_err( "FAIL: Did not get the expected type for 0x%06X. Expected: %s Got: %s\n",start,usprepTypeNames[type], usprepTypeNames[retType]);
            }
        }

        start++;
    }

}

void
doStringPrepTest(const char* binFileName, const char* txtFileName, int32_t options, UErrorCode* errorCode){

    const char *testdatapath = loadTestData(errorCode);
    const char *srcdatapath =ctest_dataOutDir();

    const char *relativepath = ".."U_FILE_SEP_STRING".."U_FILE_SEP_STRING"test"U_FILE_SEP_STRING"testdata"U_FILE_SEP_STRING;
    char *filename = (char*) malloc(strlen(srcdatapath)+strlen(relativepath)+strlen(txtFileName)+10 );
    UStringPrepProfile* profile = usprep_open(testdatapath, binFileName, errorCode);

    if(U_FAILURE(*errorCode)){
        log_err("Failed to load %s data file. Error: %s \n", binFileName, u_errorName(*errorCode));
        return;
    }
    /* open and load the txt file */
    strcpy(filename,srcdatapath);
    strcat(filename,relativepath);
    strcat(filename,txtFileName);

    parseMappings(filename,profile, TRUE,errorCode);

    free(filename);
}
#endif
/*
 * Hey, Emacs, please set the following:
 *
 * Local Variables:
 * indent-tabs-mode: nil
 * End:
 *
 */

--- NEW FILE: tracetst.c ---
/********************************************************************
 * COPYRIGHT: 
 * Copyright (c) 2003, International Business Machines Corporation and
 * others. All Rights Reserved.
 ********************************************************************/
/*
 * File tracetst.c
 *
 */


#include "unicode/utypes.h"
#include "unicode/utrace.h"
#include "unicode/uclean.h"
#include "unicode/uchar.h"
#include "unicode/ures.h"
#include "unicode/ucnv.h"
#include "cintltst.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "utracimp.h"


static void TestTraceAPI(void);


void
addUTraceTest(TestNode** root);

void
addUTraceTest(TestNode** root)
{
    addTest(root, &TestTraceAPI,            "tsutil/TraceTest/TestTraceAPI"  );
}


/*
 * Macro for assert style tests.
 */
#define TEST_ASSERT(expr) \
if (!(expr)) { \
    log_err("FAILED Assertion \"" #expr "\" at  %s:%d.\n", __FILE__, __LINE__); \
}


/*
 *  test_format.   Helper function for checking the results of a formatting
 *                 operation.  Executes the format op and compares actual 
 *                 results with the expected results.
 *                 
 *       params:   format:  the format to be applied.
 *                 bufCap   buffer size to pass to formatter.
 *                 indent:  indent value to give to formatter
 *                 result   expected result.  Do not truncate for short bufCap -
 *                          this function will do it.
 *                 line     __LINE__, so we can report where failure happened.
 *                 ...      variable args to pass to formatter
 *
 */
static void test_format(const char *format, int32_t bufCap, int32_t indent, 
                        const char *result, int32_t line, ...) {
    int32_t  len;
    va_list  args;
    char  buf[300];
    char  expectedResult[300];

    /* check that local buffers are big enough for the test case */
    if (sizeof(buf) <= bufCap) {
        log_err("At file:line %s:%d, requested bufCap too large.\n");
        return;
    }
    if (strlen(result) >= sizeof(expectedResult)) {
        log_err("At file:line %s:%d, expected result too large.\n");
        return;
    }

   /* Guarantee a nul term if buffer is smaller than output */
    strcpy(expectedResult, result);
    expectedResult[bufCap] = 0;

    /* run the formatter */
    va_start(args, line);
    memset(buf, 0, sizeof(buf));
    len = utrace_vformat(buf, bufCap, indent, format, args);

    /* Check results.   */
    if (strcmp(expectedResult, buf) != 0) {
        log_err("At file:line %s:%d  Expected \"%s\", got \"%s\"  \n",
             __FILE__, line, expectedResult, buf);
    }
    va_end(args);
}


/*
 *  define trace functions for use in this test.
 */
static int    gTraceEntryCount;
static int    gTraceExitCount;
static int    gTraceDataCount;
static UBool  gFnNameError   = FALSE;
static UBool  gFnFormatError = FALSE;

static void testTraceEntry(const void *context, int32_t fnNumber) {
    const char *fnName;
    const char *bogusFnName;

    gTraceEntryCount++;

    /* Verify that a name is available for the fnNumber passed to us */
    bogusFnName = utrace_functionName(-1);
    fnName = utrace_functionName(fnNumber);
    if (strcmp(fnName, bogusFnName) == 0) {
        gFnNameError = TRUE;
    }
    /* printf("%s() Enter\n", fnName); */

}

static void testTraceExit(const void *context, int32_t fnNumber,
                   const char *fmt, va_list args) {
    char        buf[1000];
    const char *fnName;
    const char *bogusFnName;

    gTraceExitCount++;
   
    /* Verify that a name is available for the fnNumber passed to us */
    bogusFnName = utrace_functionName(-1);
    fnName = utrace_functionName(fnNumber);
    if (strcmp(fnName, bogusFnName) == 0) {
        gFnNameError = TRUE;
    }

    /* Verify that the format can be used.  */
    buf[0] = 0;
    utrace_vformat(buf, sizeof(buf), 0, fmt, args);
    if (strlen(buf) == 0) {
        gFnFormatError = TRUE;
    }

    /* printf("%s() %s\n", fnName, buf); */

}

static void testTraceData(const void *context, int32_t fnNumber, int32_t level,
                   const char *fmt, va_list args) {
    char        buf[1000];
    const char *fnName;
    const char *bogusFnName;

    gTraceDataCount++;

    /* Verify that a name is available for the fnNumber passed to us */
    bogusFnName = utrace_functionName(-1);
    fnName = utrace_functionName(fnNumber);
    if (strcmp(fnName, bogusFnName) == 0) {
        gFnNameError = TRUE;
    }

    /* Verify that the format can be used.  */
    buf[0] = 0;
    utrace_vformat(buf, sizeof(buf), 0, fmt, args);
    if (strlen(buf) == 0) {
        gFnFormatError = TRUE;
    }

    /* printf("  %s()   %s\n", fnName, buf); */
}


/*
 *   TestTraceAPI
 */
static void TestTraceAPI() {


    UTraceEntry   *originalTEntryFunc;
    UTraceExit    *originalTExitFunc;
    UTraceData    *originalTDataFunc;
    const void    *originalTContext;
    int32_t        originalLevel;

    /*
     * Save the original tracing state so that we can restore it after the test.
     */
    utrace_getFunctions(&originalTContext, &originalTEntryFunc, &originalTExitFunc,
                        &originalTDataFunc);
    originalLevel = utrace_getLevel();


    /* verify that set/get of tracing functions returns what was set.  */
    {
        UTraceEntry *e;
        UTraceExit  *x;
        UTraceData  *d;
        const void  *context;
        const void  *newContext = (const char *)originalTContext + 1;
        
        TEST_ASSERT(originalTEntryFunc != testTraceEntry);
        TEST_ASSERT(originalTExitFunc != testTraceExit);
        TEST_ASSERT(originalTDataFunc != testTraceData);
        
        utrace_setFunctions(newContext, testTraceEntry, testTraceExit, testTraceData);
        utrace_getFunctions(&context, &e, &x, &d);
        TEST_ASSERT(e == testTraceEntry);
        TEST_ASSERT(x == testTraceExit);
        TEST_ASSERT(d == testTraceData);
        TEST_ASSERT(context == newContext);
    }

    /* verify that set/get level work as a pair, and that the level
     * identifiers all exist.
     */

    {
        int32_t  level;

        utrace_setLevel(UTRACE_OFF);
        level = utrace_getLevel();
        TEST_ASSERT(level==UTRACE_OFF);
        utrace_setLevel(UTRACE_VERBOSE);
        level = utrace_getLevel();
        TEST_ASSERT(level==UTRACE_VERBOSE);
        utrace_setLevel(UTRACE_ERROR);
        utrace_setLevel(UTRACE_WARNING);
        utrace_setLevel(UTRACE_OPEN_CLOSE);
        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;
        gFnNameError     = FALSE;
        gFnFormatError   = FALSE;
        utrace_setLevel(UTRACE_OPEN_CLOSE);
        cnv = ucnv_open(NULL, &status);
        TEST_ASSERT(U_SUCCESS(status));
        ucnv_close(cnv);
#if U_ENABLE_TRACING
        TEST_ASSERT(gTraceEntryCount > 0);
        TEST_ASSERT(gTraceExitCount  > 0);
        TEST_ASSERT(gTraceDataCount  > 0);
        TEST_ASSERT(gFnNameError   == FALSE);
        TEST_ASSERT(gFnFormatError == FALSE);
#else
        log_info("Tracing has been disabled. Testing of this feature has been skipped.\n");
#endif
    }



    /*
     * trace data formatter operation.
     */
    {
        UChar s1[] = {0x41fe, 0x42, 0x43, 00};
        const char  *a1[] = {"s1", "s2", "s3"};
        void  *ptr;

        test_format("hello, world", 50, 0, "hello, world", __LINE__);
        test_format("hello, world", 50, 4, "    hello, world", __LINE__);
        test_format("hello, world", 3, 0,  "hello, world", __LINE__);

        test_format("a character %c", 50, 0, "a character x", __LINE__, 'x');
        test_format("a string %s ", 50, 0, "a string hello ", __LINE__, "hello");
        test_format("uchars %S ", 50, 0, "uchars 41fe 0042 0043 0000  ", __LINE__, s1, -1); 
        test_format("uchars %S ", 50, 0, "uchars 41fe 0042  ", __LINE__, s1, 2); 

        test_format("a byte %b--", 50, 0, "a byte dd--", __LINE__, 0xdd);
        test_format("a 16 bit val %h", 50, 0, "a 16 bit val 1234", __LINE__, 0x1234);
        test_format("a 32 bit val %d...", 50, 0, "a 32 bit val 6789abcd...", __LINE__, 0x6789abcd);
        test_format("a 64 bit val %l", 50, 0, "a 64 bit val 123456780abcdef0"
            , __LINE__, INT64_C(0x123456780abcdef0));

        if (sizeof(void *) == 4) {
            ptr = (void *)0xdeadbeef;
            test_format("a 32 bit ptr %p", 50, 0, "a 32 bit ptr deadbeef", __LINE__, ptr);
        } else if (sizeof(void *) == 8) {
            ptr = (void *) INT64_C(0x1000200030004000);
            test_format("a 64 bit ptr %p", 50, 0, "a 64 bit ptr 1000200030004000", __LINE__, ptr);
        } else if (sizeof(void *) == 16) {
            /* iSeries */
            int32_t massiveBigEndianPtr[] = { 0x10002000, 0x30004000, 0x50006000, 0x70008000 };
            ptr = *((void **)massiveBigEndianPtr);
            test_format("a 128 bit ptr %p", 50, 0, "a 128 bit ptr 10002000300040005000600070008000", __LINE__, ptr);
        } else {
            TEST_ASSERT(FALSE);
            /*  TODO:  others? */
        }

        test_format("%vc", 100, 0, "abc[ffffffff]", __LINE__, "abc", -1);
        test_format("%vs", 100, 0, "s1\ns2\n[00000002]", __LINE__, a1, 2);
        test_format("%vs", 100, 4, "    s1\n    s2\n    [00000002]", __LINE__, a1, 2);

        test_format("%vb", 100, 0, "41 42 43 [00000003]", __LINE__, "\x41\x42\x43", 3);

        /* Null ptrs for strings, vectors  */
        test_format("Null string - %s", 50, 0, "Null string - *NULL*", __LINE__, NULL);
        test_format("Null string - %S", 50, 0, "Null string - *NULL*", __LINE__, NULL);
        test_format("Null vector - %vc", 50, 0, "Null vector - *NULL* [00000002]", __LINE__, NULL, 2);
        test_format("Null vector - %vC", 50, 0, "Null vector - *NULL* [00000002]", __LINE__, NULL, 2);
        test_format("Null vector - %vd", 50, 0, "Null vector - *NULL* [00000002]", __LINE__, NULL, 2);

    }

    /*
     * 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);
    utrace_setLevel(originalLevel);
}




Index: Makefile.in
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/Makefile.in,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- Makefile.in	10 Sep 2003 02:42:33 -0000	1.4
+++ Makefile.in	6 Apr 2004 10:09:22 -0000	1.5
@@ -46,7 +46,8 @@
 cucdapi.o cucdtst.o custrtst.o cstrcase.o cutiltst.o encoll.o nucnvtst.o nccbtst.o bocu1tst.o \
 cbiditst.o cbididat.o eurocreg.o udatatst.o utf16tst.o utransts.o \
 ncnvfbts.o ncnvtst.o putiltst.o cstrtest.o mstrmtst.o utf8tst.o ucmptst.o \
-stdnmtst.o ctstdep.o usrchtst.o custrtrn.o trietest.o usettest.o uenumtst.o
+stdnmtst.o ctstdep.o usrchtst.o custrtrn.o sorttest.o trietest.o usettest.o uenumtst.o \
+idnatest.o nfsprep.o spreptst.o sprpdata.o hpmufn.o tracetst.o
 
 DEPS = $(OBJECTS:.o=.d)
 
@@ -81,7 +82,7 @@
 -include Makefile.local
 
 check-local: all-local
-	TZ=PST8PDT $(INVOKE) ./$(TARGET) $(CINTLTST_OPTS)
+	$(INVOKE) ./$(TARGET) $(CINTLTST_OPTS)
 
 Makefile: $(srcdir)/Makefile.in  $(top_builddir)/config.status
 	cd $(top_builddir) \

Index: bocu1tst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/bocu1tst.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- bocu1tst.c	10 Sep 2003 02:42:33 -0000	1.1
+++ bocu1tst.c	6 Apr 2004 10:09:22 -0000	1.2
@@ -1,7 +1,7 @@
 /*
 ******************************************************************************
 *
-*   Copyright (C) 2002, International Business Machines
+*   Copyright (C) 2002-2003, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 ******************************************************************************
@@ -66,7 +66,9 @@
 #define BOCU1_MIN               0x21
 #define BOCU1_MIDDLE            0x90
 #define BOCU1_MAX_LEAD          0xfe
-#define BOCU1_MAX_TRAIL         0xff
+
+/* add the L suffix to make computations with BOCU1_MAX_TRAIL work on 16-bit compilers */
+#define BOCU1_MAX_TRAIL         0xffL
 #define BOCU1_RESET             0xff
 
 /* number of lead bytes */
@@ -258,8 +260,8 @@
         /* CJK Unihan */
         return 0x4e00-BOCU1_REACH_NEG_2;
     } else if(0xac00<=c && c<=0xd7a3) {
-        /* Korean Hangul */
-        return (0xd7a3+0xac00)/2;
+        /* Korean Hangul (cast to int32_t to avoid wraparound on 16-bit compilers) */
+        return ((int32_t)0xd7a3+(int32_t)0xac00)/2;
     } else {
         /* mostly small scripts */
         return (c&~0x7f)+BOCU1_ASCII_PREV;

Index: callcoll.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/callcoll.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- callcoll.c	10 Sep 2003 02:42:33 -0000	1.4
+++ callcoll.c	6 Apr 2004 10:09:23 -0000	1.5
@@ -40,6 +40,7 @@
 #include "unicode/uloc.h"
 #include "unicode/ucoleitr.h"
 #include "unicode/ustring.h"
+#include "unicode/uclean.h"
 
 #include "cintltst.h"
 #include "ccolltst.h"
@@ -80,6 +81,8 @@
 
 static void TestJitterbug1098(void);
 
+static void TestFCDCrash(void);
+
 const UCollationResult results[] = {
     UCOL_LESS,
     UCOL_LESS, /*UCOL_GREATER,*/
@@ -137,16 +140,38 @@
     addTest(root, &TestSurrogates, "tscoll/callcoll/TestSurrogates");
     addTest(root, &TestInvalidRules, "tscoll/callcoll/TestInvalidRules");
     addTest(root, &TestJB1401, "tscoll/callcoll/TestJB1401");      
-    addTest(root, &TestJitterbug1098, "tscoll/callcoll/TestJitterbug1098");      
+    addTest(root, &TestJitterbug1098, "tscoll/callcoll/TestJitterbug1098");     
+    addTest(root, &TestFCDCrash, "tscoll/callcoll/TestFCDCrash");
 
    }
 
+UBool hasCollationElements(const char *locName) {
+
+  UErrorCode status = U_ZERO_ERROR;
+  UResourceBundle *ColEl = NULL;
+
+  UResourceBundle *loc = ures_open(NULL, locName, &status);;
+
+  if(U_SUCCESS(status)) {
+    status = U_ZERO_ERROR;
+    ColEl = ures_getByKey(loc, "collations", ColEl, &status);
+    if(status == U_ZERO_ERROR) { /* do the test - there are real elements */
+      ures_close(ColEl);
+      ures_close(loc);
+      return TRUE;
+    }
+    ures_close(ColEl);
+    ures_close(loc);
+  }
+  return FALSE;
+}
+
 static UCollationResult compareUsingPartials(UCollator *coll, const UChar source[], int32_t sLen, const UChar target[], int32_t tLen, int32_t pieceSize, UErrorCode *status) {
   int32_t partialSKResult = 0;
   UCharIterator sIter, tIter;
   uint32_t sState[2], tState[2];
   int32_t sSize = pieceSize, tSize = pieceSize;
-  int32_t i = 0;
+  /*int32_t i = 0;*/
   uint8_t sBuf[16384], tBuf[16384];
   if(pieceSize > 16384) {
     log_err("Partial sortkey size buffer too small. Please consider increasing the buffer!\n");
@@ -163,9 +188,9 @@
     tSize = ucol_nextSortKeyPart(coll, &tIter, tState, tBuf, pieceSize, status);
     
     if(sState[0] != 0 || tState[0] != 0) {
-      log_verbose("State != 0 : %08X %08X\n", sState[0], tState[0]);
+      /*log_verbose("State != 0 : %08X %08X\n", sState[0], tState[0]);*/
     }
-    log_verbose("%i ", i++);
+    /*log_verbose("%i ", i++);*/
     
     partialSKResult = memcmp(sBuf, tBuf, pieceSize);
   }
@@ -246,10 +271,10 @@
       if(QUICK <= 0) {
         partialSizesSize = 7;
       }
-      log_verbose("partial sortkey test piecesize=");
+      /*log_verbose("partial sortkey test piecesize=");*/
       for(i = 0; i < partialSizesSize; i++) {
         UCollationResult partialSKResult = result, partialNormalizedSKResult = result;
-        log_verbose("%i ", partialSizes[i]);
+        /*log_verbose("%i ", partialSizes[i]);*/
 
         partialSKResult = compareUsingPartials(myCollation, source, sLen, target, tLen, partialSizes[i], &status);
         if(partialSKResult != result) {
@@ -258,7 +283,7 @@
         }
 
         if(QUICK <= 0 && norm != UCOL_ON) {
-          log_verbose("N ");
+          /*log_verbose("N ");*/
           ucol_setAttribute(myCollation, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
           partialNormalizedSKResult = compareUsingPartials(myCollation, source, sLen, target, tLen, partialSizes[i], &status);
           ucol_setAttribute(myCollation, UCOL_NORMALIZATION_MODE, norm, &status);
@@ -268,7 +293,7 @@
           }
         }
       }
-      log_verbose("\n");
+      /*log_verbose("\n");*/
     }
 
     
@@ -347,6 +372,256 @@
   }
 }
 
+
+/**
+ * Return an integer array containing all of the collation orders
+ * returned by calls to next on the specified iterator
+ */
+int32_t* getOrders(UCollationElements *iter, int32_t *orderLength)
+{
+    UErrorCode status;
+    int32_t order;
+    int32_t maxSize = 100;
+    int32_t size = 0;
+    int32_t *temp;
+    int32_t *orders =(int32_t*)malloc(sizeof(int32_t) * maxSize);
+    status= U_ZERO_ERROR;
+
+
+    while ((order=ucol_next(iter, &status)) != UCOL_NULLORDER)
+    {
+        if (size == maxSize)
+        {
+            maxSize *= 2;
+            temp = (int32_t*)malloc(sizeof(int32_t) * maxSize);
+
+            memcpy(temp, orders, size * sizeof(int32_t));
+            free(orders);
+            orders = temp;
+
+        }
+
+        orders[size++] = order;
+    }
+
+    if (maxSize > size && size > 0)
+    {
+        temp = (int32_t*)malloc(sizeof(int32_t) * size);
+
+        memcpy(temp, orders, size * sizeof(int32_t));
+        free(orders);
+        orders = temp;
+
+
+    }
+
+    *orderLength = size;
+    return orders;
+}
+
+
+void 
+backAndForth(UCollationElements *iter)
+{
+    /* Run through the iterator forwards and stick it into an array */
+    int32_t index, o;
+    UErrorCode status = U_ZERO_ERROR;
+    int32_t orderLength = 0;
+    int32_t *orders;
+    orders= getOrders(iter, &orderLength);
+
+
+    /* Now go through it backwards and make sure we get the same values */
+    index = orderLength;
+    ucol_reset(iter);
+
+    /* synwee : changed */
+    while ((o = ucol_previous(iter, &status)) != UCOL_NULLORDER)
+    {
+        if (o != orders[-- index])
+        {
+        if (o == 0)
+          index ++;
+        else
+        {
+          while (index > 0 && orders[-- index] == 0)
+          {
+          }
+          if (o != orders[index])
+          {
+            log_err("Mismatch at index : 0x%x\n", index);
+            return;
+        }
+
+        }
+      }
+    }
+
+    while (index != 0 && orders[index - 1] == 0) {
+      index --;
+    }
+
+    if (index != 0)
+    {
+        log_err("Didn't get back to beginning - index is %d\n", index);
+
+        ucol_reset(iter);
+        log_err("\nnext: ");
+        if ((o = ucol_next(iter, &status)) != UCOL_NULLORDER)
+        {
+            log_err("Error at %x\n", o);
+        }
+        log_err("\nprev: ");
+        if ((o = ucol_previous(iter, &status)) != UCOL_NULLORDER)
+        {
+            log_err("Error at %x\n", o);
+        }
+        log_verbose("\n");
+    }
+
+    free(orders);
+}
+
+void genericOrderingTestWithResult(UCollator *coll, const char *s[], uint32_t size, UCollationResult result) {
+  UChar t1[2048] = {0};
+  UChar t2[2048] = {0};
+  UCollationElements *iter;
+  UErrorCode status = U_ZERO_ERROR;
+
+  uint32_t i = 0, j = 0;
+  log_verbose("testing sequence:\n");
+  for(i = 0; i < size; i++) {
+    log_verbose("%s\n", s[i]);
+  }
+
+  iter = ucol_openElements(coll, t1, u_strlen(t1), &status);
+  if (U_FAILURE(status)) {
+    log_err("Creation of iterator failed\n");
+  }
+  for(i = 0; i < size-1; i++) {
+    for(j = i+1; j < size; j++) {
+      u_unescape(s[i], t1, 2048);
+      u_unescape(s[j], t2, 2048);
+      doTest(coll, t1, t2, result);
+      /* synwee : added collation element iterator test */
+      ucol_setText(iter, t1, u_strlen(t1), &status);
+      backAndForth(iter);
+      ucol_setText(iter, t2, u_strlen(t2), &status);
+      backAndForth(iter);
+    }
+  }
+  ucol_closeElements(iter);
+}
+
+void genericOrderingTest(UCollator *coll, const char *s[], uint32_t size) {
+  genericOrderingTestWithResult(coll, s, size, UCOL_LESS);
+}
+
+void genericLocaleStarter(const char *locale, const char *s[], uint32_t size) {
+  UErrorCode status = U_ZERO_ERROR;
+  UCollator *coll = ucol_open(locale, &status);
+
+  log_verbose("Locale starter for %s\n", locale);
+
+  if(U_SUCCESS(status)) {
+    genericOrderingTest(coll, s, size);
+  } else if(status == U_FILE_ACCESS_ERROR) {
+    log_data_err("Is your data around?\n");
+    return;
+  } else {
+    log_err("Unable to open collator for locale %s\n", locale);
+  }
+  ucol_close(coll);
+}
+
+void genericLocaleStarterWithResult(const char *locale, const char *s[], uint32_t size, UCollationResult result) {
+  UErrorCode status = U_ZERO_ERROR;
+  UCollator *coll = ucol_open(locale, &status);
+
+  log_verbose("Locale starter for %s\n", locale);
+
+  if(U_SUCCESS(status)) {
+    genericOrderingTestWithResult(coll, s, size, result);
+  } else if(status == U_FILE_ACCESS_ERROR) {
+    log_data_err("Is your data around?\n");
+    return;
+  } else {
+    log_err("Unable to open collator for locale %s\n", locale);
+  }
+  ucol_close(coll);
+}
+
+#if 0
+/* currently not used with options */
+void genericRulesStarterWithOptions(const char *rules, const char *s[], uint32_t size, const UColAttribute *attrs, const UColAttributeValue *values, uint32_t attsize) {
+  UErrorCode status = U_ZERO_ERROR;
+  UChar rlz[RULE_BUFFER_LEN] = { 0 };
+  uint32_t rlen = u_unescape(rules, rlz, RULE_BUFFER_LEN);
+  uint32_t i;
+
+  UCollator *coll = ucol_openRules(rlz, rlen, UCOL_DEFAULT, UCOL_DEFAULT,NULL, &status);
+
+  log_verbose("Rules starter for %s\n", rules);
+
+  if(U_SUCCESS(status)) {
+    log_verbose("Setting attributes\n");
+    for(i = 0; i < attsize; i++) {
+      ucol_setAttribute(coll, attrs[i], values[i], &status);
+    }
+
+    genericOrderingTest(coll, s, size);
+  } else {
+    log_err("Unable to open collator with rules %s\n", rules);
+  }
+  ucol_close(coll);
+}
+#endif
+
+void genericLocaleStarterWithOptions(const char *locale, const char *s[], uint32_t size, const UColAttribute *attrs, const UColAttributeValue *values, uint32_t attsize) {
+  UErrorCode status = U_ZERO_ERROR;
+  uint32_t i;
+
+  UCollator *coll = ucol_open(locale, &status);
+
+  log_verbose("Locale starter for %s\n", locale);
+
+  if(U_SUCCESS(status)) {
+
+    log_verbose("Setting attributes\n");
+    for(i = 0; i < attsize; i++) {
+      ucol_setAttribute(coll, attrs[i], values[i], &status);
+    }
+
+    genericOrderingTest(coll, s, size);
+  } else {
+    log_err("Unable to open collator for locale %s\n", locale);
+  }
+  ucol_close(coll);
+}
+
+void genericRulesTestWithResult(const char *rules, const char *s[], uint32_t size, UCollationResult result) {
+  UErrorCode status = U_ZERO_ERROR;
+  UChar rlz[RULE_BUFFER_LEN] = { 0 };
+  uint32_t rlen = u_unescape(rules, rlz, RULE_BUFFER_LEN);
+
+  UCollator *coll = NULL;
+  coll = ucol_openRules(rlz, rlen, UCOL_DEFAULT, UCOL_DEFAULT,NULL, &status);
+  log_verbose("Rules starter for %s\n", rules);
+
+  if(U_SUCCESS(status)) {
+    genericOrderingTestWithResult(coll, s, size, result);
+    ucol_close(coll);
+  } else if(status == U_FILE_ACCESS_ERROR) {
+    log_data_err("Is your data around?\n");
+  } else {
+    log_err("Unable to open collator with rules %s\n", rules);
+  }
+}
+
+void genericRulesStarter(const char *rules, const char *s[], uint32_t size) {
+  genericRulesTestWithResult(rules, s, size, UCOL_LESS);
+}
+
 static void TestTertiary()
 {
     int32_t len,i;
@@ -857,10 +1132,14 @@
         u_uastrcpy(rule, rules[i]);
         c1 = ucol_openRules(rule, u_strlen(rule), UCOL_OFF, UCOL_DEFAULT_STRENGTH, &parseError, &status);
         if(U_FAILURE(status)){
-            u_UCharsToChars(parseError.preContext,preContext,20);
-            u_UCharsToChars(parseError.postContext,postContext,20);
-            log_err("Could not parse the rules syntax. Error: %s ", u_errorName(status));
-            log_verbose("\n\tPre-Context: %s \n\tPost-Context:%s \n",preContext,postContext);
+			log_err("Could not parse the rules syntax. Error: %s ", u_errorName(status));
+
+			if (status == U_PARSE_ERROR) {
+				u_UCharsToChars(parseError.preContext,preContext,20);
+				u_UCharsToChars(parseError.postContext,postContext,20);
+				log_verbose("\n\tPre-Context: %s \n\tPost-Context:%s \n",preContext,postContext);
+			}
+
             return;
         }
         X[0] = input[i][0];
@@ -870,5 +1149,49 @@
     }
 }
 
+/*  These tests do cleanup and reinitialize ICU in the course of their operation.
+ *    The ICU data directory must be preserved across these operations.
+ *    Here is a helper function to assist with that.
+ */
+static char *safeGetICUDataDirectory() {
+    const char *dataDir = u_getDataDirectory();  /* Returned string vanashes with u_cleanup */
+    char *retStr = NULL;
+    if (dataDir != NULL) {
+        retStr = (char *)malloc(strlen(dataDir)+1);
+        strcpy(retStr, dataDir);
+    }
+    return retStr;
+}
+
+
+static void
+TestFCDCrash(void) {
+    static char *test[] = {
+    "Gr\\u00F6\\u00DFe",
+    "Grossist"
+    };
+
+    char *icuDataDir = safeGetICUDataDirectory();
+    UErrorCode status = U_ZERO_ERROR;
+    UCollator *coll = ucol_open("es", &status);
+    if(U_FAILURE(status)) {
+        log_err("Couldn't open collator\n");
+        return;
+    }
+    ucol_close(coll);
+    coll = NULL;
+    u_cleanup();
+    u_setDataDirectory(icuDataDir);
+    coll = ucol_open("de_DE", &status);
+    if(U_FAILURE(status)) {
+        log_err("Couldn't open collator\n");
+        return;
+    }
+    ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
+    genericOrderingTest(coll, test, 2);
+    ucol_close(coll);
+    free(icuDataDir);
+
+}
 
 #endif /* #if !UCONFIG_NO_COLLATION */

Index: callcoll.h
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/callcoll.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- callcoll.h	10 Sep 2003 02:42:33 -0000	1.3
+++ callcoll.h	6 Apr 2004 10:09:23 -0000	1.4
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2001, International Business Machines Corporation and
+ * Copyright (c) 1997-2003, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /********************************************************************************
@@ -21,15 +21,30 @@
 #define _CALLCOLLTST
 
 #include "unicode/utypes.h"
+#include "unicode/ucoleitr.h"
 
 #if !UCONFIG_NO_COLLATION
 
 #include "cintltst.h"
 
+#define RULE_BUFFER_LEN 8192
 
 
     /* tests comparison of custom collation with different strengths */
 void doTest(UCollator*, const UChar* source, const UChar* target, UCollationResult result);
+/* verify that iterating forward and backwards over the string yields same CEs */
+void backAndForth(UCollationElements *iter);
+/* gets an array of CEs for a string in UCollationElements iterator. */
+int32_t* getOrders(UCollationElements *iter, int32_t *orderLength);
+
+void genericOrderingTestWithResult(UCollator *coll, const char *s[], uint32_t size, UCollationResult result);
+void genericOrderingTest(UCollator *coll, const char *s[], uint32_t size);
+void genericLocaleStarter(const char *locale, const char *s[], uint32_t size);
+void genericLocaleStarterWithResult(const char *locale, const char *s[], uint32_t size, UCollationResult result);
+void genericLocaleStarterWithOptions(const char *locale, const char *s[], uint32_t size, const UColAttribute *attrs, const UColAttributeValue *values, uint32_t attsize);
+void genericRulesTestWithResult(const char *rules, const char *s[], uint32_t size, UCollationResult result);
+void genericRulesStarter(const char *rules, const char *s[], uint32_t size);
+UBool hasCollationElements(const char *locName);
 
 
 #endif /* #if !UCONFIG_NO_COLLATION */

Index: calltest.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/calltest.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- calltest.c	10 Sep 2003 02:42:33 -0000	1.3
+++ calltest.c	6 Apr 2004 10:09:23 -0000	1.4
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1996-2001, International Business Machines Corporation and
+ * Copyright (c) 1996-2003, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /********************************************************************************
@@ -16,7 +16,6 @@
 
 #include "cintltst.h"
 
-void addSetup(TestNode** root);
 void addUtility(TestNode** root);
 void addBreakIter(TestNode** root);
 void addStandardNamesTest(TestNode **root);
@@ -33,10 +32,14 @@
 void addTestDeprecatedAPI(TestNode** root);
 void addUCharTransformTest(TestNode** root);
 void addUSetTest(TestNode** root);
+void addUStringPrepTest(TestNode** root);
+void addIDNATest(TestNode** root);
+void addHeapMutexTest(TestNode **root);
+void addUTraceTest(TestNode** root);
+
 
 void addAllTests(TestNode** root)
 {
-    addSetup(root);  /* Leave this test first! */
     addUDataTest(root);
     addPUtilTest(root);
     addUTF16Test(root);
@@ -61,5 +64,12 @@
 #endif
     addUSetTest(root);
     addTestDeprecatedAPI(root);
+#if !UCONFIG_NO_IDNA
+    addUStringPrepTest(root);
+    addIDNATest(root);
+#endif
+    addHeapMutexTest(root);
+    addUTraceTest(root);
+
 }
 

Index: capitst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/capitst.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- capitst.c	10 Sep 2003 02:42:33 -0000	1.4
+++ capitst.c	6 Apr 2004 10:09:23 -0000	1.5
@@ -32,6 +32,8 @@
         int TestBufferSize();	/* defined in "colutil.c" */
 
 
+    
+
 /* next two function is modified from "i18n/ucol.cpp" to avoid include "ucol_imp.h" */
 static void uprv_appendByteToHexString(char *dst, uint8_t val) {
   uint32_t len = (uint32_t)strlen(dst);
@@ -273,9 +275,12 @@
       ICU 2.1 currVersionArray = {0x19, 0x00, 0x03, 0x03};
       ICU 2.2 currVersionArray = {0x21, 0x40, 0x04, 0x04};
       ICU 2.4 currVersionArray = {0x21, 0x40, 0x04, 0x04};
+      ICU 2.6 currVersionArray = {0x21, 0x40, 0x03, 0x03};
     */
-    UVersionInfo currVersionArray = {0x21, 0x40, 0x03, 0x03};
-    UVersionInfo versionArray;
+    UVersionInfo currVersionArray = {0x29, 0x80, 0x01, 0x04};
+    UVersionInfo currUCAVersionArray = {4, 0, 0, 0};
+    UVersionInfo versionArray = {0, 0, 0, 0};
+    UVersionInfo versionUCAArray = {0, 0, 0, 0};
     
     log_verbose("The property tests begin : \n");
     log_verbose("Test ucol_strcoll : \n");
@@ -294,6 +299,15 @@
       }
     }
 
+    ucol_getUCAVersion(col, versionUCAArray);
+    for (i=0; i<4; ++i) {
+      if (versionUCAArray[i] != currUCAVersionArray[i]) {
+        log_err("Testing ucol_getUCAVersion() - unexpected result: %hu.%hu.%hu.%hu\n", 
+            versionUCAArray[0], versionUCAArray[1], versionUCAArray[2], versionUCAArray[3]);
+        break;
+      }
+    }
+
     source=(UChar*)malloc(sizeof(UChar) * 12);
     target=(UChar*)malloc(sizeof(UChar) * 12);
     
@@ -365,7 +379,7 @@
         buffer[0] = '\0';
         log_verbose("ucol_getRulesEx() testing ...\n");
         tempLength = ucol_getRulesEx(col,UCOL_TAILORING_ONLY,buffer,bufLen );
-        doAssert( tempLength == 0, "getRulesEx() result incorrect" );
+        doAssert( tempLength == 0x0f, "getRulesEx() result incorrect" );
         log_verbose("getRules tests end.\n");
         
         log_verbose("ucol_getRulesEx() testing ...\n");
@@ -427,6 +441,7 @@
     u_uastrcpy(ruleset1, "&9 < a, A < b, B < c, C; ch, cH, Ch, CH < d, D, e, E");
     u_uastrcpy(ruleset2, "&9 < a, A < b, B < c, C < d, D, e, E");
     
+
     col1 = ucol_openRules(ruleset1, u_strlen(ruleset1), UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH, NULL,&status);
     if (U_FAILURE(status)) {
         log_err("RuleBased Collator creation failed.: %s\n", myErrorName(status));
@@ -746,10 +761,12 @@
 {   
     uint8_t *sortk1 = NULL, *sortk2 = NULL, *sortk3 = NULL, *sortkEmpty = NULL;
     uint8_t sortk2_compat[] = { 
+      /* 2.6.1 key */
+        0x26, 0x28, 0x2A, 0x2C, 0x26, 0x01, 
+        0x09, 0x01, 0x09, 0x01, 0x25, 0x01, 
+        0x92, 0x93, 0x94, 0x95, 0x92, 0x00 
         /* 2.2 key */
-        0x1D, 0x1F, 0x21, 0x23, 0x1D, 0x01, 
-        0x09, 0x01, 0x09, 0x01, 0x1C, 0x01, 
-        0x92, 0x93, 0x94, 0x95, 0x92, 0x00
+        /*0x1D, 0x1F, 0x21, 0x23, 0x1D, 0x01, 0x09, 0x01, 0x09, 0x01, 0x1C, 0x01, 0x92, 0x93, 0x94, 0x95, 0x92, 0x00*/
         /* 2.0 key */
         /*0x19, 0x1B, 0x1D, 0x1F, 0x19, 0x01, 0x09, 0x01, 0x09, 0x01, 0x18, 0x01, 0x92, 0x93, 0x94, 0x95, 0x92, 0x00*/
         /* 1.8.1 key.*/
@@ -1107,7 +1124,7 @@
   } testStruct[] = {
     { "sr_YU", "sr_YU", "ru" },
     { "sh_YU", "sh_YU", "sh" },
-    { "en_US_CALIFORNIA", "en_US", "root" },
+    { "en_US_CALIFORNIA", "en_US", "en" },
     { "fr_FR_NONEXISTANT", "fr_FR", "fr" }
   };
 

Index: cbididat.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cbididat.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cbididat.c	10 Sep 2003 02:42:33 -0000	1.3
+++ cbididat.c	6 Apr 2004 10:09:23 -0000	1.4
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2001, International Business Machines Corporation and
+ * Copyright (c) 1997-2003, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /*   file name:  cbididat.c
@@ -313,6 +313,36 @@
     2
 };
 
+static const uint8_t
+testText16[]={
+	L, L, L, WS, L, L, L, WS, L, L, L
+};
+
+static const UBiDiLevel
+testLevels21[]={
+	2, 2, 2, 2, 2, 2, 2, 1
+};
+
+static const uint8_t
+testVisualMap20[]={
+	1, 2, 3, 4, 5, 6, 7, 0
+};
+
+static const uint8_t
+testText17[]={
+	R, R, R, WS, R, R, R, WS, R, R, R
+};
+
+static const UBiDiLevel
+testLevels22[]={
+	1, 1, 1, 1, 1, 1, 1, 0
+};
+
+static const uint8_t
+testVisualMap21[]={
+	6, 5, 4, 3, 2, 1, 0, 7
+};
+
 BiDiTestData
 tests[]={
     {testText1,  ARRAY_LENGTH(testText1),  UBIDI_DEFAULT_LTR, -1, -1,
@@ -374,7 +404,13 @@
         testLevels19, testVisualMap19},
     {testText15, ARRAY_LENGTH(testText15), UBIDI_DEFAULT_LTR, 2, 3,
         UBIDI_LTR, 2,
-        testLevels20, testVisualMap19}
+        testLevels20, testVisualMap19},
+	{testText16, ARRAY_LENGTH(testText16), UBIDI_RTL, 0, 8,
+		UBIDI_MIXED, 1,
+		testLevels21, testVisualMap20},
+	{testText17, ARRAY_LENGTH(testText17), UBIDI_LTR, 0, 8,
+		UBIDI_MIXED, 0,
+		testLevels22, testVisualMap21}
 };
 
 int

Index: cbiditst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cbiditst.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- cbiditst.c	10 Sep 2003 02:42:33 -0000	1.4
+++ cbiditst.c	6 Apr 2004 10:09:24 -0000	1.5
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT:
- * Copyright (c) 1997-2001, International Business Machines Corporation and
+ * Copyright (c) 1997-2003, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /*   file name:  cbiditst.cpp
@@ -30,10 +30,10 @@
 doBiDiTest(void);
 
 static void
-doTests(UBiDi *pBiDi, UBiDi *pLine);
+doTests(UBiDi *pBiDi, UBiDi *pLine, UBool countRunsFirst);
 
 static void
-doTest(UBiDi *pBiDi, int testNumber, BiDiTestData *test, int32_t lineStart);
+doTest(UBiDi *pBiDi, int testNumber, BiDiTestData *test, int32_t lineStart, UBool countRunsFirst);
 
 static void
 testReordering(UBiDi *pBiDi, int testNumber);
@@ -100,7 +100,8 @@
     if(pBiDi!=NULL) {
         pLine=ubidi_open();
         if(pLine!=NULL) {
-            doTests(pBiDi, pLine);
+            doTests(pBiDi, pLine, FALSE);
+			doTests(pBiDi, pLine, TRUE);
         } else {
             log_err("ubidi_open() returned NULL, out of memory\n");
         }
@@ -119,7 +120,7 @@
 }
 
 static void
-doTests(UBiDi *pBiDi, UBiDi *pLine) {
+doTests(UBiDi *pBiDi, UBiDi *pLine, UBool countRunsFirst) {
     int i;
     UChar *s;
     UErrorCode errorCode;
@@ -136,13 +137,13 @@
                     i, paraLevel, ubidi_getDirection(pBiDi), ubidi_getParaLevel(pBiDi));
             lineStart=tests[i].lineStart;
             if(lineStart==-1) {
-                doTest(pBiDi, i, tests+i, 0);
+                doTest(pBiDi, i, tests+i, 0, countRunsFirst);
             } else {
                 ubidi_setLine(pBiDi, lineStart, tests[i].lineLimit, pLine, &errorCode);
                 if(U_SUCCESS(errorCode)) {
                     log_verbose("ubidi_setLine(%d, %d) ok, direction %d paraLevel=%d\n",
                             lineStart, tests[i].lineLimit, ubidi_getDirection(pLine), ubidi_getParaLevel(pLine));
-                    doTest(pLine, i, tests+i, lineStart);
+                    doTest(pLine, i, tests+i, lineStart, countRunsFirst);
                 } else {
                     log_err("ubidi_setLine(tests[%d], %d, %d) failed with errorCode %s\n",
                             i, lineStart, tests[i].lineLimit, myErrorName(errorCode));
@@ -432,14 +433,27 @@
 }
 
 static void
-doTest(UBiDi *pBiDi, int testNumber, BiDiTestData *test, int32_t lineStart) {
+doTest(UBiDi *pBiDi, int testNumber, BiDiTestData *test, int32_t lineStart, UBool countRunsFirst) {
     const uint8_t *dirProps=test->text+lineStart;
     const UBiDiLevel *levels=test->levels;
     const uint8_t *visualMap=test->visualMap;
-    int32_t i, len=ubidi_getLength(pBiDi), logicalIndex, runCount;
+    int32_t i, len=ubidi_getLength(pBiDi), logicalIndex, runCount = 0;
     UErrorCode errorCode=U_ZERO_ERROR;
     UBiDiLevel level, level2;
 
+	if (countRunsFirst) {
+		log_verbose("Calling ubidi_countRuns() first.\n");
+
+		runCount = ubidi_countRuns(pBiDi, &errorCode);
+
+		if(U_FAILURE(errorCode)) {
+			log_err("ubidi_countRuns(tests[%d]): error %s\n", testNumber, myErrorName(errorCode));
+			return;
+		}
+	} else {
+		log_verbose("Calling ubidi_getLogicalMap() first.\n");
+	}
+
     testReordering(pBiDi, testNumber);
 
     for(i=0; i<len; ++i) {
@@ -493,11 +507,13 @@
         }
     }
 
-    runCount=ubidi_countRuns(pBiDi, &errorCode);
-    if(U_FAILURE(errorCode)) {
-        log_err("ubidi_countRuns(tests[%d]): error %s\n", testNumber, myErrorName(errorCode));
-        return;
-    }
+	if (! countRunsFirst) {
+		runCount=ubidi_countRuns(pBiDi, &errorCode);
+		if(U_FAILURE(errorCode)) {
+			log_err("ubidi_countRuns(tests[%d]): error %s\n", testNumber, myErrorName(errorCode));
+			return;
+		}
+	}
 
     for(logicalIndex=0; logicalIndex<len;) {
         level=ubidi_getLevelAt(pBiDi, logicalIndex);

Index: ccaltst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/ccaltst.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ccaltst.c	10 Sep 2003 02:42:33 -0000	1.3
+++ ccaltst.c	6 Apr 2004 10:09:24 -0000	1.4
@@ -55,7 +55,7 @@
 {
     UCalendar *caldef = 0, *caldef2 = 0, *calfr = 0, *calit = 0;
     UEnumeration* uenum = NULL;
-    int32_t count, count2, offset,i,j;
+    int32_t count, count2, i,j;
     UChar *tzID = 0;
     UChar *tzdname = 0;
     UErrorCode status = U_ZERO_ERROR;
@@ -66,8 +66,9 @@
     char tempMsgBuf[256];
     UChar zone1[32], zone2[32];
 
+#ifdef U_USE_UCAL_OBSOLETE_2_8
     /*Testing countAvailableTimeZones*/
-    offset=0;
+    int32_t offset=0;
     log_verbose("\nTesting ucal_countAvailableTZIDs\n");
     count=ucal_countAvailableTZIDs(offset);
     log_verbose("The number of timezone id's present with offset 0 are %d:\n", count);
@@ -89,6 +90,7 @@
         log_err("FAIL:for TZID index >= count Expected INDEX_OUTOFBOUNDS_ERROR Got %s\n", u_errorName(status));
     }
     status=U_ZERO_ERROR;
+#endif
     
     /*Test ucal_openTimeZones & ucal_openCountryTimeZones*/
     for (j=0; j<2; ++j) {
@@ -415,7 +417,8 @@
     
     
     
-    
+    ctest_setTimeZone(NULL, &status);
+
     /*testing ucal_setTimeZone() function*/
     log_verbose("\nTesting if the function ucal_setTimeZone() works fine\n");
     ucal_setMillis(caldef2, d2, &status); 
@@ -474,6 +477,9 @@
     else if (zoneOffset != -28800000) {
         log_err("Error in getting the time zone using ucal_get() after using ucal_setTimeZone() offset=%d\n", zoneOffset);
     }
+
+    ctest_resetTimeZone();
+
 /*----------------------------*     */
     
     

Index: ccapitst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/ccapitst.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- ccapitst.c	10 Sep 2003 02:42:33 -0000	1.4
+++ ccapitst.c	6 Apr 2004 10:09:24 -0000	1.5
@@ -21,16 +21,17 @@
 #include "unicode/ucnv_err.h"
 #include "unicode/utypes.h"
 #include "unicode/ustring.h"
+#include "ucnv_bld.h" /* for sizeof(UConverter) */
 #include "cintltst.h"
 #include "ccapitst.h"
 
 /* for not including "cstring.h" -begin*/    
 #ifdef WIN32
-#   define stricmp(str1, str2) U_STANDARD_CPP_NAMESPACE _stricmp(str1, str2)
+#   define ctest_stricmp(str1, str2) U_STANDARD_CPP_NAMESPACE _stricmp(str1, str2)
 #elif defined(POSIX) 
-#   define stricmp(str1, str2) U_STANDARD_CPP_NAMESPACE strcasecmp(str1, str2) 
+#   define ctest_stricmp(str1, str2) U_STANDARD_CPP_NAMESPACE strcasecmp(str1, str2) 
 #else
-#   define stricmp(str1, str2) T_CString_stricmp(str1, str2)
+#   define ctest_stricmp(str1, str2) T_CString_stricmp(str1, str2)
 #endif
 
 static int U_EXPORT2
@@ -82,6 +83,15 @@
 static UConverterFromUCallback otherUnicodeAction(UConverterFromUCallback MIA);
 static UConverterToUCallback otherCharAction(UConverterToUCallback MIA);
 
+static UConverter *
+cnv_open(const char *name, UErrorCode *pErrorCode) {
+    if(name!=NULL && name[0]=='*') {
+        return ucnv_openPackage(loadTestData(pErrorCode), name+1, pErrorCode);
+    } else {
+        return ucnv_open(name, pErrorCode);
+    }
+}
+
 
 static void ListNames(void);
        void TestFlushCache(void);	/* defined in cctest.c */
@@ -569,7 +579,7 @@
         {
             log_verbose("getName o.k. %s\n", ucnv_getName(myConverter, &err));
         }
-        if (stricmp(ucnv_getName(myConverter, &err), CodePagesToTest[codepage_index]))
+        if (ctest_stricmp(ucnv_getName(myConverter, &err), CodePagesToTest[codepage_index]))
             log_err("getName failed\n");
         else 
             log_verbose("getName ok\n");
@@ -665,6 +675,7 @@
         err=U_ZERO_ERROR;
         /*------*/
 
+#ifdef U_ENABLE_GENERIC_ISO_2022
         /*resetState  ucnv_reset()*/
         log_verbose("\n---Testing ucnv_reset()..\n");
         ucnv_reset(myConverter);
@@ -684,7 +695,8 @@
              ucnv_close(cnv);
          
         }
-    
+#endif
+
         /*getDisplayName*/
         log_verbose("\n---Testing ucnv_getDisplayName()...\n");
         locale=CodePagesLocale[codepage_index];
@@ -1061,8 +1073,8 @@
     /* Predetermined aliases that we expect to map back to ISO_2022
      * and UTF-8.  UPDATE THIS DATA AS NECESSARY. */
     const char* ISO_2022_NAMES[] = 
-        {"ISO_2022", "iso-2022", "2022",
-         "cp2022", "iso2022", "iso_2022"};
+        {"ISO_2022,locale=ja,version=2", "ISO-2022-JP-2", "csISO2022JP2",
+         "Iso-2022jP2", "isO-2022_Jp_2", "iSo--2022,locale=ja,version=2"};
     int32_t ISO_2022_NAMES_LENGTH =
         sizeof(ISO_2022_NAMES) / sizeof(ISO_2022_NAMES[0]);
     const char *UTF8_NAMES[] =
@@ -1183,7 +1195,7 @@
           continue;
         }
         if (0 != strcmp(mapBack, ISO_2022_NAMES[0])) {
-            log_err("FAIL: \"%s\" -> \"%s\", expect ISO_2022\n",
+            log_err("FAIL: \"%s\" -> \"%s\", expect \"ISO_2022,locale=ja,version=2\"\n",
                     ISO_2022_NAMES[i], mapBack);
         }
     }
@@ -1549,17 +1561,48 @@
     }
 }
 
+static UBool
+containsAnyOtherByte(uint8_t *p, int32_t length, uint8_t b) {
+    while(length>0) {
+        if(*p!=b) {
+            return TRUE;
+        }
+        ++p;
+        --length;
+    }
+    return FALSE;
+}
+
 static void TestConvertSafeClone()
 {
-#define CLONETEST_CONVERTER_COUNT 12
+    /* one 'regular' & all the 'private stateful' converters */
+    static const char *const names[] = {
+        "ibm-1047",
+        "ISO_2022,locale=zh,version=1",
+        "SCSU",
+        "HZ",
+        "lmbcs",
+        "ISCII,version=0",
+        "ISO_2022,locale=kr,version=1",
+        "ISO_2022,locale=jp,version=2",
+        "BOCU-1",
+        "UTF-7",
+        "IMAP-mailbox-name",
+        "ibm-1047-s390"
+    };
+
+    static const int32_t bufferSizes[] = {
+        U_CNV_SAFECLONE_BUFFERSIZE,
+        (int32_t)(3*sizeof(UConverter))/2,  /* 1.5*sizeof(UConverter) */
+        (int32_t)sizeof(UConverter)/2       /* 0.5*sizeof(UConverter) */
+    };
 
     char charBuffer [21];   /* Leave at an odd number for alignment testing */
-    uint8_t buffer [CLONETEST_CONVERTER_COUNT] [U_CNV_SAFECLONE_BUFFERSIZE];
-    int32_t bufferSize = U_CNV_SAFECLONE_BUFFERSIZE;
-    UConverter * someConverters [CLONETEST_CONVERTER_COUNT];
-    UConverter * someClonedConverters [CLONETEST_CONVERTER_COUNT];
-    UConverter * cnv;
-    UErrorCode err = U_ZERO_ERROR;
+    uint8_t buffer [3] [U_CNV_SAFECLONE_BUFFERSIZE];
+    int32_t bufferSize, maxBufferSize;
+    const char *maxName;
+    UConverter * cnv, *cnv2;
+    UErrorCode err;
 
     char *pCharBuffer;
     const char *pConstCharBuffer;
@@ -1573,139 +1616,176 @@
     UChar *pUCharTargetLimit = uniCharBuffer + sizeof(uniCharBuffer)/sizeof(*uniCharBuffer);
     const UChar * pUniBuffer;
     const UChar *uniBufferLimit = uniBuffer + sizeof(uniBuffer)/sizeof(*uniBuffer);
-    int index;
-
-    /* one 'regular' & all the 'private stateful' converters */
-    someConverters[0] = ucnv_open("ibm-1047", &err);
-    someConverters[1] = ucnv_open("ISO_2022", &err);
-    someConverters[2] = ucnv_open("SCSU", &err);
-    someConverters[3] = ucnv_open("HZ", &err);
-    someConverters[4] = ucnv_open("lmbcs", &err);
-    someConverters[5] = ucnv_open("ISCII,version=0",&err);
-    someConverters[6] = ucnv_open("ISO_2022,locale=kr,version=1",&err);
-    someConverters[7] = ucnv_open("ISO_2022,locale=jp,version=1",&err);
-    someConverters[8] = ucnv_open("BOCU-1", &err);
-    someConverters[9] = ucnv_open("UTF-7", &err);
-    someConverters[10] = ucnv_open("IMAP-mailbox-name", &err);
-    someConverters[11] = ucnv_open("ibm-1047-s390", &err);
-    
-    if(U_FAILURE(err)) {
-      log_data_err("problems creating converters to clone- check the data.\n");
-      return; /* bail - leak */
-    }
-    /* Check the various error & informational states: */
+    int32_t index, j;
 
-    /* Null status - just returns NULL */
-    if (0 != ucnv_safeClone(someConverters[0], buffer[0], &bufferSize, 0))
-    {
-        log_err("FAIL: Cloned converter failed to deal correctly with null status\n");
-    }
-    /* error status - should return 0 & keep error the same */
-    err = U_MEMORY_ALLOCATION_ERROR;
-    if (0 != ucnv_safeClone(someConverters[0], buffer[0], &bufferSize, &err) || err != U_MEMORY_ALLOCATION_ERROR)
-    {
-        log_err("FAIL: Cloned converter failed to deal correctly with incoming error status\n");
-    }
     err = U_ZERO_ERROR;
+    cnv = ucnv_open(names[0], &err);
+    if(U_SUCCESS(err)) {
+        /* Check the various error & informational states: */
 
-    /* Null buffer size pointer - just returns NULL & set error to U_ILLEGAL_ARGUMENT_ERROR*/
-    if (0 != ucnv_safeClone(someConverters[0], buffer[0], 0, &err) || err != U_ILLEGAL_ARGUMENT_ERROR)
-    {
-        log_err("FAIL: Cloned converter failed to deal correctly with null bufferSize pointer\n");
-    }
-    err = U_ZERO_ERROR;
+        /* Null status - just returns NULL */
+        bufferSize = U_CNV_SAFECLONE_BUFFERSIZE;
+        if (0 != ucnv_safeClone(cnv, buffer[0], &bufferSize, 0))
+        {
+            log_err("FAIL: Cloned converter failed to deal correctly with null status\n");
+        }
+        /* error status - should return 0 & keep error the same */
+        err = U_MEMORY_ALLOCATION_ERROR;
+        if (0 != ucnv_safeClone(cnv, buffer[0], &bufferSize, &err) || err != U_MEMORY_ALLOCATION_ERROR)
+        {
+            log_err("FAIL: Cloned converter failed to deal correctly with incoming error status\n");
+        }
+        err = U_ZERO_ERROR;
 
-    /* buffer size pointer is 0 - fill in pbufferSize with a size */
-    bufferSize = 0;
-    if (0 != ucnv_safeClone(someConverters[0], buffer[0], &bufferSize, &err) || U_FAILURE(err) || bufferSize <= 0)
-    {
-        log_err("FAIL: Cloned converter failed a sizing request ('preflighting')\n");
-    }
-    /* Verify our define is large enough  */
-    if (U_CNV_SAFECLONE_BUFFERSIZE < bufferSize)
-    {
-        log_err("FAIL: Pre-calculated buffer size is too small\n");
-    }
-    /* Verify we can use this run-time calculated size */
-    if (0 == (cnv = ucnv_safeClone(someConverters[0], buffer[0], &bufferSize, &err)) || U_FAILURE(err))
-    {
-        log_err("FAIL: Converter can't be cloned with run-time size\n");
-    }
-    if (cnv)
-        ucnv_close(cnv);
-    /* size one byte too small - should allocate & let us know */
-    --bufferSize;
-    if (0 == (cnv = ucnv_safeClone(someConverters[0], 0, &bufferSize, &err)) || err != U_SAFECLONE_ALLOCATED_WARNING)
-    {
-        log_err("FAIL: Cloned converter failed to deal correctly with too-small buffer size\n");
-    }
-    if (cnv)
-        ucnv_close(cnv);
-    err = U_ZERO_ERROR;
-    bufferSize = U_CNV_SAFECLONE_BUFFERSIZE;
+        /* Null buffer size pointer - just returns NULL & set error to U_ILLEGAL_ARGUMENT_ERROR*/
+        if (0 != ucnv_safeClone(cnv, buffer[0], 0, &err) || err != U_ILLEGAL_ARGUMENT_ERROR)
+        {
+            log_err("FAIL: Cloned converter failed to deal correctly with null bufferSize pointer\n");
+        }
+        err = U_ZERO_ERROR;
 
-    /* Null buffer pointer - return converter & set error to U_SAFECLONE_ALLOCATED_ERROR */
-    if (0 == (cnv = ucnv_safeClone(someConverters[0], 0, &bufferSize, &err)) || err != U_SAFECLONE_ALLOCATED_WARNING)
-    {
-        log_err("FAIL: Cloned converter failed to deal correctly with null buffer pointer\n");
-    }
-    if (cnv)
-        ucnv_close(cnv);
-    err = U_ZERO_ERROR;
+        /* buffer size pointer is 0 - fill in pbufferSize with a size */
+        bufferSize = 0;
+        if (0 != ucnv_safeClone(cnv, buffer[0], &bufferSize, &err) || U_FAILURE(err) || bufferSize <= 0)
+        {
+            log_err("FAIL: Cloned converter failed a sizing request ('preflighting')\n");
+        }
+        /* Verify our define is large enough  */
+        if (U_CNV_SAFECLONE_BUFFERSIZE < bufferSize)
+        {
+            log_err("FAIL: Pre-calculated buffer size is too small\n");
+        }
+        /* Verify we can use this run-time calculated size */
+        if (0 == (cnv2 = ucnv_safeClone(cnv, buffer[0], &bufferSize, &err)) || U_FAILURE(err))
+        {
+            log_err("FAIL: Converter can't be cloned with run-time size\n");
+        }
+        if (cnv2) {
+            ucnv_close(cnv2);
+        }
+
+        /* size one byte too small - should allocate & let us know */
+        --bufferSize;
+        if (0 == (cnv2 = ucnv_safeClone(cnv, 0, &bufferSize, &err)) || err != U_SAFECLONE_ALLOCATED_WARNING)
+        {
+            log_err("FAIL: Cloned converter failed to deal correctly with too-small buffer size\n");
+        }
+        if (cnv2) {
+            ucnv_close(cnv2);
+        }
+
+        err = U_ZERO_ERROR;
+        bufferSize = U_CNV_SAFECLONE_BUFFERSIZE;
+
+        /* Null buffer pointer - return converter & set error to U_SAFECLONE_ALLOCATED_ERROR */
+        if (0 == (cnv2 = ucnv_safeClone(cnv, 0, &bufferSize, &err)) || err != U_SAFECLONE_ALLOCATED_WARNING)
+        {
+            log_err("FAIL: Cloned converter failed to deal correctly with null buffer pointer\n");
+        }
+        if (cnv2) {
+            ucnv_close(cnv2);
+        }
+
+        err = U_ZERO_ERROR;
     
-    /* Null converter - return NULL & set U_ILLEGAL_ARGUMENT_ERROR */
-    if (0 != ucnv_safeClone(0, buffer[0], &bufferSize, &err) || err != U_ILLEGAL_ARGUMENT_ERROR)
-    {
-        log_err("FAIL: Cloned converter failed to deal correctly with null converter pointer\n");
+        /* Null converter - return NULL & set U_ILLEGAL_ARGUMENT_ERROR */
+        if (0 != ucnv_safeClone(0, buffer[0], &bufferSize, &err) || err != U_ILLEGAL_ARGUMENT_ERROR)
+        {
+            log_err("FAIL: Cloned converter failed to deal correctly with null converter pointer\n");
+        }
+
+        ucnv_close(cnv);
     }
 
-    err = U_ZERO_ERROR;
+    maxBufferSize = 0;
+    maxName = "";
 
     /* Do these cloned converters work at all - shuffle UChars to chars & back again..*/
 
-    for (index = 0; index < CLONETEST_CONVERTER_COUNT; index++)
-    {
-        bufferSize = U_CNV_SAFECLONE_BUFFERSIZE;
-        someClonedConverters[index] = ucnv_safeClone(someConverters[index], buffer[index], &bufferSize, &err);
+    for(j = 0; j < LENGTHOF(bufferSizes); ++j) {
+        for (index = 0; index < LENGTHOF(names); index++)
+        {
+            err = U_ZERO_ERROR;
+            cnv = ucnv_open(names[index], &err);
+            if(U_FAILURE(err)) {
+                log_data_err("ucnv_open(\"%s\") failed - %s\n", names[index], u_errorName(err));
+                continue;
+            }
 
-        /* close the original immediately to make sure that the clone works by itself */
-        ucnv_close(someConverters[index]);
+            if(j == 0) {
+                /* preflight to get maxBufferSize */
+                bufferSize = 0;
+                ucnv_safeClone(cnv, NULL, &bufferSize, &err);
+                if(bufferSize > maxBufferSize) {
+                    maxBufferSize = bufferSize;
+                    maxName = names[index];
+                }
+            }
 
-        pCharBuffer = charBuffer;
-        pUniBuffer = uniBuffer;
+            memset(buffer, 0xaa, sizeof(buffer));
 
-        ucnv_fromUnicode(someClonedConverters[index], 
-                        &pCharBuffer, 
-                        charBufferLimit,
-                        &pUniBuffer,
-                        uniBufferLimit,
-                        NULL,
-                        TRUE,
-                        &err);
-        if(U_FAILURE(err)){
-            log_err("FAIL: cloned converter failed to do fromU conversion. Error: %s\n",u_errorName(err));
-        }
-        ucnv_toUnicode(someClonedConverters[index],
-                       &pUCharTarget,
-                       pUCharTargetLimit,
-                       &pCharSource,
-                       pCharSourceLimit,
-                       NULL,
-                       TRUE,
-                       &err
-                       );
+            bufferSize = bufferSizes[j];
+            cnv2 = ucnv_safeClone(cnv, buffer[1], &bufferSize, &err);
 
-        if(U_FAILURE(err)){
-            log_err("FAIL: cloned converter failed to do toU conversion. Error: %s\n",u_errorName(err));
-        }
+            /* close the original immediately to make sure that the clone works by itself */
+            ucnv_close(cnv);
 
-        pConstCharBuffer = charBuffer;
-        if (uniBuffer [0] != ucnv_getNextUChar(someClonedConverters[index], &pConstCharBuffer, pCharBuffer, &err))
-        {
-            log_err("FAIL: Cloned converter failed to do conversion. Error: %s\n",u_errorName(err));
+            /* check if the clone function overwrote any bytes that it is not supposed to touch */
+            if(bufferSize <= bufferSizes[j]) {
+                /* used the stack buffer */
+                if( containsAnyOtherByte(buffer[0], (int32_t)sizeof(buffer[0]), 0xaa) ||
+                    containsAnyOtherByte(buffer[1]+bufferSize, (int32_t)(sizeof(buffer)-(sizeof(buffer[0])+bufferSize)), 0xaa)
+                ) {
+                    log_err("cloning %s in a stack buffer overwrote bytes outside the bufferSize %d (requested %d)\n",
+                        names[index], bufferSize, bufferSizes[j]);
+                }
+            } else {
+                /* heap-allocated the clone */
+                if(containsAnyOtherByte(buffer[0], (int32_t)sizeof(buffer), 0xaa)) {
+                    log_err("cloning %s used the heap (bufferSize %d, requested %d) but overwrote stack buffer bytes\n",
+                        names[index], bufferSize, bufferSizes[j]);
+                }
+            }
+
+            pCharBuffer = charBuffer;
+            pUniBuffer = uniBuffer;
+
+            ucnv_fromUnicode(cnv2, 
+                            &pCharBuffer, 
+                            charBufferLimit,
+                            &pUniBuffer,
+                            uniBufferLimit,
+                            NULL,
+                            TRUE,
+                            &err);
+            if(U_FAILURE(err)){
+                log_err("FAIL: cloned converter failed to do fromU conversion. Error: %s\n",u_errorName(err));
+            }
+            ucnv_toUnicode(cnv2,
+                           &pUCharTarget,
+                           pUCharTargetLimit,
+                           &pCharSource,
+                           pCharSourceLimit,
+                           NULL,
+                           TRUE,
+                           &err
+                           );
+
+            if(U_FAILURE(err)){
+                log_err("FAIL: cloned converter failed to do toU conversion. Error: %s\n",u_errorName(err));
+            }
+
+            pConstCharBuffer = charBuffer;
+            if (uniBuffer [0] != ucnv_getNextUChar(cnv2, &pConstCharBuffer, pCharBuffer, &err))
+            {
+                log_err("FAIL: Cloned converter failed to do conversion. Error: %s\n",u_errorName(err));
+            }
+            ucnv_close(cnv2);
         }
-        ucnv_close(someClonedConverters[index]);
     }
+
+    log_verbose("ucnv_safeClone(): sizeof(UConverter)=%lu  max preflighted clone size=%d (%s)  U_CNV_SAFECLONE_BUFFERSIZE=%d\n",
+        sizeof(UConverter), maxBufferSize, maxName, (int)U_CNV_SAFECLONE_BUFFERSIZE);
 }
 
 static void TestCCSID() {
@@ -2059,7 +2139,7 @@
          * expected output when converting shiftJIS[] from UTF-8 to Shift-JIS:
          * SUB, SUB, 0x40, SUB, SUB, 0x40
          */
-        0x81, 0xa1, 0x81, 0xa1, 0x40, 0x81, 0xa1, 0x81, 0xa1, 0x40
+        0xfc, 0xfc, 0xfc, 0xfc, 0x40, 0xfc, 0xfc, 0xfc, 0xfc, 0x40
     };
 
     char srcBuffer[100], targetBuffer[100];
@@ -2307,33 +2387,69 @@
         int8_t maxSize;
         const char *name;
     } converter[] = {
-        { 2, "LMBCS-1"},
-        { 2, "LMBCS-2"},
-        { 2, "LMBCS-3"},
-        { 2, "LMBCS-4"},
-        { 2, "LMBCS-5"},
-        { 2, "LMBCS-6"},
-        { 2, "LMBCS-8"},
-        { 2, "LMBCS-11"},
-        { 2, "LMBCS-16"},
-        { 2, "LMBCS-17"},
-        { 2, "LMBCS-18"},
-        { 2, "LMBCS-19"}
+        /* some non-LMBCS converters - perfect test setup here */
+        { 1, "US-ASCII"},
+        { 1, "ISO-8859-1"},
+
+        { 2, "UTF-16"},
+        { 2, "UTF-16BE"},
+        { 3, "UTF-8"},
+        { 3, "CESU-8"},
+        { 3, "SCSU"},
+        { 4, "UTF-32"},
+        { 4, "UTF-7"},
+        { 4, "IMAP-mailbox-name"},
+        { 4, "BOCU-1"},
+
+        { 1, "windows-1256"},
+        { 2, "Shift-JIS"},
+        { 2, "ibm-16684"},
+        { 3, "ibm-930"},
+        { 3, "ibm-1390"},
+        { 4, "*test3"},
+        { 16,"*test4"},
+
+        { 4, "ISCII"},
+        { 4, "HZ"},
+
+        { 3, "ISO-2022"},
+        { 3, "ISO-2022-KR"},
+        { 6, "ISO-2022-JP"},
+        { 8, "ISO-2022-CN"},
+
+        /* LMBCS */
+        { 3, "LMBCS-1"},
+        { 3, "LMBCS-2"},
+        { 3, "LMBCS-3"},
+        { 3, "LMBCS-4"},
+        { 3, "LMBCS-5"},
+        { 3, "LMBCS-6"},
+        { 3, "LMBCS-8"},
+        { 3, "LMBCS-11"},
+        { 3, "LMBCS-16"},
+        { 3, "LMBCS-17"},
+        { 3, "LMBCS-18"},
+        { 3, "LMBCS-19"}
     };
     int32_t idx;
 
     for (idx = 0; idx < LENGTHOF(converter); idx++) {
         UErrorCode status = U_ZERO_ERROR;
-        UConverter *cnv = ucnv_open(converter[idx].name, &status);
+        UConverter *cnv = cnv_open(converter[idx].name, &status);
         if (U_FAILURE(status)) {
             continue;
         }
         if (converter[idx].maxSize != ucnv_getMaxCharSize(cnv)) {
-            log_data_err("error: for %s expected %d, got %d\n",
+            log_err("error: ucnv_getMaxCharSize(%s) expected %d, got %d\n",
                 converter[idx].name, converter[idx].maxSize, ucnv_getMaxCharSize(cnv));
         }
         ucnv_close(cnv);
     }
+
+    /* mostly test that the macro compiles */
+    if(UCNV_GET_MAX_BYTES_FOR_STRING(1, 2)<10) {
+        log_err("error UCNV_GET_MAX_BYTES_FOR_STRING(1, 2)<10\n");
+    }
 }
 
 
@@ -2576,6 +2692,3 @@
         testSwap(tests[i].name, tests[i].swap);
     }
 }
-
-
-

Index: cctest.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cctest.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- cctest.c	10 Sep 2003 02:42:33 -0000	1.1
+++ cctest.c	6 Apr 2004 10:09:25 -0000	1.2
@@ -45,7 +45,7 @@
         log_data_err("FAILURE! %s\n", myErrorName(err));
     }
 
-    someConverters[4] = ucnv_open("ibm-949", &err);
+    someConverters[4] = ucnv_open("ibm-954", &err);
     if (U_FAILURE(err)) {
         log_data_err("FAILURE! %s\n", myErrorName(err));
     }

Index: cdantst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cdantst.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cdantst.c	10 Sep 2003 02:42:34 -0000	1.3
+++ cdantst.c	6 Apr 2004 10:09:25 -0000	1.4
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2001, International Business Machines Corporation and
+ * Copyright (c) 1997-2003, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /********************************************************************************
@@ -187,8 +187,8 @@
 {
     
     
-    addTest(root, &TestTertiary, "tscoll/cdantst/TestTertiary");
-    addTest(root, &TestPrimary, "tscoll/cdantst/TestPrimary");
+    /*addTest(root, &TestTertiary, "tscoll/cdantst/TestTertiary");*/
+    /*addTest(root, &TestPrimary, "tscoll/cdantst/TestPrimary");*/
 
 }
 

Index: cdattst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cdattst.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cdattst.c	10 Sep 2003 02:42:34 -0000	1.3
+++ cdattst.c	6 Apr 2004 10:09:25 -0000	1.4
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2001, International Business Machines Corporation and
+ * Copyright (c) 1997-2003, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /********************************************************************************
@@ -60,6 +60,9 @@
     /*const char* str="yyyy.MM.dd G 'at' hh:mm:ss z";
     const char t[]="2/3/76 2:50 AM";*/
     /*Testing udat_open() to open a dateformat */
+
+    ctest_setTimeZone(NULL, &status);
+
     log_verbose("\nTesting udat_open() with various parameters\n");
     fr = udat_open(UDAT_FULL, UDAT_DEFAULT, "fr_FR", NULL,0, NULL, 0,&status);
     if(U_FAILURE(status))
@@ -325,6 +328,7 @@
     udat_close(fr_pat);
     udat_close(copy);
     
+    ctest_resetTimeZone();
 }
 
 /*Testing udat_getSymbols() and udat_setSymbols() and udat_countSymbols()*/
@@ -558,6 +562,8 @@
     UDate when;
     UErrorCode ec = U_ZERO_ERROR;
 
+    ctest_setTimeZone(NULL, &ec);
+
     /* Create a formatter for date fields. */
     date = udat_open(UDAT_NONE, UDAT_SHORT, "en_US", NULL, 0, NULL, 0, &ec);
     if (U_FAILURE(ec)) {
@@ -627,7 +633,7 @@
     if (when == 986517900000.0) {
         log_verbose("Ok: Parsed result: %s\n", cbuf);
     } else {
-        log_err("FAIL: Parsed result: %s, exp 4/5/2001 5:45 PM", cbuf);
+        log_err("FAIL: Parsed result: %s, exp 4/5/2001 5:45 PM\n", cbuf);
     }
 
  FAIL:    
@@ -635,6 +641,8 @@
     udat_close(time);
     udat_close(full);
     ucal_close(cal);
+
+    ctest_resetTimeZone();
 }
 
 /*INTERNAL FUNCTIONS USED*/

Index: cdtdptst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cdtdptst.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cdtdptst.c	10 Sep 2003 02:42:34 -0000	1.3
+++ cdtdptst.c	6 Apr 2004 10:09:25 -0000	1.4
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2001, International Business Machines Corporation and
+ * Copyright (c) 1997-2003, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /********************************************************************************
@@ -53,6 +53,8 @@
     UChar *s;
     int32_t pos;
 
+    ctest_setTimeZone(NULL, &status);
+
     pattern=(UChar*)malloc(sizeof(UChar) * (strlen("EEE MMM dd HH:mm:ss.SSS zzz yyyy G")+1 ));
     u_uastrcpy(pattern, "EEE MMM dd HH:mm:ss.SSS zzz yyyy G");
     fullFmt= udat_open(UDAT_IGNORE, UDAT_IGNORE,"en_US",NULL,0,pattern, u_strlen(pattern),&status);
@@ -94,6 +96,8 @@
     udat_close(fmt);
     free(pattern);
     free(s);
+
+    ctest_resetTimeZone();
 }
 
 
@@ -227,7 +231,6 @@
     UCalendar *cal;
     UDate june, july, d;
     UErrorCode status = U_ZERO_ERROR;
-    char buffer[512];
     UChar *date;
     
     fmt = udat_open(UDAT_FULL, UDAT_FULL, "cs", NULL, 0, NULL, 0, &status);
@@ -263,19 +266,17 @@
     }
     d = udat_parse(fmt, juneStr, u_strlen(juneStr), &pos, &status);
     date = myDateFormat(fmt, d);
-    u_UCharsToChars(date, buffer, (int32_t)(u_strlen(date)+1));
     if(u_strcmp(myDateFormat(fmt, june), myDateFormat(fmt, d) ) !=0)
         log_err("Error in handling the czech month june\n");
     else
-        log_verbose("Pass: Date = %s\n",  buffer );
+        log_verbose("Pass: Date = %s (czech month June)\n", aescstrdup(date, -1));
     pos=0;
     d = udat_parse(fmt, julyStr, u_strlen(julyStr), &pos, &status);
     date = myDateFormat(fmt, d);
-    u_UCharsToChars(date, buffer, (int32_t)(u_strlen(date)+1));
     if(u_strcmp(myDateFormat(fmt, july), myDateFormat(fmt, d) ) !=0)
         log_err("Error in handling the czech month july\n");
     else
-        log_verbose("Pass: Date = %s\n",  buffer );
+        log_verbose("Pass: Date = %s (czech month July)\n", aescstrdup(date, -1));
     
     udat_close(fmt);
     ucal_close(cal);
@@ -295,6 +296,9 @@
     UChar *dateString;
     UErrorCode status = U_ZERO_ERROR;
     const char* expStr = "04/13/1999 at 10:42:28 AM ";
+
+    ctest_setTimeZone(NULL, &status);
+
     pattern=(UChar*)malloc(sizeof(UChar) * (strlen("MM/dd/yyyy 'at' hh:mm:ss a zzz")+1) );
     u_uastrcpy(pattern, "MM/dd/yyyy 'at' hh:mm:ss a zzz");
     
@@ -331,6 +335,7 @@
     free(tzID);
     free(pattern);
     
+    ctest_resetTimeZone();
 }
 
 #endif /* #if !UCONFIG_NO_FORMATTING */

Index: cdtrgtst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cdtrgtst.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cdtrgtst.c	10 Sep 2003 02:42:34 -0000	1.3
+++ cdtrgtst.c	6 Apr 2004 10:09:25 -0000	1.4
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2001, International Business Machines Corporation and
+ * Copyright (c) 1997-2003, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /********************************************************************************
@@ -130,7 +130,6 @@
     UChar s[10];
     UChar *gotdate, *expdate;
     UChar pat[10];
-    UChar *tzID;
     UDate d[4];
     UErrorCode status = U_ZERO_ERROR;
     const char* strings[] = {
@@ -141,9 +140,7 @@
         };
 
     log_verbose("Testing s[get] 2 digit year start regressively\n");
-    tzID=(UChar*)malloc(sizeof(UChar) * 4);
-    u_uastrcpy(tzID, "PST");
-    cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_GREGORIAN, &status);
+    cal=ucal_open(NULL, 0, "en_US", UCAL_GREGORIAN, &status);
     if(U_FAILURE(status)){
         log_err("error in ucal_open caldef : %s\n", myErrorName(status));
     }
@@ -161,7 +158,7 @@
 
     
     u_uastrcpy(pat, "yyMMdd");
-    def = udat_open(UDAT_IGNORE,UDAT_IGNORE,NULL, NULL, 0,pat, u_strlen(pat), &status);
+    def = udat_open(UDAT_IGNORE,UDAT_IGNORE,NULL, NULL, 0, pat, u_strlen(pat), &status);
     if(U_FAILURE(status))
     {
         log_err("FAIL: error in creating the dateformat using u_openPattern(): %s\n", myErrorName(status));
@@ -190,7 +187,6 @@
     
     udat_close(def);
     ucal_close(cal);
-    free(tzID);
 }
 
 
@@ -203,11 +199,14 @@
     UChar *myDate;
     UErrorCode status = U_ZERO_ERROR;
     UChar *pattern;
+    UChar tzID[4];
+
     log_verbose("Testing apply pattern and to pattern regressively\n");
+    u_uastrcpy(tzID, "PST");
     pattern=(UChar*)malloc(sizeof(UChar) * 11);
     u_uastrcpy(pattern, "yyyy/MM/dd");
     log_verbose("%s\n", austrdup(pattern) );
-    def = udat_open(UDAT_IGNORE,UDAT_IGNORE,NULL,NULL,0,pattern, u_strlen(pattern),&status);
+    def = udat_open(UDAT_IGNORE,UDAT_IGNORE,NULL,tzID,-1,pattern, u_strlen(pattern),&status);
     if(U_FAILURE(status))
     {
         log_err("FAIL: error in creating the dateformat using openPattern: %s\n", myErrorName(status));
@@ -236,11 +235,11 @@
 
 void aux917( UDateFormat *fmt, UChar* str) 
 {    
-   int32_t resultlength, resultlengthneeded;
-   UErrorCode status = U_ZERO_ERROR;
-   UChar* formatted=NULL;
-   UChar *pat=NULL;
-   UDate d1=1000000000.0;
+    int32_t resultlength, resultlengthneeded;
+    UErrorCode status = U_ZERO_ERROR;
+    UChar* formatted=NULL;
+    UChar *pat=NULL;
+    UDate d1=1000000000.0;
    
     resultlength=0;
     resultlengthneeded=udat_toPattern(fmt, TRUE, NULL, resultlength, &status);
@@ -275,19 +274,20 @@
     UErrorCode status = U_ZERO_ERROR;
     UDate myDate;
     UChar *myString;
-    UChar dateString[20], pattern[20], tzID[4];
-    u_uastrcpy(dateString, "1995-040.05:01:29");
-    u_uastrcpy(pattern, "yyyy-DDD.hh:mm:ss");
+    UChar dateString[30], pattern[20], tzID[4];
+    u_uastrcpy(dateString, "1995-040.05:01:29 -8");
+    u_uastrcpy(pattern, "yyyy-DDD.hh:mm:ss z");
 
     log_verbose( "dateString= %s Using yyyy-DDD.hh:mm:ss\n", austrdup(dateString) );
     status = U_ZERO_ERROR;
-    
-    formatter = udat_open(UDAT_IGNORE,UDAT_IGNORE,"en_US",NULL,0,pattern, u_strlen(pattern), &status);
+    u_uastrcpy(tzID, "PST");
+
+    formatter = udat_open(UDAT_IGNORE,UDAT_IGNORE,"en_US",tzID,-1,pattern, u_strlen(pattern), &status);
     pos=0;
     myDate = udat_parse(formatter, dateString, u_strlen(dateString), &pos, &status);
     
     
-    fmt = udat_open(UDAT_FULL,UDAT_LONG ,NULL, NULL, 0, NULL, 0, &status);
+    fmt = udat_open(UDAT_FULL,UDAT_LONG ,NULL, tzID, -1, NULL, 0, &status);
     if(U_FAILURE(status))
     {
         log_err("FAIL: error in creating the dateformat using default date and time style: %s\n", 
@@ -295,7 +295,6 @@
         return;
     }
     myString = myFormatit(fmt, myDate);
-    u_uastrcpy(tzID, "PST");
     cal=ucal_open(tzID, u_strlen(tzID), "en_US", UCAL_GREGORIAN, &status);
     if(U_FAILURE(status)){
         log_err("FAIL: error in ucal_open caldef : %s\n", myErrorName(status));
@@ -474,6 +473,8 @@
     UChar *result;
     const char* expect =  "7:25:43 AM";
     
+    ctest_setTimeZone(NULL, &status);
+
     fmt= udat_open(UDAT_MEDIUM,UDAT_NONE ,"en_US_CA", NULL, -1, NULL, 0, &status);
     if(U_FAILURE(status))
     {
@@ -495,6 +496,8 @@
     }
         
     udat_close(fmt);
+
+    ctest_resetTimeZone();
 }
 
 /*INTERNAL FUNCTION USED */

Index: cintltst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cintltst.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- cintltst.c	10 Sep 2003 02:42:34 -0000	1.4
+++ cintltst.c	6 Apr 2004 10:09:25 -0000	1.5
@@ -29,6 +29,8 @@
 #include "unicode/ucnv.h"
 #include "unicode/ures.h"
 #include "unicode/uclean.h"
+#include "unicode/ucal.h"
+#include "uoptions.h"
 
 #ifdef XP_MAC_CONSOLE
 #   include <console.h>
@@ -37,7 +39,6 @@
 #define CTST_LEAK_CHECK 1
 #ifdef CTST_LEAK_CHECK
 U_CFUNC void ctst_freeAll(void);
-U_CFUNC void ctst_init(void);
 #endif
 
 static char* _testDataPath=NULL;
@@ -47,21 +48,7 @@
  */
 void ctest_setICU_DATA(void);
 
-static UBool gMutexInitialized = FALSE;
 
-static void TestMutex(void) {
-    if (!gMutexInitialized) {
-        log_verbose("*** Failure! The global mutex was not initialized.\n"
-                "*** Make sure the right linker was used.\n");
-    }
-}
-
-U_CFUNC void addSetup(TestNode** root);
-
-void addSetup(TestNode** root)
-{
-    addTest(root, &TestMutex,    "setup/TestMutex");
-}
 
 #if UCONFIG_NO_LEGACY_CONVERSION
 #   define TRY_CNV_1 "iso-8859-1"
@@ -71,70 +58,143 @@
 #   define TRY_CNV_2 "sjis"
 #endif
 
+
+/*
+ * Tracing functions.
+ */
+static int traceFnNestingDepth = 0;
+U_CDECL_BEGIN
+static void U_CALLCONV TraceEntry(const void *context, int32_t fnNumber) {
+    char buf[500];
+    utrace_format(buf, sizeof(buf), traceFnNestingDepth*3, "%s() enter.\n", utrace_functionName(fnNumber));
+    buf[sizeof(buf)-1]=0;  
+    fputs(buf, stdout);
+    traceFnNestingDepth++;
+}
+        
+static void U_CALLCONV TraceExit(const void *context, int32_t fnNumber, const char *fmt, va_list args) {
+    char buf[500];
+
+    if (traceFnNestingDepth>0) {
+        traceFnNestingDepth--;
+    }
+    utrace_format(buf, sizeof(buf), traceFnNestingDepth*3, "%s() ", utrace_functionName(fnNumber));
+    buf[sizeof(buf)-1]=0;
+    fputs(buf, stdout);
+    utrace_vformat(buf, sizeof(buf), traceFnNestingDepth*3, fmt, args);
+    buf[sizeof(buf)-1]=0;
+    fputs(buf, stdout);
+    putc('\n', stdout);
+}
+
+static void U_CALLCONV TraceData(const void *context, int32_t fnNumber, 
+                          int32_t level, const char *fmt, va_list args) {
+    char buf[500];
+    utrace_vformat(buf, sizeof(buf), traceFnNestingDepth*3, fmt, args);
+    buf[sizeof(buf)-1]=0;
+    fputs(buf, stdout);
+    putc('\n', stdout);
+}
+U_CDECL_END
+
+
+
 int main(int argc, const char* const argv[])
 {
     int nerrors = 0;
     int warnOnMissingData = 0;
-    int i;
+    int i, j;
     TestNode *root;
     const char *warnOrErr = "Failure"; 
+    const char** argv2;
 
     /* initial check for the default converter */
     UErrorCode errorCode = U_ZERO_ERROR;
     UResourceBundle *rb;
     UConverter *cnv;
 
-    /* This must be tested before using anything! */
-    gMutexInitialized = umtx_isInitialized(NULL);
+    U_MAIN_INIT_ARGS(argc, argv);
+
+    argv2 = (const char**) malloc(sizeof(char*) * argc);
+    if (argv2 == NULL) {
+        printf("*** Error: Out of memory (too many cmd line args?)\n");
+        return 1;
+    }
+    argv2[0] = argv[0];
+
 
     /* Checkargs */
-    for(i=1;i<argc;i++) {
+    /* TODO:  Test framework arg handling needs to be decoupled from test execution
+     *        so that the args being processed here don't need special handling,
+     *        separate from the other test args.
+     */
+    ICU_TRACE = UTRACE_OFF;
+    for(i=1,j=1;i<argc;i++) {
+        argv2[j++] = argv[i];
         if(!strcmp(argv[i],"-w")) {
             warnOnMissingData = 1;
             warnOrErr = "Warning";
         }
+        else if (strcmp( argv[i], "-t_error") == 0) {
+            ICU_TRACE = UTRACE_ERROR;
+        }
+        else if (strcmp( argv[i], "-t_warn") == 0) {
+            ICU_TRACE = UTRACE_WARNING;
+        }
+        else if (strcmp( argv[i], "-t_oc") == 0) {
+            ICU_TRACE = UTRACE_OPEN_CLOSE;
+        }
+        else if (strcmp( argv[i], "-t_info") == 0) {
+            ICU_TRACE = UTRACE_INFO;
+        }
+        else if (strcmp( argv[i], "-t_verbose") == 0) {
+            ICU_TRACE = UTRACE_VERBOSE;
+        }
     }
+    argc = j;
 
-    while (REPEAT_TESTS > 0) {
+    
+    utrace_setFunctions(NULL, TraceEntry, TraceExit, TraceData);
+    utrace_setLevel(ICU_TRACE);
+ 
+    
+    while (REPEAT_TESTS > 0) {   /* Loop runs once per complete execution of the tests 
+                                  *   used for -r  (repeat) test option.                */
 
-#ifdef CTST_LEAK_CHECK
-        ctst_init();
-#endif
-        /* try opening the data from dll instead of the dat file */
-        cnv = ucnv_open(TRY_CNV_1, &errorCode);
-        if(cnv != 0) {
-            /* ok */
-            ucnv_close(cnv);
-        } else {
+        /* Check whether ICU will initialize without forcing the build data directory into
+         *  the ICU_DATA path.  Success here means either the data dll contains data, or that
+         *  this test program was run with ICU_DATA set externally.  Failure of this check
+         *  is normal when ICU data is not packaged into a shared library.
+         *
+         *  Whether or not this test succeeds, we want to cleanup and reinitialize
+         *  with a data path so that data loading from individual files can be tested.
+         */
+        u_init(&errorCode);
+        if (U_FAILURE(errorCode)) {
             fprintf(stderr,
-                    "#### WARNING! The converter for " TRY_CNV_1 " cannot be loaded from data dll/so."
-                    "Proceeding to load data from dat file.\n");
-            errorCode = U_ZERO_ERROR;
-
-            ctest_setICU_DATA();
+                "#### Note:  ICU Init without build-specific setDataDirectory() failed.\n");
         }
+        u_cleanup();
+        errorCode = U_ZERO_ERROR;
+        utrace_setFunctions(NULL, TraceEntry, TraceExit, TraceData);
+        utrace_setLevel(ICU_TRACE);
 
-        /* If no ICU_DATA environment was set, try to fake up one. */
-        /* fprintf(stderr, "u_getDataDirectory() = %s\n", u_getDataDirectory()); */
-
-#ifdef XP_MAC_CONSOLE
-        argc = ccommand((char***)&argv);
-#endif
-
-        cnv  = ucnv_open(NULL, &errorCode);
-        if(cnv != NULL) {
-            /* ok */
-            ucnv_close(cnv);
-        } else {
+        /* Initialize ICU */
+        ctest_setICU_DATA();    /* u_setDataDirectory() must happen Before u_init() */
+        u_init(&errorCode);
+        if (U_FAILURE(errorCode)) {
             fprintf(stderr,
-                "*** %s! The default converter cannot be opened.\n"
+                "#### ERROR! %s: u_init() failed with status = \"%s\".\n" 
                 "*** Check the ICU_DATA environment variable and \n"
-                "*** check that the data files are present.\n", warnOrErr);
-            if(warnOnMissingData == 0) {
-                fprintf(stderr, "*** Exitting.  Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n");
-                return 1;
-            }
+                "*** check that the data files are present.\n", argv[0], u_errorName(errorCode));
+                if(warnOnMissingData == 0) {
+                    fprintf(stderr, "*** Exiting.  Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n");
+                    u_cleanup();
+                    return 1;
+                }
         }
+        
+
 
         /* try more data */
         cnv = ucnv_open(TRY_CNV_2, &errorCode);
@@ -148,6 +208,7 @@
                     "*** check that the data files are present.\n", warnOrErr);
             if(warnOnMissingData == 0) {
                 fprintf(stderr, "*** Exitting.  Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n");
+                u_cleanup();
                 return 1;
             }
         }
@@ -163,39 +224,35 @@
                     "*** check that the data files are present.\n", warnOrErr);
             if(warnOnMissingData == 0) {
                 fprintf(stderr, "*** Exitting.  Use the '-w' option if data files were\n*** purposely removed, to continue test anyway.\n");
+                u_cleanup();
                 return 1;
             }
         }
 
         fprintf(stdout, "Default locale for this run is %s\n", uloc_getDefault());
 
+        /* Build a tree of all tests.   
+         *   Subsequently will be used to find / iterate the tests to run */
         root = NULL;
         addAllTests(&root);
-        nerrors = processArgs(root, argc, argv);
+
+        /*  Tests acutally run HERE.   TODO:  separate command line option parsing & setting from test execution!! */
+        nerrors = processArgs(root, argc, argv2);
+
         if (--REPEAT_TESTS > 0) {
             printf("Repeating tests %d more time(s)\n", REPEAT_TESTS);
         }
         cleanUpTestTree(root);
+
 #ifdef CTST_LEAK_CHECK
         ctst_freeAll();
-
         /* To check for leaks */
-
         u_cleanup(); /* nuke the hashtable.. so that any still-open cnvs are leaked */
 #endif
-    }
 
-    if (!gMutexInitialized) {
-        fprintf(stderr,
-            "#### WARNING!\n"
-            "  The global mutex was not initialized during C++ static initialization.\n"
-            "  You must explicitly initialize ICU by calling u_init() before using ICU in multiple threads.\n"
-            "  If you are using ICU in a single threaded application, use of u_init() is recommended,\n"
-            "  but is not required.\n"
-            "#### WARNING!\n"
-            );
-    }
+    }  /* End of loop that repeats the entire test, if requested.  (Normally doesn't loop)  */
 
+    free((void*)argv2);
     return nerrors ? 1 : 0;
 }
 
@@ -371,7 +428,7 @@
     */
 #if defined (U_TOPBUILDDIR)
     {
-        dataOutDir = U_TOPBUILDDIR  U_FILE_SEP_STRING "data"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
+        dataOutDir = U_TOPBUILDDIR "data"U_FILE_SEP_STRING"out"U_FILE_SEP_STRING;
     }
 #else
 
@@ -422,11 +479,13 @@
  */
 void ctest_setICU_DATA() {
 
-
     /* No location for the data dir was identifiable.
      *   Add other fallbacks for the test data location here if the need arises
      */
-    u_setDataDirectory(ctest_dataOutDir());
+    if (getenv("ICU_DATA") == NULL) {
+        /* If ICU_DATA isn't set, set it to the usual location */
+        u_setDataDirectory(ctest_dataOutDir());
+    }
 }
 
 UChar* CharsToUChars(const char* str) {
@@ -520,19 +579,65 @@
     return _testDataPath;
 }
 
+#define CTEST_MAX_TIMEZONE_SIZE 256
+static UChar gOriginalTimeZone[CTEST_MAX_TIMEZONE_SIZE] = {0};
+
+/**
+ * Call this once to get a consistent timezone. Use ctest_resetTimeZone to set it back to the original value.
+ * @param optionalTimeZone Set this to a requested timezone.
+ *      Set to NULL to use the standard test timezone (Pacific Time)
+ */
+U_CFUNC void ctest_setTimeZone(const char *optionalTimeZone, UErrorCode *status) {
+#if !UCONFIG_NO_FORMATTING
+    UChar zoneID[CTEST_MAX_TIMEZONE_SIZE];
+
+    if (optionalTimeZone == NULL) {
+        optionalTimeZone = "America/Los_Angeles";
+    }
+    if (gOriginalTimeZone[0]) {
+        log_err("*** Error: time zone saved twice. New value will be %s\n",
+               optionalTimeZone);
+    }
+    ucal_getDefaultTimeZone(gOriginalTimeZone, CTEST_MAX_TIMEZONE_SIZE, status);
+    if (U_FAILURE(*status)) {
+        log_err("*** Error: Failed to save default time zone: %s\n",
+               u_errorName(*status));
+        *status = U_ZERO_ERROR;
+    }
+
+    u_uastrncpy(zoneID, optionalTimeZone, CTEST_MAX_TIMEZONE_SIZE-1);
+    zoneID[CTEST_MAX_TIMEZONE_SIZE-1] = 0;
+    ucal_setDefaultTimeZone(zoneID, status);
+    if (U_FAILURE(*status)) {
+        log_err("*** Error: Failed to set default time zone to \"%s\": %s\n",
+               optionalTimeZone, u_errorName(*status));
+    }
+#endif
+}
+
+/**
+ * Call this once get back the original timezone
+ */
+U_CFUNC void ctest_resetTimeZone(void) {
+#if !UCONFIG_NO_FORMATTING
+    UErrorCode status = U_ZERO_ERROR;
+
+    ucal_setDefaultTimeZone(gOriginalTimeZone, &status);
+    if (U_FAILURE(status)) {
+        log_err("*** Error: Failed to reset default time zone: %s\n",
+               u_errorName(status));
+    }
+    /* Set to an empty state */
+    gOriginalTimeZone[0] = 0;
+#endif
+}
+
 #define CTST_MAX_ALLOC 10000
 /* Array used as a queue */
-static void * ctst_allocated_stuff[CTST_MAX_ALLOC];
+static void * ctst_allocated_stuff[CTST_MAX_ALLOC] = {0};
 static int ctst_allocated = 0;
 static UBool ctst_free = FALSE;
 
-void ctst_init(void) {
-    int i;
-    for(i=0; i<CTST_MAX_ALLOC; i++) {
-        ctst_allocated_stuff[i] = NULL;
-    }
-}
-
 void *ctst_malloc(size_t size) {
     if(ctst_allocated >= CTST_MAX_ALLOC - 1) {
         ctst_allocated = 0;
@@ -550,12 +655,15 @@
     if(ctst_free == 0) {
         for(i=0; i<ctst_allocated; i++) {
             free(ctst_allocated_stuff[i]);
+            ctst_allocated_stuff[i] = NULL;
         }
     } else {
         for(i=0; i<CTST_MAX_ALLOC; i++) {
             free(ctst_allocated_stuff[i]);
+            ctst_allocated_stuff[i] = NULL;
         }
     }
+    ctst_allocated = 0;
     _testDataPath=NULL;
 }
 #endif

Index: cintltst.dsp
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cintltst.dsp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cintltst.dsp	10 Sep 2003 02:42:34 -0000	1.3
+++ cintltst.dsp	6 Apr 2004 10:09:25 -0000	1.4
@@ -325,6 +325,10 @@
 # End Source File
 # Begin Source File
 
+SOURCE=.\sorttest.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\trietest.c
 # End Source File
 # Begin Source File
@@ -526,12 +530,20 @@
 # End Source File
 # Begin Source File
 
+SOURCE=.\hpmufn.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\mstrmtst.c
 # End Source File
 # Begin Source File
 
 SOURCE=.\putiltst.c
 # End Source File
+# Begin Source File
+
+SOURCE=.\tracetst.c
+# End Source File
 # End Group
 # Begin Group "normalization"
 
@@ -603,6 +615,30 @@
 # Begin Source File
 
 SOURCE=.\utransts.c
+# End Source File
+# End Group
+# Begin Group "sprep & idna"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\idnatest.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\nfsprep.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\nfsprep.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\spreptst.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\sprpdata.c
 # End Source File
 # End Group
 # End Target

Index: cintltst.h
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cintltst.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cintltst.h	10 Sep 2003 02:42:34 -0000	1.3
+++ cintltst.h	6 Apr 2004 10:09:25 -0000	1.4
@@ -73,4 +73,16 @@
 #define myErrorName(errorCode) u_errorName(errorCode)
 
 
+/**
+ * Call this once to get a consistent timezone. Use ctest_resetTimeZone to set it back to the original value.
+ * @param optionalTimeZone Set this to a requested timezone.
+ *      Set to NULL to use the standard test timezone (Pacific Time)
+ */
+U_CFUNC void ctest_setTimeZone(const char *optionalTimeZone, UErrorCode *status);
+/**
+ * Call this once get back the original timezone
+ */
+U_CFUNC void ctest_resetTimeZone(void);
+
+
 #endif

Index: cintltst.vcproj
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cintltst.vcproj,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- cintltst.vcproj	10 Sep 2003 02:42:34 -0000	1.1
+++ cintltst.vcproj	6 Apr 2004 10:09:25 -0000	1.2
@@ -1,7 +1,7 @@
-<?xml version="1.0" encoding = "Windows-1252"?>
+<?xml version="1.0" encoding="Windows-1252"?>
 <VisualStudioProject
 	ProjectType="Visual C++"
-	Version="7.00"
+	Version="7.10"
 	Name="cintltst"
 	SccProjectName=""
 	SccLocalPath="">
@@ -44,9 +44,9 @@
 				AdditionalOptions="/MACHINE:I386"
 				AdditionalDependencies="icuucd.lib icuind.lib icutud.lib ctestfwd.lib"
 				OutputFile=".\Debug/cintltst.exe"
-				LinkIncremental="1"
+				LinkIncremental="2"
 				SuppressStartupBanner="TRUE"
-				AdditionalLibraryDirectories="..\..\..\lib"
+				AdditionalLibraryDirectories="..\..\..\lib\"
 				GenerateDebugInformation="TRUE"
 				ProgramDatabaseFile=".\Debug/cintltst.pdb"
 				SubSystem="1"/>
@@ -66,7 +66,13 @@
 			<Tool
 				Name="VCWebServiceProxyGeneratorTool"/>
 			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
 				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
 		</Configuration>
 		<Configuration
 			Name="Release|Win32"
@@ -123,9 +129,17 @@
 			<Tool
 				Name="VCWebServiceProxyGeneratorTool"/>
 			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
 				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
 		</Configuration>
 	</Configurations>
+	<References>
+	</References>
 	<Files>
 		<Filter
 			Name="bidi"
@@ -181,9 +195,6 @@
 				RelativePath=".\ccolltst.h">
 			</File>
 			<File
-				RelativePath=".\cctest.c">
-			</File>
-			<File
 				RelativePath=".\ccurrtst.c">
 			</File>
 			<File
@@ -269,6 +280,9 @@
 				RelativePath=".\chashtst.c">
 			</File>
 			<File
+				RelativePath=".\sorttest.c">
+			</File>
+			<File
 				RelativePath=".\trietest.c">
 			</File>
 			<File
@@ -294,6 +308,9 @@
 				RelativePath=".\cconvtst.c">
 			</File>
 			<File
+				RelativePath=".\cctest.c">
+			</File>
+			<File
 				RelativePath=".\eurocreg.c">
 			</File>
 			<File
@@ -436,11 +453,17 @@
 				RelativePath=".\cutiltst.c">
 			</File>
 			<File
+				RelativePath=".\hpmufn.c">
+			</File>
+			<File
 				RelativePath=".\mstrmtst.c">
 			</File>
 			<File
 				RelativePath=".\putiltst.c">
 			</File>
+			<File
+				RelativePath=".\tracetst.c">
+			</File>
 		</Filter>
 		<Filter
 			Name="normalization"
@@ -459,6 +482,9 @@
 				RelativePath=".\cucdapi.c">
 			</File>
 			<File
+				RelativePath=".\cucdapi.h">
+			</File>
+			<File
 				RelativePath=".\cucdtst.c">
 			</File>
 			<File
@@ -500,6 +526,25 @@
 		<Filter
 			Name="regex"
 			Filter="">
+		</Filter>
+		<Filter
+			Name="sprep &amp; idna"
+			Filter="">
+			<File
+				RelativePath="idnatest.c">
+			</File>
+			<File
+				RelativePath="nfsprep.c">
+			</File>
+			<File
+				RelativePath="nfsprep.h">
+			</File>
+			<File
+				RelativePath="spreptst.c">
+			</File>
+			<File
+				RelativePath="sprpdata.c">
+			</File>
 		</Filter>
 	</Files>
 	<Globals>

Index: citertst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/citertst.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- citertst.c	10 Sep 2003 02:42:34 -0000	1.4
+++ citertst.c	6 Apr 2004 10:09:26 -0000	1.5
@@ -25,6 +25,7 @@
 #include "unicode/uloc.h"
 #include "unicode/uchar.h"
 #include "unicode/ustring.h"
+#include "callcoll.h"
 #include "cmemory.h"
 #include "cintltst.h"
 #include "citertst.h"
@@ -570,7 +571,7 @@
     u_uastrcpy(test1, "What subset of all possible test cases?");
     u_uastrcpy(test2, "has the highest probability of detecting");
     en_us = ucol_open("en_US", &status);
-    log_verbose("Testing getOffset and setOffset for CollationElements\n");
+    log_verbose("Testing getOffset and setOffset for collations\n");
     iter = ucol_openElements(en_us, test1, u_strlen(test1), &status);
     if(U_FAILURE(status)){
         log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n",
@@ -578,6 +579,19 @@
         ucol_close(en_us);
         return;
     }
+
+    /* testing boundaries */
+    ucol_setOffset(iter, 0, &status);
+    if (U_FAILURE(status) || ucol_previous(iter, &status) != UCOL_NULLORDER) {
+        log_err("Error: After setting offset to 0, we should be at the end "
+                "of the backwards iteration");
+    }
+    ucol_setOffset(iter, u_strlen(test1), &status);
+    if (U_FAILURE(status) || ucol_next(iter, &status) != UCOL_NULLORDER) {
+        log_err("Error: After setting offset to end of the string, we should "
+                "be at the end of the backwards iteration");
+    }
+
     /* Run all the way through the iterator, then get the offset */
 
     orders = getOrders(iter, &orderLength);
@@ -759,69 +773,6 @@
     free(test2);
 }
 
-
-
-static void backAndForth(UCollationElements *iter)
-{
-    /* Run through the iterator forwards and stick it into an array */
-    int32_t index, o;
-    UErrorCode status = U_ZERO_ERROR;
-    int32_t orderLength = 0;
-    int32_t *orders;
-    orders= getOrders(iter, &orderLength);
-
-
-    /* Now go through it backwards and make sure we get the same values */
-    index = orderLength;
-    ucol_reset(iter);
-
-    /* synwee : changed */
-    while ((o = ucol_previous(iter, &status)) != UCOL_NULLORDER)
-    {
-      if (o != orders[-- index])
-      {
-        if (o == 0)
-          index ++;
-        else
-        {
-          while (index > 0 && orders[-- index] == 0)
-          {
-          }
-          if (o != orders[index])
-          {
-            log_err("Mismatch at index : 0x%x\n", index);
-            return;
-          }
-
-        }
-      }
-    }
-
-    while (index != 0 && orders[index - 1] == 0) {
-      index --;
-    }
-
-    if (index != 0)
-    {
-        log_err("Didn't get back to beginning - index is %d\n", index);
-
-        ucol_reset(iter);
-        log_err("\nnext: ");
-        if ((o = ucol_next(iter, &status)) != UCOL_NULLORDER)
-        {
-            log_err("Error at %x\n", o);
-        }
-        log_err("\nprev: ");
-        if ((o = ucol_previous(iter, &status)) != UCOL_NULLORDER)
-        {
-            log_err("Error at %x\n", o);
-        }
-        log_verbose("\n");
-    }
-
-    free(orders);
-}
-
 /** @bug 4108762
  * Test for getMaxExpansion()
  */
@@ -830,7 +781,10 @@
     UErrorCode          status = U_ZERO_ERROR;
     UCollator          *coll   ;/*= ucol_open("en_US", &status);*/
     UChar               ch     = 0;
-    UChar               supplementary[2] = {0xD800, 0xDC00};
+    UChar32             unassigned = 0xEFFFD;
+    UChar               supplementary[2];
+    uint32_t            index = 0;
+    UBool               isError = FALSE;
     uint32_t            sorder = 0;
     UCollationElements *iter   ;/*= ucol_openElements(coll, &ch, 1, &status);*/
     uint32_t            temporder = 0;
@@ -901,6 +855,7 @@
                   ch, 3);
       }
 
+      U16_APPEND(supplementary, index, 2, unassigned, isError);
       ucol_setText(iter, supplementary, 2, &status);
       sorder = ucol_previous(iter, &status);
 
@@ -952,57 +907,6 @@
 
 }
 
-/**
- * Return an integer array containing all of the collation orders
- * returned by calls to next on the specified iterator
- */
-static int32_t* getOrders(UCollationElements *iter, int32_t *orderLength)
-{
-    UErrorCode status;
-    int32_t order;
-    int32_t maxSize = 100;
-    int32_t size = 0;
-    int32_t *temp;
-    int32_t *orders =(int32_t*)malloc(sizeof(int32_t) * maxSize);
-    status= U_ZERO_ERROR;
-
-
-    while ((order=ucol_next(iter, &status)) != UCOL_NULLORDER)
-    {
-        if (size == maxSize)
-        {
-            maxSize *= 2;
-            temp = (int32_t*)malloc(sizeof(int32_t) * maxSize);
-
-            memcpy(temp, orders, size * sizeof(int32_t));
-            free(orders);
-            orders = temp;
-
-        }
-
-        orders[size++] = order;
-    }
-
-    if (maxSize > size)
-    {
-        if (size == 0) {
-            size = 1;
-            temp = (int32_t*)malloc(sizeof(int32_t) * size);
-            temp[0] = 0;
-        }
-        else {
-            temp = (int32_t*)malloc(sizeof(int32_t) * size);
-            memcpy(temp, orders, size * sizeof(int32_t));
-        }
-
-        free(orders);
-        orders = temp;
-    }
-
-    *orderLength = size;
-    return orders;
-}
-
 
 static void assertEqual(UCollationElements *i1, UCollationElements *i2)
 {
@@ -1682,8 +1586,13 @@
                    goto fail;
                }
            }
-           if ((primary != 0 && primary < primarymax) || (primary >= 0xFF00 && !isContinuation(ce))) {
-               log_err("UCA primary weight out of bounds\n");
+           if ((primary != 0 && primary < primarymax) 
+               || ((primary & 0xFF) == 0xFF) || (((primary>>8) & 0xFF) == 0xFF) 
+               || ((primary & 0xFF) && ((primary & 0xFF) <= 0x03)) 
+               || (((primary>>8) & 0xFF) && ((primary>>8) & 0xFF) <= 0x03)
+               || (primary >= 0xFE00 && !isContinuation(ce))) {
+               log_err("UCA primary weight out of bounds: %04X for string starting with %04X\n", 
+                   primary, codepoints[0]);
                goto fail;
            }
            /* case matching not done since data generated by ken */
@@ -1709,13 +1618,15 @@
     /* testing UCA collation elements */
     UErrorCode  status      = U_ZERO_ERROR;
     /* en_US has no tailorings */
-    UCollator  *coll        = ucol_open("en_US", &status);
+    UCollator  *coll        = ucol_open("root", &status);
     /* tailored locales */
-    char        locale[][6] = {"fr_FR", "ko_KR", "sh_YU", "th_TH", "zh_CN"};
+    char        locale[][11] = {"fr_FR", "ko_KR", "sh_YU", "th_TH", "zh_CN", "zh__PINYIN"};
+    const char *loc;
     FileStream *file = getFractionalUCA();
     char        line[1024];
     UChar       codepoints[10];
     int         count = 0;
+    int         maxCount = 0;
     UParseError parseError;
     if (U_FAILURE(status)) {
         log_err("en_US collator creation failed\n");
@@ -1750,7 +1661,12 @@
 
     /* testing tailored collation elements */
     log_verbose("Testing tailored elements\n");
-    while (count < 5) {
+    if(QUICK) {
+        maxCount = sizeof(locale)/sizeof(locale[0]);
+    } else {
+        maxCount = uloc_countAvailable();
+    }
+    while (count < maxCount) {
         const UChar *rules = NULL,
                     *current = NULL;
         UChar *rulesCopy = NULL;
@@ -1768,10 +1684,21 @@
         UColTokenParser src;
         uint32_t strength = 0;
         uint16_t specs = 0;
+        if(QUICK) {
+            loc = locale[count];
+        } else {
+            loc = uloc_getAvailable(count);
+            if(!hasCollationElements(loc)) {
+                count++;
+                continue;
+            }
+        }
 
-        coll      = ucol_open(locale[count], &status);
+        log_verbose("Testing CEs for %s\n", loc);
+
+        coll      = ucol_open(loc, &status);
         if (U_FAILURE(status)) {
-            log_err("%s collator creation failed\n", locale[count]);
+            log_err("%s collator creation failed\n", loc);
             return;
         }
 

Index: citertst.h
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/citertst.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- citertst.h	10 Sep 2003 02:42:34 -0000	1.3
+++ citertst.h	6 Apr 2004 10:09:26 -0000	1.4
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2001, International Business Machines Corporation and
+ * Copyright (c) 1997-2003, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /********************************************************************************
@@ -105,14 +105,6 @@
     /*------------------------------------------------------------------------
      Internal utilities
      */
-
-    static void backAndForth(UCollationElements* iter);
-    
-    /**
-     * Return an integer array containing all of the collation orders
-     * returned by calls to next on the specified iterator
-     */
-    static int32_t* getOrders(UCollationElements* iter, int32_t *orderLength);
 
     
     static void assertEqual(UCollationElements *i1, UCollationElements *i2);

Index: cloctst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cloctst.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- cloctst.c	10 Sep 2003 02:42:34 -0000	1.4
+++ cloctst.c	6 Apr 2004 10:09:26 -0000	1.5
@@ -12,27 +12,31 @@
 *     Madhu Katragadda            Ported for C API
 *********************************************************************************
 */
+#include "cloctst.h"
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include "unicode/utypes.h"
+#include "cintltst.h"
+#include "cmemory.h"
+#include "cstring.h"
[...1665 lines suppressed...]
+#if !UCONFIG_NO_COLLATION
+    {
+        UCollator *obj;
+        const char *req = "es_AR_BUENOSAIRES", *valid, *actual;
+        obj = ucol_open(req, &ec);
+        if (U_FAILURE(ec)) {
+            log_err("ucol_open failed\n");
+            return;
+        }
+        valid = ucol_getLocaleByType(obj, ULOC_VALID_LOCALE, &ec);
+        actual = ucol_getLocaleByType(obj, ULOC_ACTUAL_LOCALE, &ec);
+        if (U_FAILURE(ec)) {
+            log_err("ucol_getLocaleByType() failed\n");
+            return;
+        }
+        _checklocs("ucol", req, valid, actual);
+        ucol_close(obj);
+    }
+#endif
 }

Index: cloctst.h
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cloctst.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cloctst.h	10 Sep 2003 02:42:34 -0000	1.3
+++ cloctst.h	6 Apr 2004 10:09:27 -0000	1.4
@@ -67,16 +67,35 @@
  /* Make sure that Country information is the same across locales, within reason. */
  static void TestConsistentCountryInfo(void);
 
+ /* Make sure we can pass "de_DE@Collation=PHONEBOOK" */
+ static void MoreVariants(void);
+ 
+ /* Test getting keyword enumeratin */
+ static void TestKeywordVariants(void);
+
+ /* Test getting keyword values */
+ static void TestKeywordVariantParsing(void);
+
 /**
  * routine to perform subtests, used by TestDisplayNames
  */
  static void doTestDisplayNames(const char* inLocale, int32_t compareIndex);
 
+ static void TestCanonicalization(void);
+
+ static void TestDisplayKeywords(void);
+
+ static void TestDisplayKeywordValues(void);
+
+ static void TestGetBaseName(void);
+
+static void TestGetLocale(void);
+
 /**
  * additional intialization for datatables storing expected values
  */
 static void setUpDataTable(void);
 static void cleanUpDataTable(void);
-void displayDataTable(void);
+/*static void displayDataTable(void);*/
 
 #endif

Index: cmsccoll.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cmsccoll.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- cmsccoll.c	10 Sep 2003 02:42:34 -0000	1.6
+++ cmsccoll.c	6 Apr 2004 10:09:27 -0000	1.7
@@ -31,125 +31,18 @@
 #include "ucol_tok.h"
 #include "cmemory.h"
 #include "cstring.h"
+#include "uassert.h"
 #include "unicode/parseerr.h"
 #include "unicode/ucnv.h"
 #include "uparse.h"
 
 #define MAX_TOKEN_LEN 16
-#define RULE_BUFFER_LEN 8192
-
[...1438 lines suppressed...]
     addTest(root, &TestJ784, "tscoll/cmsccoll/TestJ784");
     addTest(root, &TestJ815, "tscoll/cmsccoll/TestJ815");
-    addTest(root, &TestJ831, "tscoll/cmsccoll/TestJ831");
+    /*addTest(root, &TestJ831, "tscoll/cmsccoll/TestJ831");*/ /* we changed lv locale */
     addTest(root, &TestBefore, "tscoll/cmsccoll/TestBefore");
     addTest(root, &TestRedundantRules, "tscoll/cmsccoll/TestRedundantRules");
     addTest(root, &TestExpansionSyntax, "tscoll/cmsccoll/TestExpansionSyntax");
@@ -4161,6 +4320,12 @@
     TEST(TestSettings);
     TEST(TestEquals);
     TEST(TestJ2726);
+    TEST(NullRule);
+    TEST(TestNumericCollation);
+    TEST(TestTibetanConformance);
+    TEST(TestPinyinProblem);
+    TEST(TestImplicitGeneration);
 }
 
 #endif /* #if !UCONFIG_NO_COLLATION */
+

Index: cmsgtst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cmsgtst.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cmsgtst.c	10 Sep 2003 02:42:35 -0000	1.3
+++ cmsgtst.c	6 Apr 2004 10:09:27 -0000	1.4
@@ -96,6 +96,9 @@
     int32_t resultLengthOut,resultlength,i, patternlength;
     UErrorCode status = U_ZERO_ERROR;
     UDate d1=1000000000.0;
+
+    ctest_setTimeZone(NULL, &status);
+
     str=(UChar*)malloc(sizeof(UChar) * 7);
     u_uastrncpy(str, "MyDisk", 7);
     resultlength=1;
@@ -206,10 +209,10 @@
                         austrdup(result), austrdup(testResultStrings[i]) );
                 }
 
-#if !defined(HPUX)
+#if !defined(U_HPUX)
                 /* HP/UX and possibly other platforms don't properly check for this case.
                    We pass in a UDate, but the function expects a UDate *.  When va_arg is used,
-                   most compilers will return NULL, but HP/UX won't do that and will return 2
+                   most compilers will return NULL, but HP-UX won't do that and will return 2
                    in this case.  This is a platform dependent test.
                 */
                 umsg_parse(formatter,result,resultLength,&count,&ec,one,two,d2);
@@ -232,6 +235,8 @@
         umsg_close(formatter);
     }
     FreeStrings();
+
+    ctest_resetTimeZone();
 }
 
 
@@ -244,6 +249,9 @@
     int32_t resultLengthOut, resultlength;
     UDate d = 837039928046.0;
     UErrorCode status = U_ZERO_ERROR;
+
+    ctest_setTimeZone(NULL, &status);
+
     str=(UChar*)malloc(sizeof(UChar) * 15);
     u_uastrcpy(str, "abc");    
     
@@ -328,6 +336,8 @@
     
     free(result);
     free(str);
+
+    ctest_resetTimeZone();
 }
 
 /* Test umsg_format() and umsg_parse() , format and parse sequence and round trip */
@@ -347,6 +357,9 @@
     UParseError parseError;
     UMessageFormat* fmt = NULL;
     int32_t count=0;
+
+    ctest_setTimeZone(NULL, &status);
+
     log_verbose("Testing format and parse with parse error\n");
 
     str=(UChar*)malloc(sizeof(UChar) * 25);
@@ -428,7 +441,8 @@
     free(result);
     free(str);
     free(tzID);
-    
+
+    ctest_resetTimeZone();
 }
 
 /* Test u_formatMessageWithError() and u_parseMessageWithError() , format and parse sequence and round trip */
@@ -448,6 +462,8 @@
     UChar ret[30];
     UParseError parseError;
 
+    ctest_setTimeZone(NULL, &status);
+
     log_verbose("Testing format and parse with parse error\n");
 
     str=(UChar*)malloc(sizeof(UChar) * 25);
@@ -521,6 +537,7 @@
     free(str);
     free(tzID);
     
+    ctest_resetTimeZone();
 }
 
 /* Test u_formatMessage() and u_parseMessage() , format and parse sequence and round trip */
@@ -537,6 +554,9 @@
     UErrorCode status = U_ZERO_ERROR;
     double value = 0.0;
     UChar ret[30];
+
+    ctest_setTimeZone(NULL, &status);
+
     log_verbose("Testing format and parse\n");
 
     str=(UChar*)malloc(sizeof(UChar) * 25);
@@ -610,6 +630,7 @@
     free(str);
     free(tzID);
     
+    ctest_resetTimeZone();
 }
 
 /* test message format with a choice option */
@@ -765,6 +786,9 @@
     int32_t resultLengthOut,resultlength,i, patternlength;
     UErrorCode status = U_ZERO_ERROR;
     UDate d1=1000000000.0;
+
+    ctest_setTimeZone(NULL, &status);
+
     str=(UChar*)malloc(sizeof(UChar) * 7);
     u_uastrcpy(str, "MyDisk");
     resultlength=1;
@@ -798,6 +822,8 @@
     free(result);
     free(str);
     FreeStrings();
+
+    ctest_resetTimeZone();
 }
 
 static void CallParseMessage(const char* locale, UChar* pattern, int32_t patternLength, 
@@ -864,6 +890,8 @@
     const char* PAT = "Number {1,number,#0.000}, String {0}, Date {2,date,12:mm:ss.SSS}";
     const char* EXP = "Number 0,143, String foo, Date 12:34:56.789";
 
+    ctest_setTimeZone(NULL, &status);
+
     u_uastrcpy(string, "foo");
     /* Slight hack here -- instead of date pattern HH:mm:ss.SSS, use
      * 12:mm:ss.SSS.  Why?  So this test generates the same output --
@@ -887,6 +915,8 @@
     } else {
         log_err("FAIL: got \"%s\", expected \"%s\"\n", cresult, EXP);
     }
+
+    ctest_resetTimeZone();
 }
 
 static void OpenMessageFormatTest(void)

Index: cnmdptst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cnmdptst.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- cnmdptst.c	10 Sep 2003 02:42:35 -0000	1.4
+++ cnmdptst.c	6 Apr 2004 10:09:27 -0000	1.5
@@ -21,6 +21,7 @@
 
 #if !UCONFIG_NO_FORMATTING
 
+#include "unicode/ucurr.h"
 #include "unicode/uloc.h"
 #include "unicode/unum.h"
 #include "unicode/ustring.h"
@@ -47,281 +48,281 @@
   addTest(root, &TestRounding487, "tsformat/cnmdptst/TestRounding487");
   addTest(root, &TestDoubleAttribute, "tsformat/cnmdptst/TestDoubleAttribute");
   addTest(root, &TestSecondaryGrouping, "tsformat/cnmdptst/TestSecondaryGrouping");
[...1136 lines suppressed...]
+    
+    
+    for(i = 0; i < noLocales; i++) {
+        strcpy(currLoc, uloc_getAvailable(i));
+        for(j = 0; j < sizeof(currencies)/sizeof(currencies[0]); j++) {
+            strcpy(locale, currLoc);
+            strcat(locale, "@currency=");
+            strcat(locale, currencies[j]);
+            ucurr_forLocale(locale, result, 4, &status);
+            u_charsToUChars(currencies[j], currBuffer, 3);
+            currBuffer[3] = 0;
+            if(u_strcmp(currBuffer, result) != 0) {
+                log_err("Didn't get the right currency for %s\n", locale);
+            }
+        }
+        
+    }
 }
 
 #endif /* #if !UCONFIG_NO_FORMATTING */

Index: cnmdptst.h
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cnmdptst.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cnmdptst.h	10 Sep 2003 02:42:35 -0000	1.3
+++ cnmdptst.h	6 Apr 2004 10:09:27 -0000	1.4
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2001, International Business Machines Corporation and
+ * Copyright (c) 1997-2003, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /********************************************************************************
@@ -48,6 +48,8 @@
 
 /*Internal functions used*/
 static void roundingTest(UNumberFormat*, double,  int32_t, const char*);
+
+static void TestCurrencyKeywords(void);
 
 #endif /* #if !UCONFIG_NO_FORMATTING */
 

Index: cnumtst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cnumtst.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- cnumtst.c	10 Sep 2003 02:42:35 -0000	1.4
+++ cnumtst.c	6 Apr 2004 10:09:27 -0000	1.5
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT:
- * Copyright (c) 1997-2001, International Business Machines Corporation and
+ * Copyright (c) 1997-2003, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /********************************************************************************
@@ -38,6 +38,7 @@
 {
     addTest(root, &TestNumberFormat, "tsformat/cnumtst/TestNumberFormat");
     addTest(root, &TestNumberFormatPadding, "tsformat/cnumtst/TestNumberFormatPadding");
+    addTest(root, &TestInt64Format, "tsformat/cnumtst/TestInt64Format");
 }
 
 /** copy src to dst with unicode-escapes for values < 0x20 and > 0x7e, null terminate if possible */
@@ -593,9 +594,6 @@
     else
         log_verbose("Pass: get and settextAttributes with negative suffix works fine\n");
 
-
-
-
     /*Testing unum_getAttribute and  unum_setAttribute() */
     log_verbose("\nTesting get and set Attributes\n");
     attr=UNUM_GROUPING_SIZE;
@@ -784,6 +782,131 @@
     }
 
     unum_close(pattern);
+}
+
+static UBool
+withinErr(double a, double b, double err) {
+    return uprv_fabs(a - b) < uprv_fabs(a * err); 
+}
+
+static void TestInt64Format() {
+  UChar temp1[512];
+  UChar result[512];
+  UNumberFormat *fmt;
+  UErrorCode status = U_ZERO_ERROR;
+  const double doubleInt64Max = (double)U_INT64_MAX;
+  const double doubleInt64Min = (double)U_INT64_MIN;
+  const double doubleBig = 10.0 * (double)U_INT64_MAX;      
+  int32_t val32;
+  int64_t val64;
+  double  valDouble;
+  int32_t parsepos;
+
+  /* create a number format using unum_openPattern(....) */
+  log_verbose("\nTesting Int64Format\n");
+  u_uastrcpy(temp1, "#.#E0");
+  fmt = unum_open(UNUM_IGNORE, temp1, u_strlen(temp1), NULL, NULL, &status);
+  if(U_FAILURE(status)) {
+    log_err("error in unum_openPattern(): %s\n", myErrorName(status));
+  } else {
+    unum_setAttribute(fmt, UNUM_MAX_FRACTION_DIGITS, 20);
+    unum_formatInt64(fmt, U_INT64_MAX, result, 512, NULL, &status);
+    if (U_FAILURE(status)) {
+      log_err("error in unum_format(): %s\n", myErrorName(status));
+    } else {
+      log_verbose("format int64max: '%s'\n", result);
+      parsepos = 0;
+      val32 = unum_parse(fmt, result, u_strlen(result), &parsepos, &status);
+      if (status != U_INVALID_FORMAT_ERROR) {
+        log_err("parse didn't report error: %s\n", myErrorName(status));
+      } else if (val32 != INT32_MAX) {
+        log_err("parse didn't pin return value, got: %d\n", val32);
+      }
+
+      status = U_ZERO_ERROR;
+      parsepos = 0;
+      val64 = unum_parseInt64(fmt, result, u_strlen(result), &parsepos, &status);
+      if (U_FAILURE(status)) {
+        log_err("parseInt64 returned error: %s\n", myErrorName(status));
+      } else if (val64 != U_INT64_MAX) {
+        log_err("parseInt64 returned incorrect value, got: %ld\n", val64);
+      }
+
+      status = U_ZERO_ERROR;
+      parsepos = 0;
+      valDouble = unum_parseDouble(fmt, result, u_strlen(result), &parsepos, &status);
+      if (U_FAILURE(status)) {
+        log_err("parseDouble returned error: %s\n", myErrorName(status));
+      } else if (valDouble != doubleInt64Max) {
+        log_err("parseDouble returned incorrect value, got: %g\n", valDouble);
+      }
+    }
+
+    unum_formatInt64(fmt, U_INT64_MIN, result, 512, NULL, &status);
+    if (U_FAILURE(status)) {
+      log_err("error in unum_format(): %s\n", myErrorName(status));
+    } else {
+      log_verbose("format int64min: '%s'\n", result);
+      parsepos = 0;
+      val32 = unum_parse(fmt, result, u_strlen(result), &parsepos, &status);
+      if (status != U_INVALID_FORMAT_ERROR) {
+        log_err("parse didn't report error: %s\n", myErrorName(status));
+      } else if (val32 != INT32_MIN) {
+        log_err("parse didn't pin return value, got: %d\n", val32);
+      }
+
+      status = U_ZERO_ERROR;
+      parsepos = 0;
+      val64 = unum_parseInt64(fmt, result, u_strlen(result), &parsepos, &status);
+      if (U_FAILURE(status)) {
+        log_err("parseInt64 returned error: %s\n", myErrorName(status));
+      } else if (val64 != U_INT64_MIN) {
+        log_err("parseInt64 returned incorrect value, got: %ld\n", val64);
+      }
+
+      status = U_ZERO_ERROR;
+      parsepos = 0;
+      valDouble = unum_parseDouble(fmt, result, u_strlen(result), &parsepos, &status);
+      if (U_FAILURE(status)) {
+        log_err("parseDouble returned error: %s\n", myErrorName(status));
+      } else if (valDouble != doubleInt64Min) {
+        log_err("parseDouble returned incorrect value, got: %g\n", valDouble);
+      }
+    }
+
+    unum_formatDouble(fmt, doubleBig, result, 512, NULL, &status);
+    if (U_FAILURE(status)) {
+      log_err("error in unum_format(): %s\n", myErrorName(status));
+    } else {
+      log_verbose("format doubleBig: '%s'\n", result);
+      parsepos = 0;
+      val32 = unum_parse(fmt, result, u_strlen(result), &parsepos, &status);
+      if (status != U_INVALID_FORMAT_ERROR) {
+        log_err("parse didn't report error: %s\n", myErrorName(status));
+      } else if (val32 != INT32_MAX) {
+        log_err("parse didn't pin return value, got: %d\n", val32);
+      }
+
+      status = U_ZERO_ERROR;
+      parsepos = 0;
+      val64 = unum_parseInt64(fmt, result, u_strlen(result), &parsepos, &status);
+      if (status != U_INVALID_FORMAT_ERROR) {
+        log_err("parseInt64 didn't report error error: %s\n", myErrorName(status));
+      } else if (val64 != U_INT64_MAX) {
+        log_err("parseInt64 returned incorrect value, got: %ld\n", val64);
+      }
+
+      status = U_ZERO_ERROR;
+      parsepos = 0;
+      valDouble = unum_parseDouble(fmt, result, u_strlen(result), &parsepos, &status);
+      if (U_FAILURE(status)) {
+        log_err("parseDouble returned error: %s\n", myErrorName(status));
+      } else if (!withinErr(valDouble, doubleBig, 1e-15)) {
+        log_err("parseDouble returned incorrect value, got: %g\n", valDouble);
+      }
+    }
+  }
+  unum_close(fmt);
 }
 
 #endif /* #if !UCONFIG_NO_FORMATTING */

Index: cnumtst.h
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cnumtst.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cnumtst.h	10 Sep 2003 02:42:35 -0000	1.3
+++ cnumtst.h	6 Apr 2004 10:09:28 -0000	1.4
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2001, International Business Machines Corporation and
+ * Copyright (c) 1997-2003, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /********************************************************************************
@@ -32,6 +32,11 @@
      * The function used to test the Number format API with padding
      **/
     static void TestNumberFormatPadding(void);
+
+    /**
+     * The function used to test the Number format API with padding
+     **/
+    static void TestInt64Format(void);
 
 #endif /* #if !UCONFIG_NO_FORMATTING */
 

Index: crestst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/crestst.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- crestst.c	10 Sep 2003 02:42:36 -0000	1.4
+++ crestst.c	6 Apr 2004 10:09:28 -0000	1.5
@@ -20,7 +20,7 @@
 #include "unicode/ustring.h"
 #include "cstring.h"
 #include "filestrm.h"
-#include "cmemory.h"
+#include <stdlib.h>
 
 #define RESTEST_HEAP_CHECK 0
 
@@ -28,8 +28,11 @@
 #include "crestst.h"
 #include "unicode/ctest.h"
 
+#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
+
 static void TestOpenDirect(void);
 static void TestFallback(void);
+static void TestTable32(void);
 static void TestFileStream(void);
 /*****************************************************************************/
 
@@ -90,10 +93,13 @@
 {
     addTest(root, &TestConstruction1, "tsutil/crestst/TestConstruction1");
     addTest(root, &TestOpenDirect, "tsutil/crestst/TestOpenDirect");
-    addTest(root, &TestResourceBundles, "tsutil/crestst/TestResourceBundle");
+    addTest(root, &TestResourceBundles, "tsutil/crestst/TestResourceBundles");
+    addTest(root, &TestTable32, "tsutil/crestst/TestTable32");
     addTest(root, &TestFallback, "tsutil/crestst/TestFallback");
     addTest(root, &TestAliasConflict, "tsutil/crestst/TestAliasConflict");
     addTest(root, &TestFileStream, "tsutil/crestst/TestFileStream");
+    addTest(root, &TestGetSize, "tsutil/crestst/TestGetSize");
+    addTest(root, &TestGetLocaleByType, "tsutil/crestst/TestGetLocaleByType");
 }
 
 
@@ -403,6 +409,7 @@
 {
     UErrorCode status = U_ZERO_ERROR;
     UResourceBundle *fr_FR = NULL;
+    UResourceBundle *subResource = NULL;
     const UChar *junk; /* ignored */
     int32_t resultLen;
 
@@ -426,13 +433,13 @@
     status = U_ZERO_ERROR;
 
     /* OK first one. This should be a Default value. */
-    junk = ures_getStringByKey(fr_FR, "%%PREEURO", &resultLen, &status);
+    subResource = ures_getByKey(fr_FR, "CurrencyMap", NULL, &status);
     if(status != U_USING_DEFAULT_WARNING)
     {
-        log_data_err("Expected U_USING_DEFAULT_ERROR when trying to get %%PREEURO from fr_FR, got %s\n",
+        log_data_err("Expected U_USING_DEFAULT_ERROR when trying to get LocaleScript from fr_FR, got %s\n",
             u_errorName(status));
     }
-
+    ures_close(subResource);
     status = U_ZERO_ERROR;
 
     /* and this is a Fallback, to fr */
@@ -512,12 +519,165 @@
     ures_close(translit_index);
 }
 
+static int32_t
+parseTable32Key(const char *key) {
+    int32_t number;
+    char c;
+
+    number=0;
+    while((c=*key++)!=0) {
+        number<<=1;
+        if(c=='1') {
+            number|=1;
+        }
+    }
+    return number;
+}
+
+static void
+TestTable32(void) {
+    static const struct {
+        const char *key;
+        int32_t number;
+    } testcases[]={
+        { "ooooooooooooooooo", 0 },
+        { "oooooooooooooooo1", 1 },
+        { "ooooooooooooooo1o", 2 },
+        { "oo11ooo1ooo11111o", 25150 },
+        { "oo11ooo1ooo111111", 25151 },
+        { "o1111111111111111", 65535 },
+        { "1oooooooooooooooo", 65536 },
+        { "1ooooooo11o11ooo1", 65969 },
+        { "1ooooooo11o11oo1o", 65970 },
+        { "1ooooooo111oo1111", 65999 }
+    };
+
+    /* ### TODO UResourceBundle staticItem={ 0 }; - need to know the size */
+    UResourceBundle *res, *item;
+    const UChar *s;
+    const char *key;
+    UErrorCode errorCode;
+    int32_t i, j, number, parsedNumber, length, count;
+
+    errorCode=U_ZERO_ERROR;
+    res=ures_open(loadTestData(&errorCode), "testtable32", &errorCode);
+    if(U_FAILURE(errorCode)) {
+        log_data_err("unable to open testdata/testtable32.res - %s\n", u_errorName(errorCode));
+        return;
+    }
+    if(ures_getType(res)!=URES_TABLE) {
+        log_data_err("testdata/testtable32.res has type %d instead of URES_TABLE\n", ures_getType(res));
+    }
+
+    count=ures_getSize(res);
+    if(count!=66000) {
+        log_err("testdata/testtable32.res should have 66000 entries but has %d\n", count);
+    }
+
+    /* get the items by index */
+    item=NULL;
+    for(i=0; i<count; ++i) {
+        item=ures_getByIndex(res, i, item, &errorCode);
+        if(U_FAILURE(errorCode)) {
+            log_err("unable to get item %d of %d in testdata/testtable32.res - %s\n",
+                    i, count, u_errorName(errorCode));
+            break;
+        }
+
+        key=ures_getKey(item);
+        parsedNumber=parseTable32Key(key);
+
+        switch(ures_getType(item)) {
+        case URES_STRING:
+            s=ures_getString(item, &length, &errorCode);
+            if(U_FAILURE(errorCode) || s==NULL) {
+                log_err("unable to access the string \"%s\" at %d in testdata/testtable32.res - %s\n",
+                        key, i, u_errorName(errorCode));
+                number=-1;
+            } else {
+                j=0;
+                U16_NEXT(s, j, length, number);
+            }
+            break;
+        case URES_INT:
+            number=ures_getInt(item, &errorCode);
+            if(U_FAILURE(errorCode)) {
+                log_err("unable to access the integer \"%s\" at %d in testdata/testtable32.res - %s\n",
+                        key, i, u_errorName(errorCode));
+                number=-1;
+            }
+            break;
+        default:
+            log_err("unexpected resource type %d for \"%s\" at %d in testdata/testtable32.res - %s\n",
+                    ures_getType(item), key, i, u_errorName(errorCode));
+            number=-1;
+            break;
+        }
+
+        if(number>=0 && number!=parsedNumber) {
+            log_err("\"%s\" at %d in testdata/testtable32.res has a string/int value of %d, expected %d\n",
+                    key, i, number, parsedNumber);
+        }
+    }
+
+    /* search for some items by key */
+    for(i=0; i<LENGTHOF(testcases); ++i) {
+        item=ures_getByKey(res, testcases[i].key, item, &errorCode);
+        if(U_FAILURE(errorCode)) {
+            log_err("unable to find the key \"%s\" in testdata/testtable32.res - %s\n",
+                    testcases[i].key, u_errorName(errorCode));
+            continue;
+        }
+
+        switch(ures_getType(item)) {
+        case URES_STRING:
+            s=ures_getString(item, &length, &errorCode);
+            if(U_FAILURE(errorCode) || s==NULL) {
+                log_err("unable to access the string \"%s\" in testdata/testtable32.res - %s\n",
+                        testcases[i].key, u_errorName(errorCode));
+                number=-1;
+            } else {
+                j=0;
+                U16_NEXT(s, j, length, number);
+            }
+            break;
+        case URES_INT:
+            number=ures_getInt(item, &errorCode);
+            if(U_FAILURE(errorCode)) {
+                log_err("unable to access the integer \"%s\" in testdata/testtable32.res - %s\n",
+                        testcases[i].key, u_errorName(errorCode));
+                number=-1;
+            }
+            break;
+        default:
+            log_err("unexpected resource type %d for \"%s\" in testdata/testtable32.res - %s\n",
+                    ures_getType(item), testcases[i].key, u_errorName(errorCode));
+            number=-1;
+            break;
+        }
+
+        if(number>=0 && number!=testcases[i].number) {
+            log_err("\"%s\" in testdata/testtable32.res has a string/int value of %d, expected %d\n",
+                    testcases[i].key, number, testcases[i].number);
+        }
+
+        key=ures_getKey(item);
+        if(0!=uprv_strcmp(key, testcases[i].key)) {
+            log_err("\"%s\" in testdata/testtable32.res claims to have the key \"%s\"\n",
+                    testcases[i].key, key);
+        }
+    }
+
+    ures_close(item);
+    ures_close(res);
+}
+
 static void TestFileStream(void){
     int32_t c = 0;
     int32_t c1=0;
     UErrorCode status = U_ZERO_ERROR;
     const char* testdatapath = loadTestData(&status);
-    char* fileName = (char*) uprv_malloc(uprv_strlen(testdatapath) +10);
+    char* fileName = (char*) malloc(uprv_strlen(testdatapath) +10);
     FileStream* stream = NULL;
     /* these should not be closed */
     FileStream* pStdin  = T_FileStream_stdin();
@@ -526,7 +686,7 @@
 
     const char* testline = "This is a test line";
     int32_t bufLen =uprv_strlen(testline)+10;
-    char* buf = (char*) uprv_malloc(bufLen);
+    char* buf = (char*) malloc(bufLen);
     int32_t retLen = 0;
 
     if(pStdin==NULL){
@@ -629,7 +789,134 @@
     }
 
 
-    uprv_free(fileName);
-    uprv_free(buf);
+    free(fileName);
+    free(buf);
+
+}
+
+static void 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;
+    
+    UResourceBundle *rb = NULL;
+    UResourceBundle *res = NULL;
+    UResourceBundle *helper = NULL;
+    const char* testdatapath = loadTestData(&status);
+    int32_t i = 0, j = 0;
+    int32_t size = 0;
+    
+    if(U_FAILURE(status))
+    {
+        log_err("Could not load testdata.dat %s\n", u_errorName(status));
+        return;
+    }
+    
+    rb = ures_open(testdatapath, "testtypes", &status);
+    if(U_FAILURE(status))
+    {
+        log_err("Could not testtypes resource bundle %s\n", u_errorName(status));
+        return;
+    }
+    
+    for(i = 0; i < sizeof(test)/sizeof(test[0]); i++) {
+        res = ures_getByKey(rb, test[i].key, res, &status);
+        if(U_FAILURE(status))
+        {
+            log_err("Couldn't find the key %s. Error: %s\n", test[i].key, u_errorName(status));
+            ures_close(rb);
+            return;
+        }
+        size = ures_getSize(res);
+        if(size != test[i].size) {
+            log_err("Expected size %i, got size %i for key %s\n", test[i].size, size, test[i].key);
+            for(j = 0; j < size; j++) {
+                helper = ures_getByIndex(res, j, helper, &status);
+                log_err("%s\n", ures_getKey(helper));
+            }
+        }
+    }
+    ures_close(helper); 
+    ures_close(res);
+    ures_close(rb);
+}
 
+static void TestGetLocaleByType(void) {
+    static const struct {
+        const char *requestedLocale;
+        const char *resourceKey;
+        const char *validLocale;
+        const char *actualLocale;
+    } test[] = {
+        { "te_IN_BLAH", "string_only_in_te_IN", "te_IN", "te_IN" },
+        { "te_IN_BLAH", "string_only_in_te", "te_IN", "te" },
+        { "te_IN_BLAH", "string_only_in_Root", "te_IN", "root" },
+        { "te_IN_BLAH_01234567890_01234567890_01234567890_01234567890_01234567890_01234567890", "array_2d_only_in_Root", "te_IN", "root" },
+        { "te_IN_BLAH@currency=euro", "array_2d_only_in_te_IN", "te_IN", "te_IN" },
+        { "te_IN_BLAH@collation=phonebook;calendar=thai", "array_2d_only_in_te", "te_IN", "te" }
+    };
+    
+    UErrorCode status = U_ZERO_ERROR;
+    
+    UResourceBundle *rb = NULL;
+    UResourceBundle *res = NULL;
+    const char* testdatapath = loadTestData(&status);
+    int32_t i = 0;
+    const char *locale = NULL;
+    
+    if(U_FAILURE(status))
+    {
+        log_err("Could not load testdata.dat %s\n", u_errorName(status));
+        return;
+    }
+    
+    for(i = 0; i < sizeof(test)/sizeof(test[0]); i++) {
+        rb = ures_open(testdatapath, test[i].requestedLocale, &status);
+        if(U_FAILURE(status))
+        {
+            log_err("Could not open resource bundle %s (error %s)\n", test[i].requestedLocale, u_errorName(status));
+            status = U_ZERO_ERROR;
+            continue;
+        }
+        
+        res = ures_getByKey(rb, test[i].resourceKey, res, &status);
+        if(U_FAILURE(status))
+        {
+            log_err("Couldn't find the key %s. Error: %s\n", test[i].resourceKey, u_errorName(status));
+            ures_close(rb);
+            status = U_ZERO_ERROR;
+            continue;
+        }
+        
+        locale = ures_getLocaleByType(res, ULOC_REQUESTED_LOCALE, &status);
+        if(locale) {
+            log_err("Requested locale should return NULL\n");
+        }
+        locale = ures_getLocaleByType(res, ULOC_VALID_LOCALE, &status);
+        if(!locale || strcmp(locale, test[i].validLocale) != 0) {
+            log_err("Expected valid locale to be %s. Got %s\n", test[i].requestedLocale, locale);
+        }
+        locale = ures_getLocaleByType(res, ULOC_ACTUAL_LOCALE, &status);
+        if(!locale || strcmp(locale, test[i].actualLocale) != 0) {
+            log_err("Expected actual locale to be %s. Got %s\n", test[i].requestedLocale, locale);
+        }
+        ures_close(rb);
+    }
+    ures_close(res);
 }
+

Index: crestst.h
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/crestst.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- crestst.h	10 Sep 2003 02:42:36 -0000	1.3
+++ crestst.h	6 Apr 2004 10:09:28 -0000	1.4
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2001, International Business Machines Corporation and
+ * Copyright (c) 1997-2003, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /********************************************************************************
@@ -34,6 +34,11 @@
     void TestConstruction2(void);
 
     void TestAliasConflict(void);
+
+    static void TestGetSize(void);
+
+    static void TestGetLocaleByType(void);
+
     /**
      * extensive subtests called by TestResourceBundles
      **/

Index: creststn.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/creststn.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- creststn.c	10 Sep 2003 02:42:36 -0000	1.4
+++ creststn.c	6 Apr 2004 10:09:28 -0000	1.5
@@ -233,7 +233,7 @@
   /* we look up the resource which is aliased, but it lives in fallback */
   if(U_SUCCESS(status) && r != NULL) {
     status = U_USING_DEFAULT_WARNING; 
-    r2 = ures_getByKey(r, "CollationElements", NULL, &status);
+    r2 = ures_getByKey(r, "collations", NULL, &status);
     checkStatus(U_USING_FALLBACK_WARNING, status);
   } 
   ures_close(r);
@@ -246,7 +246,7 @@
   /* we look up the resource which is aliased and at our level */
   if(U_SUCCESS(status) && r != NULL) {
     status = U_USING_DEFAULT_WARNING; 
-    r2 = ures_getByKey(r, "CollationElements", r2, &status);
+    r2 = ures_getByKey(r, "collations", r2, &status);
     checkStatus(U_USING_DEFAULT_WARNING, status);
   }
   ures_close(r);
@@ -520,29 +520,43 @@
     /* this tests if unescaping works are expected */
     len=0;
     {
-        static const char pattern[] = "[ \\\\u0020 \\\\u00A0 \\\\u1680 \\\\u2000 \\\\u2001 \\\\u2002 \\\\u2003 \\\\u2004 \\\\u2005 \\\\u2006 \\\\u2007 "
+        char pattern[2048] = "";
+        int32_t patternLen;
+        UChar* expectedEscaped;
+        const UChar* got;
+        int32_t expectedLen;
+
+        /* This strcpy fixes compiler warnings about long strings */
+        strcpy(pattern, "[ \\\\u0020 \\\\u00A0 \\\\u1680 \\\\u2000 \\\\u2001 \\\\u2002 \\\\u2003 \\\\u2004 \\\\u2005 \\\\u2006 \\\\u2007 "
             "\\\\u2008 \\\\u2009 \\\\u200A \\u200B \\\\u202F \\u205F \\\\u3000 \\u0000-\\u001F \\u007F \\u0080-\\u009F "
             "\\\\u06DD \\\\u070F \\\\u180E \\\\u200C \\\\u200D \\\\u2028 \\\\u2029 \\\\u2060 \\\\u2061 \\\\u2062 \\\\u2063 "
             "\\\\u206A-\\\\u206F \\\\uFEFF \\\\uFFF9-\\uFFFC \\U0001D173-\\U0001D17A \\U000F0000-\\U000FFFFD "
             "\\U00100000-\\U0010FFFD \\uFDD0-\\uFDEF \\uFFFE-\\uFFFF \\U0001FFFE-\\U0001FFFF \\U0002FFFE-\\U0002FFFF "
+            );
+        strcat(pattern, 
             "\\U0003FFFE-\\U0003FFFF \\U0004FFFE-\\U0004FFFF \\U0005FFFE-\\U0005FFFF \\U0006FFFE-\\U0006FFFF "
             "\\U0007FFFE-\\U0007FFFF \\U0008FFFE-\\U0008FFFF \\U0009FFFE-\\U0009FFFF \\U000AFFFE-\\U000AFFFF "
             "\\U000BFFFE-\\U000BFFFF \\U000CFFFE-\\U000CFFFF \\U000DFFFE-\\U000DFFFF \\U000EFFFE-\\U000EFFFF "
             "\\U000FFFFE-\\U000FFFFF \\U0010FFFE-\\U0010FFFF \\uD800-\\uDFFF \\\\uFFF9 \\\\uFFFA \\\\uFFFB "
             "\\uFFFC \\uFFFD \\u2FF0-\\u2FFB \\u0340 \\u0341 \\\\u200E \\\\u200F \\\\u202A \\\\u202B \\\\u202C "
+            );
+        strcat(pattern, 
             "\\\\u202D \\\\u202E \\\\u206A \\\\u206B \\\\u206C \\\\u206D \\\\u206E \\\\u206F \\U000E0001 \\U000E0020-\\U000E007F "
-            "]";
+            "]"
+            );
 
-        int32_t patternLen = uprv_strlen(pattern);
-        UChar* expectedEscaped = (UChar*)malloc(U_SIZEOF_UCHAR * patternLen);
-        const UChar* got = ures_getStringByKey(theBundle,"test_unescaping",&len,&status);
-        int32_t expectedLen = u_unescape(pattern,expectedEscaped,patternLen);
-        if(u_strncmp(expectedEscaped,got,expectedLen)!=0 || expectedLen != len){
+        patternLen = uprv_strlen(pattern);
+        expectedEscaped = (UChar*)malloc(U_SIZEOF_UCHAR * patternLen);
+        got = ures_getStringByKey(theBundle,"test_unescaping",&len,&status);
+        expectedLen = u_unescape(pattern,expectedEscaped,patternLen);
+        if(got==NULL || u_strncmp(expectedEscaped,got,expectedLen)!=0 || expectedLen != len){
             log_err("genrb failed to unescape string\n");
         }
-        for(i=0;i<expectedLen;i++){
-            if(expectedEscaped[i] != got[i]){
-                log_verbose("Expected: 0x%04X Got: 0x%04X \n",expectedEscaped[i], got[i]);
+        if(got != NULL){
+            for(i=0;i<expectedLen;i++){
+                if(expectedEscaped[i] != got[i]){
+                    log_verbose("Expected: 0x%04X Got: 0x%04X \n",expectedEscaped[i], got[i]);
+                }
             }
         }
         free(expectedEscaped);
@@ -565,10 +579,11 @@
         int32_t strLength = 0;
         const UChar my[] = {0x0026,0x0027,0x0075,0x0027,0x0020,0x003d,0x0020,0x0027,0xff55,0x0027,0x0000}; /* &'\u0075' = '\uFF55' */
         status = U_ZERO_ERROR;
-        resB = ures_getByKey(theBundle,"CollationElements", resB,&status);
+        resB = ures_getByKey(theBundle, "collations", resB, &status);
+        resB = ures_getByKey(resB, "standard", resB, &status);
         str  = ures_getStringByKey(resB,"Sequence",&strLength,&status);
         if(!str || U_FAILURE(status)) {
-            log_data_err("Could not load CollationElements from theBundle: %s\n", u_errorName(status));
+            log_data_err("Could not load collations from theBundle: %s\n", u_errorName(status));
         } else if(u_strcmp(my,str) != 0){
             log_err("Did not get the expected string for escaped \\u0075\n");
         }
@@ -590,8 +605,8 @@
         {
             int32_t strLen =0;
             const UChar* str = ures_getStringByKey(theBundle, "testincludeUTF",&strLen,&status);
-            strcpy(path, "th18057.txt");
-            path[strlen("th18057.txt")]=0;
+            strcpy(path, "riwords.txt");
+            path[strlen("riwords.txt")]=0;
             if(U_FAILURE(status)){
                 log_err("Could not get testincludeUTF resource from testtypes bundle. Error: %s\n",u_errorName(status));
             }else{
@@ -604,10 +619,10 @@
                     if(U_SUCCESS(status)){
                         /* verify the contents */
                         if(strLen != len ){
-                            log_err("Did not get the expected len for th18057. Expected: %i , Got: %i\n", len ,strLen);
+                            log_err("Did not get the expected len for riwords. Expected: %i , Got: %i\n", len ,strLen);
                         }
                         if(u_strncmp(str, buffer,strLen)!=0){
-                            log_err("Did not get the expected string from th18057. Include functionality failed for genrb.\n");
+                            log_err("Did not get the expected string from riwords. Include functionality failed for genrb.\n");
                         }
                     }else{
                         log_err("ucbuf failed to open %s. Error: %s\n", testDataFileName, u_errorName(status));
@@ -615,7 +630,7 @@
 
                     ucbuf_close(ucbuf);
                 }else{
-                    log_err("Could not get th18057.txt (path : %s). Error: %s\n",testDataFileName,u_errorName(status));
+                    log_err("Could not get riwords.txt (path : %s). Error: %s\n",testDataFileName,u_errorName(status));
                 }
             }
         }
@@ -829,7 +844,9 @@
 static void TestBinaryCollationData(){
     UErrorCode status=U_ZERO_ERROR;
     const char*      locale="te";
+#if !UCONFIG_NO_COLLATION 
     const char* testdatapath;
+#endif
     UResourceBundle *teRes = NULL;
     UResourceBundle *coll=NULL;
     UResourceBundle *binColl = NULL;
@@ -854,7 +871,8 @@
         return;
     }
     status=U_ZERO_ERROR;
-    coll = ures_getByKey(teRes, "CollationElements", coll, &status);
+    coll = ures_getByKey(teRes, "collations", coll, &status);
+    coll = ures_getByKey(coll, "standard", coll, &status);
     if(U_SUCCESS(status)){
         CONFIRM_ErrorCode(status, U_ZERO_ERROR);
         CONFIRM_INT_EQ(ures_getType(coll), URES_TABLE);
@@ -873,7 +891,7 @@
         }
     }
     else{
-        log_err("ERROR: ures_getByKey(locale(te), CollationElements) failed\n");
+        log_err("ERROR: ures_getByKey(locale(te), collations) failed\n");
         return;
     }
     ures_close(binColl);
@@ -941,7 +959,7 @@
     }
     key=ures_getKey(teFillin);
     /*if(strcmp(key, "%%CollationBin") != 0){*/
-    if(strcmp(key, "CollationElements") != 0){
+    if(strcmp(key, "array_2d_in_Root_te") != 0){
         log_err("ERROR: ures_getNextResource() failed\n");
     }
 #endif
@@ -1140,7 +1158,8 @@
     } 
     /*Test ures_getBinary(0 status != U_ILLEGAL_ARGUMENT_ERROR*/
     status=U_ZERO_ERROR;
-    coll = ures_getByKey(teRes, "CollationElements", coll, &status);
+    coll = ures_getByKey(teRes, "collations", coll, &status);
+    coll = ures_getByKey(teRes, "standard", coll, &status);
     binColl=ures_getByKey(coll, "%%CollationBin", binColl, &status);
 
     status=U_ILLEGAL_ARGUMENT_ERROR;
@@ -1815,6 +1834,7 @@
 {
     UErrorCode status = U_ZERO_ERROR;
     UResourceBundle *fr_FR = NULL;
+    UResourceBundle *subResource = NULL;
     const UChar *junk; /* ignored */
     int32_t resultLen;
 
@@ -1838,14 +1858,15 @@
     status = U_ZERO_ERROR;
 
     /* OK first one. This should be a Default value. */
-    junk = ures_getStringByKey(fr_FR, "%%PREEURO", &resultLen, &status);
+    subResource = ures_getByKey(fr_FR, "CurrencyMap", NULL, &status);
     if(status != U_USING_DEFAULT_WARNING)
     {
-        log_data_err("Expected U_USING_DEFAULT_ERROR when trying to get %%PREEURO from fr_FR, got %s\n", 
+        log_data_err("Expected U_USING_DEFAULT_ERROR when trying to get LocaleScript from fr_FR, got %s\n", 
             u_errorName(status));
     }
 
     status = U_ZERO_ERROR;
+    ures_close(subResource);
 
     /* and this is a Fallback, to fr */
     junk = ures_getStringByKey(fr_FR, "DayNames", &resultLen, &status);
@@ -1863,14 +1884,16 @@
     {
         UErrorCode err =U_ZERO_ERROR;
         UResourceBundle* myResB = ures_open(NULL,"no_NO_NY",&err);
-        UResourceBundle* resLocID = ures_getByKey(myResB, "LocaleID", NULL, &err);
+        UResourceBundle* resLocID = ures_getByKey(myResB, "Version", NULL, &err);
         UResourceBundle* tResB;
+        static const UChar versionStr[] = { 0x0033, 0x002E, 0x0030, 0};
+
         if(err != U_ZERO_ERROR){
-            log_data_err("Expected U_ZERO_ERROR when trying to test no_NO_NY aliased to nn_NO for LocaleID err=%s\n",u_errorName(err));
+            log_data_err("Expected U_ZERO_ERROR when trying to test no_NO_NY aliased to nn_NO for Version err=%s\n",u_errorName(err));
             return;
         }
-        if(ures_getInt(resLocID, &err) != 0x814){
-            log_data_err("Expected LocaleID=814, but got 0x%X\n", ures_getInt(resLocID, &err));
+        if(u_strcmp(ures_getString(resLocID, &resultLen, &err), versionStr) != 0){
+            log_data_err("ures_getString(resLocID, &resultLen, &err) returned an unexpected version value\n");
         }
         tResB = ures_getByKey(myResB, "DayNames", NULL, &err);
         if(err != U_USING_FALLBACK_WARNING){
@@ -1892,251 +1915,267 @@
 }
 
 static void TestResourceLevelAliasing(void) {
-  UErrorCode status = U_ZERO_ERROR;
-  UResourceBundle *aliasB = NULL, *tb = NULL;
-  UResourceBundle *en = NULL, *uk = NULL, *testtypes = NULL;  
-  const char* testdatapath = NULL;
-  const UChar *string = NULL, *sequence = NULL;
-  const uint8_t *binary = NULL, *binSequence = NULL;
-  int32_t strLen = 0, seqLen = 0, binLen = 0, binSeqLen = 0;
-  testdatapath=loadTestData(&status);
-  if(U_FAILURE(status))
-  {
-      log_err("Could not load testdata.dat %s \n",myErrorName(status));
-      return;
-  }
+    UErrorCode status = U_ZERO_ERROR;
+    UResourceBundle *aliasB = NULL, *tb = NULL;
+    UResourceBundle *en = NULL, *uk = NULL, *testtypes = NULL;  
+    const char* testdatapath = NULL;
+    const UChar *string = NULL, *sequence = NULL;
+    const uint8_t *binary = NULL, *binSequence = NULL;
+    int32_t strLen = 0, seqLen = 0, binLen = 0, binSeqLen = 0;
 
-  aliasB = ures_open(testdatapath, "testaliases", &status);
+#if !UCONFIG_NO_COLLATION 
+    char buffer[100];
+    char *s;
+#endif
 
-  /* this should fail - circular alias */
-  tb = ures_getByKey(aliasB, "aaa", tb, &status);
-  if(status != U_TOO_MANY_ALIASES_ERROR) {
-    log_err("Failed to detect circular alias\n");
-  } else {
-    status = U_ZERO_ERROR;
-  }
-  tb = ures_getByKey(aliasB, "aab", tb, &status);
-  if(status != U_TOO_MANY_ALIASES_ERROR) {
-    log_err("Failed to detect circular alias\n");
-  } else {
-    status = U_ZERO_ERROR;
-  }
-  if(U_FAILURE(status) ) {
-    log_data_err("err loading tb resource\n");
-  }  else {
-    /* testing aliasing to a non existing resource */
-    tb = ures_getByKey(aliasB, "nonexisting", tb, &status);
-    if(status != U_MISSING_RESOURCE_ERROR) {
-      log_err("Managed to find an alias to non-existing resource\n");
-    } else {
-      status = U_ZERO_ERROR;
+    testdatapath=loadTestData(&status);
+    if(U_FAILURE(status))
+    {
+        log_err("Could not load testdata.dat %s \n",myErrorName(status));
+        return;
     }
     
-
-    /* testing referencing/composed alias */
-    uk = ures_findResource("uk/CollationElements/Sequence", uk, &status);
-    if((uk == NULL) || U_FAILURE(status)) {
-      log_err("Couldn't findResource('uk/collationelements/sequence') err %s\n", u_errorName(status));
-      return;
-    } 
-
-    sequence = ures_getString(uk, &seqLen, &status);
-    
-    tb = ures_getByKey(aliasB, "referencingalias", tb, &status);
-    string = ures_getString(tb, &strLen, &status);
+    aliasB = ures_open(testdatapath, "testaliases", &status);
     
-    if(seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
-      log_err("Referencing alias didn't get the right string\n");
-    }
-
-    string = ures_getStringByKey(aliasB, "referencingalias", &strLen, &status);
-    if(seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
-      log_err("Referencing alias didn't get the right string\n");
+    /* this should fail - circular alias */
+    tb = ures_getByKey(aliasB, "aaa", tb, &status);
+    if(status != U_TOO_MANY_ALIASES_ERROR) {
+        log_err("Failed to detect circular alias\n");
+    } else {
+        status = U_ZERO_ERROR;
     }
-
-    tb = ures_getByKey(aliasB, "CollationElements", tb, &status);
-    tb = ures_getByKey(tb, "Sequence", tb, &status);
-    string = ures_getString(tb, &strLen, &status);
-    
-    if(seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
-      log_err("Referencing alias didn't get the right string\n");
+    tb = ures_getByKey(aliasB, "aab", tb, &status);
+    if(status != U_TOO_MANY_ALIASES_ERROR) {
+        log_err("Failed to detect circular alias\n");
+    } else {
+        status = U_ZERO_ERROR;
     }
+    if(U_FAILURE(status) ) {
+        log_data_err("err loading tb resource\n");
+    }  else {
+        /* testing aliasing to a non existing resource */
+        tb = ures_getByKey(aliasB, "nonexisting", tb, &status);
+        if(status != U_MISSING_RESOURCE_ERROR) {
+            log_err("Managed to find an alias to non-existing resource\n");
+        } else {
+            status = U_ZERO_ERROR;
+        }
+        
+        
+        /* testing referencing/composed alias */
+        uk = ures_findResource("uk/collations/standard/Sequence", uk, &status);
+        if((uk == NULL) || U_FAILURE(status)) {
+            log_err("Couldn't findResource('uk/collations/standard/sequence') err %s\n", u_errorName(status));
+            return;
+        } 
+        
+        sequence = ures_getString(uk, &seqLen, &status);
+        
+        tb = ures_getByKey(aliasB, "referencingalias", tb, &status);
+        string = ures_getString(tb, &strLen, &status);
+        
+        if(seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
+            log_err("Referencing alias didn't get the right string\n");
+        }
+        
+        string = ures_getStringByKey(aliasB, "referencingalias", &strLen, &status);
+        if(seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
+            log_err("Referencing alias didn't get the right string\n");
+        }
+        
+        tb = ures_getByKey(aliasB, "collations", tb, &status);
+        tb = ures_getByKey(tb, "standard", tb, &status);
+        tb = ures_getByKey(tb, "Sequence", tb, &status);
+        string = ures_getString(tb, &strLen, &status);
+        
+        if(seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
+            log_err("Referencing alias didn't get the right string\n");
+        }
 
 #if !UCONFIG_NO_COLLATION
 
-    /*
-     * TODO for Vladimir: Make this test independent of UCONFIG_NO_xyz-switchable
-     * modules like collation, so that it can be tested even when collation
-     * data is not included in resource bundles.
-     */
+        /*
+         * TODO for Vladimir: Make this test independent of UCONFIG_NO_xyz-switchable
+         * modules like collation, so that it can be tested even when collation
+         * data is not included in resource bundles.
+         */
 
-    /* check whether the binary collation data is properly referenced by an alias */
-    uk = ures_findResource("uk/CollationElements/%%CollationBin", uk, &status);
-    binSequence = ures_getBinary(uk, &binSeqLen, &status);
+        /* check whether the binary collation data is properly referenced by an alias */
+        uk = ures_findResource("uk/collations/standard/%%CollationBin", uk, &status);
+        binSequence = ures_getBinary(uk, &binSeqLen, &status);
 
-    tb = ures_getByKey(aliasB, "CollationElements", tb, &status);
-    tb = ures_getByKey(tb, "%%CollationBin", tb, &status);
-    binary = ures_getBinary(tb, &binLen, &status);
+        tb = ures_getByKey(aliasB, "collations", tb, &status);
+        tb = ures_getByKey(tb, "standard", tb, &status);
+        tb = ures_getByKey(tb, "%%CollationBin", tb, &status);
+        binary = ures_getBinary(tb, &binLen, &status);
 
-    if(binSeqLen != binLen || uprv_memcmp(binSequence, binary, binSeqLen) != 0) {
-      log_err("Referencing alias didn't get the right string\n");
-    }
+        if(binSeqLen != binLen || uprv_memcmp(binSequence, binary, binSeqLen) != 0) {
+          log_err("Referencing alias didn't get the right string\n");
+        }
 
-    /* simple alias */
-    testtypes = ures_open(testdatapath, "testtypes", &status);
-    uk = ures_findSubResource(testtypes, "menu/file/open", uk, &status);
-    sequence = ures_getString(uk, &seqLen, &status);
+        /* simple alias */
+        testtypes = ures_open(testdatapath, "testtypes", &status);
+        strcpy(buffer, "menu/file/open");
+        s = buffer;
+        uk = ures_findSubResource(testtypes, s, uk, &status);
+        sequence = ures_getString(uk, &seqLen, &status);
 
-    tb = ures_getByKey(aliasB, "simplealias", tb, &status);
-    string = ures_getString(tb, &strLen, &status);
+        tb = ures_getByKey(aliasB, "simplealias", tb, &status);
+        string = ures_getString(tb, &strLen, &status);
 
-    if(U_FAILURE(status) || seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
-      log_err("Referencing alias didn't get the right string\n");
-    }
+        if(U_FAILURE(status) || seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
+          log_err("Referencing alias didn't get the right string\n");
+        }
 
-    /* test indexed aliasing */
+        /* test indexed aliasing */
 
-    tb = ures_getByKey(aliasB, "zoneTests", tb, &status);
-    tb = ures_getByKey(tb, "zoneAlias2", tb, &status);
-    string = ures_getString(tb, &strLen, &status);
+        tb = ures_getByKey(aliasB, "zoneTests", tb, &status);
+        tb = ures_getByKey(tb, "zoneAlias2", tb, &status);
+        string = ures_getString(tb, &strLen, &status);
 
-    en = ures_findResource("en/zoneStrings/3/0", en, &status);
-    sequence = ures_getString(en, &seqLen, &status);
+        en = ures_findResource("en/zoneStrings/3/0", en, &status);
+        sequence = ures_getString(en, &seqLen, &status);
 
-    if(U_FAILURE(status) || seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
-      log_err("Referencing alias didn't get the right string\n");
-    }
+        if(U_FAILURE(status) || seqLen != strLen || u_strncmp(sequence, string, seqLen) != 0) {
+          log_err("Referencing alias didn't get the right string\n");
+        }
 
 #endif
-  }
-  /* test getting aliased string by index */
-  {
-    const char* keys[] = {
-        "KeyAlias0PST",
-        "KeyAlias1PacificStandardTime",
-        "KeyAlias2PDT",
-        "KeyAlias3LosAngeles"
-    };
-
-    const char* strings[] = {
-      "PST",
-      "Pacific Standard Time",
-      "PDT",
-      "Los Angeles",
-    };
-    UChar buffer[256];
-    const UChar* result;
-    int32_t bufferLen = 0, resultLen = 0;
-    int32_t i = 0;
-    const char *key = NULL;
-    tb = ures_getByKey(aliasB, "testGetStringByKeyAliasing", tb, &status);
-    if(U_FAILURE(status)) {
-      log_err("Couldn't get testGetStringByKeyAliasing resource\n");
-    }
-    for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
-      result = ures_getStringByKey(tb, keys[i], &resultLen, &status);
-      bufferLen = u_unescape(strings[i], buffer, 256);
-      if(resultLen != bufferLen || u_strncmp(result, buffer, resultLen) != 0) {
-        log_err("Didn't get correct string while accesing alias table by key\n");
-      }
-    }
-    for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
-      result = ures_getStringByIndex(tb, i, &resultLen, &status);
-      bufferLen = u_unescape(strings[i], buffer, 256);
-      if(resultLen != bufferLen || u_strncmp(result, buffer, resultLen) != 0) {
-        log_err("Didn't get correct string while accesing alias table by index\n");
-      }
-    }
-    for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
-      result = ures_getNextString(tb, &resultLen, &key, &status);
-      bufferLen = u_unescape(strings[i], buffer, 256);
-      if(resultLen != bufferLen || u_strncmp(result, buffer, resultLen) != 0) {
-        log_err("Didn't get correct string while iterating over alias table\n");
-      }
-    }
-    tb = ures_getByKey(aliasB, "testGetStringByIndexAliasing", tb, &status);
-    if(U_FAILURE(status)) {
-      log_err("Couldn't get testGetStringByIndexAliasing resource\n");
-    }
-    for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
-      result = ures_getStringByIndex(tb, i, &resultLen, &status);
-      bufferLen = u_unescape(strings[i], buffer, 256);
-      if(resultLen != bufferLen || u_strncmp(result, buffer, resultLen) != 0) {
-        log_err("Didn't get correct string while accesing alias by index in an array\n");
-      }
     }
-    for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
-      result = ures_getNextString(tb, &resultLen, &key, &status);
-      bufferLen = u_unescape(strings[i], buffer, 256);
-      if(resultLen != bufferLen || u_strncmp(result, buffer, resultLen) != 0) {
-        log_err("Didn't get correct string while iterating over aliases in an array\n");
-      }
+    /* test getting aliased string by index */
+    {
+        const char* keys[] = {
+            "KeyAlias0PST",
+                "KeyAlias1PacificStandardTime",
+                "KeyAlias2PDT",
+                "KeyAlias3LosAngeles"
+        };
+        
+        const char* strings[] = {
+            "PST",
+                "Pacific Standard Time",
+                "PDT",
+                "Los Angeles",
+        };
+        UChar uBuffer[256];
+        const UChar* result;
+        int32_t uBufferLen = 0, resultLen = 0;
+        int32_t i = 0;
+        const char *key = NULL;
+        tb = ures_getByKey(aliasB, "testGetStringByKeyAliasing", tb, &status);
+        if(U_FAILURE(status)) {
+            log_err("Couldn't get testGetStringByKeyAliasing resource\n");
+        }
+        for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
+            result = ures_getStringByKey(tb, keys[i], &resultLen, &status);
+            uBufferLen = u_unescape(strings[i], uBuffer, 256);
+            if(resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) {
+                log_err("Didn't get correct string while accesing alias table by key\n");
+            }
+        }
+        for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
+            result = ures_getStringByIndex(tb, i, &resultLen, &status);
+            uBufferLen = u_unescape(strings[i], uBuffer, 256);
+            if(resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) {
+                log_err("Didn't get correct string while accesing alias table by index\n");
+            }
+        }
+        for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
+            result = ures_getNextString(tb, &resultLen, &key, &status);
+            uBufferLen = u_unescape(strings[i], uBuffer, 256);
+            if(resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) {
+                log_err("Didn't get correct string while iterating over alias table\n");
+            }
+        }
+        tb = ures_getByKey(aliasB, "testGetStringByIndexAliasing", tb, &status);
+        if(U_FAILURE(status)) {
+            log_err("Couldn't get testGetStringByIndexAliasing resource\n");
+        }
+        for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
+            result = ures_getStringByIndex(tb, i, &resultLen, &status);
+            uBufferLen = u_unescape(strings[i], uBuffer, 256);
+            if(resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) {
+                log_err("Didn't get correct string while accesing alias by index in an array\n");
+            }
+        }
+        for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
+            result = ures_getNextString(tb, &resultLen, &key, &status);
+            uBufferLen = u_unescape(strings[i], uBuffer, 256);
+            if(resultLen != uBufferLen || u_strncmp(result, uBuffer, resultLen) != 0) {
+                log_err("Didn't get correct string while iterating over aliases in an array\n");
+            }
+        }
     }
-  }
-
-  ures_close(aliasB);
-  ures_close(tb);
-  ures_close(en);
-  ures_close(uk);
-  ures_close(testtypes);
+    
+    ures_close(aliasB);
+    ures_close(tb);
+    ures_close(en);
+    ures_close(uk);
+    ures_close(testtypes);
 }
 
 static void TestDirectAccess(void) {
-  UErrorCode status = U_ZERO_ERROR;
-  UResourceBundle *t = NULL, *t2 = NULL;
-  const char* key = NULL;
-
-  t = ures_findResource("en/zoneStrings/3/2", t, &status);
-  if(U_FAILURE(status)) {
-    log_err("Couldn't access indexed resource, error %s\n", u_errorName(status));
-    status = U_ZERO_ERROR;
-  } else {
-    key = ures_getKey(t);
-    if(key != NULL) {
-      log_err("Got a strange key, expected NULL, got %s\n", key);
-    }
-  }
-  t = ures_findResource("en/zoneStrings/3", t, &status);
-  if(U_FAILURE(status)) {
-    log_err("Couldn't access indexed resource, error %s\n", u_errorName(status));
-    status = U_ZERO_ERROR;
-  } else {
-    key = ures_getKey(t);
-    if(key != NULL) {
-      log_err("Got a strange key, expected NULL, got %s\n", key);
+    UErrorCode status = U_ZERO_ERROR;
+    UResourceBundle *t = NULL, *t2 = NULL;
+    const char* key = NULL;
+    
+    char buffer[100];
+    char *s;
+    
+    t = ures_findResource("en/zoneStrings/3/2", t, &status);
+    if(U_FAILURE(status)) {
+        log_err("Couldn't access indexed resource, error %s\n", u_errorName(status));
+        status = U_ZERO_ERROR;
+    } else {
+        key = ures_getKey(t);
+        if(key != NULL) {
+            log_err("Got a strange key, expected NULL, got %s\n", key);
+        }
     }
-  }
-
-  t = ures_findResource("sh/CollationElements/Sequence", t, &status);
-  if(U_FAILURE(status)) {
-    log_err("Couldn't access keyed resource, error %s\n", u_errorName(status));
-    status = U_ZERO_ERROR;
-  } else {
-    key = ures_getKey(t);
-    if(strcmp(key, "Sequence")!=0) {
-      log_err("Got a strange key, expected 'Sequence', got %s\n", key);
+    t = ures_findResource("en/zoneStrings/3", t, &status);
+    if(U_FAILURE(status)) {
+        log_err("Couldn't access indexed resource, error %s\n", u_errorName(status));
+        status = U_ZERO_ERROR;
+    } else {
+        key = ures_getKey(t);
+        if(key != NULL) {
+            log_err("Got a strange key, expected NULL, got %s\n", key);
+        }
     }
-  }
-
-  t2 = ures_open(NULL, "sh", &status);
-  if(U_FAILURE(status)) {
-    log_err("Couldn't open 'sh' resource bundle, error %s\n", u_errorName(status));
-    log_data_err("No 'sh', no test - you have bigger problems than testing direct access. You probably have no data! Aborting this test\n");
-  }
-
-  if(U_SUCCESS(status)) {
-    t = ures_findSubResource(t2, "CollationElements/Sequence", t, &status);
+    
+    t = ures_findResource("sh/collations/standard/Sequence", t, &status);
     if(U_FAILURE(status)) {
-      log_err("Couldn't access keyed resource, error %s\n", u_errorName(status));
-      status = U_ZERO_ERROR;
+        log_err("Couldn't access keyed resource, error %s\n", u_errorName(status));
+        status = U_ZERO_ERROR;
     } else {
-      key = ures_getKey(t);
-      if(strcmp(key, "Sequence")!=0) {
-        log_err("Got a strange key, expected 'Sequence', got %s\n", key);
-      }
+        key = ures_getKey(t);
+        if(strcmp(key, "Sequence")!=0) {
+            log_err("Got a strange key, expected 'Sequence', got %s\n", key);
+        }
     }
-  }
-
-  ures_close(t);
-  ures_close(t2);
+    
+    t2 = ures_open(NULL, "sh", &status);
+    if(U_FAILURE(status)) {
+        log_err("Couldn't open 'sh' resource bundle, error %s\n", u_errorName(status));
+        log_data_err("No 'sh', no test - you have bigger problems than testing direct access. You probably have no data! Aborting this test\n");
+    }
+    
+    if(U_SUCCESS(status)) {
+        strcpy(buffer, "collations/standard/Sequence");
+        s = buffer;
+        t = ures_findSubResource(t2, s, t, &status);
+        if(U_FAILURE(status)) {
+            log_err("Couldn't access keyed resource, error %s\n", u_errorName(status));
+            status = U_ZERO_ERROR;
+        } else {
+            key = ures_getKey(t);
+            if(strcmp(key, "Sequence")!=0) {
+                log_err("Got a strange key, expected 'Sequence', got %s\n", key);
+            }
+        }
+    }
+    
+    ures_close(t);
+    ures_close(t2);
 }
+

Index: cstrtest.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cstrtest.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cstrtest.c	10 Sep 2003 02:42:38 -0000	1.3
+++ cstrtest.c	6 Apr 2004 10:09:28 -0000	1.4
@@ -13,18 +13,22 @@
 *******************************************************************************
 */
 
-
+#include "unicode/ustring.h"
+#include "unicode/ucnv.h"
 #include "cstring.h"
 #include "cintltst.h"
 #include "cmemory.h"
 
+#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
+
 static void TestAPI(void);
 void addCStringTest(TestNode** root);
 
+static void TestInvariant(void);
+
 void addCStringTest(TestNode** root) {
-   
     addTest(root, &TestAPI,   "tsutil/cstrtest/TestAPI");
-  
+    addTest(root, &TestInvariant,   "tsutil/cstrtest/TestInvariant");
 }
 
 static void TestAPI(void)
@@ -143,4 +147,128 @@
         log_err("FAIL: T_CString_strnicmp(\"abc\", \"\", 10) failed.  Expected: 1, returned %d\n", intValue);
     }
     
+}
+
+/* test invariant-character handling */
+static void
+TestInvariant() {
+    /* all invariant graphic chars and some control codes (not \n!) */
+    const char invariantChars[]=
+        "\t\r \"%&'()*+,-./"
+        "0123456789:;<=>?"
+        "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"
+        "abcdefghijklmnopqrstuvwxyz";
+
+    const UChar invariantUChars[]={
+        9, 0xd, 0x20, 0x22, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+        0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+        0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
+        0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5f,
+        0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+        0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0
+    };
+
+    const char variantChars[]="\n!#$@[\\]^`{|}~";
+
+    const UChar variantUChars[]={
+        0x0a, 0x21, 0x23, 0x24, 0x40, 0x5b, 0x5c, 0x5d, 0x5e, 0x60, 0x7b, 0x7c, 0x7d, 0x7e, 0
+    };
+
+    const UChar nonASCIIUChars[]={ 0x80, 0xa0, 0x900, 0xff51 };
+
+    UChar us[120];
+    char cs[120];
+
+    int32_t i, length;
+
+    /* make sure that all invariant characters convert both ways */
+    length=sizeof(invariantChars);
+    u_charsToUChars(invariantChars, us, length);
+    if(u_strcmp(us, invariantUChars)!=0) {
+        log_err("u_charsToUChars(invariantChars) failed\n");
+    }
+
+    u_UCharsToChars(invariantUChars, cs, length);
+    if(strcmp(cs, invariantChars)!=0) {
+        log_err("u_UCharsToChars(invariantUChars) failed\n");
+    }
+
+
+    /*
+     * make sure that variant characters convert from source code literals to Unicode
+     * but not back to char *
+     */
+    length=sizeof(variantChars);
+    u_charsToUChars(variantChars, us, length);
+    if(u_strcmp(us, variantUChars)!=0) {
+        log_err("u_charsToUChars(variantChars) failed\n");
+    }
+
+#ifdef NDEBUG
+    /*
+     * Test u_UCharsToChars(variantUChars) only in release mode because it will
+     * cause an assertion failure in debug builds.
+     */
+    u_UCharsToChars(variantUChars, cs, length);
+    for(i=0; i<length; ++i) {
+        if(cs[i]!=0) {
+            log_err("u_UCharsToChars(variantUChars) converted the %d-th character to %02x instead of 00\n", i, cs[i]);
+        }
+    }
+#endif
+
+    /*
+     * Verify that invariant characters roundtrip from Unicode to the
+     * default converter and back.
+     */
+    {
+        UConverter *cnv;
+        UErrorCode errorCode;
+
+        errorCode=U_ZERO_ERROR;
+        cnv=ucnv_open(NULL, &errorCode);
+        if(U_FAILURE(errorCode)) {
+            log_err("unable to open the default converter\n");
+        } else {
+            length=ucnv_fromUChars(cnv, cs, sizeof(cs), invariantUChars, -1, &errorCode);
+            if(U_FAILURE(errorCode)) {
+                log_err("ucnv_fromUChars(invariantUChars) failed - %s\n", u_errorName(errorCode));
+            } else if(length!=sizeof(invariantChars)-1 || strcmp(cs, invariantChars)!=0) {
+                log_err("ucnv_fromUChars(invariantUChars) failed\n");
+            }
+
+            errorCode=U_ZERO_ERROR;
+            length=ucnv_toUChars(cnv, us, LENGTHOF(us), invariantChars, -1, &errorCode);
+            if(U_FAILURE(errorCode)) {
+                log_err("ucnv_toUChars(invariantChars) failed - %s\n", u_errorName(errorCode));
+            } else if(length!=LENGTHOF(invariantUChars)-1 || u_strcmp(us, invariantUChars)!=0) {
+                log_err("ucnv_toUChars(invariantChars) failed\n");
+            }
+
+            ucnv_close(cnv);
+        }
+    }
+
+    /* API tests */
+    if(!uprv_isInvariantString(invariantChars, -1)) {
+        log_err("uprv_isInvariantString(invariantChars) failed\n");
+    }
+    if(!uprv_isInvariantUString(invariantUChars, -1)) {
+        log_err("uprv_isInvariantUString(invariantUChars) failed\n");
+    }
+
+    for(i=0; i<(sizeof(variantChars)-1); ++i) {
+        if(uprv_isInvariantString(variantChars+i, 1)) {
+            log_err("uprv_isInvariantString(variantChars[%d]) failed\n", i);
+        }
+        if(uprv_isInvariantUString(variantUChars+i, 1)) {
+            log_err("uprv_isInvariantUString(variantUChars[%d]) failed\n", i);
+        }
+    }
+
+    for(i=0; i<LENGTHOF(nonASCIIUChars); ++i) {
+        if(uprv_isInvariantUString(nonASCIIUChars+i, 1)) {
+            log_err("uprv_isInvariantUString(nonASCIIUChars[%d]) failed\n", i);
+        }
+    }
 }

Index: cucdapi.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cucdapi.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- cucdapi.c	10 Sep 2003 02:42:38 -0000	1.1
+++ cucdapi.c	6 Apr 2004 10:09:28 -0000	1.2
@@ -9,6 +9,7 @@
 #include "unicode/uscript.h"
 #include "unicode/uchar.h"
 #include "cintltst.h"
+#include "cucdapi.h"
 
 void TestUScriptCodeAPI(){
     int i =0;

Index: cucdtst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cucdtst.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- cucdtst.c	10 Sep 2003 02:42:38 -0000	1.5
+++ cucdtst.c	6 Apr 2004 10:09:28 -0000	1.6
@@ -28,6 +28,7 @@
 #include "uprops.h"
 #include "usc_impl.h"
 #include "unormimp.h"
+#include "cucdapi.h"
 
 #define LENGTHOF(array) (sizeof(array)/sizeof((array)[0]))
 
@@ -45,7 +46,7 @@
 static void TestCharLength(void);
 static void TestCharNames(void);
 static void TestMirroring(void);
-       void TestUScriptCodeAPI(void);    /* defined in cucdapi.c */
+/*       void TestUScriptCodeAPI(void);*/    /* defined in cucdapi.h */
 static void TestUScriptRunAPI(void);
 static void TestAdditionalProperties(void);
 static void TestNumericProperties(void);
@@ -1336,6 +1337,23 @@
         }
     }
 
+    if(
+        !U_IS_BMP(0) || !U_IS_BMP(0x61) || !U_IS_BMP(0x20ac) ||
+        !U_IS_BMP(0xd9da) || !U_IS_BMP(0xdfed) || !U_IS_BMP(0xffff) ||
+        U_IS_BMP(U_SENTINEL) || U_IS_BMP(0x10000) || U_IS_BMP(0x50005) ||
+        U_IS_BMP(0x10ffff) || U_IS_BMP(0x110000) || U_IS_BMP(0x7fffffff)
+    ) {
+        log_err("error with U_IS_BMP()\n");
+    }
+
+    if(
+        U_IS_SUPPLEMENTARY(0) || U_IS_SUPPLEMENTARY(0x61) || U_IS_SUPPLEMENTARY(0x20ac) ||
+        U_IS_SUPPLEMENTARY(0xd9da) || U_IS_SUPPLEMENTARY(0xdfed) || U_IS_SUPPLEMENTARY(0xffff) ||
+        U_IS_SUPPLEMENTARY(U_SENTINEL) || !U_IS_SUPPLEMENTARY(0x10000) || !U_IS_SUPPLEMENTARY(0x50005) ||
+        !U_IS_SUPPLEMENTARY(0x10ffff) || U_IS_SUPPLEMENTARY(0x110000) || U_IS_SUPPLEMENTARY(0x7fffffff)
+    ) {
+        log_err("error with U_IS_SUPPLEMENTARY()\n");
+    }
 }
 
 static void TestCharLength()
@@ -1606,8 +1624,9 @@
         uprv_getCharNameCharacters(set);
 
         /* build set the dumb (but sure-fire) way */
-        for (i=0; i<256; ++i)
+        for (i=0; i<256; ++i) {
             map[i] = FALSE;
+        }
 
         maxLength=0;
         for (cp=0; cp<0x110000; ++cp) {
@@ -1629,6 +1648,15 @@
                     map[(uint8_t) buf[i]] = TRUE;
                 }
             }
+
+            /* test for leading/trailing whitespace */
+            if(buf[0]==' ' || buf[0]=='\t' || buf[len-1]==' ' || buf[len-1]=='\t') {
+                log_err("u_charName(U+%04x) returns a name with leading or trailing whitespace\n", cp);
+            }
+        }
+
+        if(map[(uint8_t)'\t']) {
+            log_err("u_charName() returned a name with a TAB for some code point\n", cp);
         }
 
         length=uprv_getMaxCharNameLength();
@@ -1670,17 +1698,10 @@
         }
 
         if (!ok) {
-            char c1[256], c2[256];
-            u_UCharsToChars(pat, c1, l1);
-            u_UCharsToChars(dumbPat, c2, l2);
-            c1[l1] = c2[l2] = 0;
             log_err("FAIL: uprv_getCharNameCharacters() returned %s, expected %s (too many lowercase a-z are ok)\n",
-                    c1, c2);
-        } else {
-            char c1[256];
-            u_UCharsToChars(pat, c1, l1);
-            c1[l1] = 0;
-            log_verbose("Ok: uprv_getCharNameCharacters() returned %s\n", c1);
+                    aescstrdup(pat, l1), aescstrdup(dumbPat, l2));
+        } else if(VERBOSITY) {
+            log_verbose("Ok: uprv_getCharNameCharacters() returned %s\n", aescstrdup(pat, l1));
         }
 
         uset_close(set);
@@ -2678,19 +2699,23 @@
     set1=uset_open(1, 0);
     set2=uset_open(1, 0);
 
-    unorm_getCanonStartSet(0x49, &sset);
-    _setAddSerialized(set1, &sset);
+    if (unorm_getCanonStartSet(0x49, &sset)) {
+        _setAddSerialized(set1, &sset);
 
-    /* enumerate all characters that are plausible to be latin letters */
-    for(start=0xa0; start<0x2000; ++start) {
-        if(unorm_getDecomposition(start, FALSE, buffer16, LENGTHOF(buffer16))>1 && buffer16[0]==0x49) {
-            uset_add(set2, start);
+        /* enumerate all characters that are plausible to be latin letters */
+        for(start=0xa0; start<0x2000; ++start) {
+            if(unorm_getDecomposition(start, FALSE, buffer16, LENGTHOF(buffer16))>1 && buffer16[0]==0x49) {
+                uset_add(set2, start);
+            }
         }
+
+        compareUSets(set1, set2,
+                     "[canon start set of 0049]", "[all c with canon decomp with 0049]",
+                     TRUE);
+    } else {
+      log_err("error calling unorm_getCanonStartSet()\n");
     }
 
-    compareUSets(set1, set2,
-                 "[canon start set of 0049]", "[all c with canon decomp with 0049]",
-                 TRUE);
     uset_close(set1);
     uset_close(set2);
 

Index: custrtrn.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/custrtrn.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- custrtrn.c	10 Sep 2003 02:42:39 -0000	1.4
+++ custrtrn.c	6 Apr 2004 10:09:29 -0000	1.5
@@ -19,8 +19,10 @@
 #include <stdio.h>
 #include "unicode/utypes.h"
 #include "unicode/ustring.h"
+#include "unicode/ures.h"
 #include "ustr_imp.h"
 #include "cintltst.h"
+#include "cwchar.h"
 
 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
 
@@ -29,6 +31,8 @@
 static void Test_UChar_UTF32_API(void);
 static void Test_UChar_UTF8_API(void);
 static void Test_UChar_WCHART_API(void);
+static void Test_widestrs(void);
+static void Test_WCHART_LongString(void);
 
 void 
 addUCharTransformTest(TestNode** root)
@@ -36,6 +40,8 @@
    addTest(root, &Test_UChar_UTF32_API, "custrtrn/Test_UChar_UTF32_API");
    addTest(root, &Test_UChar_UTF8_API, "custrtrn/Test_UChar_UTF8_API");
    addTest(root, &Test_UChar_WCHART_API,  "custrtrn/Test_UChar_WCHART_API");
+   addTest(root, &Test_widestrs,  "custrtrn/Test_widestrs");
+   addTest(root, &Test_WCHART_LongString, "custrtrn/Test_WCHART_LongString");
 }
 
 static const UChar32 src32[]={
@@ -432,16 +438,7 @@
     0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x000D, 0x000A,
     0x0000,
     /* Test only ASCII */
-    /*
-    0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD,
-    0x00AE, 0x00AF, 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
-    0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF, 0x00C0, 0x00C1,
-    0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB,
-    0x00CC, 0x00CD, 0x00CE, 0x00CF, 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 
-    0x00D6, 0x00D7, 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, 
-    0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7, 0x00E8, 0x00E9,
-    0x0054, 0x0000
-    */
+
 };
 static const uint16_t src16WithNulls[] = {
     0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0000,
@@ -652,3 +649,103 @@
         }
     }
 } 
+
+static void Test_widestrs()
+{
+        wchar_t ws[100];
+        UChar rts[100];
+        int32_t wcap = sizeof(ws) / sizeof(*ws);
+        int32_t wl;
+        int32_t rtcap = sizeof(rts) / sizeof(*rts);
+        int32_t rtl;
+        wchar_t *wcs;
+        UChar *cp;
+        const char *errname;
+        UChar ustr[] = {'h', 'e', 'l', 'l', 'o', 0};
+        int32_t ul = sizeof(ustr)/sizeof(*ustr) -1;
+        char astr[100];
+
+        UErrorCode err;
+
+        err = U_ZERO_ERROR;
+        wcs = u_strToWCS(ws, wcap, &wl, ustr, ul, &err);
+        if (U_FAILURE(err)) {
+                errname = u_errorName(err);
+                log_err("test_widestrs: u_strToWCS error: %s!\n",errname);
+        }
+        if(ul!=wl){
+            log_err("u_strToWCS: ustr = %s, ul = %d, ws = %S, wl = %d!\n", u_austrcpy(astr, ustr), ul, ws, wl);
+        }
+        err = U_ZERO_ERROR;
+        wl = uprv_wcslen(wcs);
+        cp = u_strFromWCS(rts, rtcap, &rtl, wcs, wl, &err);
+        if (U_FAILURE(err)) {
+                errname = u_errorName(err);
+                fprintf(stderr, "test_widestrs: ucnv_wcstombs error: %s!\n",errname);
+        }
+        if(wl != rtl){
+            log_err("u_strFromWCS: wcs = %S, wl = %d,rts = %s, rtl = %d!\n", wcs, wl, u_austrcpy(astr, rts), rtl);
+        }
+}
+
+static void
+Test_WCHART_LongString(){
+    UErrorCode status = U_ZERO_ERROR;
+    const char* testdatapath=loadTestData(&status);
+    UResourceBundle *theBundle = ures_open(testdatapath, "testtypes", &status);
+    int32_t strLen =0;
+    const UChar* str = ures_getStringByKey(theBundle, "testinclude",&strLen,&status);
+    const UChar* uSrc = str;
+    int32_t uSrcLen = strLen;
+    int32_t wDestLen =0, reqLen=0, i=0;
+    int32_t uDestLen =0;
+    wchar_t* wDest = NULL;
+    UChar* uDest = NULL;
+    UBool failed = FALSE;
+
+    if(U_FAILURE(status)){
+        log_err("Could not get testinclude resource from testtypes bundle. Error: %s\n",u_errorName(status));
+        return;
+    }
+
+    /* pre-flight*/
+    u_strToWCS(wDest,wDestLen,&reqLen,uSrc,-1,&status);
+
+    if(status == U_BUFFER_OVERFLOW_ERROR){
+        status=U_ZERO_ERROR;
+        wDest =(wchar_t*) malloc(sizeof(wchar_t) * (reqLen+1));
+        wDestLen = reqLen+1;
+        u_strToWCS(wDest,wDestLen,&reqLen,uSrc,-1,&status);
+    }
+    uDestLen = 0;
+    /* pre-flight */
+    u_strFromWCS(uDest, uDestLen,&reqLen,wDest,-1,&status);
+
+    if(status == U_BUFFER_OVERFLOW_ERROR){
+        status =U_ZERO_ERROR;
+        uDest = (UChar*) malloc(sizeof(UChar) * (reqLen+1));
+        uDestLen = reqLen + 1;
+        u_strFromWCS(uDest, uDestLen,&reqLen,wDest,-1,&status);
+    }
+
+
+    for(i=0; i< uSrcLen; i++){
+        if(uDest[i] != str[i]){
+            log_verbose("u_str*WCS() failed for null terminated string expected: \\u%04X got: \\u%04X at index: %i \n", src16j[i] ,uDest[i],i);
+            failed =TRUE;
+        }
+    }
+
+    if(U_FAILURE(status)){
+        failed = TRUE;
+    }
+    if(failed){
+        log_err("u_strToWCS() failed \n");
+    }
+    free(wDest);
+    free(uDest);
+    /* close the bundle */
+    ures_close(theBundle);    
+    
+}
+

Index: cutiltst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/cutiltst.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cutiltst.c	10 Sep 2003 02:42:39 -0000	1.3
+++ cutiltst.c	6 Apr 2004 10:09:29 -0000	1.4
@@ -25,11 +25,13 @@
 void addTrieTest(TestNode** root);
 void addEnumerationTest(TestNode** root);
 void addPosixTest(TestNode** root);
+void addSortTest(TestNode** root);
 
 void addUtility(TestNode** root);
 
 void addUtility(TestNode** root)
 {
+    addCStringTest(root);
     addTrieTest(root);
     addLocaleTest(root);
     addUnicodeTest(root);
@@ -37,8 +39,8 @@
     addResourceBundleTest(root);
     addNEWResourceBundleTest(root);
     addHashtableTest(root);
-    addCStringTest(root);
     addMemoryStreamTest(root);
     addEnumerationTest(root);
     addPosixTest(root);
+    addSortTest(root);
 }

Index: encoll.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/encoll.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- encoll.c	10 Sep 2003 02:42:39 -0000	1.3
+++ encoll.c	6 Apr 2004 10:09:29 -0000	1.4
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT: 
- * Copyright (c) 1997-2001, International Business Machines Corporation and
+ * Copyright (c) 1997-2003, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 /********************************************************************************
@@ -240,9 +240,9 @@
 
 static const UChar testMore[][MAX_TOKEN_LEN] = {
     {(UChar)0x0061 /* 'a' */, (UChar)0x0065 /* 'e' */, 0},
-    {(UChar)0x0061 /* 'a' */, (UChar)0x0066 /* 'f' */, 0},
     { 0x00E6, 0},
     { 0x00C6, 0},
+    {(UChar)0x0061 /* 'a' */, (UChar)0x0066 /* 'f' */, 0},
     {(UChar)0x006F /* 'o' */, (UChar)0x0065 /* 'e' */, 0},
     { 0x0153, 0},
     { 0x0152, 0},

Index: nccbtst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/nccbtst.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- nccbtst.c	10 Sep 2003 02:42:39 -0000	1.4
+++ nccbtst.c	6 Apr 2004 10:09:30 -0000	1.5
@@ -167,7 +167,6 @@
 
         static const int32_t  toIBM949Offsskip [] = { 0, 1, 1, 2, 2, 4, 4 };
         static const int32_t  toIBM943Offsskip [] = { 0, 0, 1, 1, 3, 3 };
-        static const int32_t  toIBM930Offsskip [] = { 0, 0, 0, 1, 1, 3, 3, 3 };
 
         if(!testConvertFromUnicode(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
                 expskipIBM_949, sizeof(expskipIBM_949), "ibm-949",
@@ -177,15 +176,6 @@
                 expskipIBM_943, sizeof(expskipIBM_943), "ibm-943",
                 UCNV_FROM_U_CALLBACK_SKIP, toIBM943Offsskip, NULL, 0 ))
             log_err("u-> ibm-943 with skip did not match.\n");
-        if(!testConvertFromUnicode(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
-                expskipIBM_930, sizeof(expskipIBM_930), "ibm-930",
-                UCNV_FROM_U_CALLBACK_SKIP, toIBM930Offsskip , NULL, 0))
-            log_err("u-> ibm-930 with skip did not match.\n");
-    
-        if(!testConvertFromUnicodeWithContext(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
-                expskipIBM_930, sizeof(expskipIBM_930), "ibm-930",
-                UCNV_FROM_U_CALLBACK_SKIP, toIBM930Offsskip , NULL, 0,"i", U_ILLEGAL_CHAR_FOUND))
-            log_err("u-> ibm-930 with skip did not match.\n");
     }
 
     {
@@ -283,14 +273,6 @@
         };
         static const int32_t from_iso_2022_jpOffs [] ={0,2};
 
-        static const UChar iso_2022_jp_inputText1[]={0x3000, 0x00E9, 0x3001, };
-        static const uint8_t to_iso_2022_jp1[]={ 
-            0x1b,   0x24,   0x42,   0x21, 0x21,       
-            0x21,   0x22,
-
-        };
-        static const int32_t from_iso_2022_jpOffs1 [] ={0,0,0,0,0,2,2,};
-
         /*ISO-2022-JP*/
         UChar const iso_2022_jp_inputText2[]={0x0041, 0x00E9/*unassigned*/,0x43,0xd800/*illegal*/,0x0042, };
         static const uint8_t to_iso_2022_jp2[]={ 
@@ -303,22 +285,19 @@
         /*ISO-2022-cn*/
         static const UChar iso_2022_cn_inputText[]={ 0x0041, 0x3712/*unassigned*/, 0x0042, };
         static const uint8_t to_iso_2022_cn[]={  
-            0x0F,   0x41,   
-            0x0F,   0x42, 
+            0x41, 0x42
         };
         static const int32_t from_iso_2022_cnOffs [] ={ 
-            0,0,
-            2,2,
+            0, 2
         };
         
         /*ISO-2022-CN*/
         static const UChar iso_2022_cn_inputText1[]={0x0041, 0x3712/*unassigned*/,0x43,0xd800/*illegal*/,0x0042, };
         static const uint8_t to_iso_2022_cn1[]={ 
-            0x0F,   0x41,   
-            0x0F,   0x43, 
+            0x41, 0x43
 
         };
-        static const int32_t from_iso_2022_cnOffs1 [] ={0,0,2,2};
+        static const int32_t from_iso_2022_cnOffs1 [] ={ 0, 2 };
 
         /*ISO-2022-kr*/
         static const UChar iso_2022_kr_inputText[]={ 0x0041, 0x03A0,0x3712/*unassigned*/,0x03A0, 0x0042, };
@@ -440,10 +419,6 @@
                 UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_jpOffs, NULL, 0 ))
             log_err("u-> iso-2022-jp with skip did not match.\n"); 
         
-        if(!testConvertFromUnicode(iso_2022_jp_inputText1, sizeof(iso_2022_jp_inputText1)/sizeof(iso_2022_jp_inputText1[0]),
-                to_iso_2022_jp1, sizeof(to_iso_2022_jp1), "iso-2022-jp",
-                UCNV_FROM_U_CALLBACK_SKIP, from_iso_2022_jpOffs1, NULL, 0 ))
-            log_err("u-> iso-2022-jp with skip did not match.\n"); 
         /* with context */
         if(!testConvertFromUnicodeWithContext(iso_2022_jp_inputText2, sizeof(iso_2022_jp_inputText2)/sizeof(iso_2022_jp_inputText2[0]),
                 to_iso_2022_jp2, sizeof(to_iso_2022_jp2), "iso-2022-jp",
@@ -1135,7 +1110,7 @@
         /*ISO-2022-cn*/
         static const UChar iso_2022_cn_inputText[]={ 0x0041, 0x3712, 0x0042, };
         static const uint8_t to_iso_2022_cn[]={  
-            0x0F,   0x41,   
+            0x41,   
 
         };
         static const int32_t from_iso_2022_cnOffs [] ={ 
@@ -1392,24 +1367,6 @@
             0x61, 0xe6, 0xca, 0x8a,
         };
 
-        /*ISO-2022-JP*/
-        static const UChar iso_2022_jp_inputText[]={ 0x0041, 0x00E9, 0x0042,0x00E9,0x3000 };
-        static const uint8_t to_iso_2022_jp[]={  
-               0x41,   
-               0x1a, 
-               0x42,
-               0x1a,
-               0x1b,  0x24,   0x42,   0x21,   0x21, 
-        };
-
-        static const int32_t from_iso_2022_jpOffs [] ={ 
-            0,
-            1,
-            2,
-            3,
-            4,4,4,4,4
-        };
-
         static const int32_t from_euc_twOffs [] ={ 0, 1, 1, 2, 2, 2, 2, 3, 3, 5, 5, 6, 7, 7, 8,};
 
         if(!testConvertFromUnicode(inputTest, sizeof(inputTest)/sizeof(inputTest[0]),
@@ -1426,13 +1383,6 @@
                 to_euc_tw, sizeof(to_euc_tw), "euc-tw",
                 UCNV_FROM_U_CALLBACK_SUBSTITUTE, from_euc_twOffs, NULL, 0 ))
             log_err("u-> euc-tw with substitute did not match.\n");
-
-        if(!testConvertFromUnicodeWithContext(iso_2022_jp_inputText, sizeof(iso_2022_jp_inputText)/sizeof(iso_2022_jp_inputText[0]),
-                to_iso_2022_jp, sizeof(to_iso_2022_jp), "iso-2022-jp",
-                UCNV_FROM_U_CALLBACK_SUBSTITUTE, from_iso_2022_jpOffs, NULL, 0,"i",U_ILLEGAL_CHAR_FOUND ))
-            log_err("u-> iso-2022-jp with substitute did not match.\n");
-        
-
     }
 
     log_verbose("Testing fromUnicode for SCSU with UCNV_FROM_U_CALLBACK_SUBSTITUTE \n");
@@ -1660,13 +1610,6 @@
 
     log_verbose("Testing GB 18030 with substitute callbacks\n");
     {
-        static const UChar u1[]={
-            0x24, 0x7f, 0x80,                   0x1f9,      0x20ac,     0x4e00,     0x9fa6,                 0xffff,                 0xd800, 0xdc00,         0xdbff, 0xdfff };
-        static const uint8_t gb1[]={
-            0x24, 0x7f, 0x81, 0x30, 0x81, 0x30, 0xa8, 0xbf, 0xa2, 0xe3, 0xd2, 0xbb, 0x82, 0x35, 0x8f, 0x33, 0x84, 0x31, 0xa4, 0x39, 0x90, 0x30, 0x81, 0x30, 0xe3, 0x32, 0x9a, 0x35 };
-        static const int32_t offsets1[]={
-            0, 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 10, 10, 10, 10 };
-
         static const UChar u2[]={
             0x24, 0x7f, 0x80,                   0x1f9,      0x20ac,     0x4e00,     0x9fa6,                 0xffff,                 0xd800, 0xdc00,         0xfffd,                 0xdbff, 0xdfff };
         static const uint8_t gb2[]={
@@ -1674,12 +1617,6 @@
         static const int32_t offsets2[]={
             0, 1, 2, 6, 8, 10, 12, 16, 20, 20, 24, 28, 28 };
 
-        if(!testConvertFromUnicode(u1, ARRAY_LENGTH(u1), gb1, ARRAY_LENGTH(gb1), "gb18030", 
-                                   UCNV_FROM_U_CALLBACK_SUBSTITUTE, offsets1, NULL, 0)
-        ) {
-            log_err("u->gb18030 with substitute did not match.\n");
-        }
-
         if(!testConvertToUnicode(gb2, ARRAY_LENGTH(gb2), u2, ARRAY_LENGTH(u2), "gb18030", 
                                  UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets2, NULL, 0)
         ) {
@@ -1707,26 +1644,6 @@
         }
     }
 
-    log_verbose("Testing IMAP-mailbox-name toUnicode with substitute callbacks\n");
-    {
-        static const uint8_t bytes[]={
-         /* aDEL          a&AB~                         a&AB\x0c                      a&AB-                         a&AB.                         a&. */
-            0x61, 0x7f,   0x61, 0x26, 0x41, 0x42, 0x7e, 0x61, 0x26, 0x41, 0x42, 0x0c, 0x61, 0x26, 0x41, 0x42, 0x2d, 0x61, 0x26, 0x41, 0x42, 0x2e, 0x61, 0x26, 0x2e
-        };
-        static const UChar unicode[]={
-            0x61, 0xfffd, 0x61,       0xfffd,           0x61,       0xfffd,           0x61,       0xfffd,           0x61,       0xfffd,           0x61, 0xfffd
-        };
-        static const int32_t offsets[]={
-            0,    1,      2,          4,                7,          9,                12,         14,               17,         19,               22,   23
-        };
-
-        if(!testConvertToUnicode(bytes, ARRAY_LENGTH(bytes), unicode, ARRAY_LENGTH(unicode), "IMAP-mailbox-name", 
-                                 UCNV_TO_U_CALLBACK_SUBSTITUTE, offsets, NULL, 0)
-        ) {
-            log_err("IMAP-mailbox-name->u with substitute did not match.\n");
-        }
-    }
-
     log_verbose("Testing UTF-16 toUnicode with substitute callbacks\n");
     {
         static const uint8_t
@@ -1774,7 +1691,7 @@
         static const UChar
             out1[]={ UTF16_LEAD(0x100f00), UTF16_TRAIL(0x100f00), 0xfeff },
             out2[]={ UTF16_LEAD(0x0f1000), UTF16_TRAIL(0x0f1000), 0xfffe },
-            out3[]={ 0xfefe, UTF16_LEAD(0x100f00), UTF16_TRAIL(0x100f00), 0xd840, 0xdc01 },
+            out3[]={ 0xfefe, UTF16_LEAD(0x100f00), UTF16_TRAIL(0x100f00), 0xfffd, 0xfffd },
             out4[]={ UTF16_LEAD(0x10203), UTF16_TRAIL(0x10203), 0xfffd, 0x4e00 };
 
         static const int32_t
@@ -1889,22 +1806,6 @@
              6, 7, 7, 8,
         };
         /*ISO-2022-JP*/
-        static const UChar iso_2022_jp_inputText[]={ 0x0041, 0x00E9, 0x0042,0x00E9,0x3000 };
-        static const uint8_t to_iso_2022_jp[]={  
-               0x41,   
-               0x25,  0x55,   0x30,   0x30,   0x45,   0x39,   
-               0x42,
-               0x25,  0x55,   0x30,   0x30,   0x45,   0x39,
-               0x1b,  0x24,   0x42,   0x21,   0x21, 
-        };
-
-        static const int32_t from_iso_2022_jpOffs [] ={ 
-            0,
-            1,1,1,1,1,1,
-            2,
-            3,3,3,3,3,3,
-            4,4,4,4,4
-        };
         static const UChar iso_2022_jp_inputText1[]={ 0x3000, 0x00E9, 0x3001,0x00E9, 0x0042} ;
         static const uint8_t to_iso_2022_jp1[]={  
             0x1b,   0x24,   0x42,   0x21, 0x21,   
@@ -1945,48 +1846,15 @@
         /*ISO-2022-cn*/
         static const UChar iso_2022_cn_inputText[]={ 0x0041, 0x3712, 0x0042, };
         static const uint8_t to_iso_2022_cn[]={  
-            0x0F,   0x41,   
-            0x0f,   0x25, 0x55,   0x33,   0x37,   0x31,   0x32,   
+            0x41,   
+            0x25, 0x55,   0x33,   0x37,   0x31,   0x32,   
             0x42, 
         };
         static const int32_t from_iso_2022_cnOffs [] ={ 
-            0,0,
-            1,1,1,1,1,1,1,
+            0,
+            1,1,1,1,1,1,
             2,
         };
-        static const UChar iso_2022_cn_inputText1[]={ 0x4e00, 0x3712, 0x4e01, };
-        static const uint8_t to_iso_2022_cn1[]={  
-                        0x1b,   0x24,   0x29,   0x41,   0x0e,   0x52,   0x3b,   
-                        0x0f,   0x25,   0x55,   0x33,   0x37,   0x31,   0x32, 
-                        0x1b,   0x24,   0x29,   0x41,   0x0e,   0x36,   0x21,
-        };
-        static const int32_t from_iso_2022_cnOffs1 [] ={ 
-                0, 0, 0, 0, 0, 0, 0, 
-                1, 1, 1, 1, 1, 1, 1, 
-                2, 2, 2, 2, 2, 2, 2,
-        };
-        static const UChar iso_2022_cn_inputText3[]={ 0x3000, 0x3712, 0x3001, };
-        static const uint8_t to_iso_2022_cn3[]={  
-               0x1b,   0x24,   0x29,   0x41,   0x0e,   0x21,   0x21,   
-              0x0f,   0x25,   0x55,   0x33,   0x37,   0x31,   0x32,   
-             0x1b,   0x24,   0x29,   0x41,   0x0e,   0x21,   0x22, 
-        };
-        static const int32_t from_iso_2022_cnOffs3 [] ={ 
-            0,0,0,0,0,0,0,
-            1,1,1,1,1,1,1,
-            2,2,2,2,2,2,2
-        };
-        static const UChar iso_2022_cn_inputText2[]={ 0x0041, 0x3712, 0x4e00, };
-        static const uint8_t to_iso_2022_cn2[]={  
-            0x0F,   0x41,   
-            0x0f,   0x25,   0x55,   0x33,   0x37,   0x31,   0x32,   
-            0x1b,   0x24,   0x29,   0x41,   0x0e,   0x52,   0x3b,
-        };
-        static const int32_t from_iso_2022_cnOffs2 [] ={ 
-            0,0,
-            1,1,1,1,1,1,1,
-            2,2,2,2,2,2,2
-        };
         
         static const UChar iso_2022_cn_inputText4[]={ 0x3000, 0xD84D, 0xDC56, 0x3001,0xD84D,0xDC56, 0x0042};
 
@@ -1994,7 +1862,7 @@
                              0x1b,   0x24,   0x29,   0x41,   0x0e,   0x21,   0x21,   
                              0x0f,   0x25,   0x55,   0x44,   0x38,   0x34,   0x44,   
                              0x25,   0x55,   0x44,   0x43,   0x35,   0x36,   
-                             0x1b,   0x24,   0x29,   0x41,   0x0e,   0x21,   0x22,   
+                             0x0e,   0x21,   0x22,   
                              0x0f,   0x25,   0x55,   0x44,   0x38,   0x34,   0x44,   
                              0x25,   0x55,   0x44,   0x43,   0x35,   0x36,   
                              0x42, 
@@ -2003,7 +1871,7 @@
             0,0,0,0,0,0,0,
             1,1,1,1,1,1,1,
             1,1,1,1,1,1,
-            3,3,3,3,3,3,3,
+            3,3,3,
             4,4,4,4,4,4,4,
             4,4,4,4,4,4,
             6
@@ -2104,30 +1972,6 @@
         };
 
                 /*ISCII*/
-        static const UChar iscii_inputText2[]={ 0x0041, 0x0901,0xD84D, 0xDC56/*unassigned*/,0x0902, 0x0042,0xD84D, 0xDC56/*unassigned*/,0x43 };
-        static const uint8_t to_iscii2[]={  
-            0x41,   
-            0xef,   0x42,   0xa1,    
-            0x25,   0x55,   0x44,   0x38,   0x34,   0x44,   
-            0x25,   0x55,   0x44,   0x43,   0x35,   0x36,  
-            0xa2, 
-            0x42, 
-            0x25,   0x55,   0x44,   0x38,   0x34,   0x44,   
-            0x25,   0x55,   0x44,   0x43,   0x35,   0x36,  
-            0x43
-        };
-        static const int32_t from_isciiOffs2 [] ={ 
-            0,
-            1,1,1,
-            2,2,2,2,2,2,
-            2,2,2,2,2,2,
-            4,
-            5,
-            6,6,6,6,6,6,
-            6,6,6,6,6,6,
-            8,
-        };
-
         static const UChar iscii_inputText[]={ 0x0041, 0x0901,0x3712/*unassigned*/,0x0902, 0x0042,0x3712/*unassigned*/,0x43 };
         static const uint8_t to_iscii[]={   
             0x41,   
@@ -2165,11 +2009,6 @@
                 UCNV_FROM_U_CALLBACK_ESCAPE, from_euc_twOffs, NULL, 0 ))
             log_err("u-> euc-tw with subst with value did not match.\n");  
         
-        if(!testConvertFromUnicode(iso_2022_jp_inputText, sizeof(iso_2022_jp_inputText)/sizeof(iso_2022_jp_inputText[0]),
-                to_iso_2022_jp, sizeof(to_iso_2022_jp), "iso-2022-jp",
-                UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs, NULL, 0 ))
-            log_err("u-> iso_2022_jp with subst with value did not match.\n"); 
-     
         if(!testConvertFromUnicode(iso_2022_jp_inputText1, sizeof(iso_2022_jp_inputText1)/sizeof(iso_2022_jp_inputText1[0]),
                 to_iso_2022_jp1, sizeof(to_iso_2022_jp1), "iso-2022-jp",
                 UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs1, NULL, 0 ))
@@ -2216,56 +2055,26 @@
                 log_err("u-> iso-2022-jp with sub & UCNV_ESCAPE_XML_DEC did not match.\n"); 
         }
         {
-            /* surrogate pair*/
-            static const UChar iso_2022_jp_inputText4[]={ 0x3000, 0xD84D, 0xDC56, 0x3001,0xD84D,0xDC56, 0x0042,0x0901c } ;
-            static const uint8_t to_iso_2022_jp4_v3[]={  
-                    0x1b,   0x24,   0x42,   0x21,   0x21,   
-                    0x1b,   0x28,   0x42,   0x26,   0x23,   0x78,  0x32,   0x33,   0x34,   0x35, 0x36, 0x3b ,  
-                      
-                    0x1b,   0x24,   0x42,   0x21,   0x22,
-                    0x1b,   0x28,   0x42,   0x26,   0x23,   0x78,  0x32,   0x33,   0x34,   0x35, 0x36, 0x3b ,
-                    
-                    0x42,
-                    0x26,   0x23,   0x78,   0x39,   0x30,   0x31,   0x43,   0x3b,
-                    };
-
-            static const int32_t from_iso_2022_jpOffs4_v3 [] ={ 
-                0,0,0,0,0,
-                1,1,1,1,1,1,1,1,1,1,1,1,
-
-                3,3,3,3,3,
-                4,4,4,4,4,4,4,4,4,4,4,4,
-
-                6,
-                7,7,7,7,7,7,7,7
-            };
-            if(!testConvertFromUnicodeWithContext(iso_2022_jp_inputText4, sizeof(iso_2022_jp_inputText4)/sizeof(iso_2022_jp_inputText4[0]),
-                to_iso_2022_jp4_v3, sizeof(to_iso_2022_jp4_v3), "iso-2022-jp",
-                UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_jpOffs4_v3, NULL, 0,UCNV_ESCAPE_XML_HEX,U_ZERO_ERROR ))
-                log_err("u-> iso-2022-jp with sub & UCNV_ESCAPE_XML_HEX did not match.\n"); 
-
-        }
-        {
             static const UChar iso_2022_cn_inputText5[]={ 0x3000, 0xD84D, 0xDC56, 0x3001,0xD84D,0xDC56, 0x0042,0x0902};
             static const uint8_t to_iso_2022_cn5_v2[]={  
                              0x1b,   0x24,   0x29,   0x41,   0x0e,   0x21,   0x21,   
                              0x0f,   0x5c,   0x75,   0x44,   0x38,   0x34,   0x44,   
                              0x5c,   0x75,   0x44,   0x43,   0x35,   0x36,   
-                             0x1b,   0x24,   0x29,   0x41,   0x0e,   0x21,   0x22,   
+                             0x0e,   0x21,   0x22,   
                              0x0f,   0x5c,   0x75,   0x44,   0x38,   0x34,   0x44,   
                              0x5c,   0x75,   0x44,   0x43,   0x35,   0x36,   
                              0x42,
-                             0x0f,   0x5c,   0x75,   0x30,   0x39,   0x30,   0x32,
+                             0x5c,   0x75,   0x30,   0x39,   0x30,   0x32,
                              };
             static const int32_t from_iso_2022_cnOffs5_v2 [] ={ 
                 0,0,0,0,0,0,0,
                 1,1,1,1,1,1,1,
                 1,1,1,1,1,1,
-                3,3,3,3,3,3,3,
+                3,3,3,
                 4,4,4,4,4,4,4,
                 4,4,4,4,4,4,
                 6, 
-                7,7,7,7,7,7,7
+                7,7,7,7,7,7
             };
             if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText5, sizeof(iso_2022_cn_inputText5)/sizeof(iso_2022_cn_inputText5[0]),
                 to_iso_2022_cn5_v2, sizeof(to_iso_2022_cn5_v2), "iso-2022-cn",
@@ -2278,18 +2087,18 @@
             static const uint8_t to_iso_2022_cn6_v2[]={  
                                 0x1b,   0x24,   0x29,   0x41,   0x0e,   0x21,   0x21,   
                                 0x0f,   0x7b,   0x55,   0x2b,   0x32,   0x33,   0x34,   0x35,   0x36,   0x7d,   
-                                0x1b,   0x24,   0x29,   0x41,   0x0e,   0x21,   0x22,   
+                                0x0e,   0x21,   0x22,   
                                 0x0f,   0x7b,   0x55,   0x2b,   0x32,   0x33,   0x34,   0x35,   0x36,   0x7d,   
                                 0x42,   
-                                0x0f,   0x7b,   0x55,   0x2b,   0x30,   0x39,   0x30,   0x32,   0x7d
+                                0x7b,   0x55,   0x2b,   0x30,   0x39,   0x30,   0x32,   0x7d
                              };
             static const int32_t from_iso_2022_cnOffs6_v2 [] ={ 
                     0,  0,  0,  0,  0,  0,  0,  
                     1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  
-                    3,  3,  3,  3,  3,  3,  3,  
+                    3,  3,  3,  
                     4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  
                     6, 
-                    7,  7,  7,  7,  7,  7,  7,  7,  7,
+                    7,  7,  7,  7,  7,  7,  7,  7,
             };
             if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText6, sizeof(iso_2022_cn_inputText6)/sizeof(iso_2022_cn_inputText6[0]),
                 to_iso_2022_cn6_v2, sizeof(to_iso_2022_cn6_v2), "iso-2022-cn",
@@ -2302,17 +2111,17 @@
             static const uint8_t to_iso_2022_cn7_v2[]={  
                                 0x1b,   0x24,   0x29,   0x41,   0x0e,   0x21,   0x21,   
                                 0x0f,   0x25,   0x55,   0x44,   0x38,   0x34,   0x44,   0x25,   0x55,   0x44,   0x43,   0x35,   0x36,   
-                                0x1b,   0x24,   0x29,   0x41,   0x0e,   0x21,   0x22,   
+                                0x0e,   0x21,   0x22,   
                                 0x0f,   0x25,   0x55,   0x44,   0x38,   0x34,   0x44,   0x25,   0x55,   0x44,   0x43,   0x35,   0x36,   
-                                0x42,   0x0f,   0x25,   0x55,   0x30,   0x39,   0x30,   0x32, 
+                                0x42,   0x25,   0x55,   0x30,   0x39,   0x30,   0x32, 
                             };
             static const int32_t from_iso_2022_cnOffs7_v2 [] ={ 
                                 0,  0,  0,  0,  0,  0,  0,  
                                 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  
-                                3,  3,  3,  3,  3,  3,  3,  
+                                3,  3,  3,  
                                 4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  
                                 6,  
-                                7,  7,  7,  7,  7,  7,  7,
+                                7,  7,  7,  7,  7,  7,
             };
             if(!testConvertFromUnicodeWithContext(iso_2022_cn_inputText7, sizeof(iso_2022_cn_inputText7)/sizeof(iso_2022_cn_inputText7[0]),
                 to_iso_2022_cn7_v2, sizeof(to_iso_2022_cn7_v2), "iso-2022-cn",
@@ -2324,7 +2133,7 @@
             static const uint8_t to_iso_2022_cn4_v3[]={  
                             0x1b,   0x24,   0x29,   0x41,   0x0e,   0x21,   0x21,   
                             0x0f,   0x5c,   0x55,   0x30,   0x30,   0x30,   0x32,   0x33,   0x34,   0x35,   0x36,   
-                            0x1b,   0x24,   0x29,   0x41,   0x0e,   0x21,   0x22,
+                            0x0e,   0x21,   0x22,
                             0x0f,   0x5c,   0x55,   0x30,   0x30,   0x30,   0x32,   0x33,   0x34,   0x35,   0x36, 
                             0x42 
                              };
@@ -2334,7 +2143,7 @@
                 0,0,0,0,0,0,0,
                 1,1,1,1,1,1,1,1,1,1,1,
 
-                3,3,3,3,3,3,3,
+                3,3,3,
                 4,4,4,4,4,4,4,4,4,4,4,
 
                 6
@@ -2352,18 +2161,6 @@
                 UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs, NULL, 0 ))
             log_err("u-> iso_2022_cn with subst with value did not match.\n");
 
-        if(!testConvertFromUnicode(iso_2022_cn_inputText1, sizeof(iso_2022_cn_inputText1)/sizeof(iso_2022_cn_inputText1[0]),
-                to_iso_2022_cn1, sizeof(to_iso_2022_cn1), "iso-2022-cn",
-                UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs1, NULL, 0 ))
-            log_err("u-> iso_2022_cn with subst with value did not match.\n"); 
-        if(!testConvertFromUnicode(iso_2022_cn_inputText2, sizeof(iso_2022_cn_inputText2)/sizeof(iso_2022_cn_inputText2[0]),
-                to_iso_2022_cn2, sizeof(to_iso_2022_cn2), "iso-2022-cn",
-                UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs2, NULL, 0 ))
-            log_err("u-> iso_2022_cn with subst with value did not match.\n");
-        if(!testConvertFromUnicode(iso_2022_cn_inputText3, sizeof(iso_2022_cn_inputText3)/sizeof(iso_2022_cn_inputText3[0]),
-                to_iso_2022_cn3, sizeof(to_iso_2022_cn3), "iso-2022-cn",
-                UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs3, NULL, 0 ))
-            log_err("u-> iso_2022_cn with subst with value did not match.\n");
         if(!testConvertFromUnicode(iso_2022_cn_inputText4, sizeof(iso_2022_cn_inputText4)/sizeof(iso_2022_cn_inputText4[0]),
                 to_iso_2022_cn4, sizeof(to_iso_2022_cn4), "iso-2022-cn",
                 UCNV_FROM_U_CALLBACK_ESCAPE, from_iso_2022_cnOffs4, NULL, 0 ))
@@ -2389,11 +2186,6 @@
                 to_iscii, sizeof(to_iscii), "ISCII,version=0",
                 UCNV_FROM_U_CALLBACK_ESCAPE, from_isciiOffs, NULL, 0 ))
             log_err("u-> iscii with subst with value did not match.\n");
-        
-        if(!testConvertFromUnicode(iscii_inputText2, sizeof(iscii_inputText2)/sizeof(iscii_inputText2[0]),
-                to_iscii2, sizeof(to_iscii2), "ISCII,version=0",
-                UCNV_FROM_U_CALLBACK_ESCAPE, from_isciiOffs2, NULL, 0 ))
-            log_err("u-> iscii2 with subst with value did not match.\n");
     }
 
 
@@ -2512,18 +2304,6 @@
         static const int32_t from_isciiOffs [] ={0,1,2,2,2,2,3,4,5,5,5,5,6  };
 
 
-        /*LMBCS*/
-        static const uint8_t sampleTxtLMBCS[]={ 0x12, 0xc9, 0x50, 
-            0x12, 0x92, 0xa0, /*unassigned*/
-            0x12, 0x92, 0xa1,
-        };
-        static const UChar LMBCSToUnicode[]={ 0x4e2e, 
-            0x25, 0x58, 0x31, 0x32, 0x25, 0x58, 0x39, 0x32, 0x25, 0x58, 0x41, 0x30, 
-            0xe5c4, };
-        static const int32_t fromLMBCS[] = {0, 
-            3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
-            6, };
-
         /*UTF8*/
         static const uint8_t sampleTxtUTF8[]={
             0x20, 0x64, 0x50, 
@@ -2644,10 +2424,6 @@
                  isciitoUnicode, sizeof(isciitoUnicode)/sizeof(isciitoUnicode[0]),"ISCII,version=0",
                 UCNV_TO_U_CALLBACK_ESCAPE, from_isciiOffs, NULL, 0))
             log_err("ISCII ->u with substitute with value did not match.\n");
-        if(!testConvertToUnicode(sampleTxtLMBCS, sizeof(sampleTxtLMBCS),
-                LMBCSToUnicode, sizeof(LMBCSToUnicode)/sizeof(LMBCSToUnicode[0]),"LMBCS",
-                UCNV_TO_U_CALLBACK_ESCAPE, fromLMBCS, NULL, 0))
-            log_err("LMBCS->u with substitute with value did not match.\n"); 
         if(!testConvertToUnicode(sampleTxtUTF8, sizeof(sampleTxtUTF8),
                 UTF8ToUnicode, sizeof(UTF8ToUnicode)/sizeof(UTF8ToUnicode[0]),"UTF-8",
                 UCNV_TO_U_CALLBACK_ESCAPE, fromUTF8, NULL, 0))

Index: ncnvfbts.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/ncnvfbts.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ncnvfbts.c	10 Sep 2003 02:42:40 -0000	1.3
+++ ncnvfbts.c	6 Apr 2004 10:09:31 -0000	1.4
@@ -519,6 +519,8 @@
     static const char* nativeCodePage[]={
         /*NLCS Mapping*/
         "ibm-367",
+        "ibm-437",
+        "ibm-850",
         "ibm-1051",
         "ibm-1089",
         "ibm-1250",
@@ -529,8 +531,8 @@
         "ibm-1256",
         "ibm-1257",
         "ibm-1258",
-        "ibm-1275",
-        "ibm-1276"
+        "ibm-1276",
+        "ibm-1277"
     };
 
     int32_t i=0;
@@ -709,7 +711,7 @@
                 0x01, 0x02, 0x03, 0x0a, 0x01, 0x02, 0x03, 0x0e, 0x01, 0x02, 0x03, 0x0d, 0x03, 0x01, 0x02, 0x03, 0x0c,};
         const UChar expectedUnicode[] = 
                 { 0x20ac, 0x0005, 0x0006, 0x000b, 0xdbc4, 0xde34, 0xdbba, 0xdfcd,
-                  0xd84d, 0xdc56, 0x000e, 0xd891, 0xdd67, 0xfffd, 0xfffd}; 
+                  0xd84d, 0xdc56, 0x000e, 0xd891, 0xdd67, 0x1a, 0xfffd}; 
         int32_t fromtest4Offs[]       = 
                 { 0, 1, 2, 3, 7, 7, 8, 8, 9, 9, 13, 17, 17, 21, 22,};
 

Index: ncnvtst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/ncnvtst.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ncnvtst.c	10 Sep 2003 02:42:40 -0000	1.3
+++ ncnvtst.c	6 Apr 2004 10:09:31 -0000	1.4
@@ -190,7 +190,7 @@
                                     0x36, 0x21,
                                     0x0F, 0x31, 
                                     0x1A, 
-                                    0x0f, 0x32
+                                    0x32
                                     };
 
         
@@ -200,7 +200,7 @@
                                     1,    1,
                                     2,    2,
                                     3,  
-                                    5,    5,  };
+                                    5,  };
 
         /*iso-2022-CN*/
         if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
@@ -317,15 +317,16 @@
     {
         static const UChar    sampleText[] =   { 0x0031, 0xd801};
         static const UChar    sampleText2[] =   { 0x0031, 0xd801, 0x0032};
-        static const uint8_t expected[] =          { 0x31};
+        static const uint8_t expected0[] =          { 0x31};
+        static const uint8_t expected[] =          { 0x31, 0x1a};
         static const uint8_t expected2[] =         { 0x31, 0x1a, 0x32};
 
         /*SBCS*/
         if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
-                expected, sizeof(expected), "ibm-920", 0, TRUE, U_TRUNCATED_CHAR_FOUND))
+                expected, sizeof(expected), "ibm-920", 0, TRUE, U_ZERO_ERROR))
             log_err("u-> ibm-920 [UCNV_SBCS] \n");
         if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
-                expected, sizeof(expected), "ibm-920", 0, FALSE, U_ZERO_ERROR))
+                expected0, sizeof(expected0), "ibm-920", 0, FALSE, U_ZERO_ERROR))
             log_err("u-> ibm-920 [UCNV_SBCS] \n");
         if(!convertFromU(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
                 expected2, sizeof(expected2), "ibm-920", 0, TRUE, U_ZERO_ERROR))
@@ -334,10 +335,10 @@
 
         /*LATIN_1*/
         if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
-                expected, sizeof(expected), "LATIN_1", 0, TRUE, U_TRUNCATED_CHAR_FOUND))
+                expected, sizeof(expected), "LATIN_1", 0, TRUE, U_ZERO_ERROR))
             log_err("u-> LATIN_1 is supposed to fail\n");
         if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
-                expected, sizeof(expected), "LATIN_1", 0, FALSE, U_ZERO_ERROR))
+                expected0, sizeof(expected0), "LATIN_1", 0, FALSE, U_ZERO_ERROR))
             log_err("u-> LATIN_1 is supposed to fail\n");
 
         if(!convertFromU(sampleText2, sizeof(sampleText2)/sizeof(sampleText2[0]),
@@ -350,7 +351,9 @@
     {
         static const UChar    sampleText[]    = { 0x00a1, 0xd801};
         static const uint8_t expected[] = { 0xa2, 0xae};
-        static const int32_t offsets[]        = { 0x00, 0x00, 0x01, 0x01};
+        static const int32_t offsets[]        = { 0x00, 0x00};
+        static const uint8_t expectedSUB[] = { 0xa2, 0xae, 0xa1, 0xe0};
+        static const int32_t offsetsSUB[]        = { 0x00, 0x00, 0x01, 0x01};
 
         static const UChar       sampleText2[] = { 0x00a1, 0xd801, 0x00a4};
         static const uint8_t expected2[] = { 0xa2, 0xae, 0xa1, 0xe0, 0xa2, 0xb4};
@@ -370,14 +373,14 @@
 
         /*DBCS*/
         if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
-                expected, sizeof(expected), "ibm-1363", 0, TRUE, U_TRUNCATED_CHAR_FOUND))
+                expectedSUB, sizeof(expectedSUB), "ibm-1363", 0, TRUE, U_ZERO_ERROR))
             log_err("u-> ibm-1363 [UCNV_DBCS portion] is supposed to fail\n");
         if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
                 expected, sizeof(expected), "ibm-1363", 0, FALSE, U_ZERO_ERROR))
             log_err("u-> ibm-1363 [UCNV_DBCS portion] is supposed to fail\n");
 
         if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
-                expected, sizeof(expected), "ibm-1363", offsets, TRUE, U_TRUNCATED_CHAR_FOUND))
+                expectedSUB, sizeof(expectedSUB), "ibm-1363", offsetsSUB, TRUE, U_ZERO_ERROR))
             log_err("u-> ibm-1363 [UCNV_DBCS portion] is supposed to fail\n");
         if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
                 expected, sizeof(expected), "ibm-1363", offsets, FALSE, U_ZERO_ERROR))
@@ -393,7 +396,7 @@
 
         /*MBCS*/
         if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
-                expected, sizeof(expected), "ibm-1363", 0, TRUE, U_TRUNCATED_CHAR_FOUND))
+                expectedSUB, sizeof(expectedSUB), "ibm-1363", 0, TRUE, U_ZERO_ERROR))
             log_err("u-> ibm-1363 [UCNV_MBCS] \n");
         if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
                 expected, sizeof(expected), "ibm-1363", 0, FALSE, U_ZERO_ERROR))
@@ -428,21 +431,18 @@
     {
         static const UChar    sampleText[]    = { 0x0031, 0xd801};
         static const uint8_t expected[] = {  0x31};
-        static const int32_t offsets[]        = { 0x00};
+        static const uint8_t expectedSUB[] = {  0x31, 0x1a};
+        static const int32_t offsets[]        = { 0x00, 1};
 
         static const UChar       sampleText2[] = { 0x0031, 0xd801, 0x0032};
         static const uint8_t expected2[] = {  0x31,0x1A,0x32};
         static const int32_t offsets2[]        = { 0x00,0x01,0x02};
 
-        static const UChar       sampleText3MBCS[] = { 0x3000, 0x0050, 0xdc01,0x3001};
-        static const uint8_t expected3MBCS[] = { 0x1B, 0x24, 0x42, 0x21, 0x21, 0x1B, 0x28, 0x42, 0x50, 0x1A, 0x1B, 0x24, 0x42, 0x21, 0x22,};
-        static const int32_t offsets3MBCS[]        = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03,};
-
         static const UChar       sampleText4MBCS[] = { 0x0061, 0x4e00, 0xdc01};
         static const uint8_t expected4MBCS[] = { 0x61, 0x1b, 0x24, 0x42, 0x30, 0x6c,0x1b,0x28,0x42,0x1a};
         static const int32_t offsets4MBCS[]        = { 0x00, 0x01, 0x01 ,0x01, 0x01, 0x01,0x02,0x02,0x02,0x02 };
         if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
-                expected, sizeof(expected), "iso-2022-jp", offsets, TRUE, U_TRUNCATED_CHAR_FOUND))
+                expectedSUB, sizeof(expectedSUB), "iso-2022-jp", offsets, TRUE, U_ZERO_ERROR))
             log_err("u-> iso-2022-jp [UCNV_MBCS] \n");
         if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
                 expected, sizeof(expected), "iso-2022-jp", offsets, FALSE, U_ZERO_ERROR))
@@ -458,13 +458,6 @@
                 expected2, sizeof(expected2), "iso-2022-jp", offsets2, FALSE, U_ZERO_ERROR))
             log_err("u-> iso-2022-jp [UCNV_DBCS] did not match\n");
 
-        if(!convertFromU(sampleText3MBCS, sizeof(sampleText3MBCS)/sizeof(sampleText3MBCS[0]),
-                expected3MBCS, sizeof(expected3MBCS), "iso-2022-jp", offsets3MBCS, TRUE, U_ZERO_ERROR))
-            log_err("u->iso-2022-jp [UCNV_MBCS] \n");
-        if(!convertFromU(sampleText3MBCS, sizeof(sampleText3MBCS)/sizeof(sampleText3MBCS[0]),
-                expected3MBCS, sizeof(expected3MBCS), "iso-2022-jp", offsets3MBCS, FALSE, U_ZERO_ERROR))
-            log_err("u-> iso-2022-jp[UCNV_MBCS] \n");
-
         if(!convertFromU(sampleText4MBCS, sizeof(sampleText4MBCS)/sizeof(sampleText4MBCS[0]),
                 expected4MBCS, sizeof(expected4MBCS), "iso-2022-jp", offsets4MBCS, TRUE, U_ZERO_ERROR))
             log_err("u-> iso-2022-jp [UCNV_MBCS] \n");
@@ -476,22 +469,23 @@
     log_verbose("Testing for iso-2022-cn\n");
     {
         static const UChar    sampleText[]    = { 0x0031, 0xd801};
-        static const uint8_t expected[] = { 0x0f, 0x31};
-        static const int32_t offsets[]        = { 0x00, 0x00};
+        static const uint8_t expected[] = { 0x31};
+        static const uint8_t expectedSUB[] = { 0x31, 0x1A};
+        static const int32_t offsets[]        = { 0x00, 1};
 
         static const UChar       sampleText2[] = { 0x0031, 0xd801, 0x0032};
-        static const uint8_t expected2[] = { 0x0f, 0x31, 0x1A,0x32};
-        static const int32_t offsets2[]        = { 0x00, 0x00, 0x01,0x02};
+        static const uint8_t expected2[] = { 0x31, 0x1A,0x32};
+        static const int32_t offsets2[]        = { 0x00, 0x01,0x02};
 
         static const UChar       sampleText3MBCS[] = { 0x0051, 0x0050, 0xdc01};
-        static const uint8_t expected3MBCS[] = {0x0f, 0x51, 0x50, 0x1A};
-        static const int32_t offsets3MBCS[]        = { 0x00, 0x00, 0x01, 0x02 };
+        static const uint8_t expected3MBCS[] = {0x51, 0x50, 0x1A};
+        static const int32_t offsets3MBCS[]        = { 0x00, 0x01, 0x02 };
 
         static const UChar       sampleText4MBCS[] = { 0x0061, 0x4e00, 0xdc01};
-        static const uint8_t expected4MBCS[] = { 0x0f, 0x61, 0x1b, 0x24, 0x29, 0x41, 0x0e, 0x52, 0x3b, 0x0f, 0x1a };
-        static const int32_t offsets4MBCS[]        = { 0x00, 0x00, 0x01, 0x01 ,0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02 };
+        static const uint8_t expected4MBCS[] = { 0x61, 0x1b, 0x24, 0x29, 0x41, 0x0e, 0x52, 0x3b, 0x0f, 0x1a };
+        static const int32_t offsets4MBCS[]        = { 0x00, 0x01, 0x01 ,0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02 };
         if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
-                expected, sizeof(expected), "iso-2022-cn", offsets, TRUE, U_TRUNCATED_CHAR_FOUND))
+                expectedSUB, sizeof(expectedSUB), "iso-2022-cn", offsets, TRUE, U_ZERO_ERROR))
             log_err("u-> iso-2022-cn [UCNV_MBCS] \n");
         if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
                 expected, sizeof(expected), "iso-2022-cn", offsets, FALSE, U_ZERO_ERROR))
@@ -526,7 +520,8 @@
     {
         static const UChar    sampleText[]    = { 0x0031, 0xd801};
         static const uint8_t expected[] = { 0x1b, 0x24, 0x29, 0x43, 0x31};
-        static const int32_t offsets[]        = { -1,   -1,   -1,   -1,   0x00};
+        static const uint8_t expectedSUB[] = { 0x1b, 0x24, 0x29, 0x43, 0x31, 0x1A};
+        static const int32_t offsets[]        = { -1,   -1,   -1,   -1,   0x00, 1};
 
         static const UChar       sampleText2[] = { 0x0031, 0xd801, 0x0032};
         static const uint8_t expected2[] = { 0x1b, 0x24, 0x29, 0x43, 0x31, 0x1A, 0x32};
@@ -536,15 +531,8 @@
         static const uint8_t expected3MBCS[] = { 0x1b, 0x24, 0x29, 0x43,  0x51, 0x50, 0x1A };
         static const int32_t offsets3MBCS[]        = { -1,   -1,   -1,   -1,    0x00, 0x01, 0x02, 0x02 };
 
-        static const UChar       sampleText4MBCS[] = { 0x0061, 0x4e00, 0xdc01,0x4e00};
-        static const uint8_t expected4MBCS[] = { 0x1b, 0x24, 0x29, 0x43,
-                                          0x61, 
-                                          0x0e, 0x6c, 0x69, 
-                                          0x0f, 0x1a,
-                                          0x0e, 0x6c, 0x69,};
-        static const int32_t offsets4MBCS[]        = { -1,   -1,   -1,   -1, 0x00, 0x01 ,0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x03 };
         if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
-                expected, sizeof(expected), "iso-2022-kr", offsets, TRUE, U_TRUNCATED_CHAR_FOUND))
+                expectedSUB, sizeof(expectedSUB), "iso-2022-kr", offsets, TRUE, U_ZERO_ERROR))
             log_err("u-> iso-2022-kr [UCNV_MBCS] \n");
         if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
                 expected, sizeof(expected), "iso-2022-kr", offsets, FALSE, U_ZERO_ERROR))
@@ -566,13 +554,6 @@
         if(!convertFromU(sampleText3MBCS, sizeof(sampleText3MBCS)/sizeof(sampleText3MBCS[0]),
                 expected3MBCS, sizeof(expected3MBCS), "iso-2022-kr", offsets3MBCS, FALSE, U_ZERO_ERROR))
             log_err("u-> iso-2022-kr[UCNV_MBCS] \n");
-
-        if(!convertFromU(sampleText4MBCS, sizeof(sampleText4MBCS)/sizeof(sampleText4MBCS[0]),
-                expected4MBCS, sizeof(expected4MBCS), "iso-2022-kr", offsets4MBCS, TRUE, U_ZERO_ERROR))
-            log_err("u-> iso-2022-kr [UCNV_MBCS] \n");
-        if(!convertFromU(sampleText4MBCS, sizeof(sampleText4MBCS)/sizeof(sampleText4MBCS[0]),
-                expected4MBCS, sizeof(expected4MBCS), "iso-2022-kr", offsets4MBCS, FALSE, U_ZERO_ERROR))
-            log_err("u-> iso-2022-kr [UCNV_MBCS] \n");
     }
 
     /*HZ*/
@@ -580,7 +561,8 @@
     {
         static const UChar    sampleText[]    = { 0x0031, 0xd801};
         static const uint8_t expected[] = { 0x7e, 0x7d, 0x31};
-        static const int32_t offsets[]        = { 0x00, 0x00, 0x00};
+        static const uint8_t expectedSUB[] = { 0x7e, 0x7d, 0x31, 0x1A};
+        static const int32_t offsets[]        = { 0x00, 0x00, 0x00, 1};
 
         static const UChar       sampleText2[] = { 0x0031, 0xd801, 0x0032};
         static const uint8_t expected2[] = { 0x7e, 0x7d, 0x31,  0x1A,  0x32 };
@@ -594,7 +576,7 @@
         static const uint8_t expected4MBCS[] = { 0x7e, 0x7d, 0x61, 0x7e, 0x7b, 0x52, 0x3b, 0x7e, 0x7d, 0x1a };
         static const int32_t offsets4MBCS[]        = { 0x00, 0x00, 0x00, 0x01, 0x01, 0x01 ,0x01, 0x02, 0x02, 0x02 };
         if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
-                expected, sizeof(expected), "HZ", offsets, TRUE, U_TRUNCATED_CHAR_FOUND))
+                expectedSUB, sizeof(expectedSUB), "HZ", offsets, TRUE, U_ZERO_ERROR))
             log_err("u-> HZ [UCNV_MBCS] \n");
         if(!convertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
                 expected, sizeof(expected), "HZ", offsets, FALSE, U_ZERO_ERROR))
@@ -636,21 +618,12 @@
         uint8_t sampleText[] = { 0xa2, 0xae, 0x03, 0x04};
         const UChar expected[] = { 0x00a1 };
         
-        uint8_t sampleText2[] = { 0xa2, 0xae, 0xa2};
-        const UChar expected2[] = { 0x00a1 };
-
         if(!convertToU(sampleText, sizeof(sampleText), 
                 expected, sizeof(expected)/sizeof(expected[0]), "ibm-1363", 0, TRUE, U_ZERO_ERROR ))
             log_err("DBCS (ibm-1363)->Unicode  did not match.\n");
         if(!convertToU(sampleText, sizeof(sampleText), 
                 expected, sizeof(expected)/sizeof(expected[0]), "ibm-1363", 0, FALSE, U_ZERO_ERROR ))
             log_err("DBCS (ibm-1363)->Unicode  with flush = false did not match.\n");
-       
-        if(!convertToU(sampleText2, sizeof(sampleText2), 
-                expected2, sizeof(expected2)/sizeof(expected2[0]), "ibm-1363", 0, TRUE, U_TRUNCATED_CHAR_FOUND ))
-            log_err("DBCS (ibm-1363)->Unicode with TRUNCATED CHARACTER  did not match.\n");
-       
-    
     }
     log_verbose("Testing error conditions for SBCS\n");
     {
@@ -668,57 +641,6 @@
             log_err("SBCS (ibm-1051)->Unicode  with flush = false did not match.\n");
 
     }
-    log_verbose("Testing error conditions for UTF8\n");
-    {
-        const uint8_t sampleText[] = { 0x31, 0xe4, 0xba, 0x8c, 0xe4, 0xb8 };
-        UChar    expectedUTF8[] = {  0x0031, 0x4e8c};
-        int32_t offsets[] = {   0x0000, 0x0001};
-
-        const uint8_t sampleText2[] = { 0x31, 0xff, 0xe4, 0xba, 0x8c, 
-            0xe0, 0x80, 0x61};
-        UChar    expected2UTF8[] = {  0x0031, 0xfffd, 0x4e8c, 0xfffd, 0x0061};
-        int32_t offsets2[] = {   0x0000, 0x0001, 0x0002, 0x0005, 0x0007};
-
-        const uint8_t sampleText3[] = { 0x31, 0xfb, 0xbf, 0xbf, 0xbf, 0xbf, 
-            0x61};
-        UChar    expected3UTF8[] = {  0x0031, 0xfffd, 0x0061};
-        int32_t offsets3[] = {   0x0000, 0x0001, 0x0006};
-
-        if(!convertToU(sampleText, sizeof(sampleText), 
-                expectedUTF8, sizeof(expectedUTF8)/sizeof(expectedUTF8[0]), "utf-8", 0, TRUE, U_TRUNCATED_CHAR_FOUND ))
-            log_err("utf-8->Unicode  did not match.\n");
-        if(!convertToU(sampleText, sizeof(sampleText), 
-                expectedUTF8, sizeof(expectedUTF8)/sizeof(expectedUTF8[0]), "utf-8", 0, FALSE, U_ZERO_ERROR ))
-            log_err("utf-8->Unicode  did not match.\n");
-        if(!convertToU(sampleText, sizeof(sampleText), 
-                expectedUTF8, sizeof(expectedUTF8)/sizeof(expectedUTF8[0]), "utf-8", offsets, TRUE, U_TRUNCATED_CHAR_FOUND ))
-            log_err("utf-8->Unicode  did not match.\n");
-        if(!convertToU(sampleText, sizeof(sampleText), 
-                expectedUTF8, sizeof(expectedUTF8)/sizeof(expectedUTF8[0]), "utf-8", offsets, FALSE, U_ZERO_ERROR ))
-            log_err("utf-8->Unicode  did not match.\n");
-
-        if(!convertToU(sampleText2, sizeof(sampleText2), 
-                expected2UTF8, sizeof(expected2UTF8)/sizeof(expected2UTF8[0]), "utf-8", 0, TRUE, U_ZERO_ERROR ))
-            log_err("utf-8->Unicode  did not match.\n");
-        if(!convertToU(sampleText2, sizeof(sampleText2), 
-                expected2UTF8, sizeof(expected2UTF8)/sizeof(expected2UTF8[0]), "utf-8", 0, FALSE, U_ZERO_ERROR ))
-            log_err("utf-8->Unicode  did not match.\n");
-        if(!convertToU(sampleText2, sizeof(sampleText2), 
-                expected2UTF8, sizeof(expected2UTF8)/sizeof(expected2UTF8[0]), "utf-8", offsets2, TRUE, U_ZERO_ERROR ))
-            log_err("utf-8->Unicode  did not match.\n");
-        if(!convertToU(sampleText2, sizeof(sampleText2), 
-                expected2UTF8, sizeof(expected2UTF8)/sizeof(expected2UTF8[0]), "utf-8", offsets2, FALSE, U_ZERO_ERROR ))
-            log_err("utf-8->Unicode  did not match.\n");
-
-        if(!convertToU(sampleText3, sizeof(sampleText3), 
-                expected3UTF8, sizeof(expected3UTF8)/sizeof(expected3UTF8[0]), "utf-8", offsets3, TRUE, U_ZERO_ERROR ))
-            log_err("utf-8->Unicode  did not match.\n");
-        if(!convertToU(sampleText3, sizeof(sampleText3), 
-                expected3UTF8, sizeof(expected3UTF8)/sizeof(expected3UTF8[0]), "utf-8", offsets3, FALSE, U_ZERO_ERROR ))
-            log_err("utf-8->Unicode  did not match with flush false.\n");
-
-    }
-
 }
 
 static void TestGetNextErrorBehaviour(){
@@ -1439,37 +1361,6 @@
 
 
 static void TestResetBehaviour(void){
-    log_verbose("Testing  Reset for SBCS and LATIN_1\n");
-    {
-        static const UChar sampleText[] = {0x0031, 0xd801, 0xdc01, 0x0032};
-        static const uint8_t expected[] = {0x31, 0x1a, 0x32};
-        static const int32_t offsets[] =  { 0,1,3};
-
-        static const UChar sampleText1[] = {0x0031, 0x0033, 0x0034, 0x0032};
-        static const uint8_t expected1[] = {0x31, 0x33,0x34, 0x32};
-        static const int32_t offsets1[] =  { 0,1,2,3};
-
-        /*SBCS*/
-        if(!testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
-                expected, sizeof(expected), "ibm-920", UCNV_FROM_U_CALLBACK_SUBSTITUTE , offsets, TRUE))
-            log_err("u-> ibm-920 [UCNV_SBCS] not match.\n");
-        if(!testConvertToU(expected1, sizeof(expected1), 
-                sampleText1, sizeof(sampleText1)/sizeof(sampleText1[0]), "ibm-920",UCNV_TO_U_CALLBACK_SUBSTITUTE , 
-                offsets1, TRUE))
-           log_err("ibm -920 -> did not match.\n");
-
-        /*LATIN_1*/
-        if(!testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
-                expected, sizeof(expected), "LATIN1", UCNV_FROM_U_CALLBACK_SUBSTITUTE , offsets, TRUE))
-            log_err("u-> LATIN_1 not match.\n");
-        if(!testConvertToU(expected1, sizeof(expected1), 
-                sampleText1, sizeof(sampleText1)/sizeof(sampleText1[0]), "LATIN1",UCNV_TO_U_CALLBACK_SUBSTITUTE , 
-                offsets1, TRUE))
-           log_err("LATIN1 -> did not match.\n");
-        
-
-
-    }
     log_verbose("Testing Reset for DBCS and MBCS\n");
     {
         static const UChar sampleText[]       = {0x00a1, 0xd801, 0xdc01, 0x00a4};
@@ -1546,7 +1437,7 @@
                                     0x36, 0x21,
                                     0x0f, 0x31,
                                     0x1A, 
-                                    0x0f, 0x32
+                                    0x32
                                     };
         
 
@@ -1555,17 +1446,17 @@
                                     1,    1,
                                     2,    2,
                                     3,    
-                                    5,    5,  };
+                                    5,  };
         
         UChar sampleText1[] = {0x4e00, 0x04e01, 0x0031,0x001A, 0x0032};
         static const uint8_t expected1[] = {
                                     0x1B, 0x24, 0x29, 0x41, 0x0E, 0x52, 0x3B, 
                                     0x36, 0x21,
-                                    0x1B, 0x24, 0x29, 0x47, 0x1B, 0x4E, 0x24, 0x22, 
+                                    0x1B, 0x24, 0x29, 0x47, 0x24, 0x22, 
                                     0x0f, 0x1A, 
                                     0x32
                                     };
-        static const int32_t offsets1[] =  { 5,7,15,18,19};
+        static const int32_t offsets1[] =  { 5,7,13,16,17};
 
         /*iso-2022-CN*/
         if(!testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
@@ -1729,6 +1620,13 @@
         log_data_err("error TestTruncated: unable to open \"%s\" - %s\n", cnvName, u_errorName(errorCode));
         return;
     }
+    ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode);
+    if(U_FAILURE(errorCode)) {
+        log_data_err("error TestTruncated: unable to set the stop callback on \"%s\" - %s\n",
+                    cnvName, u_errorName(errorCode));
+        ucnv_close(cnv);
+        return;
+    }
 
     source=(const char *)bytes;
     sourceLimit=source+length;
@@ -1747,16 +1645,10 @@
     target=buffer;
     ucnv_toUnicode(cnv, &target, targetLimit, &source, sourceLimit, NULL, TRUE, &errorCode);
     if(errorCode!=U_TRUNCATED_CHAR_FOUND || target!=buffer) {
-        log_err("error TestTruncated(%s, 1b): no input, flush=TRUE: %s (should be U_TRUNCATED_CHAR_FOUND), output %d\n",
-                cnvName, u_errorName(errorCode), (int)(target-buffer));
+        log_err("error TestTruncated(%s, 1b): no input (previously %d), flush=TRUE: %s (should be U_TRUNCATED_CHAR_FOUND), output %d\n",
+                cnvName, (int)length, u_errorName(errorCode), (int)(target-buffer));
     }
 
-    /*
-     * ### TODO: flush=TRUE resets; make sure this is well documented; question -
-     * does it also delete ucnv_getInvalidChars()?
-     * resetting logically should delete them, but then it is not possible to figure out which bytes are left in the converter.
-     */
-
     /* 2. input bytes with flush=TRUE */
     ucnv_resetToUnicode(cnv);
 
@@ -1764,7 +1656,7 @@
     source=(const char *)bytes;
     target=buffer;
     ucnv_toUnicode(cnv, &target, targetLimit, &source, sourceLimit, NULL, TRUE, &errorCode);
-    if(errorCode!=U_TRUNCATED_CHAR_FOUND || target!=buffer) {
+    if(errorCode!=U_TRUNCATED_CHAR_FOUND || source!=sourceLimit || target!=buffer) {
         log_err("error TestTruncated(%s, 2): input bytes[%d], flush=TRUE: %s (should be U_TRUNCATED_CHAR_FOUND), input left %d, output %d\n",
                 cnvName, length, u_errorName(errorCode), (int)(sourceLimit-source), (int)(target-buffer));
     }
@@ -1840,7 +1732,10 @@
         "BOCU-1",
         "CESU-8",
         "gb18030",
-        "IMAP-mailbox-name",
+        "IMAP-mailbox-name"
+    };
+
+    static const char *const lmbcsNames[]={
         "LMBCS-1",
         "LMBCS-2",
         "LMBCS-3",
@@ -1909,6 +1804,29 @@
                     name, u_errorName(errorCode));
         } else if(!uset_containsRange(set, 0, 0xd7ff) || !uset_containsRange(set, 0xe000, 0x10ffff)) {
             log_err("error: ucnv_getUnicodeSet(%s) does not return an all-Unicode set\n", name);
+        }
+
+        ucnv_close(cnv);
+    }
+
+    /* test LMBCS variants which convert all of Unicode except for U+F6xx */
+    for(i=0; i<LENGTHOF(lmbcsNames); ++i) {
+        errorCode=U_ZERO_ERROR;
+        name=lmbcsNames[i];
+        cnv=ucnv_open(name, &errorCode);
+        if(U_FAILURE(errorCode)) {
+            log_err("error: unable to open converter %s - %s\n",
+                    name, u_errorName(errorCode));
+            continue;
+        }
+
+        uset_clear(set);
+        ucnv_getUnicodeSet(cnv, set, UCNV_ROUNDTRIP_SET, &errorCode);
+        if(U_FAILURE(errorCode)) {
+            log_err("error: ucnv_getUnicodeSet(%s) failed - %s\n",
+                    name, u_errorName(errorCode));
+        } else if(!uset_containsRange(set, 0, 0xf5ff) || !uset_containsRange(set, 0xf700, 0x10ffff)) {
+            log_err("error: ucnv_getUnicodeSet(%s) does not return an all-Unicode set (minus U+F6xx)\n", name);
         }
 
         ucnv_close(cnv);

Index: nucnvtst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/nucnvtst.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- nucnvtst.c	10 Sep 2003 02:42:40 -0000	1.4
+++ nucnvtst.c	6 Apr 2004 10:09:31 -0000	1.5
@@ -23,7 +23,7 @@
 #include "unicode/ucol.h"
 #include "cmemory.h"
 
-static void TestNextUChar(UConverter* cnv, const char* source, const char* limit, const uint32_t results[], const char* message);
+static void TestNextUChar(UConverter* cnv, const char* source, const char* limit, const int32_t results[], const char* message);
 static void TestNextUCharError(UConverter* cnv, const char* source, const char* limit, UErrorCode expected, const char* message);
 #if !UCONFIG_NO_COLLATION
 static void TestJitterbug981(void);
@@ -47,7 +47,9 @@
 static void TestSBCS(void);
 static void TestDBCS(void);
 static void TestMBCS(void);
+#ifdef U_ENABLE_GENERIC_ISO_2022
 static void TestISO_2022(void);
+#endif
 static void TestISO_2022_JP(void);
 static void TestISO_2022_JP_1(void);
 static void TestISO_2022_JP_2(void);
@@ -92,7 +94,7 @@
 static UConverter *my_ucnv_open(const char *cnv, UErrorCode *err)
 {
   if(cnv && cnv[0] == '@') {
-    return ucnv_openPackage("testdata", cnv+1, err);
+    return ucnv_openPackage(loadTestData(err), cnv+1, err);
   } else {
     return ucnv_open(cnv, err);
   }
@@ -134,13 +136,13 @@
 }
 
 static void
-TestNextUChar(UConverter* cnv, const char* source, const char* limit, const uint32_t results[], const char* message)
+TestNextUChar(UConverter* cnv, const char* source, const char* limit, const int32_t results[], const char* message)
 {
      const char* s0;
      const char* s=(char*)source;
-     const uint32_t *r=results;
+     const int32_t *r=results;
      UErrorCode errorCode=U_ZERO_ERROR;
-     uint32_t c;
+     UChar32 c;
 
      while(s<limit) {
         s0=s;
@@ -150,7 +152,11 @@
         } else if(U_FAILURE(errorCode)) {
             log_err("%s ucnv_getNextUChar() failed: %s\n", message, u_errorName(errorCode));
             break;
-        } else if((uint32_t)(s-s0)!=*r || c!=*(r+1)) {
+        } else if(
+            /* test the expected number of input bytes only if >=0 */
+            (*r>=0 && (int32_t)(s-s0)!=*r) ||
+            c!=*(r+1)
+        ) {
             log_err("%s ucnv_getNextUChar() result %lx from %d bytes, should have been %lx from %d bytes.\n",
                 message, c, (s-s0), *(r+1), *r);
             break;
@@ -214,6 +220,8 @@
    addTest(root, &TestUTF7, "tsconv/nucnvtst/TestUTF7");
    addTest(root, &TestIMAP, "tsconv/nucnvtst/TestIMAP");
    addTest(root, &TestUTF8, "tsconv/nucnvtst/TestUTF8");
+
+   /* test ucnv_getNextUChar() for charsets that encode single surrogates with complete byte sequences */
    addTest(root, &TestCESU8, "tsconv/nucnvtst/TestCESU8");
    addTest(root, &TestUTF16, "tsconv/nucnvtst/TestUTF16");
    addTest(root, &TestUTF16BE, "tsconv/nucnvtst/TestUTF16BE");
@@ -221,11 +229,15 @@
    addTest(root, &TestUTF32, "tsconv/nucnvtst/TestUTF32");
    addTest(root, &TestUTF32BE, "tsconv/nucnvtst/TestUTF32BE");
    addTest(root, &TestUTF32LE, "tsconv/nucnvtst/TestUTF32LE");
+   addTest(root, &TestLMBCS, "tsconv/nucnvtst/TestLMBCS");
+
    addTest(root, &TestLATIN1, "tsconv/nucnvtst/TestLATIN1");
    addTest(root, &TestSBCS, "tsconv/nucnvtst/TestSBCS");
    addTest(root, &TestDBCS, "tsconv/nucnvtst/TestDBCS");
    addTest(root, &TestMBCS, "tsconv/nucnvtst/TestMBCS");
+#ifdef U_ENABLE_GENERIC_ISO_2022
    addTest(root, &TestISO_2022, "tsconv/nucnvtst/TestISO_2022");
+#endif
    addTest(root, &TestISO_2022_JP, "tsconv/nucnvtst/TestISO_2022_JP");
    addTest(root, &TestJIS, "tsconv/nucnvtst/TestJIS");
    addTest(root, &TestISO_2022_JP_1, "tsconv/nucnvtst/TestISO_2022_JP_1");
@@ -239,7 +251,6 @@
    addTest(root, &TestSCSU, "tsconv/nucnvtst/TestSCSU");
    addTest(root, &TestEBCDIC_STATEFUL, "tsconv/nucnvtst/TestEBCDIC_STATEFUL");
    addTest(root, &TestGB18030, "tsconv/nucnvtst/TestGB18030");
-   addTest(root, &TestLMBCS, "tsconv/nucnvtst/TestLMBCS");
    addTest(root, &TestJitterbug255, "tsconv/nucnvtst/TestJitterbug255");
    addTest(root, &TestEBCDICUS4XML, "tsconv/nucnvtst/TestEBCDICUS4XML");
    addTest(root, &TestISCII, "tsconv/nucnvtst/TestISCII");
@@ -614,6 +625,7 @@
     int32_t fmUTF8Offs[] =
      { 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0007, 0x000a, 0x000d };
 
+#ifdef U_ENABLE_GENERIC_ISO_2022
     /* Same as UTF8, but with ^[%B preceeding */
     const uint8_t expectedISO2022[] =
      { 0x1b, 0x25, 0x42, 0x31, 0x32, 0x33, 0x00, 0xe4, 0xb8, 0x80, 0xe4, 0xba, 0x8c, 0xe4, 0xb8, 0x89, 0x2E };
@@ -622,6 +634,7 @@
        0x04, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x07 }; /* right? */
     int32_t fmISO2022Offs[] =
      { 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x000a, 0x000d, 0x0010 }; /* is this right? */
+#endif
 
     /*  1 2 3 0, <SO> h1 h2 h3 <SI> . EBCDIC_STATEFUL */
     const uint8_t expectedIBM930[] =
@@ -763,9 +776,11 @@
 
 
     }
+#ifdef U_ENABLE_GENERIC_ISO_2022
     /*ISO-2022*/
     testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
         expectedISO2022, sizeof(expectedISO2022), "ISO_2022", toISO2022Offs,FALSE );
+#endif
     /*UTF16 LE*/
     testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
         expectedUTF16LE, sizeof(expectedUTF16LE), "utf-16le", toUTF16LEOffs,FALSE );
@@ -810,9 +825,11 @@
     /*UTF-8*/
     testConvertToU(expectedUTF8, sizeof(expectedUTF8),
         sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf8", fmUTF8Offs,FALSE);
+#ifdef U_ENABLE_GENERIC_ISO_2022
     /*ISO-2022*/
     testConvertToU(expectedISO2022, sizeof(expectedISO2022),
         sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "ISO_2022", fmISO2022Offs,FALSE);
+#endif
     /*UTF16 LE*/
     testConvertToU(expectedUTF16LE, sizeof(expectedUTF16LE),
         sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf-16le", fmUTF16LEOffs,FALSE);
@@ -1135,18 +1152,9 @@
         const uint8_t expectedtest1[] = { 0x00, 0x05, 0xff, 0x07, 0xff,};
         int32_t  totest1Offs[]        = { 0, 1, 2, 3, 5, };
 
-        const uint8_t test1input[]    = { 0x00, 0x05, 0x06, 0x07, 0x08, 0x09};
-        const UChar expectedUnicode[] = { 0x20ac, 0x0005, 0x0006, 0xdbc4, 0xde34, 0xfffd, 0xfffd};
-        int32_t fromtest1Offs[]       = { 0, 1, 2, 3, 3, 4, 5};
-
         /*from Unicode*/
         testConvertFromU(unicodeInput, sizeof(unicodeInput)/sizeof(unicodeInput[0]),
             expectedtest1, sizeof(expectedtest1), "@test1", totest1Offs,FALSE );
-
-        /*to Unicode*/
-        testConvertToU(test1input, sizeof(test1input),
-            expectedUnicode, sizeof(expectedUnicode)/sizeof(expectedUnicode[0]), "@test1", fromtest1Offs ,FALSE);
-
     }
 
     /*some more test to increase the code coverage in MBCS.  Create an test converter from test3.ucm
@@ -1296,7 +1304,9 @@
     TestConverterType("UTF-16LE", UCNV_UTF16_LittleEndian);
     TestConverterType("UTF-32BE", UCNV_UTF32_BigEndian);
     TestConverterType("UTF-32LE", UCNV_UTF32_LittleEndian);
+#ifdef U_ENABLE_GENERIC_ISO_2022
     TestConverterType("iso-2022", UCNV_ISO_2022);
+#endif
     TestConverterType("hz", UCNV_HZ);
     TestConverterType("scsu", UCNV_SCSU);
     TestConverterType("x-iscii-de", UCNV_ISCII);
@@ -1660,7 +1670,7 @@
     };
 
     /* expected test results */
-    static const uint32_t results[]={
+    static const int32_t results[]={
         /* number of bytes read, code point */
         1, 0x48,
         1, 0x2d,
@@ -1704,7 +1714,7 @@
     };
 
     /* expected test results */
-    static const uint32_t results[]={
+    static const int32_t results[]={
         /* number of bytes read, code point */
         1, 0x48,
         1, 0x2d,
@@ -1746,7 +1756,7 @@
     };
 
     /* expected test results */
-    static const uint32_t results[]={
+    static const int32_t results[]={
         /* number of bytes read, code point */
         1, 0x61,
         2, 0x80,
@@ -1770,7 +1780,7 @@
     };
 
     /* expected error test results */
-    static const uint32_t results2[]={
+    static const int32_t results2[]={
         /* number of bytes read, code point */
         1, 0x61,
         22, 0x62
@@ -1813,15 +1823,15 @@
     };
 
     /* expected test results */
-    static const uint32_t results[]={
+    static const int32_t results[]={
         /* number of bytes read, code point */
         1, 0x61,
         2, 0x80,
         3, 0x800,
         6, 0x10000,
         3, 0xdc01,
-        3, 0xd802,
-        6, 0x10ffff,
+        -1,0xd802,  /* may read 3 or 6 bytes */
+        -1,0x10ffff,/* may read 0 or 3 bytes */
         3, 0xfffc
     };
 
@@ -1842,7 +1852,7 @@
     };
 
     /* expected error test results */
-    static const uint32_t results2[]={
+    static const int32_t results2[]={
         /* number of bytes read, code point */
         1, 0x61,
         34, 0x62
@@ -1885,17 +1895,17 @@
     };
 
     /* expected test results */
-    static const uint32_t results1[]={
+    static const int32_t results1[]={
         /* number of bytes read, code point */
         4, 0x4e00,
         2, 0xfeff
     };
-    static const uint32_t results2[]={
+    static const int32_t results2[]={
         /* number of bytes read, code point */
         4, 0x004e,
         2, 0xfffe
     };
-    static const uint32_t results3[]={
+    static const int32_t results3[]={
         /* number of bytes read, code point */
         2, 0xfefe,
         2, 0x4e00,
@@ -1943,7 +1953,7 @@
     };
 
     /* expected test results */
-    static const uint32_t results[]={
+    static const int32_t results[]={
         /* number of bytes read, code point */
         2, 0x61,
         2, 0xc0,
@@ -1966,13 +1976,23 @@
     /*Test for the condition where there is an invalid character*/
     {
         static const uint8_t source2[]={0x61};
+        ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode);
         TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_TRUNCATED_CHAR_FOUND, "an invalid character");
     }
+#if 0
+    /*
+     * Test disabled because currently the UTF-16BE/LE converters are supposed
+     * to not set errors for unpaired surrogates.
+     * This may change with
+     * Jitterbug 1838 - forbid converting surrogate code points in UTF-16/32
+     */
+
     /*Test for the condition where there is a surrogate pair*/
     {
         const uint8_t source2[]={0xd8, 0x01};
         TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_TRUNCATED_CHAR_FOUND, "an truncated surrogate character");
     }
+#endif
     ucnv_close(cnv);
 }
 
@@ -1988,7 +2008,7 @@
     };
 
     /* expected test results */
-    static const uint32_t results[]={
+    static const int32_t results[]={
         /* number of bytes read, code point */
         2, 0x61,
         2, 0x31,
@@ -2010,13 +2030,23 @@
     /*Test for the condition where there is an invalid character*/
     {
         static const uint8_t source2[]={0x61};
+        ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode);
         TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_TRUNCATED_CHAR_FOUND, "an invalid character");
     }
+#if 0
+    /*
+     * Test disabled because currently the UTF-16BE/LE converters are supposed
+     * to not set errors for unpaired surrogates.
+     * This may change with
+     * Jitterbug 1838 - forbid converting surrogate code points in UTF-16/32
+     */
+
     /*Test for the condition where there is a surrogate character*/
     {
         static const uint8_t source2[]={0x01, 0xd8};
         TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_TRUNCATED_CHAR_FOUND, "an truncated surrogate character");
     }
+#endif
 
     ucnv_close(cnv);
 }
@@ -2035,22 +2065,22 @@
     };
 
     /* expected test results */
-    static const uint32_t results1[]={
+    static const int32_t results1[]={
         /* number of bytes read, code point */
         8, 0x100f00,
         4, 0xfeff
     };
-    static const uint32_t results2[]={
+    static const int32_t results2[]={
         /* number of bytes read, code point */
         8, 0x0f1000,
         4, 0xfffe
     };
-    static const uint32_t results3[]={
+    static const int32_t results3[]={
         /* number of bytes read, code point */
         4, 0xfefe,
         4, 0x100f00,
-        4, 0xd840,
-        4, 0xdc01
+        4, 0xfffd, /* unmatched surrogate */
+        4, 0xfffd  /* unmatched surrogate */
     };
 
     const char *source, *limit;
@@ -2085,22 +2115,24 @@
     /* test input */
     static const uint8_t in[]={
         0x00, 0x00, 0x00, 0x61,
+        0x00, 0x00, 0x30, 0x61,
         0x00, 0x00, 0xdc, 0x00,
         0x00, 0x00, 0xd8, 0x00,
         0x00, 0x00, 0xdf, 0xff,
-        0x00, 0x00, 0xff, 0xfd,
+        0x00, 0x00, 0xff, 0xfe,
         0x00, 0x10, 0xab, 0xcd,
         0x00, 0x10, 0xff, 0xff
     };
 
     /* expected test results */
-    static const uint32_t results[]={
+    static const int32_t results[]={
         /* number of bytes read, code point */
         4, 0x61,
-        4, 0xdc00,
-        4, 0xd800,
-        4, 0xdfff,
+        4, 0x3061,
+        4, 0xfffd,
+        4, 0xfffd,
         4, 0xfffd,
+        4, 0xfffe,
         4, 0x10abcd,
         4, 0x10ffff
     };
@@ -2117,7 +2149,7 @@
     };
 
     /* expected error test results */
-    static const uint32_t results2[]={
+    static const int32_t results2[]={
         /* number of bytes read, code point */
         4,  0x61,
         8,  0x62,
@@ -2154,22 +2186,24 @@
     /* test input */
     static const uint8_t in[]={
         0x61, 0x00, 0x00, 0x00,
+        0x61, 0x30, 0x00, 0x00,
         0x00, 0xdc, 0x00, 0x00,
         0x00, 0xd8, 0x00, 0x00,
         0xff, 0xdf, 0x00, 0x00,
-        0xfd, 0xff, 0x00, 0x00,
+        0xfe, 0xff, 0x00, 0x00,
         0xcd, 0xab, 0x10, 0x00,
         0xff, 0xff, 0x10, 0x00
     };
 
     /* expected test results */
-    static const uint32_t results[]={
+    static const int32_t results[]={
         /* number of bytes read, code point */
         4, 0x61,
-        4, 0xdc00,
-        4, 0xd800,
-        4, 0xdfff,
+        4, 0x3061,
+        4, 0xfffd,
+        4, 0xfffd,
         4, 0xfffd,
+        4, 0xfffe,
         4, 0x10abcd,
         4, 0x10ffff
     };
@@ -2186,7 +2220,7 @@
     };
 
     /* expected error test results */
-    static const uint32_t results2[]={
+    static const int32_t results2[]={
         /* number of bytes read, code point */
         4,  0x61,
         8,  0x62,
@@ -2231,7 +2265,7 @@
     };
 
     /* expected test results */
-    static const uint32_t results[]={
+    static const int32_t results[]={
         /* number of bytes read, code point */
         1, 0x61,
         1, 0x31,
@@ -2351,7 +2385,7 @@
     /* test input */
     static const uint8_t in[]={ 0x61, 0xc0, 0x80, 0xe0, 0xf0, 0xf4};
     /* expected test results */
-    static const uint32_t results[]={
+    static const int32_t results[]={
         /* number of bytes read, code point */
         1, 0x61,
         1, 0xbf,
@@ -2363,12 +2397,12 @@
 
     const char *source=(const char *)in, *limit=(const char *)in+sizeof(in);
     UErrorCode errorCode=U_ZERO_ERROR;
-    UConverter *cnv=ucnv_open("ibm-1281", &errorCode);
+    UConverter *cnv=ucnv_open("x-mac-turkish", &errorCode);
     if(U_FAILURE(errorCode)) {
-        log_data_err("Unable to open a SBCS(ibm-1281) converter: %s\n", u_errorName(errorCode));
+        log_data_err("Unable to open a SBCS(x-mac-turkish) converter: %s\n", u_errorName(errorCode));
         return;
     }
-    TestNextUChar(cnv, source, limit, results, "SBCS(ibm-1281)");
+    TestNextUChar(cnv, source, limit, results, "SBCS(x-mac-turkish)");
     /* Test the condition when source >= sourceLimit */
     TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source");
     /*Test for Illegal character */ /*
@@ -2394,7 +2428,7 @@
     };
 
     /* expected test results */
-    static const uint32_t results[]={
+    static const int32_t results[]={
         /* number of bytes read, code point */
         2, 0x00a7,
         2, 0xe1d2,
@@ -2414,16 +2448,17 @@
     TestNextUChar(cnv, source, limit, results, "DBCS(@ibm9027)");
     /* Test the condition when source >= sourceLimit */
     TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source");
-    /*Test for the condition where we have a truncated char*/
-    {
-        static const uint8_t source1[]={0xc4};
-        TestNextUCharError(cnv, (const char*)source1, (const char*)source1+sizeof(source1), U_TRUNCATED_CHAR_FOUND, "a character is truncated");
-    }
     /*Test for the condition where there is an invalid character*/
     {
         static const uint8_t source2[]={0x1a, 0x1b};
         TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_ZERO_ERROR, "an invalid character");
     }
+    /*Test for the condition where we have a truncated char*/
+    {
+        static const uint8_t source1[]={0xc4};
+        ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode);
+        TestNextUCharError(cnv, (const char*)source1, (const char*)source1+sizeof(source1), U_TRUNCATED_CHAR_FOUND, "a character is truncated");
+    }
     ucnv_close(cnv);
 }
 
@@ -2442,7 +2477,7 @@
     };
 
     /* expected test results */
-    static const uint32_t results[]={
+    static const int32_t results[]={
         /* number of bytes read, code point */
         1, 0x0001,
         2, 0x250c,
@@ -2464,25 +2499,29 @@
     TestNextUChar(cnv, source, limit, results, "MBCS(ibm-1363)");
     /* Test the condition when source >= sourceLimit */
     TestNextUCharError(cnv, source, source, U_INDEX_OUTOFBOUNDS_ERROR, "sourceLimit <= source");
-    /*Test for the condition where we have a truncated char*/
-    {
-        static const uint8_t source1[]={0xc4};
-        TestNextUCharError(cnv, (const char*)source1, (const char*)source1+sizeof(source1), U_TRUNCATED_CHAR_FOUND, "a character is truncated");
-    }
     /*Test for the condition where there is an invalid character*/
     {
         static const uint8_t source2[]={0xa1, 0x01};
         TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_ZERO_ERROR, "an invalid character");
     }
+    /*Test for the condition where we have a truncated char*/
+    {
+        static const uint8_t source1[]={0xc4};
+        ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode);
+        TestNextUCharError(cnv, (const char*)source1, (const char*)source1+sizeof(source1), U_TRUNCATED_CHAR_FOUND, "a character is truncated");
+    }
     ucnv_close(cnv);
 
 }
 
+#ifdef U_ENABLE_GENERIC_ISO_2022
+
 static void
 TestISO_2022() {
     /* test input */
     static const uint8_t in[]={
-        0x1b, 0x25, 0x42, 0x31,
+        0x1b, 0x25, 0x42,
+        0x31,
         0x32,
         0x61,
         0xc2, 0x80,
@@ -2493,15 +2532,14 @@
 
 
     /* expected test results */
-    static const uint32_t results[]={
+    static const int32_t results[]={
         /* number of bytes read, code point */
-        4, 0x0031,
+        4, 0x0031,  /* 4 bytes including the escape sequence */
         1, 0x0032,
         1, 0x61,
         2, 0x80,
         3, 0x800,
-        4, 0x10000,
-
+        4, 0x10000
     };
 
     const char *source=(const char *)in, *limit=(const char *)in+sizeof(in);
@@ -2521,16 +2559,19 @@
     /*Test for the condition where we have a truncated char*/
     {
         static const uint8_t source1[]={0xc4};
+        ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode);
         TestNextUCharError(cnv, (const char*)source1, (const char*)source1+sizeof(source1), U_TRUNCATED_CHAR_FOUND, "a character is truncated");
     }
     /*Test for the condition where there is an invalid character*/
     {
         static const uint8_t source2[]={0xa1, 0x01};
-        TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_ZERO_ERROR, "an invalid character");
+        TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_ILLEGAL_CHAR_FOUND, "an invalid character");
     }
     ucnv_close(cnv);
 }
 
+#endif
+
 static void
 TestSmallTargetBuffer(const uint16_t* source, const UChar* sourceLimit,UConverter* cnv){
     const UChar* uSource;
@@ -3078,7 +3119,7 @@
     int32_t* myOff= offsets;
     cnv=ucnv_open("ISO_2022_JP_1", &errorCode);
     if(U_FAILURE(errorCode)) {
-        log_data_err("Unable to open a iso-2022 converter: %s\n", u_errorName(errorCode));
+        log_data_err("Unable to open an ISO_2022_JP_1 converter: %s\n", u_errorName(errorCode));
         return;
     }
 
@@ -3816,6 +3857,7 @@
     ucnv_reset(cnv);
     {
         static const uint8_t source2[]={0x1b,0x24,0x053};
+        ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode);
         TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_ILLEGAL_ESCAPE_SEQUENCE, "an invalid character [ISO-2022-KR]");
     }
     ucnv_close(cnv);
@@ -3895,6 +3937,7 @@
     ucnv_reset(cnv);
     {
         static const uint8_t source2[]={0x1b,0x24,0x053};
+        ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode);
         TestNextUCharError(cnv, (const char*)source2, (const char*)source2+sizeof(source2), U_ILLEGAL_ESCAPE_SEQUENCE, "an invalid character [ISO-2022-KR]");
     }
     ucnv_close(cnv);
@@ -3942,98 +3985,7 @@
 
 static void
 TestJIS(){
-    /* From Unicode */
-    {
-        /* JIS Encoding */
-        UChar sampleTextJIS[] ={
-            0xFF81, 0xFF82,
-            0x30EC, 0x30ED,
-            0x30EE, 0x30EF,
-            0xFF93, 0xFF94,
-            0xFF95, 0xFF96,
-            0xFF97, 0xFF98
-        };
-        const uint8_t expectedISO2022JIS[] ={
-                0x1b, 0x24, 0x42,
-                0x25, 0x41, 0x25, 0x44,
-                0x25, 0x6c, 0x25, 0x6d,
-                0x25, 0x6e, 0x25, 0x6F,
-                0x25, 0x62, 0x25, 0x64,
-                0x25, 0x66, 0x25, 0x68,
-                0x25, 0x69, 0x25, 0x6a
-
-        };
-        int32_t fmISO2022JISOffs[] ={
-            0,0,0,
-            0,0,1,1,
-            2,2,3,3,
-            4,4,5,5,
-            6,6,7,7,
-            8,8,9,9,
-            10,10,11,11
-
-        };
-
-        /* JIS7 Encoding */
-        const uint8_t expectedISO2022JIS7[] ={
-                0x1b, 0x28, 0x49,
-                0x41, 0x42,
-                0x1b, 0x24, 0x42,
-                0x25, 0x6c, 0x25, 0x6d,
-                0x25, 0x6e, 0x25, 0x6F,
-                0x1b, 0x28, 0x49,
-                0x53, 0x54,
-                0x55, 0x56,
-                0x57, 0x58
-
-        };
-        int32_t fmISO2022JIS7Offs[] ={
-            0,0,0,
-            0,1,
-            2,2,2,
-            2,2,3,3,
-            4,4,5,5,
-            6,6,6,
-            6,7,
-            8,9,
-            10,11
-
-        };
-
-        /* JIS8 Encoding */
-        const uint8_t expectedISO2022JIS8[] ={
-                0x1b, 0x28, 0x4A,
-                0xC1, 0xC2,
-                0x1b, 0x24, 0x42,
-                0x25, 0x6c, 0x25, 0x6d,
-                0x25, 0x6e, 0x25, 0x6F,
-                0x1b, 0x28, 0x4A,
-                0xD3, 0xD4,
-                0xD5, 0xD6,
-                0xD7, 0xD8
-
-        };
-        int32_t fmISO2022JIS8Offs[] ={
-            0,0,0,
-            0,1,
-            2,2,2,
-            2,2,3,3,
-            4,4,5,5,
-            6,6,6,
-            6,7,
-            8,9,
-            10,11
-
-        };
-        testConvertFromU(sampleTextJIS, sizeof(sampleTextJIS)/sizeof(sampleTextJIS[0]),
-            expectedISO2022JIS, sizeof(expectedISO2022JIS), "JIS", fmISO2022JISOffs,TRUE );
-        testConvertFromU(sampleTextJIS, sizeof(sampleTextJIS)/sizeof(sampleTextJIS[0]),
-            expectedISO2022JIS7, sizeof(expectedISO2022JIS7), "JIS7", fmISO2022JIS7Offs,FALSE );
-        testConvertFromU(sampleTextJIS, sizeof(sampleTextJIS)/sizeof(sampleTextJIS[0]),
-            expectedISO2022JIS8, sizeof(expectedISO2022JIS8), "JIS8", fmISO2022JIS8Offs,FALSE );
-
-
-    }
+    /* From Unicode moved to testdata/conversion.txt */
     /*To Unicode*/
     {
         const uint8_t sampleTextJIS[] = {
@@ -4123,28 +4075,28 @@
         0x70, 0x6C, 0x61, 0x6E, 0x65, 0x20, 0x31, 0x20, 0x2A, 0x2F,
         0x0D, 0x0A, 0x1B, 0x24, 0x2A, 0x48, 0x1B, 0x4E, 0x22, 0x21,
         0x1B, 0x4E, 0x22, 0x22, 0x1B, 0x4E, 0x22, 0x23, 0x1B, 0x4E,
-        0x22, 0x24, 0x1B, 0x4E, 0x22, 0x25, 0x0F, 0x2F, 0x2A, 0x70,
+        0x22, 0x24, 0x1B, 0x4E, 0x22, 0x25, 0x2F, 0x2A, 0x70,
         0x6C, 0x61, 0x6E, 0x65, 0x32, 0x2A, 0x2F, 0x20, 0x0D, 0x0A,
         0x1B, 0x24, 0x2B, 0x49, 0x1B, 0x4F, 0x22, 0x44, 0x1B, 0x4F,
         0x22, 0x45, 0x1B, 0x4F, 0x22, 0x46, 0x1B, 0x4F, 0x22, 0x47,
-        0x1B, 0x4F, 0x22, 0x48, 0x0F, 0x2F, 0x2A, 0x70, 0x6C, 0x61,
+        0x1B, 0x4F, 0x22, 0x48, 0x2F, 0x2A, 0x70, 0x6C, 0x61,
         0x6E, 0x65, 0x20, 0x33, 0x20, 0x2A, 0x2F, 0x0D, 0x0A, 0x1B,
         0x24, 0x2B, 0x4A, 0x1B, 0x4F, 0x21, 0x44, 0x1B, 0x4F, 0x21,
         0x45, 0x1B, 0x4F, 0x22, 0x6A, 0x1B, 0x4F, 0x22, 0x6B, 0x1B,
-        0x4F, 0x22, 0x6C, 0x0F, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 0x6E,
+        0x4F, 0x22, 0x6C, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 0x6E,
         0x65, 0x20, 0x34, 0x20, 0x2A, 0x2F, 0x0D, 0x0A, 0x1B, 0x24,
         0x2B, 0x4B, 0x1B, 0x4F, 0x21, 0x74, 0x1B, 0x4F, 0x22, 0x50,
         0x1B, 0x4F, 0x22, 0x51, 0x1B, 0x4F, 0x23, 0x37, 0x1B, 0x4F,
-        0x22, 0x5C, 0x0F, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 0x6E,
+        0x22, 0x5C, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 0x6E,
         0x65, 0x20, 0x35, 0x20, 0x2A, 0x2F, 0x0D, 0x0A, 0x1B, 0x24,
         0x2B, 0x4C, 0x1B, 0x4F, 0x21, 0x23, 0x1B, 0x4F, 0x22, 0x2C,
         0x1B, 0x4F, 0x23, 0x4E, 0x1B, 0x4F, 0x21, 0x6E, 0x1B, 0x4F,
-        0x23, 0x71, 0x0F, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 0x6E, 0x65,
+        0x23, 0x71, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 0x6E, 0x65,
         0x20, 0x36, 0x20, 0x2A, 0x2F, 0x0D, 0x0A, 0x1B, 0x24, 0x2B,
         0x4D, 0x1B, 0x4F, 0x22, 0x71, 0x1B, 0x4F, 0x21, 0x4E, 0x1B,
         0x4F, 0x21, 0x6A, 0x1B, 0x4F, 0x23, 0x3A, 0x1B, 0x4F, 0x23,
-        0x6F, 0x0F, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 0x6E, 0x65, 0x20,
-        0x37, 0x20, 0x2A, 0x2F,
+        0x6F, 0x2F, 0x2A, 0x70, 0x6C, 0x61, 0x6E, 0x65, 0x20,
+        0x37, 0x20, 0x2A, 0x2F
     };
     UChar uTarget[500]={'\0'};
     UChar* utarget=uTarget;
@@ -4177,9 +4129,11 @@
     ctargetLimit=ctarget;
     ctarget =cTarget;
     while(ctarget<ctargetLimit){
-        if(*(ctarget++) != *(tempSrc++)){
-            log_err("Expected : \\x%02X \t Got: \\x%02X\n",*ctarget,(int)*tempSrc) ;
+        if(*ctarget != *tempSrc){
+            log_err("j915[%d] Expected : \\x%02X \t Got: \\x%02X\n", (int)(ctarget-cTarget), *ctarget,(int)*tempSrc) ;
         }
+        ++ctarget;
+        ++tempSrc;
     }
 
     ucnv_close(conv);
@@ -4407,7 +4361,7 @@
     };
 
     /* expected test results */
-    static const uint32_t results[]={
+    static const int32_t results[]={
         /* number of bytes read, code point */
         1, 0x002f,
         1, 0x0092,
@@ -4424,7 +4378,7 @@
     };
 
     /* expected test results */
-    static const uint32_t results2[]={
+    static const int32_t results2[]={
         /* number of bytes read, code point */
         2, 0x203E,
         1, 0x0001,
@@ -4488,7 +4442,7 @@
     };
 
     /* expected test results */
-    static const uint32_t results[]={
+    static const int32_t results[]={
         /* number of bytes read, code point */
         1, 0x24,
         1, 0x7f,
@@ -4942,7 +4896,7 @@
          }
          /*0 byte source request - GetNextUChar : error & value == fffe or ffff */
          uniChar = ucnv_getNextUChar(cnv, (const char **)&pLIn, (const char *)pLIn, &errorCode);
-         if (errorCode != U_ILLEGAL_ARGUMENT_ERROR)
+         if (errorCode != U_INDEX_OUTOFBOUNDS_ERROR)
          {
             log_err("Unexpected Error on 0-byte source request to ucnv_getnextUChar: %s\n", u_errorName(errorCode));
          }
@@ -4982,6 +4936,7 @@
          errorCode = U_ZERO_ERROR;
          pUOut = UOut;
 
+         ucnv_setToUCallBack(cnv, UCNV_TO_U_CALLBACK_STOP, NULL, NULL, NULL, &errorCode);
          ucnv_toUnicode(cnv, &pUOut,pUOut+sizeof(UOut)/sizeof(UChar),(const char **)&pLIn,(const char *)(pLIn+5),off,TRUE, &errorCode);
          if (UOut[0] != 0xD801 || errorCode != U_TRUNCATED_CHAR_FOUND || pUOut != UOut + 1 || pLIn != LIn + 5)
          {

Index: stdnmtst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/stdnmtst.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- stdnmtst.c	10 Sep 2003 02:42:40 -0000	1.4
+++ stdnmtst.c	6 Apr 2004 10:09:33 -0000	1.5
@@ -30,9 +30,9 @@
 void
 addStandardNamesTest(TestNode** root)
 {
-  addTest(root, &TestStandardName,  "stdnmtst/TestStandardName");
-  addTest(root, &TestStandardNames, "stdnmtst/TestStandardNames");
-  addTest(root, &TestCanonicalName, "stdnmtst/TestCanonicalName");
+  addTest(root, &TestStandardName,  "tsconv/stdnmtst/TestStandardName");
+  addTest(root, &TestStandardNames, "tsconv/stdnmtst/TestStandardNames");
+  addTest(root, &TestCanonicalName, "tsconv/stdnmtst/TestCanonicalName");
 }
 
 static int dotestname(const char *name, const char *standard, const char *expected) {
@@ -99,8 +99,8 @@
     if (dotestname("ibm-1208", "MIME", "UTF-8") &&
         /*dotestname("cp1252", "MIME", "windows-1252") &&*/
         dotestname("ascii", "MIME", "US-ASCII") &&
-        dotestname("ISO_2022", "MIME", "ISO-2022") &&
-        dotestname("ISO-2022", "MIME", "ISO-2022") &&
+        dotestname("csiso2022jp2", "MIME", "ISO-2022-JP-2") &&
+        dotestname("Iso20-22__cN", "MIME", "ISO-2022-CN") &&
         dotestname("ascii", "IANA", "ANSI_X3.4-1968") &&
         dotestname("cp850", "IANA", "IBM850") &&
         dotestname("crazy", "MIME", NULL) &&
@@ -147,7 +147,7 @@
         dotestconv("ibm-5305", "IANA", NULL) &&     /* mapping does not exist */
         dotestconv("cp1208", "", "UTF-8") &&        /* default name due to ordering */
         dotestconv("UTF16_BigEndian", "", "UTF-16BE") &&        /* non-default name due to ordering */
-        dotestconv("ISO-2022", "MIME", "ISO_2022") &&/* default name */
+        dotestconv("ISO-2022-CN", "MIME", "ISO_2022,locale=zh,version=0") &&/* default name */
         dotestconv("Shift_JIS", "MIME", "ibm-943_P14A-1999") &&/* ambiguous alias */
         dotestconv("Shift_JIS", "", "ibm-943_P130-1999") &&/* ambiguous alias */
         dotestconv("ibm-943", "", "ibm-943_P14A-1999") &&/* ambiguous alias */
@@ -262,7 +262,7 @@
     };
 
     static const char *iso2022MIME[] = {
-        "ISO-2022",
+        "ISO-2022-KR",
     };
 
     doTestNames("ASCII", "IANA", asciiIANA, ARRAY_SIZE(asciiIANA));
@@ -275,8 +275,8 @@
 
     doTestNames("LMBCS-1", "MIME", asciiMIME, 0);
 
-    doTestNames("ISO_2022", "MIME", iso2022MIME, ARRAY_SIZE(iso2022MIME));
-    doTestNames("ISO-2022", "MIME", iso2022MIME, ARRAY_SIZE(iso2022MIME));
+    doTestNames("ISO_2022,locale=ko,version=0", "MIME", iso2022MIME, ARRAY_SIZE(iso2022MIME));
+    doTestNames("csiso2022kr", "MIME", iso2022MIME, ARRAY_SIZE(iso2022MIME));
 
     log_verbose(" Testing unext()\n");
     doTestUCharNames("ASCII", "IANA", asciiIANA, ARRAY_SIZE(asciiIANA));

Index: trietest.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/trietest.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- trietest.c	10 Sep 2003 02:42:40 -0000	1.1
+++ trietest.c	6 Apr 2004 10:09:33 -0000	1.2
@@ -1,7 +1,7 @@
 /*
 ******************************************************************************
 *
-*   Copyright (C) 2001, International Business Machines
+*   Copyright (C) 2001-2003, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 ******************************************************************************
@@ -273,7 +273,9 @@
     storage = (uint8_t*) uprv_malloc(sizeof(uint8_t)*100000);
 
     log_verbose("\ntesting Trie '%s'\n", testName);
-    newTrie=utrie_open(NULL, NULL, 2000, checkRanges[0].value, latin1Linear);
+    newTrie=utrie_open(NULL, NULL, 2000,
+                       checkRanges[0].value, checkRanges[0].value,
+                       latin1Linear);
 
     /* set values from setRanges[] */
     ok=TRUE;
@@ -457,7 +459,9 @@
     UBool overwrite, ok;
 
     log_verbose("\ntesting Trie '%s'\n", testName);
-    newTrie=utrie_open(NULL, NULL, 2000, checkRanges[0].value, latin1Linear);
+    newTrie=utrie_open(NULL, NULL, 2000,
+                       checkRanges[0].value, checkRanges[0].value,
+                       latin1Linear);
 
     /* set values from setRanges[] */
     ok=TRUE;
@@ -682,11 +686,11 @@
     {0x20,   0xa7,       0x1234, FALSE},
     {0xa7,   0x3400,     0,      FALSE},
     {0x3400, 0x9fa6,     0x6162, FALSE},
-    {0x9fa6, 0xdada,     0x3132, FALSE},
-    {0xdada, 0xeeee,     0x27,   FALSE},
+    {0x9fa6, 0xda9e,     0x3132, FALSE},
+    {0xdada, 0xeeee,     0x87ff, FALSE}, /* try to disrupt _testFoldingOffset16() */
     {0xeeee, 0x11111,    1,      FALSE},
     {0x11111, 0x44444,   0x6162, FALSE},
-    {0x44444, 0xf0003,   0,      FALSE},
+    {0x44444, 0x60003,   0,      FALSE},
     {0xf0003, 0xf0004,   0xf,    FALSE},
     {0xf0004, 0xf0006,   0x10,   FALSE},
     {0xf0006, 0xf0007,   0x11,   FALSE},
@@ -701,8 +705,9 @@
     {0xa7,   0x1234},
     {0x3400, 0},
     {0x9fa6, 0x6162},
-    {0xdada, 0x3132},
-    {0xeeee, 0x27},
+    {0xda9e, 0x3132},
+    {0xdada, 0},
+    {0xeeee, 0x87ff},
     {0x11111,1},
     {0x44444,0x6162},
     {0xf0003,0},
@@ -782,7 +787,7 @@
 
 void
 addTrieTest(TestNode** root) {
-    addTest(root, &TrieTest, "tsutil/TrieTest");
+    addTest(root, &TrieTest, "tsutil/trietest/TrieTest");
 }
 #else
 /* standalone utrie development */

Index: udatatst.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/udatatst.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- udatatst.c	10 Sep 2003 02:42:40 -0000	1.5
+++ udatatst.c	6 Apr 2004 10:09:34 -0000	1.6
@@ -22,6 +22,7 @@
 #include "cmemory.h"
 #include "cstring.h"
 #include "filestrm.h"
+#include "udatamem.h"
 #include "cintltst.h"
 
 #include <sys/types.h>
@@ -36,6 +37,24 @@
 #include <unistd.h>
 #endif
 
+/* includes for TestSwapData() */
+#include "udataswp.h"
+
+/* swapping implementations in common */
+#include "uresdata.h"
+#include "ucnv_io.h"
+#include "uprops.h"
+#include "ucol_swp.h"
+#include "ucnv_bld.h"
+#include "unormimp.h"
+#include "sprpimpl.h"
+#include "propname.h"
+#include "rbbidata.h"
+
+/* other definitions and prototypes */
+
+#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
+
 static void TestUDataOpen(void);
 static void TestUDataOpenChoiceDemo1(void);
 static void TestUDataOpenChoiceDemo2(void);
@@ -45,6 +64,7 @@
 static void TestErrorConditions(void);
 static void TestAppData(void);
 static void TestICUDataName(void);
+static void TestSwapData(void);
 
 void addUDataTest(TestNode** root);
 
@@ -60,7 +80,7 @@
     addTest(root, &TestErrorConditions, "udatatst/TestErrorConditions");
     addTest(root, &TestAppData, "udatatst/TestAppData" );
     addTest(root, &TestICUDataName, "udatatst/TestICUDataName" );
-
+    addTest(root, &TestSwapData, "udatatst/TestSwapData" );
 }
 
 #if 0
@@ -80,14 +100,17 @@
     UDataMemory *result;
     UErrorCode status=U_ZERO_ERROR;
     const char* memMap[][2]={
-        {"tz", "icu"},
+        {"root", "res"},
+        {"unorm", "icu"},
         {"cnvalias", "icu"},
         {"unames",   "icu"},
         {"ibm-37_P100-1995",   "cnv"}
     };
-    const char* name           = "test";
-    const char* type           = "icu";
-    const char  dirSepString[] = {U_FILE_SEP_CHAR, 0};
+    const char* name            = "test";
+    const char* type            = "icu";
+    const char  dirSepString[]  = {U_FILE_SEP_CHAR, 0};
+    const char  pathSepString[] = {U_PATH_SEP_CHAR, 0};
+
 
     char* path=(char*)malloc(sizeof(char) * (strlen(ctest_dataOutDir())
                                            + strlen(U_ICUDATA_NAME)
@@ -125,11 +148,11 @@
         int i;
         log_verbose("Testing udata_open() on %s\n", icuDataFilePath);
         for(i=0; i<sizeof(memMap)/sizeof(memMap[0]); i++){
-    /* lots_of_mallocs(); */
+            /* lots_of_mallocs(); */
             status=U_ZERO_ERROR;
             result=udata_open(path, memMap[i][1], memMap[i][0], &status);
             if(U_FAILURE(status)) {
-                log_err("FAIL: udata_open() failed for path = %s, name=%s, type=%s, \n errorcode=%s\n", path, memMap[i][0], memMap[i][1], myErrorName(status));
+                log_data_err("FAIL: udata_open() failed for path = %s, name=%s, type=%s, \n errorcode=%s\n", path, memMap[i][0], memMap[i][1], myErrorName(status));
             } else {
                 log_verbose("PASS: udata_open worked for path = %s, name=%s, type=%s\n",  path, memMap[i][0], memMap[i][1]);
                 udata_close(result);
@@ -161,10 +184,10 @@
     strcat(icuDataFilePath, dirSepString);
     strcat(icuDataFilePath, U_ICUDATA_NAME);
     strcat(icuDataFilePath, "_");
-    strcat(icuDataFilePath, "tz.icu");
+    strcat(icuDataFilePath, "unorm.icu");
 
     /* lots_of_mallocs(); */
-    if (stat(icuDataFilePath, &stat_buf) == 0)
+/*    if (stat(icuDataFilePath, &stat_buf) == 0)*/
     {
         int i;
         log_verbose("%s exists, so..\n", icuDataFilePath);
@@ -177,18 +200,18 @@
             status=U_ZERO_ERROR;
             result=udata_open(icuDataFilePath, memMap[i][1], memMap[i][0], &status);
             if(U_FAILURE(status)) {
-                log_err("FAIL: udata_open() failed for path = %s, name=%s, type=%s, \n errorcode=%s\n", icuDataFilePath, memMap[i][0], memMap[i][1], myErrorName(status));
+                log_data_err("FAIL: udata_open() failed for path = %s, name=%s, type=%s, \n errorcode=%s\n", icuDataFilePath, memMap[i][0], memMap[i][1], myErrorName(status));
             } else {
                 log_verbose("PASS: udata_open worked for path = %s, name=%s, type=%s\n",  icuDataFilePath, memMap[i][0], memMap[i][1]);
                 udata_close(result);
             }
         }
     }
-    else
+/*    else
     {
          log_verbose("Skipping tests of udata_open() on %s.  File not present in this configuration.\n",
              icuDataFilePath);
-    }
+    }*/
 
     free(icuDataFilePath);
     icuDataFilePath = NULL;
@@ -252,6 +275,54 @@
         log_verbose("calling udat_open with non-existing file returned null as expected\n");
     }
 
+    /*
+     *  Try opening data with absurdly long path and name, to trigger buffer size 
+     *   overflow handling code.
+     */
+    {
+        char longTestPath[1024];    /* Implementation goes to heap at length of 128.  */
+        char longName[1024];
+
+        /* Try a very long nonexistent directory path.  
+         * udata_open should still succeed.  Opening with the path will fail,
+         * then fall back to skipping the directory portion of the path.
+         */
+        log_verbose("Testing udata_open() with really long names\n");
+        longTestPath[0] = 0;
+        strcat(longTestPath, "bogus_directory_name");
+        while (strlen(longTestPath) < 500) {
+            strcat(longTestPath, dirSepString);
+            strcat(longTestPath, "bogus_directory_name");
+        }
+        strcat(longTestPath, pathSepString);
+        strcat(longTestPath, testPath);
+        result=udata_open(longTestPath, type, name, &status);
+        if(U_FAILURE(status)){
+            log_err("FAIL: udata_open() failed for path = %s\n name=%s, type=%s, \n errorcode=%s\n",
+                longTestPath, name, type, myErrorName(status));
+        } else {
+            log_verbose("PASS: udata_open worked\n");
+            udata_close(result);
+        }
+
+        /* Try a very long name.  Won't open, but shouldn't blow up.
+         */
+        longName[0] = 0;
+        while (strlen(longName) < 500) {
+            strcat(longName, name);
+            strcat(longName, "_");
+        }
+        strcat(longName, dirSepString);
+        strcat(longName, name);
+
+        result=udata_open(longTestPath, type, longName, &status);
+        if (status != U_FILE_ACCESS_ERROR) {
+            log_err("FAIL: udata_open() failed for path = %s\n name=%s, type=%s, \n errorcode=%s\n",
+                longTestPath, longName, type, myErrorName(status));
+        }
+        udata_close(result);
+    }
+
     free(path);
 }
 
@@ -944,4 +1015,315 @@
     }
 #endif
 
+}
+
+/* test data swapping ------------------------------------------------------- */
+
+/* test cases for maximum data swapping code coverage */
+static const struct {
+    const char *name, *type;
+    UDataSwapFn *swapFn;
+} swapCases[]={
+    /* resource bundles */
+
+    /* resource bundle with many data types */
+    {"*testtypes",               "res", ures_swap},
+    /* resource bundle with collation data */
+    {"ja",                       "res", ures_swap},
+    /* resource bundle with options-only collation data */
+    {"ru",                       "res", ures_swap},
+    {"el",                       "res", ures_swap},
+    /* ICU's root */
+    {"root",                     "res", ures_swap},
+
+    /* ICU 2.6 resource bundle - data format 1.0, without indexes[] (little-endian ASCII) */
+    {"*icu26_testtypes",         "res", ures_swap},
+    /* same for big-endian EBCDIC */
+    {"*icu26e_testtypes",        "res", ures_swap},
+
+#if !UCONFIG_NO_COLLATION
+    /* standalone collation data files */
+    {"ucadata",                  "icu", ucol_swap},
+    {"invuca",                   "icu", ucol_swapInverseUCA},
+#endif
+
+#if !UCONFIG_NO_LEGACY_CONVERSION
+    /* conversion table files */
+
+    /* SBCS conversion table file without extension */
+    {"ibm-913_P100-2000",        "cnv", ucnv_swap},
+    /* EBCDIC_STATEFUL conversion table file with extension */
+    {"ibm-1390_P110-2003",       "cnv", ucnv_swap},
+    /* DBCS extension-only conversion table file */
+    {"ibm-16684_P110-2003",      "cnv", ucnv_swap},
+    /* EUC-TW (3-byte) conversion table file without extension */
+    {"ibm-964_P110-1999",        "cnv", ucnv_swap},
+    /* GB 18030 (4-byte) conversion table file without extension */
+    {"gb18030",                  "cnv", ucnv_swap},
+    /* MBCS conversion table file with extension */
+    {"*test4x",                  "cnv", ucnv_swap},
+
+    /* alias table */
+    {"cnvalias",                 "icu", ucnv_swapAliases},
+#endif
+
+#if !UCONFIG_NO_IDNA
+    {"uidna",                    "spp", usprep_swap},
+#endif
+
+#if !UCONFIG_NO_BREAK_ITERATION
+    {"char",                     "brk", ubrk_swap},
+#endif
+
+    /* the last item should not be #if'ed so that it can reliably omit the last comma */
+
+    /* Unicode properties */
+    {"unames",                   "icu", uchar_swapNames},
+    {"pnames",                   "icu", upname_swap},
+#if !UCONFIG_NO_NORMALIZATION
+    {"unorm",                    "icu", unorm_swap},
+#endif
+    {"uprops",                   "icu", uprops_swap}
+};
+
+#define SWAP_BUFFER_SIZE 1000000
+
+static void U_CALLCONV
+printError(void *context, const char *fmt, va_list args) {
+    vlog_info("[swap] ", fmt, args);
+}
+
+static void
+TestSwapCase(UDataMemory *pData, const char *name,
+             UDataSwapFn *swapFn,
+             uint8_t *buffer, uint8_t *buffer2) {
+    UDataSwapper *ds;
+    const void *inData, *inHeader;
+    int32_t length, dataLength, length2, headerLength;
+
+    UErrorCode errorCode;
+
+    UBool inEndian, oppositeEndian;
+    uint8_t inCharset, oppositeCharset;
+
+    inData=udata_getMemory(pData);
+
+    /*
+     * get the data length if possible, to verify that swapping and preflighting
+     * handles the entire data
+     */
+    dataLength=udata_getLength(pData);
+
+    /*
+     * get the header and its length
+     * all of the swap implementation functions require the header to be included
+     */
+    inHeader=udata_getRawMemory(pData);
+    headerLength=(int32_t)((const char *)inData-(const char *)inHeader);
+
+    /* first swap to opposite endianness but same charset family */
+    errorCode=U_ZERO_ERROR;
+    ds=udata_openSwapperForInputData(inHeader, headerLength,
+            !U_IS_BIG_ENDIAN, U_CHARSET_FAMILY, &errorCode);
+    if(U_FAILURE(errorCode)) {
+        log_err("udata_openSwapperForInputData(%s->!isBig+same charset) failed - %s\n",
+                name, u_errorName(errorCode));
+        return;
+    }
+
+    inEndian=ds->inIsBigEndian;
+    inCharset=ds->inCharset;
+
+    oppositeEndian=!inEndian;
+    oppositeCharset= inCharset==U_ASCII_FAMILY ? U_EBCDIC_FAMILY : U_ASCII_FAMILY;
+
+    /* make this test work with data files that are built for a different platform */
+    if(inEndian!=U_IS_BIG_ENDIAN || inCharset!=U_CHARSET_FAMILY) {
+        udata_closeSwapper(ds);
+        ds=udata_openSwapper(inEndian, inCharset, oppositeEndian, inCharset, &errorCode);
+        if(U_FAILURE(errorCode)) {
+            log_err("udata_openSwapper(%s->!isBig+same charset) failed - %s\n",
+                    name, u_errorName(errorCode));
+            return;
+        }
+    }
+
+    ds->printError=printError;
+
+    /* preflight the length */
+    length=swapFn(ds, inHeader, -1, NULL, &errorCode);
+    if(U_FAILURE(errorCode)) {
+        log_err("swapFn(preflight %s->!isBig+same charset) failed - %s\n",
+                name, u_errorName(errorCode));
+        udata_closeSwapper(ds);
+        return;
+    }
+
+    /* compare the preflighted length against the data length */
+    if(dataLength>=0 && (length+15)<(headerLength+dataLength)) {
+        log_err("swapFn(preflight %s->!isBig+same charset) length too small: %d < data length %d\n",
+                name, length, (headerLength+dataLength));
+        udata_closeSwapper(ds);
+        return;
+    }
+
+    /* swap, not in-place */
+    length2=swapFn(ds, inHeader, length, buffer, &errorCode);
+    udata_closeSwapper(ds);
+    if(U_FAILURE(errorCode)) {
+        log_err("swapFn(%s->!isBig+same charset) failed - %s\n",
+                name, u_errorName(errorCode));
+        return;
+    }
+
+    /* compare the swap length against the preflighted length */
+    if(length2!=length) {
+        log_err("swapFn(%s->!isBig+same charset) length differs from preflighting: %d != preflighted %d\n",
+                name, length2, length);
+        return;
+    }
+
+    /* next swap to opposite charset family */
+    ds=udata_openSwapper(oppositeEndian, inCharset,
+                         oppositeEndian, oppositeCharset,
+                         &errorCode);
+    if(U_FAILURE(errorCode)) {
+        log_err("udata_openSwapper(%s->!isBig+other charset) failed - %s\n",
+                name, u_errorName(errorCode));
+        return;
+    }
+    ds->printError=printError;
+
+    /* swap in-place */
+    length2=swapFn(ds, buffer, length, buffer, &errorCode);
+    udata_closeSwapper(ds);
+    if(U_FAILURE(errorCode)) {
+        log_err("swapFn(%s->!isBig+other charset) failed - %s\n",
+                name, u_errorName(errorCode));
+        return;
+    }
+
+    /* compare the swap length against the original length */
+    if(length2!=length) {
+        log_err("swapFn(%s->!isBig+other charset) length differs from original: %d != original %d\n",
+                name, length2, length);
+        return;
+    }
+
+    /* finally swap to original platform values */
+    ds=udata_openSwapper(oppositeEndian, oppositeCharset,
+                         inEndian, inCharset,
+                         &errorCode);
+    if(U_FAILURE(errorCode)) {
+        log_err("udata_openSwapper(%s->back to original) failed - %s\n",
+                name, u_errorName(errorCode));
+        return;
+    }
+    ds->printError=printError;
+
+    /* swap, not in-place */
+    length2=swapFn(ds, buffer, length, buffer2, &errorCode);
+    udata_closeSwapper(ds);
+    if(U_FAILURE(errorCode)) {
+        log_err("swapFn(%s->back to original) failed - %s\n",
+                name, u_errorName(errorCode));
+        return;
+    }
+
+    /* compare the swap length against the original length */
+    if(length2!=length) {
+        log_err("swapFn(%s->back to original) length differs from original: %d != original %d\n",
+                name, length2, length);
+        return;
+    }
+
+    /* compare the final contents with the original */
+    if(0!=uprv_memcmp(inHeader, buffer2, length)) {
+        const uint8_t *original;
+        uint8_t diff[8];
+        int32_t i, j;
+
+        log_err("swapFn(%s->back to original) contents differs from original\n",
+                name);
+
+        /* find the first difference */
+        original=(const uint8_t *)inHeader;
+        for(i=0; i<length && original[i]==buffer2[i]; ++i) {}
+
+        /* find the next byte that is the same */
+        for(j=i+1; j<length && original[j]!=buffer2[j]; ++j) {}
+        log_info("    difference at index %d=0x%x, until index %d=0x%x\n", i, i, j, j);
+
+        /* round down to the last 4-boundary for better result output */
+        i&=~3;
+        log_info("showing bytes from index %d=0x%x (length %d=0x%x):\n", i, i, length, length);
+
+        /* print 8 bytes but limit to the buffer contents */
+        length2=i+sizeof(diff);
+        if(length2>length) {
+            length2=length;
+        }
+
+        /* print the original bytes */
+        uprv_memset(diff, 0, sizeof(diff));
+        for(j=i; j<length2; ++j) {
+            diff[j-i]=original[j];
+        }
+        log_info("    original: %02x %02x %02x %02x %02x %02x %02x %02x\n",
+            diff[0], diff[1], diff[2], diff[3], diff[4], diff[5], diff[6], diff[7]);
+
+        /* print the swapped bytes */
+        uprv_memset(diff, 0, sizeof(diff));
+        for(j=i; j<length2; ++j) {
+            diff[j-i]=buffer2[j];
+        }
+        log_info("    swapped:  %02x %02x %02x %02x %02x %02x %02x %02x\n",
+            diff[0], diff[1], diff[2], diff[3], diff[4], diff[5], diff[6], diff[7]);
+    }
+}
+
+static void
+TestSwapData() {
+    char name[100];
+    UDataMemory *pData;
+    uint8_t *buffer;
+    const char *pkg, *nm;
+
+    UErrorCode errorCode;
+    int32_t i;
+
+    buffer=(uint8_t *)uprv_malloc(2*SWAP_BUFFER_SIZE);
+    if(buffer==NULL) {
+        log_err("unable to allocate %d bytes\n", 2*SWAP_BUFFER_SIZE);
+        return;
+    }
+
+    for(i=0; i<LENGTHOF(swapCases); ++i) {
+        /* build the name for logging */
+        errorCode=U_ZERO_ERROR;
+        if(swapCases[i].name[0]=='*') {
+            pkg=loadTestData(&errorCode);
+            nm=swapCases[i].name+1;
+            uprv_strcpy(name, "testdata");
+        } else {
+            pkg=NULL;
+            nm=swapCases[i].name;
+            uprv_strcpy(name, "NULL");
+        }
+        uprv_strcat(name, "/");
+        uprv_strcat(name, nm);
+        uprv_strcat(name, ".");
+        uprv_strcat(name, swapCases[i].type);
+
+        pData=udata_open(pkg, swapCases[i].type, nm, &errorCode);
+        if(U_SUCCESS(errorCode)) {
+            TestSwapCase(pData, name, swapCases[i].swapFn, buffer, buffer+SWAP_BUFFER_SIZE);
+            udata_close(pData);
+        } else {
+            log_data_err("udata_open(%s) failed - %s\n",
+                name, u_errorName(errorCode));
+        }
+    }
+
+    uprv_free(buffer);
 }

Index: usettest.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/usettest.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- usettest.c	10 Sep 2003 02:42:40 -0000	1.1
+++ usettest.c	6 Apr 2004 10:09:34 -0000	1.2
@@ -160,13 +160,17 @@
                               UBool isIn) {
     const char* p = list;
     UChar ustr[128];
-    char pat[128];
+    char *pat;
     UErrorCode ec;
-    int32_t rangeStart = -1, rangeEnd = -1;
+    int32_t rangeStart = -1, rangeEnd = -1, length;
             
     ec = U_ZERO_ERROR;
-    uset_toPattern(set, ustr, sizeof(ustr), TRUE, &ec);
-    u_UCharsToChars(ustr, pat, u_strlen(ustr)+1);
+    length = uset_toPattern(set, ustr, sizeof(ustr), TRUE, &ec);
+    if(U_FAILURE(ec)) {
+        log_err("FAIL: uset_toPattern() fails in expectContainment() - %s\n", u_errorName(ec));
+        return;
+    }
+    pat=aescstrdup(ustr, length);
 
     while (*p) {
         if (*p=='{') {
@@ -243,7 +247,7 @@
     }
 }
 
-/* This only works for BMP chars */
+/* This only works for invariant BMP chars */
 static char oneUCharToChar(UChar32 c) {
     UChar ubuf[1];
     char buf[1];
@@ -256,21 +260,22 @@
                         const char* items) {
     const char* p = items;
     UChar ustr[128], itemStr[128];
-    char pat[128], buf[128];
+    char buf[128];
+    char *pat;
     UErrorCode ec;
     int32_t expectedSize = 0;
     int32_t itemCount = uset_getItemCount(set);
     int32_t itemIndex = 0;
     UChar32 start = 1, end = 0;
-    int32_t itemLen = 0;
+    int32_t itemLen = 0, length;
 
     ec = U_ZERO_ERROR;
-    uset_toPattern(set, ustr, sizeof(ustr), TRUE, &ec);
+    length = uset_toPattern(set, ustr, sizeof(ustr), TRUE, &ec);
     if (U_FAILURE(ec)) {
         log_err("FAIL: uset_toPattern => %s\n", u_errorName(ec));
         return;
     }
-    u_UCharsToChars(ustr, pat, u_strlen(ustr)+1);
+    pat=aescstrdup(ustr, length);
 
     if (uset_isEmpty(set) != (strlen(items)==0)) {
         log_err("FAIL: %s should return %s from isEmpty\n",
@@ -279,7 +284,7 @@
     }
 
     /* Don't test patterns starting with "[^" */
-    if (strlen(pat) > 2 && pat[1] == '^') {
+    if (u_strlen(ustr) > 2 && ustr[1] == 0x5e /*'^'*/) {
         return;
     }
 

Index: usrchdat.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/usrchdat.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- usrchdat.c	10 Sep 2003 02:42:40 -0000	1.3
+++ usrchdat.c	6 Apr 2004 10:09:34 -0000	1.4
@@ -206,6 +206,16 @@
     {"abc \\uD800\\uDC00 \\uD800\\uDC01 \\uD801\\uDC00 \\uD800\\uDC00abc abc\\uD800\\uDC00 \\uD800\\uD800\\uDC00 \\uD800\\uDC00\\uDC00", 
      "\\uD800\\uDC00", NULL, UCOL_TERTIARY, NULL, {4, 13, 22, 26, 29, -1}, 
     {2, 2, 2, 2, 2}},
+    {"and\\uD834\\uDDB9this sentence", "\\uD834\\uDDB9", NULL, 
+     UCOL_TERTIARY, NULL, {3, -1}, {2}},
+    {"and \\uD834\\uDDB9 this sentence", " \\uD834\\uDDB9 ", NULL, 
+     UCOL_TERTIARY, NULL, {3, -1}, {4}},
+    {"and-\\uD834\\uDDB9-this sentence", "-\\uD834\\uDDB9-", NULL, 
+     UCOL_TERTIARY, NULL, {3, -1}, {4}},
+    {"and,\\uD834\\uDDB9,this sentence", ",\\uD834\\uDDB9,", NULL, 
+     UCOL_TERTIARY, NULL, {3, -1}, {4}},
+    {"and?\\uD834\\uDDB9?this sentence", "?\\uD834\\uDDB9?", NULL, 
+     UCOL_TERTIARY, NULL, {3, -1}, {4}},
     {NULL, NULL, NULL, UCOL_TERTIARY, NULL, {-1}, {0}}
 };
 
@@ -271,6 +281,8 @@
     NULL, {0, -1}, {5}},
     {"a\\u0300\\u0325b\\u0300\\u0325c \\u0325b\\u0300 \\u0300b\\u0325", 
     "\\u0300b\\u0325", NULL, UCOL_TERTIARY, NULL, {1, 12, -1}, {5, 3}},
+    {"\\u00c4\\u0323", "A\\u0323\\u0308", NULL, UCOL_TERTIARY, NULL, {0, -1}, {2}},
+    {"\\u0308\\u0323", "\\u0323\\u0308", NULL, UCOL_TERTIARY, NULL, {0, -1}, {2}},
     {NULL, NULL, NULL, UCOL_TERTIARY, NULL, {-1}, {0}}
 };
 
@@ -428,6 +440,16 @@
     {"abc \\uD800\\uDC00 \\uD800\\uDC01 \\uD801\\uDC00 \\uD800\\uDC00abc abc\\uD800\\uDC00 \\uD800\\uD800\\uDC00 \\uD800\\uDC00\\uDC00", 
      "\\uD800\\uDC00", NULL, UCOL_TERTIARY, NULL, {4, 13, 22, 26, 29, -1}, 
     {2, 2, 2, 2, 2}},
+    {"and\\uD834\\uDDB9this sentence", "\\uD834\\uDDB9", NULL, 
+     UCOL_TERTIARY, NULL, {3, -1}, {2}},
+    {"and \\uD834\\uDDB9 this sentence", " \\uD834\\uDDB9 ", NULL, 
+     UCOL_TERTIARY, NULL, {3, -1}, {4}},
+    {"and-\\uD834\\uDDB9-this sentence", "-\\uD834\\uDDB9-", NULL, 
+     UCOL_TERTIARY, NULL, {3, -1}, {4}},
+    {"and,\\uD834\\uDDB9,this sentence", ",\\uD834\\uDDB9,", NULL, 
+     UCOL_TERTIARY, NULL, {3, -1}, {4}},
+    {"and?\\uD834\\uDDB9?this sentence", "?\\uD834\\uDDB9?", NULL, 
+     UCOL_TERTIARY, NULL, {3, -1}, {4}},
     {NULL, NULL, NULL, UCOL_TERTIARY, NULL, {-1}, {0}}
 };
 

Index: utransts.c
===================================================================
RCS file: /cvs/core/icu-sword/source/test/cintltst/utransts.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- utransts.c	10 Sep 2003 02:42:40 -0000	1.4
+++ utransts.c	6 Apr 2004 10:09:34 -0000	1.5
@@ -173,6 +173,71 @@
     }
 }
 
+static void TestUnicodeIDs() {
+    UEnumeration *uenum;
+    UTransliterator *utrans;
+    const UChar *id, *id2;
+    int32_t idLength, id2Length, count, count2;
+
+    UErrorCode errorCode;
+
+    errorCode=U_ZERO_ERROR;
+    uenum=utrans_openIDs(&errorCode);
+    if(U_FAILURE(errorCode)) {
+        log_err("utrans_openIDs() failed - %s\n", u_errorName(errorCode));
+        return;
+    }
+
+    count=uenum_count(uenum, &errorCode);
+    if(U_FAILURE(errorCode) || count<1) {
+        log_err("uenum_count(transliterator IDs)=%d - %s\n", count, u_errorName(errorCode));
+    }
+
+    count=0;
+    for(;;) {
+        id=uenum_unext(uenum, &idLength, &errorCode);
+        if(U_FAILURE(errorCode)) {
+            log_err("uenum_unext(transliterator ID %d) failed - %s\n", count, u_errorName(errorCode));
+            break;
+        }
+        if(id==NULL) {
+            break;
+        }
+
+        if(++count==5) {
+            /* try to actually open only a few transliterators */
+            continue;
+        }
+
+        utrans=utrans_openU(id, idLength, UTRANS_FORWARD, NULL, 0, NULL, &errorCode);
+        if(U_FAILURE(errorCode)) {
+            log_err("utrans_openU(%s) failed - %s\n", aescstrdup(id, idLength), u_errorName(errorCode));
+            continue;
+        }
+
+        id2=utrans_getUnicodeID(utrans, &id2Length);
+        if(idLength!=id2Length || 0!=u_memcmp(id, id2, idLength)) {
+            log_err("utrans_getUnicodeID(%s) does not match the original ID\n", aescstrdup(id, idLength));
+        }
+
+        utrans_close(utrans);
+    }
+
+    uenum_reset(uenum, &errorCode);
+    if(U_FAILURE(errorCode) || count<1) {
+        log_err("uenum_reset(transliterator IDs) failed - %s\n", u_errorName(errorCode));
+    } else {
+        count2=uenum_count(uenum, &errorCode);
+        if(U_FAILURE(errorCode) || count<1) {
+            log_err("2nd uenum_count(transliterator IDs)=%d - %s\n", count2, u_errorName(errorCode));
+        } else if(count!=count2) {
+            log_err("uenum_unext(transliterator IDs) returned %d IDs but uenum_count() after uenum_reset() claims there are %d\n", count, count2);
+        }
+    }
+
+    uenum_close(uenum);
+}
+
 static void TestOpenInverse(){
     UErrorCode status=U_ZERO_ERROR;
     UTransliterator* t1=NULL;
@@ -271,10 +336,13 @@
 static void TestRegisterUnregister(){
     UErrorCode status=U_ZERO_ERROR;
     UTransliterator* t1=NULL;
-    UTransliterator* rules=NULL;
+    UTransliterator* rules=NULL, *rules2;
     UTransliterator* inverse1=NULL;
     UChar rule[]={ 0x0061, 0x003c, 0x003e, 0x0063}; /*a<>b*/
 
+    U_STRING_DECL(ID, "TestA-TestB", 11);
+    U_STRING_INIT(ID, "TestA-TestB", 11);
+
     /* Make sure it doesn't exist */
     t1=utrans_open("TestA-TestB", UTRANS_FORWARD,NULL,0,NULL, &status);
     if(t1 != NULL || U_SUCCESS(status)) {
@@ -295,6 +363,14 @@
         log_err("FAIL: utrans_openRules(a<>B) failed with error=%s\n", myErrorName(status));
         return;
     }
+
+    /* clone it so we can register it a second time */
+    rules2=utrans_clone(rules, &status);
+    if(U_FAILURE(status)) {
+        log_err("FAIL: utrans_clone(a<>B) failed with error=%s\n", myErrorName(status));
+        return;
+    }
+
     status=U_ZERO_ERROR;
     /* Register it */
     utrans_register(rules, &status);
@@ -320,7 +396,34 @@
         log_err("FAIL: TestA-TestB isn't unregistered\n");
         return;
     }
-    
+    utrans_close(t1);
+
+    /* now with utrans_unregisterID(const UChar *) */
+    status=U_ZERO_ERROR;
+    utrans_register(rules2, &status);
+    if(U_FAILURE(status)){
+        log_err("FAIL: 2nd utrans_register failed with error=%s\n", myErrorName(status));
+        return;
+    }
+    status=U_ZERO_ERROR;
+    /* Now check again -- should exist now*/
+    t1= utrans_open("TestA-TestB", UTRANS_FORWARD, NULL,0,NULL,&status);
+    if(U_FAILURE(status) || t1 == NULL){
+        log_err("FAIL: 2nd TestA-TestB not registered\n");
+        return;
+    }
+    utrans_close(t1);
+   
+    /*unregister the instance*/
+    status=U_ZERO_ERROR;
+    utrans_unregisterID(ID, -1);
+    /* now Make sure it doesn't exist */
+    t1=utrans_openU(ID, -1, UTRANS_FORWARD,NULL,0,NULL, &status);
+    if(U_SUCCESS(status) || t1 != NULL) {
+        log_err("FAIL: 2nd TestA-TestB isn't unregistered\n");
+        return;
+    }
+
     utrans_close(t1);
     utrans_close(inverse1);
 }
@@ -376,7 +479,7 @@
     UChar filt[128];
     UChar buf[128];
     UChar exp[128];
-    char cbuf[128];
+    char *cbuf;
     int32_t limit;
     const char* DATA[] = {
         "[^c]", /* Filter out 'c' */
@@ -420,9 +523,7 @@
             goto exit;
         }
         
-        /*u_austrcpy(cbuf, buf);*/
-        u_UCharsToChars(buf, cbuf, u_strlen(buf)+1);
-        /*u_uastrcpy(exp, DATA[i+2]);*/
+        cbuf=aescstrdup(buf, -1);
         u_charsToUChars(DATA[i+2], exp, strlen(DATA[i+2])+1);
         if (0 == u_strcmp(buf, exp)) {
             log_verbose("Ok: %s | %s -> %s\n", DATA[i+1], DATA[i], cbuf);
@@ -494,7 +595,10 @@
     UChar from[CAP];
     UChar to[CAP];
     UChar buf[CAP];
-    char id[CAP];
+    const UChar *ID;
+    int32_t IDLength;
+    const char *id;
+
     UErrorCode status = U_ZERO_ERROR;
     int32_t limit;
     UTransPosition pos;
@@ -504,7 +608,8 @@
     u_uastrcpy(from, cfrom);
     u_uastrcpy(to, cto);
 
-    utrans_getID(trans, id, CAP);
+    ID = utrans_getUnicodeID(trans, &IDLength);
+    id = aescstrdup(ID, IDLength);
 
     /* utrans_transUChars() */
     u_strcpy(buf, from);