home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / cintltst / nucnvtst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  19.0 KB  |  599 lines

  1. /*
  2. *****************************************************************************************
  3. *                                                                                       *
  4. * COPYRIGHT:                                                                            *
  5. *   (C) Copyright Taligent, Inc.,  1996                                                 *
  6. *   (C) Copyright International Business Machines Corporation,  1999                    *
  7. *   Licensed Material - Program-Property of IBM - All Rights Reserved.                  *
  8. *   US Government Users Restricted Rights - Use, duplication, or disclosure             *
  9. *   restricted by GSA ADP Schedule Contract with IBM Corp.                              *
  10. *                                                                                       *
  11. *****************************************************************************************
  12. ********************************************************************************
  13. *
  14. * File CCONVTST.C
  15. *
  16. * Modification History:
  17. *        Name                     Description            
  18. *    Steven R. Loomis     7/8/1999      Adding input buffer test
  19. *********************************************************************************
  20. */
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <ctype.h>
  25. #include "uloc.h"
  26. #include "ucnv.h"
  27. #include "ucnv_err.h"
  28. #include "cintltst.h"
  29. #include "utypes.h"
  30. #include "ustring.h"
  31.  
  32. static void printSeq(const char* a, int len);
  33. static void printUSeq(const UChar* a, int len);
  34.  
  35. void TestNewConvertWithBufferSizes(int32_t osize, int32_t isize) ;
  36. void TestConverterTypesAndStarters();
  37.  
  38. #define NEW_MAX_BUFFER 999
  39.  
  40. static int32_t  gInBufferSize = 0;
  41. static int32_t  gOutBufferSize = 0;
  42. static char     gNuConvTestName[1024];
  43.  
  44. #define nct_min(x,y)  ((x<y) ? x : y)
  45.  
  46. void printSeq(const char* a, int len)
  47. {
  48.     int i=0;
  49.     log_verbose("\n{");
  50.     while (i<len) log_verbose("%X", a[i++]);
  51.     log_verbose("}\n");
  52. }
  53. void printUSeq(const UChar* a, int len)
  54. {
  55.     int i=0;
  56.     log_verbose("\n{");
  57.     while (i<len) log_verbose("%4X", a[i++]);
  58.     log_verbose("}\n");
  59. }
  60.  
  61. void printSeqErr(const char* a, int len)
  62. {
  63.     int i=0;
  64.     fprintf(stderr, "\n{");
  65.     while (i<len)  fprintf(stderr, "%X", a[i++]);
  66.     fprintf(stderr, "}\n");
  67. }
  68. void printUSeqErr(const UChar* a, int len)
  69. {
  70.     int i=0;
  71.     fprintf(stderr, "\n{");
  72.     while (i<len) fprintf(stderr, "%4X", a[i++]);
  73.     fprintf(stderr,"}\n");
  74. }
  75.  
  76. void TestInBufSizes()
  77. {
  78.   TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,1);
  79. #if 0
  80.   TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,2);
  81.   TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,3);
  82.   TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,4);
  83.   TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,5);
  84.   TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,6);
  85.   TestNewConvertWithBufferSizes(1,1);
  86.   TestNewConvertWithBufferSizes(2,3);
  87.   TestNewConvertWithBufferSizes(3,2);
  88. #endif
  89. }
  90.  
  91. void TestOutBufSizes()
  92. {
  93. #if 0
  94.   TestNewConvertWithBufferSizes(NEW_MAX_BUFFER,NEW_MAX_BUFFER);
  95.   TestNewConvertWithBufferSizes(1,NEW_MAX_BUFFER);
  96.   TestNewConvertWithBufferSizes(2,NEW_MAX_BUFFER);
  97.   TestNewConvertWithBufferSizes(3,NEW_MAX_BUFFER);
  98.   TestNewConvertWithBufferSizes(4,NEW_MAX_BUFFER);
  99.   TestNewConvertWithBufferSizes(5,NEW_MAX_BUFFER);
  100. #endif
  101. }
  102.  
  103.  
  104. void addTestNewConvert(TestNode** root)
  105. {
  106.    addTest(root, &TestInBufSizes, "tsconv/nucnvtst/TestInBufSizes");
  107.    addTest(root, &TestOutBufSizes, "tsconv/nucnvtst/TestOutBufSizes");
  108.    addTest(root, &TestConverterTypesAndStarters, "tsconv/nucnvtst/TestConverterTypesAndStarters");
  109.  
  110. }
  111.  
  112.  
  113. /* Note that this test already makes use of statics, so it's not really 
  114.    multithread safe. 
  115.    This convenience function lets us make the error messages actually useful.
  116. */
  117.  
  118. void setNuConvTestName(const char *codepage, const char *direction)
  119. {
  120.   sprintf(gNuConvTestName, "[Testing %s %s Unicode, InputBufSiz=%d, OutputBufSiz=%d]",
  121.       codepage,
  122.       direction,
  123.       gInBufferSize,
  124.       gOutBufferSize);
  125. }
  126.  
  127. bool_t testConvertFromU( const UChar *source, int sourceLen,  const char *expect, int expectLen, 
  128.                 const char *codepage, int32_t *expectOffsets)
  129. {
  130.     UErrorCode status = U_ZERO_ERROR;
  131.     UConverter *conv = 0;
  132.     char    junkout[NEW_MAX_BUFFER]; /* FIX */
  133.     int32_t    junokout[NEW_MAX_BUFFER]; /* FIX */
  134.     const UChar *src;
  135.     char *end;
  136.     char *targ;
  137.     int32_t *offs;
  138.     int i;
  139.     int32_t   realBufferSize;
  140.     char *realBufferEnd;
  141.     const UChar *realSourceEnd;
  142.     const UChar *sourceLimit;
  143.     bool_t checkOffsets = TRUE;
  144.     bool_t doFlush;
  145.  
  146.     for(i=0;i<NEW_MAX_BUFFER;i++)
  147.         junkout[i] = 0xF0;
  148.     for(i=0;i<NEW_MAX_BUFFER;i++)
  149.         junokout[i] = 0xFF;
  150.  
  151.     setNuConvTestName(codepage, "FROM");
  152.  
  153.     log_verbose("\n=========  %s\n", gNuConvTestName);
  154.  
  155.     conv = ucnv_open(codepage, &status);
  156.     if(U_FAILURE(status))
  157.     {
  158.         log_err("Couldn't open converter %s\n",codepage);    
  159.         return FALSE;
  160.     }
  161.  
  162.     log_verbose("Converter opened..\n");
  163.  
  164.     src = source;
  165.     targ = junkout;
  166.     offs = junokout;
  167.  
  168.     realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
  169.     realBufferEnd = junkout + realBufferSize;
  170.     realSourceEnd = source + sourceLen;
  171.  
  172.     if ( gOutBufferSize != realBufferSize )
  173.       checkOffsets = FALSE;
  174.  
  175.     if( gInBufferSize != NEW_MAX_BUFFER )
  176.       checkOffsets = FALSE;
  177.  
  178.     do
  179.       {
  180.         end = nct_min(targ + gOutBufferSize, realBufferEnd);
  181.         sourceLimit = nct_min(src + gInBufferSize, realSourceEnd);
  182.  
  183.         doFlush = (sourceLimit == realSourceEnd);
  184.  
  185.         if(targ == realBufferEnd)
  186.           {
  187.         log_err("Error, overflowed the real buffer while about to call fromUnicode! targ=%08lx %s", targ, gNuConvTestName);
  188.         return FALSE;
  189.           }
  190.         log_verbose("calling fromUnicode @ SOURCE:%08lx to %08lx  TARGET: %08lx to %08lx, flush=%s\n", src,sourceLimit, targ,end, doFlush?"TRUE":"FALSE");
  191.         
  192.  
  193.         status = U_ZERO_ERROR;
  194.  
  195.         ucnv_fromUnicode (conv,
  196.                   &targ,
  197.                   end,
  198.                   &src,
  199.                   sourceLimit,
  200.                   checkOffsets ? offs : NULL,
  201.                   doFlush, /* flush if we're at the end of the input data */
  202.                   &status);
  203.     
  204.       } while ( (status == U_INDEX_OUTOFBOUNDS_ERROR) || (sourceLimit < realSourceEnd) );
  205.         
  206.     if(U_FAILURE(status))
  207.       {
  208.         log_err("Problem tdoing fromUnicode, errcode %d %s\n", codepage, status, gNuConvTestName);
  209.         return FALSE;
  210.       }
  211.  
  212.     log_verbose("\nConversion done [%d uchars in -> %d chars out]. \nResult :",
  213.         sourceLen, targ-junkout);
  214.     if(VERBOSITY)
  215.     {
  216.         char junk[9999];
  217.         char offset_str[9999];
  218.         char *p;
  219.         
  220.         junk[0] = 0;
  221.         offset_str[0] = 0;
  222.         for(p = junkout;p<targ;p++)
  223.         {
  224.             sprintf(junk + strlen(junk), "0x%02x, ", (0xFF) & (unsigned int)*p);
  225.             sprintf(offset_str + strlen(offset_str), "0x%02x, ", (0xFF) & (unsigned int)junokout[p-junkout]);
  226.         }
  227.         
  228.         log_verbose(junk);
  229.         printSeq(expect, expectLen);
  230.         if ( checkOffsets )
  231.           {
  232.             log_verbose("\nOffsets:");
  233.             log_verbose(offset_str);
  234.           }
  235.         log_verbose("\n");
  236.     }
  237.     ucnv_close(conv);
  238.  
  239.  
  240.     if(expectLen != targ-junkout)
  241.     {
  242.         log_err("Expected %d chars out, got %d %s\n", expectLen, targ-junkout, gNuConvTestName);
  243.         return FALSE;
  244.     }
  245.  
  246.     if (checkOffsets && (expectOffsets != 0) )
  247.     {
  248.         log_verbose("comparing %d offsets..\n", targ-junkout);
  249.         if(memcmp(junokout,expectOffsets,(targ-junkout) * sizeof(int32_t) ))
  250.             log_err("did not get the expected offsets. %s", gNuConvTestName);
  251.     }
  252.  
  253.     log_verbose("comparing..\n");
  254.     if(!memcmp(junkout, expect, expectLen))
  255.     {
  256.         log_verbose("Matches!\n");
  257.         return TRUE;
  258.     }
  259.     else
  260.     {    
  261.         log_err("String does not match. %s\n", gNuConvTestName);
  262.         printSeqErr(junkout, expectLen);
  263.         printSeqErr(expect, expectLen);
  264.         
  265.         return FALSE;
  266.     }
  267. }
  268.  
  269. bool_t testConvertToU( const char *source, int sourcelen, const UChar *expect, int expectlen, 
  270.                const char *codepage, int32_t *expectOffsets)
  271. {
  272.     UErrorCode status = U_ZERO_ERROR;
  273.     UConverter *conv = 0;
  274.     UChar    junkout[NEW_MAX_BUFFER]; /* FIX */
  275.     int32_t    junokout[NEW_MAX_BUFFER]; /* FIX */
  276.     const char *src;
  277.     const char *realSourceEnd;
  278.     const char *srcLimit;
  279.     UChar *targ;
  280.     UChar *end;
  281.     int32_t *offs;
  282.     int i;
  283.     bool_t   checkOffsets = TRUE;
  284.     
  285.     int32_t   realBufferSize;
  286.     UChar *realBufferEnd;
  287.     
  288.  
  289.     for(i=0;i<NEW_MAX_BUFFER;i++)
  290.         junkout[i] = 0xFFFE;
  291.  
  292.     for(i=0;i<NEW_MAX_BUFFER;i++)
  293.         junokout[i] = -1;
  294.  
  295.     setNuConvTestName(codepage, "TO");
  296.  
  297.     log_verbose("\n=========  %s\n", gNuConvTestName);
  298.  
  299.     conv = ucnv_open(codepage, &status);
  300.     if(U_FAILURE(status))
  301.     {
  302.         log_err("Couldn't open converter %s\n",gNuConvTestName);
  303.         return FALSE;
  304.     }
  305.  
  306.     log_verbose("Converter opened..\n");
  307.  
  308.     src = source;
  309.     targ = junkout;
  310.     offs = junokout;
  311.     
  312.     realBufferSize = (sizeof(junkout)/sizeof(junkout[0]));
  313.     realBufferEnd = junkout + realBufferSize;
  314.     realSourceEnd = src + sourcelen;
  315.  
  316.     if ( gOutBufferSize != realBufferSize )
  317.       checkOffsets = FALSE;
  318.  
  319.     if( gInBufferSize != NEW_MAX_BUFFER )
  320.       checkOffsets = FALSE;
  321.  
  322.     do
  323.       {
  324.         end = nct_min( targ + gOutBufferSize, realBufferEnd);
  325.         srcLimit = nct_min(realSourceEnd, src + gInBufferSize);
  326.  
  327.         if(targ == realBufferEnd)
  328.           {
  329.         log_err("Error, the end would overflow the real output buffer while about to call toUnicode! tarjey=%08lx %s",targ,gNuConvTestName);
  330.         return FALSE;
  331.           }
  332.         log_verbose("calling toUnicode @ %08lx to %08lx\n", targ,end);
  333.  
  334.         /* oldTarg = targ; */
  335.  
  336.         status = U_ZERO_ERROR;
  337.  
  338.         ucnv_toUnicode (conv,
  339.                 &targ,
  340.                 end,
  341.                 &src,
  342.                 srcLimit,
  343.                 checkOffsets ? offs : NULL,
  344.                 (srcLimit == realSourceEnd), /* flush if we're at the end of hte source data */
  345.                 &status);
  346.  
  347.         /*        offs += (targ-oldTarg); */
  348.  
  349.       } while ( (status == U_INDEX_OUTOFBOUNDS_ERROR) || (srcLimit < realSourceEnd) ); /* while we just need another buffer */
  350.  
  351.     if(U_FAILURE(status))
  352.     {
  353.         log_err("Problem doing toUnicode, errcode %d %s\n", status, gNuConvTestName);
  354.         return FALSE;
  355.     }
  356.  
  357.     log_verbose("\nConversion done. %d bytes -> %d chars.\nResult :",
  358.         sourcelen, targ-junkout);
  359.     if(VERBOSITY)
  360.     {
  361.         char junk[9999];
  362.         char offset_str[9999];
  363.     
  364.         UChar *p;
  365.         
  366.         junk[0] = 0;
  367.         offset_str[0] = 0;
  368.  
  369.         for(p = junkout;p<targ;p++)
  370.         {
  371.             sprintf(junk + strlen(junk), "0x%04x, ", (0xFFFF) & (unsigned int)*p);
  372.             sprintf(offset_str + strlen(offset_str), "0x%04x, ", (0xFFFF) & (unsigned int)junokout[p-junkout]);
  373.         }
  374.         
  375.         log_verbose(junk);
  376.  
  377.         if ( checkOffsets )
  378.           {
  379.             log_verbose("\nOffsets:");
  380.             log_verbose(offset_str);
  381.           }
  382.         log_verbose("\n");
  383.     }
  384.     ucnv_close(conv);
  385.  
  386.     log_verbose("comparing %d uchars (%d bytes)..\n",expectlen,expectlen*2);
  387.  
  388.     if (checkOffsets && (expectOffsets != 0))
  389.     {
  390.         if(memcmp(junokout,expectOffsets,(targ-junkout) * sizeof(int32_t)))
  391.             log_err("did not get the expected offsets. %s",gNuConvTestName);
  392.     }
  393.  
  394.     if(!memcmp(junkout, expect, expectlen*2))
  395.     {
  396.         log_verbose("Matches!\n");
  397.         return TRUE;
  398.     }
  399.     else
  400.     {    
  401.         log_err("String does not match. %s\n", gNuConvTestName);
  402.         printUSeq(expect, expectlen); 
  403.         return FALSE;
  404.     }
  405. }
  406.  
  407.  
  408. void TestNewConvertWithBufferSizes(int32_t outsize, int32_t insize ) 
  409. {
  410. /** test chars #1 */
  411.     /*  1 2 3  1Han 2Han 3Han .  */
  412.     UChar    sampleText[] = 
  413.      { 0x0031, 0x0032, 0x0033, 0x4e00, 0x4e8c, 0x4e09, 0x002E     };
  414.  
  415.     int32_t fmUTF8Offs[] = 
  416.      { 0x0000, 0x0001, 0x0002, 0x0003, 0x0006, 0x0009, 0x000c };
  417.  
  418.     int32_t fmISO2022Offs[] = 
  419.      { 0x03, 0x04, 0x05, 0x06, 0x09, 0x0c, 0x0f }; /* is this right? */
  420.  
  421.     int32_t fmIBM930Offs[] = 
  422.      { 0x0000, 0x0001, 0x0002, 0x0004, 0x0006, 0x0008, 0x000b,    };
  423.  
  424.     int32_t fmIBM943Offs[] = 
  425.      { 0x0000, 0x0001, 0x0002, 0x0003, 0x0005, 0x0007, 0x0009,  };
  426.  
  427.     int32_t fmUTF16LEOffs[] = 
  428.      { 0x0000, 0x0002, 0x0004, 0x0006, 0x0008, 0x000a, 0x000c,  }; 
  429.     
  430.     const char expectedUTF8[] = 
  431.      { (char)0x31, (char)0x32, (char)0x33, (char)0xe4, (char)0xb8, (char)0x80, (char)0xe4, (char)0xba, (char)0x8c, (char)0xe4, (char)0xb8, (char)0x89, (char)0x2E };
  432.  
  433.     int32_t  toUTF8Offs[] = 
  434.      { (char)0x00, (char)0x01, (char)0x02, (char)0x03, (char)0x03, (char)0x03, (char)0x04, (char)0x04, (char)0x04, (char)0x05, (char)0x05, (char)0x05, (char)0x06   };
  435.  
  436.     /* Same as UTF8, but with ^[%B preceeding */
  437.     const char expectedISO2022[] = 
  438.      { (char)0x1b, (char)0x25, (char)0x42, (char)0x31, (char)0x32, (char)0x33, (char)0xe4, (char)0xb8, (char)0x80, (char)0xe4, (char)0xba, (char)0x8c, (char)0xe4, (char)0xb8, (char)0x89, (char)0x2E };
  439.  
  440.     int32_t  toISO2022Offs[]     = 
  441.      { (char)0xff, (char)0xff, (char)0xff, (char)0x00, (char)0x01, (char)0x02, (char)0x03, (char)0x03, (char)0x03, 
  442.        (char)0x04, (char)0x04, (char)0x04, (char)0x05, (char)0x05, (char)0x05, (char)0x06 }; /* right? */
  443.     
  444.     /*  1 2 3 <SO> h1 h2 h3 <SI> . */
  445.     const char expectedIBM930[] = 
  446.      { (char)0xF1, (char)0xF2, (char)0xF3, (char)0x0E, (char)0x45, (char)0x41, (char)0x45, (char)0x42, (char)0x45, (char)0x43, (char)0x0F, (char)0x4B };
  447.  
  448.     int32_t  toIBM930Offs[] = 
  449.      { (char)0x00, (char)0x01, (char)0x02, (char)0x03, (char)0x03, (char)0x03, (char)0x04, (char)0x04, (char)0x05, (char)0x05, (char)0x06, (char)0x06, };
  450.  
  451.     /* 1 2 3 <?> <?> <?> . */
  452.     const char expectedISO88593[] = 
  453.      { (char)0x31, (char)0x32, (char)0x33, (char)0x1a, (char)0x1a, (char)0x1a, (char)0x2E };
  454.  
  455.     int32_t  toISO88593Offs[]     = 
  456.      {(char) 0x00, (char)0x01, (char)0x02, (char)0x03, (char)0x04, (char)0x05, (char)0x06, };
  457.  
  458.     /* 1 2 3 h1 h2 h3 . */
  459.     const char expectedIBM943[] = 
  460.      {  (char)0x31, (char)0x32, (char)0x33, (char)0x88, (char)0xea, (char)0x93, (char)0xf1, (char)0x8e, (char)0x4f, (char)0x2e };
  461.  
  462.     int32_t  toIBM943Offs    [] = 
  463.      {  (char)0x00, (char)0x01, (char)0x02, (char)0x03, (char)0x03, (char)0x04, (char)0x04, (char)0x05, (char)0x05, (char)0x06,  };
  464.  
  465.     /*  etc */
  466.     const char expectedUTF16LE[] = 
  467.      { (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 };
  468.     int32_t      toUTF16LEOffs[]=  
  469.      { (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, };
  470.  
  471.  
  472. /** Test chars #2  NOT USED YET**/
  473.  
  474.     /* Sahha [health],  slashed h's */
  475.     const UChar malteseUChars[] = { 0x0053, 0x0061, 0x0127, 0x0127, 0x0061 };
  476.     const char  maltesechars[]  = { '\0' };
  477.     /*********************************** START OF CODE finally *************/
  478.  
  479.   gInBufferSize = insize;
  480.   gOutBufferSize = outsize;
  481.  
  482.   log_verbose("\n\n\nTesting conversions with InputBufferSize = %d, OutputBufferSize = %d\n", gInBufferSize, gOutBufferSize);
  483.  
  484.     
  485. #if 0
  486.     if(!testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
  487.             expectedUTF8, sizeof(expectedUTF8), "UTF8", toUTF8Offs ))
  488.         log_err("u-> UTF8 did not match.\n");
  489.  
  490.     if(!testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
  491.             expectedISO2022, sizeof(expectedISO2022), "iso-2022", toISO2022Offs ))
  492.         log_err("u-> iso-2022 did not match.\n");
  493.  
  494.     if(!testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
  495.             expectedIBM930, sizeof(expectedIBM930), "ibm-930", toIBM930Offs ))
  496.         log_err("u-> ibm-930 did not match.\n");
  497.  
  498.     if(!testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
  499.             expectedISO88593, sizeof(expectedISO88593), "iso-8859-3", toISO88593Offs ))
  500.         log_err("u-> iso-8859-3 did not match.\n");
  501.  
  502.     if(!testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
  503.             expectedIBM943, sizeof(expectedIBM943), "ibm-943", toIBM943Offs ))
  504.         log_err("u-> ibm-943 [UCNV_MBCS] not match.\n");
  505.  
  506.     if(!testConvertFromU(sampleText, sizeof(sampleText)/sizeof(sampleText[0]),
  507.             expectedUTF16LE, sizeof(expectedUTF16LE), "utf-16le", toUTF16LEOffs ))
  508.         log_err("u-> utf-16le did not match.\n");
  509.  
  510. /****/
  511. #endif
  512.     if(!testConvertToU(expectedUTF8, sizeof(expectedUTF8),
  513.                sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf8", fmUTF8Offs ))
  514.       log_err("utf8 -> u did not match\n");
  515.  
  516.     if(!testConvertToU(expectedISO2022, sizeof(expectedISO2022),
  517.                sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "iso-2022", fmISO2022Offs ))
  518.     
  519.         log_err("iso-2022  -> u  did not match");
  520.  
  521. #if 0
  522.     if(!testConvertToU(expectedIBM930, sizeof(expectedIBM930),
  523.                sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "ibm-930", fmIBM930Offs ))
  524.       log_err("ibm-930  -> u  did not match");
  525.  
  526.     if(!testConvertToU(expectedIBM943, sizeof(expectedIBM943),
  527.                sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "ibm-943", fmIBM943Offs ))
  528.       log_err("ibm-943 -> u  did not match");
  529.  
  530.     if(!testConvertToU(expectedUTF16LE, sizeof(expectedUTF16LE),
  531.                sampleText, sizeof(sampleText)/sizeof(sampleText[0]), "utf-16le", fmUTF16LEOffs ))
  532.       log_err("utf-16le -> u  did not match");
  533. #endif
  534. }
  535.  
  536. void TestConverterTypesAndStarters()
  537. {
  538.     UConverter* myConverter[3];
  539.     UErrorCode err = U_ZERO_ERROR;
  540.     bool_t mystarters[256];
  541.     int i;
  542.     
  543.     const bool_t expectedKSCstarters[256] = {
  544.         FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
  545.         FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
  546.         FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
  547.         FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
  548.         FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
  549.         FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
  550.         FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
  551.         FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
  552.         FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
  553.         FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
  554.         FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
  555.         FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
  556.         FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
  557.         FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
  558.         FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
  559.         TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
  560.         TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
  561.         TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE,
  562.         TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
  563.         TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
  564.         TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
  565.         TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
  566.         TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
  567.         TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
  568.         TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
  569.         TRUE, TRUE, TRUE, TRUE, TRUE, TRUE};
  570.  
  571.  
  572.   log_verbose("Testing KSC, ibm-930, ibm-878  for starters and their conversion types.");
  573.  
  574.     myConverter[0] = ucnv_open("ksc", &err);
  575.     if (U_FAILURE(err)) log_err("Failed to create an ibm-949 converter\n");
  576.     myConverter[1] = ucnv_open("ibm-930", &err);
  577.     if (U_FAILURE(err)) log_err("Failed to create an ibm-930 converter\n");
  578.     myConverter[2] = ucnv_open("ibm-878", &err);
  579.     if (U_FAILURE(err)) log_err("Failed to create an ibm-815 converter\n");
  580.  
  581.     if (ucnv_getType(myConverter[0])!=UCNV_MBCS) log_err("ucnv_getType Failed for ibm-949\n");
  582.     else log_verbose("ucnv_getType ibm-949 ok\n");
  583.     if (ucnv_getType(myConverter[1])!=UCNV_EBCDIC_STATEFUL) log_err("ucnv_getType Failed for ibm-930\n");
  584.     else log_verbose("ucnv_getType ibm-930 ok\n");
  585.     if (ucnv_getType(myConverter[2])!=UCNV_SBCS) log_err("ucnv_getType Failed for ibm-815\n");
  586.     else log_verbose("ucnv_getType ibm-815 ok\n");
  587.  
  588.  
  589.     ucnv_getStarters(myConverter[0], mystarters, &err);
  590.     /*if (memcmp(expectedKSCstarters, mystarters, sizeof(expectedKSCstarters)))
  591.         log_err("Failed ucnv_getStarters for ksc\n");
  592.     else
  593.         log_verbose("ucnv_getStarters ok\n");*/
  594.     
  595.     ucnv_close(myConverter[0]);
  596.     ucnv_close(myConverter[1]);
  597.     ucnv_close(myConverter[2]);
  598. }
  599.