2000-01-15 02:00:06 +00:00
|
|
|
/********************************************************************
|
|
|
|
* COPYRIGHT:
|
2003-06-03 20:58:22 +00:00
|
|
|
* Copyright (c) 1997-2003, International Business Machines Corporation and
|
2000-01-15 02:00:06 +00:00
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
|
|
|
/* file name: strtest.cpp
|
1999-11-22 20:29:44 +00:00
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 1999nov22
|
|
|
|
* created by: Markus W. Scherer
|
|
|
|
*/
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/putil.h"
|
1999-11-22 20:29:44 +00:00
|
|
|
#include "intltest.h"
|
|
|
|
#include "strtest.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/ustring.h"
|
1999-11-22 20:29:44 +00:00
|
|
|
|
2003-06-11 22:58:40 +00:00
|
|
|
#if defined(WIN32) && defined(_MSC_VER)
|
|
|
|
#include <vector>
|
|
|
|
using namespace std;
|
|
|
|
#endif
|
|
|
|
|
2003-10-24 01:04:44 +00:00
|
|
|
StringTest::~StringTest() {}
|
2003-06-11 22:58:40 +00:00
|
|
|
|
1999-12-22 22:57:04 +00:00
|
|
|
void StringTest::TestEndian(void) {
|
1999-11-22 20:52:33 +00:00
|
|
|
union {
|
|
|
|
uint8_t byte;
|
|
|
|
uint16_t word;
|
|
|
|
} u;
|
|
|
|
u.word=0x0100;
|
|
|
|
if(U_IS_BIG_ENDIAN!=u.byte) {
|
|
|
|
errln("TestEndian: U_IS_BIG_ENDIAN needs to be fixed in platform.h");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-11 16:51:15 +00:00
|
|
|
void StringTest::TestSizeofTypes(void) {
|
1999-11-22 20:29:44 +00:00
|
|
|
if(U_SIZEOF_WCHAR_T!=sizeof(wchar_t)) {
|
|
|
|
errln("TestSizeofWCharT: U_SIZEOF_WCHAR_T!=sizeof(wchar_t) - U_SIZEOF_WCHAR_T needs to be fixed in platform.h");
|
|
|
|
}
|
2002-03-26 01:17:49 +00:00
|
|
|
#ifdef U_INT64_T_UNAVAILABLE
|
|
|
|
errln("int64_t and uint64_t are undefined.");
|
|
|
|
#else
|
2002-02-27 21:52:11 +00:00
|
|
|
if(8!=sizeof(int64_t)) {
|
2004-05-11 16:51:15 +00:00
|
|
|
errln("TestSizeofTypes: 8!=sizeof(int64_t) - int64_t needs to be fixed in platform.h");
|
2002-02-27 21:52:11 +00:00
|
|
|
}
|
|
|
|
if(8!=sizeof(uint64_t)) {
|
2004-05-11 16:51:15 +00:00
|
|
|
errln("TestSizeofTypes: 8!=sizeof(uint64_t) - uint64_t needs to be fixed in platform.h");
|
2002-02-27 21:52:11 +00:00
|
|
|
}
|
2002-03-26 01:17:49 +00:00
|
|
|
#endif
|
2003-05-13 00:26:47 +00:00
|
|
|
if(8!=sizeof(double)) {
|
|
|
|
errln("8!=sizeof(double) - putil.c code may not work");
|
|
|
|
}
|
2004-05-11 16:51:15 +00:00
|
|
|
if(4!=sizeof(int32_t)) {
|
|
|
|
errln("4!=sizeof(int32_t)");
|
|
|
|
}
|
|
|
|
if(4!=sizeof(uint32_t)) {
|
|
|
|
errln("4!=sizeof(uint32_t)");
|
|
|
|
}
|
|
|
|
if(2!=sizeof(int16_t)) {
|
|
|
|
errln("2!=sizeof(int16_t)");
|
|
|
|
}
|
|
|
|
if(2!=sizeof(uint16_t)) {
|
|
|
|
errln("2!=sizeof(uint16_t)");
|
|
|
|
}
|
|
|
|
if(2!=sizeof(UChar)) {
|
|
|
|
errln("2!=sizeof(UChar)");
|
|
|
|
}
|
|
|
|
if(1!=sizeof(int8_t)) {
|
|
|
|
errln("1!=sizeof(int8_t)");
|
|
|
|
}
|
|
|
|
if(1!=sizeof(uint8_t)) {
|
|
|
|
errln("1!=sizeof(uint8_t)");
|
|
|
|
}
|
|
|
|
if(1!=sizeof(UBool)) {
|
|
|
|
errln("1!=sizeof(UBool)");
|
|
|
|
}
|
2002-02-27 21:52:11 +00:00
|
|
|
}
|
|
|
|
|
1999-12-22 22:57:04 +00:00
|
|
|
void StringTest::TestCharsetFamily(void) {
|
1999-11-22 20:52:33 +00:00
|
|
|
unsigned char c='A';
|
|
|
|
if( U_CHARSET_FAMILY==U_ASCII_FAMILY && c!=0x41 ||
|
|
|
|
U_CHARSET_FAMILY==U_EBCDIC_FAMILY && c!=0xc1
|
|
|
|
) {
|
|
|
|
errln("TestCharsetFamily: U_CHARSET_FAMILY needs to be fixed in platform.h");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-30 23:25:49 +00:00
|
|
|
U_STRING_DECL(ustringVar, "aZ0 -", 5);
|
|
|
|
|
2000-08-23 19:11:16 +00:00
|
|
|
void StringTest::runIndexedTest(int32_t index, UBool exec, const char *&name, char * /*par*/) {
|
1999-11-22 20:29:44 +00:00
|
|
|
if(exec) {
|
|
|
|
logln("TestSuite Character and String Test: ");
|
|
|
|
}
|
|
|
|
switch(index) {
|
|
|
|
case 0:
|
1999-11-22 20:52:33 +00:00
|
|
|
name="TestEndian";
|
|
|
|
if(exec) {
|
|
|
|
TestEndian();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
2004-05-11 16:51:15 +00:00
|
|
|
name="TestSizeofTypes";
|
1999-11-22 20:29:44 +00:00
|
|
|
if(exec) {
|
2004-05-11 16:51:15 +00:00
|
|
|
TestSizeofTypes();
|
1999-11-22 20:29:44 +00:00
|
|
|
}
|
|
|
|
break;
|
1999-11-22 20:52:33 +00:00
|
|
|
case 2:
|
|
|
|
name="TestCharsetFamily";
|
|
|
|
if(exec) {
|
|
|
|
TestCharsetFamily();
|
|
|
|
}
|
|
|
|
break;
|
2004-05-11 16:51:15 +00:00
|
|
|
case 3:
|
1999-11-30 23:25:49 +00:00
|
|
|
name="Test_U_STRING";
|
|
|
|
if(exec) {
|
|
|
|
U_STRING_INIT(ustringVar, "aZ0 -", 5);
|
|
|
|
if( sizeof(ustringVar)/sizeof(*ustringVar)!=6 ||
|
|
|
|
ustringVar[0]!=0x61 ||
|
|
|
|
ustringVar[1]!=0x5a ||
|
|
|
|
ustringVar[2]!=0x30 ||
|
|
|
|
ustringVar[3]!=0x20 ||
|
|
|
|
ustringVar[4]!=0x2d ||
|
|
|
|
ustringVar[5]!=0
|
|
|
|
) {
|
|
|
|
errln("Test_U_STRING: U_STRING_DECL with U_STRING_INIT does not work right! "
|
|
|
|
"See putil.h and utypes.h with platform.h.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-05-11 16:51:15 +00:00
|
|
|
case 4:
|
1999-12-01 17:52:21 +00:00
|
|
|
name="Test_UNICODE_STRING";
|
|
|
|
if(exec) {
|
|
|
|
UnicodeString ustringVar=UNICODE_STRING("aZ0 -", 5);
|
|
|
|
if( ustringVar.length()!=5 ||
|
|
|
|
ustringVar[0]!=0x61 ||
|
|
|
|
ustringVar[1]!=0x5a ||
|
|
|
|
ustringVar[2]!=0x30 ||
|
|
|
|
ustringVar[3]!=0x20 ||
|
|
|
|
ustringVar[4]!=0x2d
|
|
|
|
) {
|
|
|
|
errln("Test_UNICODE_STRING: UNICODE_STRING does not work right! "
|
|
|
|
"See unistr.h and utypes.h with platform.h.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-05-11 16:51:15 +00:00
|
|
|
case 5:
|
2002-03-26 19:55:28 +00:00
|
|
|
name="Test_UNICODE_STRING_SIMPLE";
|
|
|
|
if(exec) {
|
|
|
|
UnicodeString ustringVar=UNICODE_STRING_SIMPLE("aZ0 -");
|
|
|
|
if( ustringVar.length()!=5 ||
|
|
|
|
ustringVar[0]!=0x61 ||
|
|
|
|
ustringVar[1]!=0x5a ||
|
|
|
|
ustringVar[2]!=0x30 ||
|
|
|
|
ustringVar[3]!=0x20 ||
|
|
|
|
ustringVar[4]!=0x2d
|
|
|
|
) {
|
|
|
|
errln("Test_UNICODE_STRING_SIMPLE: UNICODE_STRING_SIMPLE does not work right! "
|
|
|
|
"See unistr.h and utypes.h with platform.h.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-05-11 16:51:15 +00:00
|
|
|
case 6:
|
2002-08-30 01:22:26 +00:00
|
|
|
name="Test_UTF8_COUNT_TRAIL_BYTES";
|
|
|
|
if(exec) {
|
|
|
|
if(UTF8_COUNT_TRAIL_BYTES(0x7F) != 0
|
|
|
|
|| UTF8_COUNT_TRAIL_BYTES(0xC0) != 1
|
|
|
|
|| UTF8_COUNT_TRAIL_BYTES(0xE0) != 2
|
|
|
|
|| UTF8_COUNT_TRAIL_BYTES(0xF0) != 3)
|
|
|
|
{
|
|
|
|
errln("Test_UTF8_COUNT_TRAIL_BYTES: UTF8_COUNT_TRAIL_BYTES does not work right! "
|
|
|
|
"See utf8.h.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-05-11 16:51:15 +00:00
|
|
|
case 7:
|
2003-06-11 22:58:40 +00:00
|
|
|
name="TestSTLCompatibility";
|
|
|
|
if(exec) {
|
|
|
|
#if defined(WIN32) && defined(_MSC_VER)
|
|
|
|
/* Just make sure that it compiles with STL's placement new usage. */
|
|
|
|
vector<UnicodeString> myvect;
|
|
|
|
myvect.push_back(UnicodeString("blah"));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
1999-11-22 20:29:44 +00:00
|
|
|
default:
|
|
|
|
name="";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|