| 1 |
#ifdef RCSID |
| 2 |
static char RCSid[] = |
| 3 |
"$Header: d:/cvsroot/tads/tads3/test/test_utf8.cpp,v 1.2 1999/05/17 02:52:31 MJRoberts Exp $"; |
| 4 |
#endif |
| 5 |
|
| 6 |
/* |
| 7 |
* Copyright (c) 1998, 2002 Michael J. Roberts. All Rights Reserved. |
| 8 |
* |
| 9 |
* Please see the accompanying license file, LICENSE.TXT, for information |
| 10 |
* on using and copying this software. |
| 11 |
*/ |
| 12 |
/* |
| 13 |
Name |
| 14 |
test_utf8.cpp - test for UTF8 class |
| 15 |
Function |
| 16 |
|
| 17 |
Notes |
| 18 |
|
| 19 |
Modified |
| 20 |
10/16/98 MJRoberts - Creation |
| 21 |
*/ |
| 22 |
|
| 23 |
#include <stdlib.h> |
| 24 |
#include <stdio.h> |
| 25 |
|
| 26 |
#include "utf8.h" |
| 27 |
#include "t3test.h" |
| 28 |
|
| 29 |
int main() |
| 30 |
{ |
| 31 |
static wchar_t test1[] = |
| 32 |
{ |
| 33 |
0x0010, 0x0020, 0x0030, 0x0040, 0x0050, 0x0060, 0x0070, 0x007f, |
| 34 |
0x0080, 0x0100, 0x0200, 0x0400, 0x0500, 0x0600, 0x0700, 0x07ff, |
| 35 |
0x0800, 0x1000, 0x2000, 0x4000, 0x8000, 0xA000, 0xF000, 0xFFFF, |
| 36 |
0 |
| 37 |
}; |
| 38 |
wchar_t *wp; |
| 39 |
char buf[256]; |
| 40 |
utf8_ptr p; |
| 41 |
size_t len; |
| 42 |
size_t i; |
| 43 |
wchar_t ch; |
| 44 |
|
| 45 |
/* initialize for testing */ |
| 46 |
test_init(); |
| 47 |
|
| 48 |
/* encode the test string */ |
| 49 |
p.set(buf); |
| 50 |
p.setwcharsz(test1, sizeof(buf)); |
| 51 |
|
| 52 |
/* go back to the start of the buffer */ |
| 53 |
p.set(buf); |
| 54 |
|
| 55 |
/* compute the length */ |
| 56 |
len = p.lenz(); |
| 57 |
printf("test1: len = %lu - %s\n", |
| 58 |
(unsigned long)len, |
| 59 |
(len == sizeof(test1)/sizeof(test1[0]) - 1) ? "ok" : "ERROR"); |
| 60 |
|
| 61 |
/* |
| 62 |
* run through the string, decode characters, and compare the |
| 63 |
* results to the original |
| 64 |
*/ |
| 65 |
printf("-- incrementing --\n"); |
| 66 |
for (i = 0, wp = test1 ; i < len ; p.inc(), ++wp, ++i) |
| 67 |
{ |
| 68 |
/* decode the current character */ |
| 69 |
ch = p.getch(); |
| 70 |
|
| 71 |
/* check it */ |
| 72 |
printf("ch[%lu] = %04x - %s\n", |
| 73 |
(unsigned long)i, ch, (ch == *wp ? "ok" : "ERROR")); |
| 74 |
} |
| 75 |
|
| 76 |
/* go backwards through the buffer */ |
| 77 |
printf("-- decrementing --\n"); |
| 78 |
do |
| 79 |
{ |
| 80 |
/* move back one character */ |
| 81 |
--wp; |
| 82 |
p.dec(); |
| 83 |
--i; |
| 84 |
|
| 85 |
/* decode the current character */ |
| 86 |
ch = p.getch(); |
| 87 |
|
| 88 |
/* check it */ |
| 89 |
printf("ch[%lu] = %04x - %s\n", |
| 90 |
(unsigned long)i, ch, (ch == *wp ? "ok" : "ERROR")); |
| 91 |
} while (i != 0); |
| 92 |
|
| 93 |
/* success */ |
| 94 |
return 0; |
| 95 |
} |
| 96 |
|