1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
/* Test driver for thwchar
*/
#define MAXLINELENGTH 1000
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <thai/thwchar.h>
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;
}
|