home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / test / intltest / cppcnvt.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  19.8 KB  |  556 lines

  1. /*Bertrand A. DAMIBA -> damiba@us.ibm.com*/
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <ctype.h>
  7. #include "locid.h"
  8. #include "unistr.h"
  9. #include "convert.h"
  10. #include "ucnv_err.h"
  11. #include <iostream.h>
  12. #include "cppcnvt.h"
  13.  
  14. #define NUM_CODEPAGE 1
  15. #define MAX_FILE_LEN 1024*20
  16. #define UCS_FILE_NAME_SIZE 100
  17.  
  18. /*writes and entire UnicodeString along with a BOM to a file*/
  19. void WriteToFile(const UnicodeString *a, FILE *myfile); 
  20. /*Case insensitive compare*/
  21. int32_t strCaseIcmp(const char* a1,const char * a2); 
  22. /*returns an action other than the one provided*/
  23. UConverterFromUCallback otherUnicodeAction(UConverterFromUCallback MIA);
  24. UConverterToUCallback otherCharAction(UConverterToUCallback MIA);
  25. /*Asciifies the UErrorCodes*/
  26. #define myErrorName(errorCode) errorName(errorCode)
  27.  
  28. void ConvertTest::runIndexedTest( int32_t index, bool_t exec, char* &name, char* par )
  29. {
  30.     if (exec) logln("TestSuite ConvertTest: ");
  31.     switch (index) {
  32.         case 0: name = "TestConvert"; if (exec) TestConvert(); break;
  33.         default: name = ""; break; //needed to end loop
  34.     }
  35. }
  36.  
  37. void ConvertTest::TestConvert() 
  38. {
  39.     char                subchar [4]         =   {(char)0xBE, (char)0xEF};
  40.     char                myptr[4];
  41.     char                save[4];
  42.     int32_t             testLong1;
  43.     int16_t             rest                =   0;
  44.     FILE*               f                   =   NULL;
  45.     FILE*               f2                  =   NULL;
  46.     int32_t             uniLen              =   0;
  47.     int32_t             len                 =   0;
  48.     int32_t             x                   =   0;
  49.     FILE*               ucs_file_in         =   NULL;
  50.     UChar             BOM                 =   0x0000;
  51.     UChar             myUChar           =   0x0000;
  52.     char                myChar              =   0x00;
  53.     char                mytarget[MAX_FILE_LEN];
  54.     char*               mytarget_1 = mytarget;
  55.     char*               mytarget_use        = mytarget;
  56.     UChar*            consumedUni         =   NULL;
  57.     char*               consumedChar        =   NULL;
  58.     char*               consumed            =   NULL;
  59.     char                output_cp_buffer    [MAX_FILE_LEN];
  60.     UChar             ucs_file_buffer     [MAX_FILE_LEN];
  61.     UChar*            ucs_file_buffer_use = ucs_file_buffer;
  62.     UChar             my_ucs_file_buffer  [MAX_FILE_LEN];
  63.     UChar*            my_ucs_file_buffer_1 = my_ucs_file_buffer;
  64.     int32_t             i                   =   0;
  65.     int8_t             ii                  =   0;
  66.     uint16_t            ij                  =   0;
  67.     int32_t             j                   =   0;
  68.     int32_t             k                   =   0;
  69.     uint16_t            codepage_index      =   0;
  70.     int32_t             cp                  =   0;
  71.     UErrorCode           err                 =   U_ZERO_ERROR;
  72.     const char* const*  available_conv      =   NULL;
  73.     char       ucs_file_name[UCS_FILE_NAME_SIZE];
  74.     UConverterFromUCallback          MIA1;
  75.     UConverterToUCallback MIA2;
  76.     UChar             myUnitarget[MAX_FILE_LEN];
  77.     UChar             *myUnitarget_1 = myUnitarget;
  78.     UnicodeConverterCPP* someConverters[5];
  79.     /******************************************************************
  80.                                 Checking Unicode -> ksc
  81.      ******************************************************************/
  82.  
  83.     const char*      CodePagesToTest[NUM_CODEPAGE]       =
  84.     {
  85.        "IBM-949"
  86.  
  87.         
  88.     }; 
  89.     const uint16_t CodePageNumberToTest[NUM_CODEPAGE]             =
  90.     {
  91.         949
  92.     };
  93.     
  94.  
  95.     const int32_t        CodePagesAsciiControls[NUM_CODEPAGE]    =
  96.     { 
  97.         0xFFFFFFFF
  98.             
  99.     
  100.     };
  101.  
  102.     const int32_t        CodePagesOtherControls[NUM_CODEPAGE]    =
  103.     {
  104.          0x00000005
  105.     };
  106.  
  107.  
  108.     const int8_t     CodePagesMinChars[NUM_CODEPAGE] =
  109.     { 
  110.         1
  111.     
  112.     };
  113.  
  114.     const int8_t     CodePagesMaxChars[NUM_CODEPAGE] =
  115.     { 
  116.         2
  117.     
  118.     };
  119.  
  120.     const int16_t        CodePagesSubstitutionChars[NUM_CODEPAGE]    =
  121.     { 
  122.         (int16_t)0xAFFE
  123.     
  124.     };
  125.  
  126.     const char* CodePagesTestFiles[NUM_CODEPAGE]    =
  127.     { 
  128.         "uni-text.txt" 
  129.     };
  130.  
  131.     
  132.     const UConverterPlatform        CodePagesPlatform[NUM_CODEPAGE]    =
  133.     { 
  134.         UCNV_IBM
  135.     
  136.     };
  137.  
  138.     const UConverterToUCallback CodePagesMissingCharAction[NUM_CODEPAGE] =
  139.     {
  140.         UCNV_TO_U_CALLBACK_SUBSTITUTE
  141.     };
  142.     
  143.     const UConverterFromUCallback CodePagesMissingUnicodeAction[NUM_CODEPAGE] =
  144.     {
  145.       UCNV_FROM_U_CALLBACK_SUBSTITUTE
  146.     };
  147.  
  148.     const Locale CodePagesLocale[NUM_CODEPAGE] =
  149.     {
  150.         Locale::KOREAN
  151.     };
  152.  
  153.     UChar CodePagesFlakySequence[NUM_CODEPAGE][20] =
  154.     {
  155.         {(UChar)0xAC10,(UChar)0xAC11, (UChar)0xAC12, (UChar)0xAC13 , (UChar)0xAC14, (UChar)0xAC15, (UChar)0xAC16, (UChar)0xAC17, (UChar)0xd7a4 /*Offensive Codepoint*/, (UChar)0xAC14, (UChar)0xAC15}
  156.     };
  157.     
  158.     char CodePagesFlakyCharSequence[NUM_CODEPAGE][20] =
  159.     {
  160.         {   (char)0xB0, (char)0xA8,
  161.             (char)0xB0, (char)0xA9,
  162.             (char)0xB0, (char)0xAA,
  163.             (char)0xB0, (char)0xAB,
  164.             (char)0xb0, (char)0xff,/*Offensive Codepoint*/
  165.             (char)0xB0, (char)0xAC,
  166.             (char)0xB0, (char)0xAD
  167.         }
  168.     };
  169.     /*Calling all the UnicodeConverterCPP API and checking functionality*/
  170.   
  171.         /*Tests UnicodeConverterCPP::getAvailableNames*/
  172.     logln("\n---Testing UnicodeConverterCPP::getAvailableNames...");
  173.     available_conv = UnicodeConverterCPP::getAvailableNames(testLong1, err);
  174.  
  175.     if (U_FAILURE(err)) 
  176.     {
  177.         errln("Error getting Available names!");
  178.         exit(0);
  179.     }
  180.     logln("Number of available Codepages:\t" + testLong1);
  181.     while (testLong1--) logln((UnicodeString)"\t\t[" + available_conv[testLong1] + (UnicodeString)"]");
  182.  
  183.      
  184.  
  185.     someConverters[0] = new UnicodeConverterCPP("ibm-949",err);
  186.     if (U_FAILURE(err)) errln ((UnicodeString)"FAILURE! " + myErrorName(err));
  187.     someConverters[1] = new UnicodeConverterCPP("ibm-949",err);
  188.     if (U_FAILURE(err)) errln ((UnicodeString)"FAILURE! " + myErrorName(err));
  189.     someConverters[2] = new UnicodeConverterCPP("ibm-949",err);
  190.     if (U_FAILURE(err)) errln ((UnicodeString)"FAILURE! " + myErrorName(err));
  191.     someConverters[3] = new UnicodeConverterCPP("ibm-834", err);
  192.     if (U_FAILURE(err)) errln ((UnicodeString)"FAILURE! " + myErrorName(err));
  193.     someConverters[4] = new UnicodeConverterCPP("ibm-943", err);
  194.     if (U_FAILURE(err)) errln ((UnicodeString)"FAILURE! " + myErrorName(err));
  195.    
  196.     logln("\n---Testing UnicodeConverterCPP::flushCache...");
  197.     if (UnicodeConverterCPP::flushCache()==0) logln("Flush cache ok");
  198.     else errln("Flush Cache failed");
  199.     
  200.     delete someConverters[0];
  201.     delete someConverters[1];
  202.     delete someConverters[2];
  203.     delete someConverters[3];
  204.     if (j=UnicodeConverterCPP::flushCache()==2) logln("Flush cache ok");
  205.     else errln("Flush Cache failed");
  206.     
  207.     delete someConverters[4];
  208.     if (UnicodeConverterCPP::flushCache()==1) logln("Flush cache ok");
  209.     else errln("Flush Cache failed");
  210.  
  211.     logln("\n---Testing UnicodeConverterCPP::UnicodeConverterCPP()...");
  212.     someConverters[0] = new UnicodeConverterCPP;
  213.     someConverters[1] = new UnicodeConverterCPP;
  214.     someConverters[2] = new UnicodeConverterCPP("utf8", err);
  215.     if (U_FAILURE(err)) errln ((UnicodeString)"FAILURE! " + err);
  216. #ifdef WIN32   
  217.     if ((strcmp(someConverters[1]->getName(err),"IBM-1252")==0)&&
  218.     (strcmp(someConverters[0]->getName(err),"IBM-1252")==0))
  219.       logln("getName ok");
  220.     else errln("getName failed");
  221.     logln(someConverters[1]->getName(err));
  222. #else
  223.     if ((strcmp(someConverters[1]->getName(err),"LATIN_1")==0)&&
  224.     (strcmp(someConverters[0]->getName(err),"LATIN_1")==0))
  225.       logln("getName ok");
  226.     else errln("getName failed");
  227.     logln(someConverters[1]->getName(err));
  228. #endif
  229.     logln("\n---Testing UnicodeConverterCPP::operator==...");
  230.     if (((*someConverters[1] == *someConverters[0])==TRUE)&&
  231.     (*someConverters[1] == *someConverters[2])==FALSE)
  232.       logln("Equality test ok");
  233.     else errln("Equality test failed");
  234.     
  235.     logln("\n---Testing UnicodeConverterCPP::operator!=...");
  236.     if (((*someConverters[1] != *someConverters[0])==FALSE)&&
  237.     (*someConverters[1] != *someConverters[2])==TRUE)
  238.       logln("Not Equal test ok");
  239.     else errln("Not Equal test failed");
  240.     
  241.     logln("\n---Testing UnicodeConverterCPP::operator=...");
  242.     someConverters[3] = new UnicodeConverterCPP;
  243.     *someConverters[3] = *someConverters[2];
  244.     if ((*someConverters[2] == *someConverters[3]))
  245.       logln("Equality test ok");
  246.     else errln("Equality test failed");
  247.    
  248.     delete someConverters[0];
  249.     delete someConverters[1];
  250.     delete someConverters[2];
  251.     delete someConverters[3];
  252.  
  253.     for (codepage_index=0; codepage_index <  NUM_CODEPAGE; codepage_index++)
  254.     {
  255.         i = 0;  
  256.     strcpy(ucs_file_name, IntlTest::getTestDirectory());
  257.     strcat(ucs_file_name, CodePagesTestFiles[codepage_index]);
  258.  
  259.     ucs_file_in = fopen(ucs_file_name, "rb");
  260.         if (!ucs_file_in) 
  261.         {
  262.             errln("Couldn't open the Unicode file...");
  263.             exit(0);
  264.         }
  265.  
  266.         /*Creates a converter*/
  267.  
  268.     UnicodeConverterCPP* myConverter = new UnicodeConverterCPP(CodePageNumberToTest[codepage_index],UCNV_IBM, err);
  269.     
  270.         if (!myConverter)   
  271.         {
  272.             errln("Error Creating the converter from " + (UnicodeString)CodePagesToTest[codepage_index] + " codepage.\nMake sure you have ran the uconvdef tool to create " + (UnicodeString)CodePagesToTest[codepage_index] + ".cnv in the locales directory"); 
  273.             exit(0);
  274.         }
  275.  
  276.     
  277.         /*Tests getMaxBytesPerChar and getMinBytesPerChar*/
  278.     logln("\n---Testing UnicodeConverterCPP::getMaxBytesPerChar...");
  279.     if (myConverter->getMaxBytesPerChar()==CodePagesMaxChars[codepage_index])  logln("Max byte per character OK");
  280.     else errln("Max byte per character failed");
  281.     
  282.     logln("\n---Testing UnicodeConverterCPP::getMinBytesPerChar...");
  283.     if (myConverter->getMinBytesPerChar()==CodePagesMinChars[codepage_index])  logln("Min byte per character OK");
  284.     else errln("Min byte per character failed");
  285.       
  286.  
  287.         /*getSubstitutions char*/
  288.     logln("\n---Testing UnicodeConverterCPP::getSubstitutionChars...");
  289.     ii=4;
  290.     myConverter->getSubstitutionChars(myptr,ii,err);
  291.    
  292.     for(x=0;x<ii;x++) rest = ((unsigned char)rest << 8) + (unsigned char)myptr[x];
  293.     if (rest==CodePagesSubstitutionChars[codepage_index])   logln("Substitution character ok");
  294.     else errln("Substitution character failed.");
  295.     
  296.     
  297.     
  298.     logln("\n---Testing UnicodeConverterCPP::setSubstitutionChars RoundTrip Test ...");
  299.     myConverter->setSubstitutionChars(myptr, ii, err);
  300.     if (U_FAILURE(err)) errln ("FAILURE! " + (UnicodeString)myErrorName(err));
  301.     myConverter->getSubstitutionChars(save, ii, err);
  302.     if (U_FAILURE(err)) errln ("FAILURE! " + (UnicodeString)myErrorName(err));
  303.     if (strncmp(save, myptr, ii)) errln("Saved substitution character failed");
  304.     else logln("Saved substitution character ok");
  305.     
  306.     /*resetState*/
  307.     logln("\n---Testing UnicodeConverterCPP::resetState...");
  308.     myConverter->resetState();
  309.     
  310.     
  311.     /*getName*/
  312.     UnicodeString* testUnistr          =   new UnicodeString();
  313.     logln("\n---Testing UnicodeConverterCPP::getName...");
  314.     if (strCaseIcmp(myConverter->getName(err),
  315.             CodePagesToTest[codepage_index])) errln("getName failed");
  316.     else logln("getName ok");
  317.     
  318.     /*getDisplayName*/
  319.     testUnistr->remove();
  320.     logln("\n---Testing UnicodeConverterCPP::getDisplayName...");
  321.     myConverter->getDisplayName(CodePagesLocale[codepage_index],*testUnistr);
  322.  
  323.     /*printUChar(T_UnicodeString_getUChars(testUnistr));
  324.     logln("\nAbove is DisplayName!!");*/
  325.     
  326.  
  327.         /*getMissingUnicodeAction*/
  328.     /*    logln("\n---Testing UnicodeConverterCPP::getMissingUnicodeAction...");
  329.     if ((MIA1 = myConverter->getMissingUnicodeAction()) != CodePagesMissingUnicodeAction[codepage_index]) errln("Missing action failed");
  330.     else logln("Missing action ok");*/
  331.  
  332.  
  333.  
  334.         /*getMissingCharAction*/
  335.     /*    logln("\n---Testing UnicodeConverterCPP::getMissingCharAction...");
  336.     if ((MIA2 = myConverter->getMissingCharAction()) != CodePagesMissingCharAction[codepage_index]) errln("Missing action failed");
  337.     else logln("Missing action ok");*/
  338.  
  339.     MIA1 = myConverter->getMissingUnicodeAction();
  340.     MIA2 = myConverter->getMissingCharAction();
  341.  
  342.         /*setMissingUnicodeAction*/
  343.     logln("\n---Testing UnicodeConverterCPP::setMissingUnicodeAction...");
  344.     myConverter->setMissingUnicodeAction(otherUnicodeAction(MIA1),err);
  345.     if (U_FAILURE(err)) errln ("FAILURE! " + (UnicodeString)myErrorName(err));    
  346.     if (myConverter->getMissingUnicodeAction() != otherUnicodeAction(MIA1)) logln("Missing action failed");
  347.     else logln("Missing action ok");
  348.  
  349.  
  350.     logln("\n---Testing UnicodeConverterCPP::setMissingUnicodeAction Roundtrip...");
  351.     myConverter->setMissingUnicodeAction(MIA1, err);
  352.     if (U_FAILURE(err)) errln ("FAILURE! " + (UnicodeString)myErrorName(err));    
  353.     if (myConverter->getMissingUnicodeAction() != MIA1) errln("Missing action failed");
  354.     else logln("Missing action ok");
  355.  
  356.  
  357.         /*setMissingCharAction*/
  358.     logln("\n---Testing UnicodeConverterCPP::setMissingCharAction...");
  359.     myConverter->setMissingCharAction(otherCharAction(MIA2),err);
  360.     if (U_FAILURE(err)) errln ("FAILURE! " + (UnicodeString)myErrorName(err));
  361.     if (myConverter->getMissingCharAction() != otherCharAction(MIA2)) errln("Missing action failed");
  362.     else logln("Missing action ok");
  363.     
  364.     logln("\n---Testing UnicodeConverterCPP::setMissingCharAction Roundtrip...");
  365.     myConverter->setMissingCharAction(MIA2, err);
  366.     if (U_FAILURE(err)) errln ("FAILURE! " + (UnicodeString)myErrorName(err));    
  367.     if (myConverter->getMissingCharAction() != MIA2) errln("Missing action failed");
  368.     else logln("Missing action ok");
  369.  
  370.  
  371.         /*getCodepage*/
  372.     logln("\n---Testing UnicodeConverterCPP::getCodepage...");
  373.     cp =    myConverter->getCodepage(err);
  374.     if (U_FAILURE(err)) errln ("FAILURE! " + (UnicodeString)myErrorName(err));    
  375.     if (cp != CodePageNumberToTest[codepage_index]) errln("Codepage number test failed");
  376.     else logln("Codepage number test OK");
  377.     
  378.  
  379.     
  380.         /*getCodepagePlatform*/
  381.     logln("\n---Testing UnicodeConverterCPP::getCodepagePlatform ...");
  382.     if (CodePagesPlatform[codepage_index]!=myConverter->getCodepagePlatform(err)) errln("Platform codepage test failed");
  383.     else logln("Platform codepage test ok");
  384.     if (U_FAILURE(err)) errln ("FAILURE! " + (UnicodeString)myErrorName(err));  
  385.  
  386.  
  387.         /*Reads the BOM*/
  388.         fread(&BOM, sizeof(UChar), 1, ucs_file_in);
  389.         if (BOM!=0xFEFF && BOM!=0xFFFE) 
  390.           {
  391.             errln("File Missing BOM...Bailing!");
  392.             exit(0);
  393.           }
  394.  
  395.         
  396.         /*Reads in the file*/
  397.      while(!feof(ucs_file_in)&&(i+=fread(ucs_file_buffer+i, sizeof(UChar), 1, ucs_file_in)))
  398.         {
  399.             myUChar = ucs_file_buffer[i-1];
  400.             
  401.             ucs_file_buffer[i-1] = (BOM==0xFEFF)?myUChar:((myUChar >> 8) | (myUChar << 8)); /*adjust if BIG_ENDIAN*/
  402.         }
  403.  
  404.       myUChar = ucs_file_buffer[i-1];
  405.       ucs_file_buffer[i-1] = (BOM==0xFEFF)?myUChar:((myUChar >> 8) | (myUChar << 8)); /*adjust if BIG_ENDIAN Corner Case*/
  406.  
  407.       UnicodeString* uniString  = new UnicodeString(ucs_file_buffer,i);
  408.       UnicodeString* uniString3 = new UnicodeString(ucs_file_buffer,i);
  409.       UnicodeString* uniString2 = new UnicodeString();
  410.     
  411.     
  412.         /*Calls the Conversion Routine*/
  413.         
  414.         testLong1 = MAX_FILE_LEN;
  415.  
  416.         logln("\n---Testing UnicodeConverterCPP::fromUnicodeString");
  417.         myConverter->fromUnicodeString(output_cp_buffer, testLong1, *uniString, err);
  418.         if (U_FAILURE(err))   logln("\nFAILURE...");
  419.  
  420.         
  421.         
  422.  
  423.             /******************************************************************
  424.                                     Checking ksc -> Unicode
  425.             ******************************************************************/
  426.  
  427.         /*Clean up re-usable vars*/
  428.         j=0;
  429.     
  430.     
  431.         /*Calls the Conversion Routine*/
  432.         /*Uni1 ----ToUnicodeString----> Cp1 ----FromUnicodeString---->Uni2*/
  433.  
  434.         logln("\n---Testing UnicodeConverterCPP::toUnicodeString");
  435.         myConverter->toUnicodeString(*uniString2 , output_cp_buffer, testLong1,  err);
  436.  
  437.         if (U_FAILURE(err))   logln ("FAILURE! " + (UnicodeString)myErrorName(err));
  438.  
  439.  
  440.  
  441.     logln("\n---Testing UnicodeString RoundTrip ...");
  442.    
  443.     /*check if Uni1 == Uni2*/
  444.     if (uniString->compare(*uniString2)) errln("Equality check test failed");
  445.     else logln("Equality check test ok");
  446.  
  447.     /*AIX Compiler hacks*/
  448.     const UChar* tmp_ucs_buf = ucs_file_buffer_use; 
  449.     const UChar* tmp_consumedUni = NULL;
  450.  
  451.     myConverter->fromUnicode(mytarget_1,
  452.                  mytarget + MAX_FILE_LEN,
  453.                  tmp_ucs_buf,
  454.                  ucs_file_buffer_use+i,
  455.                  NULL,
  456.                  TRUE,
  457.                  err);
  458.     //    consumedUni = (UChar*)tmp_consumedUni;
  459.     
  460.     if (U_FAILURE(err)) errln ("FAILURE! " + (UnicodeString)myErrorName(err));
  461.     
  462.     /*Uni1 ----ToUnicode----> Cp2 ----FromUnicode---->Uni3*/
  463.  
  464.         /*AIX Compiler hacks*/
  465.     const char* tmp_mytarget_use = mytarget_use;
  466.     const char* tmp_consumed = consumed;
  467.     myConverter->toUnicode(my_ucs_file_buffer_1,
  468.                my_ucs_file_buffer + MAX_FILE_LEN,
  469.                tmp_mytarget_use,
  470.                mytarget_use+strlen((char*)mytarget_use),
  471.                NULL,
  472.                FALSE,
  473.                err);
  474.         consumed = (char*)tmp_consumed;
  475.     if (U_FAILURE(err)) errln ("FAILURE! " + (UnicodeString)myErrorName(err));
  476.     
  477.     
  478.     logln("\n---Testing UChar* RoundTrip ...");
  479.    // uniString3->remove();
  480.     uniString3->replace(0, uniString3->size(), my_ucs_file_buffer, i);
  481.     //uniString3 = new UnicodeString(my_ucs_file_buffer,i);
  482.     
  483.     /*checks if Uni1 == Uni3*/ 
  484.     if (uniString->compare(*uniString3)) errln("Equality test failed");
  485.     else logln("Equality test ok");
  486.  
  487.     /*checks if Uni2 == Uni3 This is a sanity check for the consistency of the
  488.     UnicodeString and Unicode Convters*/ 
  489.     logln("\n---Testing Consistency between UChar* and UnicodeString Conversion...");
  490.     if (uniString2->compare(*uniString3)) errln("Equality test failed");
  491.     else logln("Equality test ok");
  492.  
  493.     logln("\n---Testing Regression 1100057 ...");
  494.     char mySJIS[12] = {(char)0xFA, (char)0X51, (char)0XB8, (char)0XDB, (char)0XBD, (char)0XCB, (char)0XDB, (char)0XCC, (char)0XDE, (char)0XD0 , (char)0XFA, (char)0X50};
  495.     
  496.  
  497.     UnicodeConverterCPP SJIS(943, UCNV_IBM, err);
  498.     UnicodeString myString;
  499.  
  500.  
  501.     SJIS.toUnicodeString(myString, mySJIS, 12, err);
  502.     if (U_FAILURE(err)||(myString.size()!=10)) errln("toUnicodeString test failed");
  503.     else logln("toUnicodeString test ok");
  504.  
  505.     fclose(ucs_file_in);    
  506.     delete myConverter;
  507. #ifndef WIN32
  508.     delete uniString;
  509.     delete uniString2;
  510.     delete uniString3;
  511.     delete testUnistr;
  512. #endif
  513.   
  514.     }
  515. }
  516.  
  517. void WriteToFile(const UnicodeString *a, FILE *myfile)
  518. {
  519.       uint32_t  size    =   a->size();
  520.       uint16_t  i       =   0;
  521.       UChar   b       =   0xFEFF;
  522.  
  523.      /*Writes the BOM*/
  524.      fwrite(&b, sizeof(UChar), 1, myfile);
  525.      for (i=0; i< size; i++)
  526.      {
  527.          b = (*a)[i];
  528.          fwrite(&b, sizeof(UChar), 1, myfile);
  529.      }
  530.      return;
  531. }
  532.  
  533.      
  534. int32_t strCaseIcmp(const char* a1, const char * a2)
  535. {
  536.     int32_t i=0, ret=0;
  537.     while(a1[i]&&a2[i]) 
  538.     { 
  539.         ret += tolower(a1[i])-tolower(a2[i]); 
  540.         i++;
  541.     }
  542.     return ret;
  543. }
  544.  
  545. UConverterFromUCallback otherUnicodeAction(UConverterFromUCallback MIA)
  546. {
  547.     return (MIA==(UConverterFromUCallback)UCNV_FROM_U_CALLBACK_STOP)?(UConverterFromUCallback)UCNV_FROM_U_CALLBACK_SUBSTITUTE:(UConverterFromUCallback)UCNV_FROM_U_CALLBACK_STOP;
  548. }
  549.  
  550.  
  551. UConverterToUCallback otherCharAction(UConverterToUCallback MIA)
  552.  
  553. {
  554.     return (MIA==(UConverterToUCallback)UCNV_TO_U_CALLBACK_STOP)?(UConverterToUCallback)UCNV_TO_U_CALLBACK_SUBSTITUTE:(UConverterToUCallback)UCNV_TO_U_CALLBACK_STOP;
  555. }
  556.