]> git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/strtest.cpp
ICU-3.13.tar.gz
[apple/icu.git] / icuSources / test / intltest / strtest.cpp
1 /********************************************************************
2 * COPYRIGHT:
3 * Copyright (c) 1997-2003, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /* file name: strtest.cpp
7 * encoding: US-ASCII
8 * tab size: 8 (not used)
9 * indentation:4
10 *
11 * created on: 1999nov22
12 * created by: Markus W. Scherer
13 */
14
15 #include "unicode/utypes.h"
16 #include "unicode/putil.h"
17 #include "intltest.h"
18 #include "strtest.h"
19 #include "unicode/ustring.h"
20
21 void StringTest::TestEndian(void) {
22 union {
23 uint8_t byte;
24 uint16_t word;
25 } u;
26 u.word=0x0100;
27 if(U_IS_BIG_ENDIAN!=u.byte) {
28 errln("TestEndian: U_IS_BIG_ENDIAN needs to be fixed in platform.h");
29 }
30 }
31
32 void StringTest::TestSizeofWCharT(void) {
33 if(U_SIZEOF_WCHAR_T!=sizeof(wchar_t)) {
34 errln("TestSizeofWCharT: U_SIZEOF_WCHAR_T!=sizeof(wchar_t) - U_SIZEOF_WCHAR_T needs to be fixed in platform.h");
35 }
36 }
37
38 void StringTest::TestSizeofInt64(void) {
39 #ifdef U_INT64_T_UNAVAILABLE
40 errln("int64_t and uint64_t are undefined.");
41 #else
42 if(8!=sizeof(int64_t)) {
43 errln("TestSizeofInt64: 8!=sizeof(int64_t) - int64_t needs to be fixed in platform.h");
44 }
45 if(8!=sizeof(uint64_t)) {
46 errln("TestSizeofInt64: 8!=sizeof(uint64_t) - uint64_t needs to be fixed in platform.h");
47 }
48 #endif
49 if(8!=sizeof(double)) {
50 errln("8!=sizeof(double) - putil.c code may not work");
51 }
52 }
53
54 void StringTest::TestCharsetFamily(void) {
55 unsigned char c='A';
56 if( U_CHARSET_FAMILY==U_ASCII_FAMILY && c!=0x41 ||
57 U_CHARSET_FAMILY==U_EBCDIC_FAMILY && c!=0xc1
58 ) {
59 errln("TestCharsetFamily: U_CHARSET_FAMILY needs to be fixed in platform.h");
60 }
61 }
62
63 U_STRING_DECL(ustringVar, "aZ0 -", 5);
64
65 void StringTest::runIndexedTest(int32_t index, UBool exec, const char *&name, char * /*par*/) {
66 if(exec) {
67 logln("TestSuite Character and String Test: ");
68 }
69 switch(index) {
70 case 0:
71 name="TestEndian";
72 if(exec) {
73 TestEndian();
74 }
75 break;
76 case 1:
77 name="TestSizeofWCharT";
78 if(exec) {
79 TestSizeofWCharT();
80 }
81 break;
82 case 2:
83 name="TestSizeofInt64";
84 if(exec) {
85 TestSizeofInt64();
86 }
87 break;
88 case 3:
89 name="TestCharsetFamily";
90 if(exec) {
91 TestCharsetFamily();
92 }
93 break;
94 case 4:
95 name="Test_U_STRING";
96 if(exec) {
97 U_STRING_INIT(ustringVar, "aZ0 -", 5);
98 if( sizeof(ustringVar)/sizeof(*ustringVar)!=6 ||
99 ustringVar[0]!=0x61 ||
100 ustringVar[1]!=0x5a ||
101 ustringVar[2]!=0x30 ||
102 ustringVar[3]!=0x20 ||
103 ustringVar[4]!=0x2d ||
104 ustringVar[5]!=0
105 ) {
106 errln("Test_U_STRING: U_STRING_DECL with U_STRING_INIT does not work right! "
107 "See putil.h and utypes.h with platform.h.");
108 }
109 }
110 break;
111 case 5:
112 name="Test_UNICODE_STRING";
113 if(exec) {
114 UnicodeString ustringVar=UNICODE_STRING("aZ0 -", 5);
115 if( ustringVar.length()!=5 ||
116 ustringVar[0]!=0x61 ||
117 ustringVar[1]!=0x5a ||
118 ustringVar[2]!=0x30 ||
119 ustringVar[3]!=0x20 ||
120 ustringVar[4]!=0x2d
121 ) {
122 errln("Test_UNICODE_STRING: UNICODE_STRING does not work right! "
123 "See unistr.h and utypes.h with platform.h.");
124 }
125 }
126 break;
127 case 6:
128 name="Test_UNICODE_STRING_SIMPLE";
129 if(exec) {
130 UnicodeString ustringVar=UNICODE_STRING_SIMPLE("aZ0 -");
131 if( ustringVar.length()!=5 ||
132 ustringVar[0]!=0x61 ||
133 ustringVar[1]!=0x5a ||
134 ustringVar[2]!=0x30 ||
135 ustringVar[3]!=0x20 ||
136 ustringVar[4]!=0x2d
137 ) {
138 errln("Test_UNICODE_STRING_SIMPLE: UNICODE_STRING_SIMPLE does not work right! "
139 "See unistr.h and utypes.h with platform.h.");
140 }
141 }
142 break;
143 case 7:
144 name="Test_UTF8_COUNT_TRAIL_BYTES";
145 if(exec) {
146 if(UTF8_COUNT_TRAIL_BYTES(0x7F) != 0
147 || UTF8_COUNT_TRAIL_BYTES(0xC0) != 1
148 || UTF8_COUNT_TRAIL_BYTES(0xE0) != 2
149 || UTF8_COUNT_TRAIL_BYTES(0xF0) != 3)
150 {
151 errln("Test_UTF8_COUNT_TRAIL_BYTES: UTF8_COUNT_TRAIL_BYTES does not work right! "
152 "See utf8.h.");
153 }
154 }
155 break;
156 default:
157 name="";
158 break;
159 }
160 }