/* ***************************************************************************************** * * * COPYRIGHT: * * (C) Copyright Taligent, Inc., 1996 * * (C) Copyright International Business Machines Corporation, 1999 * * Licensed Material - Program-Property of IBM - All Rights Reserved. * * US Government Users Restricted Rights - Use, duplication, or disclosure * * restricted by GSA ADP Schedule Contract with IBM Corp. * * * ***************************************************************************************** ******************************************************************************** * * File CCONVTST.C * * Modification History: * Name Description * Steven R. Loomis 7/8/1999 Adding input buffer test ********************************************************************************* */ #include #include #include #include #include "uloc.h" #include "ucnv.h" #include "ucnv_err.h" #include "cintltst.h" #include "utypes.h" #include "ustring.h" static void printSeq(const char* a, int len); static void printUSeq(const UChar* a, int len); void TestNewConvertWithBufferSizes(int32_t osize, int32_t isize) ; void TestConverterTypesAndStarters(); #define NEW_MAX_BUFFER 999 static int32_t gInBufferSize = 0; static int32_t gOutBufferSize = 0; static char gNuConvTestName[1024]; #define nct_min(x,y) ((x %d chars out]. \nResult :", sourceLen, targ-junkout); if(VERBOSITY) { char junk[9999]; char offset_str[9999]; char *p; junk[0] = 0; offset_str[0] = 0; for(p = junkout;p %d chars.\nResult :", sourcelen, targ-junkout); if(VERBOSITY) { char junk[9999]; char offset_str[9999]; UChar *p; junk[0] = 0; offset_str[0] = 0; for(p = junkout;p h1 h2 h3 . */ const char expectedIBM930[] = { (char)0xF1, (char)0xF2, (char)0xF3, (char)0x0E, (char)0x45, (char)0x41, (char)0x45, (char)0x42, (char)0x45, (char)0x43, (char)0x0F, (char)0x4B }; int32_t toIBM930Offs[] = { (char)0x00, (char)0x01, (char)0x02, (char)0x03, (char)0x03, (char)0x03, (char)0x04, (char)0x04, (char)0x05, (char)0x05, (char)0x06, (char)0x06, }; /* 1 2 3 . */ const char expectedISO88593[] = { (char)0x31, (char)0x32, (char)0x33, (char)0x1a, (char)0x1a, (char)0x1a, (char)0x2E }; int32_t toISO88593Offs[] = {(char) 0x00, (char)0x01, (char)0x02, (char)0x03, (char)0x04, (char)0x05, (char)0x06, }; /* 1 2 3 h1 h2 h3 . */ const char expectedIBM943[] = { (char)0x31, (char)0x32, (char)0x33, (char)0x88, (char)0xea, (char)0x93, (char)0xf1, (char)0x8e, (char)0x4f, (char)0x2e }; int32_t toIBM943Offs [] = { (char)0x00, (char)0x01, (char)0x02, (char)0x03, (char)0x03, (char)0x04, (char)0x04, (char)0x05, (char)0x05, (char)0x06, }; /* etc */ const char expectedUTF16LE[] = { (char)0x31, (char)0x00, (char)0x32, (char)0x00, (char)0x33, (char)0x00, (char)0x00, (char)0x4e, (char)0x8c, (char)0x4e, (char)0x09, (char)0x4e, (char)0x2e, (char)0x00 }; int32_t toUTF16LEOffs[]= { (char)0x00, (char)0x00, (char)0x02, (char)0x02, (char)0x04, (char)0x04, (char)0x06, (char)0x06, (char)0x08, (char)0x08, (char)0x0a, (char)0x0a, (char)0x0c, (char)0x0c, }; /** Test chars #2 NOT USED YET**/ /* Sahha [health], slashed h's */ const UChar malteseUChars[] = { 0x0053, 0x0061, 0x0127, 0x0127, 0x0061 }; const char maltesechars[] = { '\0' }; /*********************************** START OF CODE finally *************/ gInBufferSize = insize; gOutBufferSize = outsize; log_verbose("\n\n\nTesting conversions with InputBufferSize = %d, OutputBufferSize = %d\n", gInBufferSize, gOutBufferSize); #if 0 if(!testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]), expectedUTF8, sizeof(expectedUTF8), "UTF8", toUTF8Offs )) log_err("u-> UTF8 did not match.\n"); if(!testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]), expectedISO2022, sizeof(expectedISO2022), "iso-2022", toISO2022Offs )) log_err("u-> iso-2022 did not match.\n"); if(!testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]), expectedIBM930, sizeof(expectedIBM930), "ibm-930", toIBM930Offs )) log_err("u-> ibm-930 did not match.\n"); if(!testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]), expectedISO88593, sizeof(expectedISO88593), "iso-8859-3", toISO88593Offs )) log_err("u-> iso-8859-3 did not match.\n"); if(!testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]), expectedIBM943, sizeof(expectedIBM943), "ibm-943", toIBM943Offs )) log_err("u-> ibm-943 [MBCS] not match.\n"); if(!testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]), expectedUTF16LE, sizeof(expectedUTF16LE), "utf-16le", toUTF16LEOffs )) log_err("u-> utf-16le did not match.\n"); /****/ #endif if(!testConvertToU(expectedUTF8, sizeof(expectedUTF8), sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf8", fmUTF8Offs )) log_err("utf8 -> u did not match\n"); if(!testConvertToU(expectedISO2022, sizeof(expectedISO2022), sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "iso-2022", fmISO2022Offs )) log_err("iso-2022 -> u did not match"); #if 0 if(!testConvertToU(expectedIBM930, sizeof(expectedIBM930), sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "ibm-930", fmIBM930Offs )) log_err("ibm-930 -> u did not match"); if(!testConvertToU(expectedIBM943, sizeof(expectedIBM943), sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "ibm-943", fmIBM943Offs )) log_err("ibm-943 -> u did not match"); if(!testConvertToU(expectedUTF16LE, sizeof(expectedUTF16LE), sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf-16le", fmUTF16LEOffs )) log_err("utf-16le -> u did not match"); #endif } void TestConverterTypesAndStarters() { UConverter* myConverter[3]; UErrorCode err = U_ZERO_ERROR; bool_t mystarters[256]; int i; const bool_t expectedKSCstarters[256] = { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE}; log_verbose("Testing KSC, ibm-930, ibm-878 for starters and their conversion types."); myConverter[0] = ucnv_open("ksc", &err); if (FAILURE(err)) log_err("Failed to create an ibm-949 converter\n"); myConverter[1] = ucnv_open("ibm-930", &err); if (FAILURE(err)) log_err("Failed to create an ibm-930 converter\n"); myConverter[2] = ucnv_open("ibm-878", &err); if (FAILURE(err)) log_err("Failed to create an ibm-815 converter\n"); if (ucnv_getType(myConverter[0])!=MBCS) log_err("ucnv_getType Failed for ibm-949\n"); else log_verbose("ucnv_getType ibm-949 ok\n"); if (ucnv_getType(myConverter[1])!=EBCDIC_STATEFUL) log_err("ucnv_getType Failed for ibm-930\n"); else log_verbose("ucnv_getType ibm-930 ok\n"); if (ucnv_getType(myConverter[2])!=SBCS) log_err("ucnv_getType Failed for ibm-815\n"); else log_verbose("ucnv_getType ibm-815 ok\n"); ucnv_getStarters(myConverter[0], mystarters, &err); /*if (memcmp(expectedKSCstarters, mystarters, sizeof(expectedKSCstarters))) log_err("Failed ucnv_getStarters for ksc\n"); else log_verbose("ucnv_getStarters ok\n");*/ ucnv_close(myConverter[0]); ucnv_close(myConverter[1]); ucnv_close(myConverter[2]); }