/* Test driver for thwchar */ #define MAXLINELENGTH 1000 #include #include #include #include static const thchar_t win_sample[] = "¾\x8bÍ»Ù\x86¾Õè»\x82\x9b®\xfc\x80Ø\x90Ø¡íÒ»\x99Ò¡íéÒ»\x99\x9cÒ»\x99Ò \x8c·\x8b Õ¡ç»\x9a"; static const thchar_t mac_sample[] = "¾\x88Í»Ù\x83¾Õè»\x95\x98®\xd8\xb0Ø\xadØ¡íÒ»\x8fÒ¡íéÒ»\x8f\x99Ò»\x8fÒ \x89·\x88 Õ¡ç»\x93"; int main (int argc, char* argv[]) { thchar_t tis_620_0[MAXLINELENGTH]; thchar_t newtis_620_0[MAXLINELENGTH]; thwchar_t uni[MAXLINELENGTH]; int outputLength; const thchar_t *pc; int err = 0; strcpy(tis_620_0,"ÊÇÑÊ´Õ¤ÃѺ ¹Õèà»ç¹¡Ò÷´ÊͺµÑÇàͧ"); fprintf(stderr, "Testing thwchar...\n"); fprintf(stderr, "Input: tis-620-0 string of length %d: %s\n", strlen(tis_620_0), tis_620_0); /* tis-620-0 to Unicode conversion */ outputLength = th_tis2uni_line(tis_620_0, uni, MAXLINELENGTH); fprintf(stderr, "Output: Unicode string of length %d:", wcslen(uni)); /* Unicode to tis-620-0 conversion */ fprintf(stderr, "\nConvert back to tis-620-0 string...\n"); outputLength = th_uni2tis_line(uni, newtis_620_0, MAXLINELENGTH); fprintf(stderr, "Output: tis-620-0 string of length %d: %s\n", strlen(newtis_620_0), newtis_620_0); if (strcmp(newtis_620_0, tis_620_0) == 0) { fprintf(stderr, " Input = output, correct! Test thwchar OK.\n"); } else { fprintf(stderr, " Input != output, incorrect!!\n"); err = 1; } /* Test Unicode <-> Win/Mac extensions */ for (pc = win_sample; *pc; ++pc) { if (th_uni2winthai(th_winthai2uni(*pc)) != *pc) { fprintf(stderr, "Inconsistent uni<->winthai conv: %02x -> %04lx, %02x\n", *pc, th_winthai2uni(*pc), th_uni2winthai(th_winthai2uni(*pc))); err = 1; } } for (pc = mac_sample; *pc; ++pc) { if (th_uni2macthai(th_macthai2uni(*pc)) != *pc) { fprintf(stderr, "Inconsistent uni<->macthai conv: %02x -> %04lx, %02x\n", *pc, th_macthai2uni(*pc), th_uni2macthai(th_macthai2uni(*pc))); err = 1; } } return err; }