]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/strtest.cpp
1 /********************************************************************
3 * Copyright (c) 1997-2004, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
6 /* file name: strtest.cpp
8 * tab size: 8 (not used)
11 * created on: 1999nov22
12 * created by: Markus W. Scherer
15 #include "unicode/utypes.h"
16 #include "unicode/putil.h"
19 #include "unicode/ustring.h"
21 #if defined(WIN32) && defined(_MSC_VER)
26 StringTest::~StringTest() {}
28 void StringTest::TestEndian(void) {
34 if(U_IS_BIG_ENDIAN
!=u
.byte
) {
35 errln("TestEndian: U_IS_BIG_ENDIAN needs to be fixed in platform.h");
39 void StringTest::TestSizeofTypes(void) {
40 if(U_SIZEOF_WCHAR_T
!=sizeof(wchar_t)) {
41 errln("TestSizeofWCharT: U_SIZEOF_WCHAR_T!=sizeof(wchar_t) - U_SIZEOF_WCHAR_T needs to be fixed in platform.h");
43 #ifdef U_INT64_T_UNAVAILABLE
44 errln("int64_t and uint64_t are undefined.");
46 if(8!=sizeof(int64_t)) {
47 errln("TestSizeofTypes: 8!=sizeof(int64_t) - int64_t needs to be fixed in platform.h");
49 if(8!=sizeof(uint64_t)) {
50 errln("TestSizeofTypes: 8!=sizeof(uint64_t) - uint64_t needs to be fixed in platform.h");
53 if(8!=sizeof(double)) {
54 errln("8!=sizeof(double) - putil.c code may not work");
56 if(4!=sizeof(int32_t)) {
57 errln("4!=sizeof(int32_t)");
59 if(4!=sizeof(uint32_t)) {
60 errln("4!=sizeof(uint32_t)");
62 if(2!=sizeof(int16_t)) {
63 errln("2!=sizeof(int16_t)");
65 if(2!=sizeof(uint16_t)) {
66 errln("2!=sizeof(uint16_t)");
68 if(2!=sizeof(UChar
)) {
69 errln("2!=sizeof(UChar)");
71 if(1!=sizeof(int8_t)) {
72 errln("1!=sizeof(int8_t)");
74 if(1!=sizeof(uint8_t)) {
75 errln("1!=sizeof(uint8_t)");
77 if(1!=sizeof(UBool
)) {
78 errln("1!=sizeof(UBool)");
82 void StringTest::TestCharsetFamily(void) {
84 if( U_CHARSET_FAMILY
==U_ASCII_FAMILY
&& c
!=0x41 ||
85 U_CHARSET_FAMILY
==U_EBCDIC_FAMILY
&& c
!=0xc1
87 errln("TestCharsetFamily: U_CHARSET_FAMILY needs to be fixed in platform.h");
91 U_STRING_DECL(ustringVar
, "aZ0 -", 5);
93 void StringTest::runIndexedTest(int32_t index
, UBool exec
, const char *&name
, char * /*par*/) {
95 logln("TestSuite Character and String Test: ");
105 name
="TestSizeofTypes";
111 name
="TestCharsetFamily";
117 name
="Test_U_STRING";
119 U_STRING_INIT(ustringVar
, "aZ0 -", 5);
120 if( sizeof(ustringVar
)/sizeof(*ustringVar
)!=6 ||
121 ustringVar
[0]!=0x61 ||
122 ustringVar
[1]!=0x5a ||
123 ustringVar
[2]!=0x30 ||
124 ustringVar
[3]!=0x20 ||
125 ustringVar
[4]!=0x2d ||
128 errln("Test_U_STRING: U_STRING_DECL with U_STRING_INIT does not work right! "
129 "See putil.h and utypes.h with platform.h.");
134 name
="Test_UNICODE_STRING";
136 UnicodeString ustringVar
=UNICODE_STRING("aZ0 -", 5);
137 if( ustringVar
.length()!=5 ||
138 ustringVar
[0]!=0x61 ||
139 ustringVar
[1]!=0x5a ||
140 ustringVar
[2]!=0x30 ||
141 ustringVar
[3]!=0x20 ||
144 errln("Test_UNICODE_STRING: UNICODE_STRING does not work right! "
145 "See unistr.h and utypes.h with platform.h.");
150 name
="Test_UNICODE_STRING_SIMPLE";
152 UnicodeString ustringVar
=UNICODE_STRING_SIMPLE("aZ0 -");
153 if( ustringVar
.length()!=5 ||
154 ustringVar
[0]!=0x61 ||
155 ustringVar
[1]!=0x5a ||
156 ustringVar
[2]!=0x30 ||
157 ustringVar
[3]!=0x20 ||
160 errln("Test_UNICODE_STRING_SIMPLE: UNICODE_STRING_SIMPLE does not work right! "
161 "See unistr.h and utypes.h with platform.h.");
166 name
="Test_UTF8_COUNT_TRAIL_BYTES";
168 if(UTF8_COUNT_TRAIL_BYTES(0x7F) != 0
169 || UTF8_COUNT_TRAIL_BYTES(0xC0) != 1
170 || UTF8_COUNT_TRAIL_BYTES(0xE0) != 2
171 || UTF8_COUNT_TRAIL_BYTES(0xF0) != 3)
173 errln("Test_UTF8_COUNT_TRAIL_BYTES: UTF8_COUNT_TRAIL_BYTES does not work right! "
179 name
="TestSTLCompatibility";
181 #if defined(WIN32) && defined(_MSC_VER)
182 /* Just make sure that it compiles with STL's placement new usage. */
183 vector
<UnicodeString
> myvect
;
184 myvect
.push_back(UnicodeString("blah"));