Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: source/test/intltest/ustrtest.cpp

Issue 845603002: Update ICU to 54.1 step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@master
Patch Set: remove unusued directories Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/test/intltest/usettest.cpp ('k') | source/test/intltest/uts46test.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /******************************************************************** 1 /********************************************************************
2 * COPYRIGHT: 2 * COPYRIGHT:
3 * Copyright (c) 1997-2013, International Business Machines Corporation and 3 * Copyright (c) 1997-2014, International Business Machines Corporation and
4 * others. All Rights Reserved. 4 * others. All Rights Reserved.
5 ********************************************************************/ 5 ********************************************************************/
6 6
7 #include "ustrtest.h" 7 #include "ustrtest.h"
8 #include "unicode/appendable.h" 8 #include "unicode/appendable.h"
9 #include "unicode/std_string.h" 9 #include "unicode/std_string.h"
10 #include "unicode/unistr.h" 10 #include "unicode/unistr.h"
11 #include "unicode/uchar.h" 11 #include "unicode/uchar.h"
12 #include "unicode/ustring.h" 12 #include "unicode/ustring.h"
13 #include "unicode/locid.h" 13 #include "unicode/locid.h"
14 #include "unicode/ucnv.h" 14 #include "unicode/ucnv.h"
15 #include "unicode/uenum.h" 15 #include "unicode/uenum.h"
16 #include "unicode/utf16.h" 16 #include "unicode/utf16.h"
17 #include "cmemory.h" 17 #include "cmemory.h"
18 #include "charstr.h" 18 #include "charstr.h"
19 19
20 #if 0 20 #if 0
21 #include "unicode/ustream.h" 21 #include "unicode/ustream.h"
22 22
23 #include <iostream> 23 #include <iostream>
24 using namespace std; 24 using namespace std;
25 25
26 #endif 26 #endif
27 27
28 #define LENGTHOF(array) (int32_t)((sizeof(array)/sizeof((array)[0])))
29
30 UnicodeStringTest::~UnicodeStringTest() {} 28 UnicodeStringTest::~UnicodeStringTest() {}
31 29
32 void UnicodeStringTest::runIndexedTest( int32_t index, UBool exec, const char* & name, char *par) 30 void UnicodeStringTest::runIndexedTest( int32_t index, UBool exec, const char* & name, char *par)
33 { 31 {
34 if (exec) logln("TestSuite UnicodeStringTest: "); 32 if (exec) logln("TestSuite UnicodeStringTest: ");
35 switch (index) { 33 switch (index) {
36 case 0: 34 case 0:
37 name = "StringCaseTest"; 35 name = "StringCaseTest";
38 if (exec) { 36 if (exec) {
39 logln("StringCaseTest---"); logln(""); 37 logln("StringCaseTest---"); logln("");
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 190
193 { 191 {
194 // tests for Jitterbug 2360 192 // tests for Jitterbug 2360
195 // verify that APIs with source pointer + length accept length == -1 193 // verify that APIs with source pointer + length accept length == -1
196 // mostly test only where modified, only few functions did not already d o this 194 // mostly test only where modified, only few functions did not already d o this
197 if(UnicodeString("abc", -1, "")!=UnicodeString("abc", "")) { 195 if(UnicodeString("abc", -1, "")!=UnicodeString("abc", "")) {
198 errln("UnicodeString(codepageData, dataLength, codepage) does not wo rk with dataLength==-1"); 196 errln("UnicodeString(codepageData, dataLength, codepage) does not wo rk with dataLength==-1");
199 } 197 }
200 198
201 UChar buffer[10]={ 0x61, 0x62, 0x20ac, 0xd900, 0xdc05, 0, 0x62, 0xffff , 0xdbff, 0xdfff }; 199 UChar buffer[10]={ 0x61, 0x62, 0x20ac, 0xd900, 0xdc05, 0, 0x62, 0xffff , 0xdbff, 0xdfff };
202 UnicodeString s, t(buffer, -1, LENGTHOF(buffer)); 200 UnicodeString s, t(buffer, -1, UPRV_LENGTHOF(buffer));
203 201
204 if(s.setTo(buffer, -1, LENGTHOF(buffer)).length()!=u_strlen(buffer)) { 202 if(s.setTo(buffer, -1, UPRV_LENGTHOF(buffer)).length()!=u_strlen(buffer) ) {
205 errln("UnicodeString.setTo(buffer, length, capacity) does not work w ith length==-1"); 203 errln("UnicodeString.setTo(buffer, length, capacity) does not work w ith length==-1");
206 } 204 }
207 if(t.length()!=u_strlen(buffer)) { 205 if(t.length()!=u_strlen(buffer)) {
208 errln("UnicodeString(buffer, length, capacity) does not work with le ngth==-1"); 206 errln("UnicodeString(buffer, length, capacity) does not work with le ngth==-1");
209 } 207 }
210 208
211 if(0!=s.caseCompare(buffer, -1, U_FOLD_CASE_DEFAULT)) { 209 if(0!=s.caseCompare(buffer, -1, U_FOLD_CASE_DEFAULT)) {
212 errln("UnicodeString.caseCompare(const UChar *, length, options) doe s not work with length==-1"); 210 errln("UnicodeString.caseCompare(const UChar *, length, options) doe s not work with length==-1");
213 } 211 }
214 if(0!=s.caseCompare(0, s.length(), buffer, U_FOLD_CASE_DEFAULT)) { 212 if(0!=s.caseCompare(0, s.length(), buffer, U_FOLD_CASE_DEFAULT)) {
215 errln("UnicodeString.caseCompare(start, _length, const UChar *, opti ons) does not work"); 213 errln("UnicodeString.caseCompare(start, _length, const UChar *, opti ons) does not work");
216 } 214 }
217 215
218 buffer[u_strlen(buffer)]=0xe4; 216 buffer[u_strlen(buffer)]=0xe4;
219 UnicodeString u(buffer, -1, LENGTHOF(buffer)); 217 UnicodeString u(buffer, -1, UPRV_LENGTHOF(buffer));
220 if(s.setTo(buffer, -1, LENGTHOF(buffer)).length()!=LENGTHOF(buffer)) { 218 if(s.setTo(buffer, -1, UPRV_LENGTHOF(buffer)).length()!=UPRV_LENGTHOF(bu ffer)) {
221 errln("UnicodeString.setTo(buffer without NUL, length, capacity) doe s not work with length==-1"); 219 errln("UnicodeString.setTo(buffer without NUL, length, capacity) doe s not work with length==-1");
222 } 220 }
223 if(u.length()!=LENGTHOF(buffer)) { 221 if(u.length()!=UPRV_LENGTHOF(buffer)) {
224 errln("UnicodeString(buffer without NUL, length, capacity) does not work with length==-1"); 222 errln("UnicodeString(buffer without NUL, length, capacity) does not work with length==-1");
225 } 223 }
226 224
227 static const char cs[]={ 0x61, (char)0xe4, (char)0x85, 0 }; 225 static const char cs[]={ 0x61, (char)0xe4, (char)0x85, 0 };
228 UConverter *cnv; 226 UConverter *cnv;
229 UErrorCode errorCode=U_ZERO_ERROR; 227 UErrorCode errorCode=U_ZERO_ERROR;
230 228
231 cnv=ucnv_open("ISO-8859-1", &errorCode); 229 cnv=ucnv_open("ISO-8859-1", &errorCode);
232 UnicodeString v(cs, -1, cnv, errorCode); 230 UnicodeString v(cs, -1, cnv, errorCode);
233 ucnv_close(cnv); 231 ucnv_close(cnv);
234 if(v!=CharsToUnicodeString("a\\xe4\\x85")) { 232 if(v!=CharsToUnicodeString("a\\xe4\\x85")) {
235 errln("UnicodeString(const char *, length, cnv, errorCode) does not work with length==-1"); 233 errln("UnicodeString(const char *, length, cnv, errorCode) does not work with length==-1");
236 } 234 }
237 } 235 }
238 236
239 #if U_CHARSET_IS_UTF8 237 #if U_CHARSET_IS_UTF8
240 { 238 {
241 // Test the hardcoded-UTF-8 UnicodeString optimizations. 239 // Test the hardcoded-UTF-8 UnicodeString optimizations.
242 static const uint8_t utf8[]={ 0x61, 0xC3, 0xA4, 0xC3, 0x9F, 0xE4, 0xB8, 0x80, 0 }; 240 static const uint8_t utf8[]={ 0x61, 0xC3, 0xA4, 0xC3, 0x9F, 0xE4, 0xB8, 0x80, 0 };
243 static const UChar utf16[]={ 0x61, 0xE4, 0xDF, 0x4E00 }; 241 static const UChar utf16[]={ 0x61, 0xE4, 0xDF, 0x4E00 };
244 UnicodeString from8a = UnicodeString((const char *)utf8); 242 UnicodeString from8a = UnicodeString((const char *)utf8);
245 UnicodeString from8b = UnicodeString((const char *)utf8, (int32_t)sizeof (utf8)-1); 243 UnicodeString from8b = UnicodeString((const char *)utf8, (int32_t)sizeof (utf8)-1);
246 UnicodeString from16(FALSE, utf16, LENGTHOF(utf16)); 244 UnicodeString from16(FALSE, utf16, UPRV_LENGTHOF(utf16));
247 if(from8a != from16 || from8b != from16) { 245 if(from8a != from16 || from8b != from16) {
248 errln("UnicodeString(const char * U_CHARSET_IS_UTF8) failed"); 246 errln("UnicodeString(const char * U_CHARSET_IS_UTF8) failed");
249 } 247 }
250 char buffer[16]; 248 char buffer[16];
251 int32_t length8=from16.extract(0, 0x7fffffff, buffer, (uint32_t)sizeof(b uffer)); 249 int32_t length8=from16.extract(0, 0x7fffffff, buffer, (uint32_t)sizeof(b uffer));
252 if(length8!=((int32_t)sizeof(utf8)-1) || 0!=uprv_memcmp(buffer, utf8, si zeof(utf8))) { 250 if(length8!=((int32_t)sizeof(utf8)-1) || 0!=uprv_memcmp(buffer, utf8, si zeof(utf8))) {
253 errln("UnicodeString::extract(char * U_CHARSET_IS_UTF8) failed"); 251 errln("UnicodeString::extract(char * U_CHARSET_IS_UTF8) failed");
254 } 252 }
255 length8=from16.extract(1, 2, buffer, (uint32_t)sizeof(buffer)); 253 length8=from16.extract(1, 2, buffer, (uint32_t)sizeof(buffer));
256 if(length8!=4 || buffer[length8]!=0 || 0!=uprv_memcmp(buffer, utf8+1, le ngth8)) { 254 if(length8!=4 || buffer[length8]!=0 || 0!=uprv_memcmp(buffer, utf8+1, le ngth8)) {
(...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 } 1401 }
1404 1402
1405 /* test data and variables for hasMoreChar32Than() */ 1403 /* test data and variables for hasMoreChar32Than() */
1406 static const UChar str[]={ 1404 static const UChar str[]={
1407 0x61, 0x62, 0xd800, 0xdc00, 1405 0x61, 0x62, 0xd800, 0xdc00,
1408 0xd801, 0xdc01, 0x63, 0xd802, 1406 0xd801, 0xdc01, 0x63, 0xd802,
1409 0x64, 0xdc03, 0x65, 0x66, 1407 0x64, 0xdc03, 0x65, 0x66,
1410 0xd804, 0xdc04, 0xd805, 0xdc05, 1408 0xd804, 0xdc04, 0xd805, 0xdc05,
1411 0x67 1409 0x67
1412 }; 1410 };
1413 UnicodeString string(str, LENGTHOF(str)); 1411 UnicodeString string(str, UPRV_LENGTHOF(str));
1414 int32_t start, length, number; 1412 int32_t start, length, number;
1415 1413
1416 /* test hasMoreChar32Than() */ 1414 /* test hasMoreChar32Than() */
1417 for(length=string.length(); length>=0; --length) { 1415 for(length=string.length(); length>=0; --length) {
1418 for(start=0; start<=length; ++start) { 1416 for(start=0; start<=length; ++start) {
1419 for(number=-1; number<=((length-start)+2); ++number) { 1417 for(number=-1; number<=((length-start)+2); ++number) {
1420 _testUnicodeStringHasMoreChar32Than(string, start, length-start, number); 1418 _testUnicodeStringHasMoreChar32Than(string, start, length-start, number);
1421 } 1419 }
1422 } 1420 }
1423 } 1421 }
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1657 "c", 1655 "c",
1658 "this is a long string which helps us test some buffer limits", 1656 "this is a long string which helps us test some buffer limits",
1659 "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeee" 1657 "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeee"
1660 }; 1658 };
1661 1659
1662 class TestEnumeration : public StringEnumeration { 1660 class TestEnumeration : public StringEnumeration {
1663 public: 1661 public:
1664 TestEnumeration() : i(0) {} 1662 TestEnumeration() : i(0) {}
1665 1663
1666 virtual int32_t count(UErrorCode& /*status*/) const { 1664 virtual int32_t count(UErrorCode& /*status*/) const {
1667 return LENGTHOF(testEnumStrings); 1665 return UPRV_LENGTHOF(testEnumStrings);
1668 } 1666 }
1669 1667
1670 virtual const UnicodeString *snext(UErrorCode &status) { 1668 virtual const UnicodeString *snext(UErrorCode &status) {
1671 if(U_SUCCESS(status) && i<LENGTHOF(testEnumStrings)) { 1669 if(U_SUCCESS(status) && i<UPRV_LENGTHOF(testEnumStrings)) {
1672 unistr=UnicodeString(testEnumStrings[i++], ""); 1670 unistr=UnicodeString(testEnumStrings[i++], "");
1673 return &unistr; 1671 return &unistr;
1674 } 1672 }
1675 1673
1676 return NULL; 1674 return NULL;
1677 } 1675 }
1678 1676
1679 virtual void reset(UErrorCode& /*status*/) { 1677 virtual void reset(UErrorCode& /*status*/) {
1680 i=0; 1678 i=0;
1681 } 1679 }
(...skipping 17 matching lines...) Expand all
1699 UnicodeStringTest::TestStringEnumeration() { 1697 UnicodeStringTest::TestStringEnumeration() {
1700 UnicodeString s; 1698 UnicodeString s;
1701 TestEnumeration ten; 1699 TestEnumeration ten;
1702 int32_t i, length; 1700 int32_t i, length;
1703 UErrorCode status; 1701 UErrorCode status;
1704 1702
1705 const UChar *pu; 1703 const UChar *pu;
1706 const char *pc; 1704 const char *pc;
1707 1705
1708 // test the next() default implementation and ensureCharsCapacity() 1706 // test the next() default implementation and ensureCharsCapacity()
1709 for(i=0; i<LENGTHOF(testEnumStrings); ++i) { 1707 for(i=0; i<UPRV_LENGTHOF(testEnumStrings); ++i) {
1710 status=U_ZERO_ERROR; 1708 status=U_ZERO_ERROR;
1711 pc=ten.next(&length, status); 1709 pc=ten.next(&length, status);
1712 s=UnicodeString(testEnumStrings[i], ""); 1710 s=UnicodeString(testEnumStrings[i], "");
1713 if(U_FAILURE(status) || pc==NULL || length!=s.length() || UnicodeString( pc, length, "")!=s) { 1711 if(U_FAILURE(status) || pc==NULL || length!=s.length() || UnicodeString( pc, length, "")!=s) {
1714 errln("StringEnumeration.next(%d) failed", i); 1712 errln("StringEnumeration.next(%d) failed", i);
1715 } 1713 }
1716 } 1714 }
1717 status=U_ZERO_ERROR; 1715 status=U_ZERO_ERROR;
1718 if(ten.next(&length, status)!=NULL) { 1716 if(ten.next(&length, status)!=NULL) {
1719 errln("StringEnumeration.next(done)!=NULL"); 1717 errln("StringEnumeration.next(done)!=NULL");
1720 } 1718 }
1721 1719
1722 // test the unext() default implementation 1720 // test the unext() default implementation
1723 ten.reset(status); 1721 ten.reset(status);
1724 for(i=0; i<LENGTHOF(testEnumStrings); ++i) { 1722 for(i=0; i<UPRV_LENGTHOF(testEnumStrings); ++i) {
1725 status=U_ZERO_ERROR; 1723 status=U_ZERO_ERROR;
1726 pu=ten.unext(&length, status); 1724 pu=ten.unext(&length, status);
1727 s=UnicodeString(testEnumStrings[i], ""); 1725 s=UnicodeString(testEnumStrings[i], "");
1728 if(U_FAILURE(status) || pu==NULL || length!=s.length() || UnicodeString( TRUE, pu, length)!=s) { 1726 if(U_FAILURE(status) || pu==NULL || length!=s.length() || UnicodeString( TRUE, pu, length)!=s) {
1729 errln("StringEnumeration.unext(%d) failed", i); 1727 errln("StringEnumeration.unext(%d) failed", i);
1730 } 1728 }
1731 } 1729 }
1732 status=U_ZERO_ERROR; 1730 status=U_ZERO_ERROR;
1733 if(ten.unext(&length, status)!=NULL) { 1731 if(ten.unext(&length, status)!=NULL) {
1734 errln("StringEnumeration.unext(done)!=NULL"); 1732 errln("StringEnumeration.unext(done)!=NULL");
1735 } 1733 }
1736 1734
1737 // test that the default clone() implementation works, and returns NULL 1735 // test that the default clone() implementation works, and returns NULL
1738 if(ten.clone()!=NULL) { 1736 if(ten.clone()!=NULL) {
1739 errln("StringEnumeration.clone()!=NULL"); 1737 errln("StringEnumeration.clone()!=NULL");
1740 } 1738 }
1741 1739
1742 // test that uenum_openFromStringEnumeration() works 1740 // test that uenum_openFromStringEnumeration() works
1743 // Need a heap allocated string enumeration because it is adopted by the UEn umeration. 1741 // Need a heap allocated string enumeration because it is adopted by the UEn umeration.
1744 StringEnumeration *newTen = new TestEnumeration; 1742 StringEnumeration *newTen = new TestEnumeration;
1745 status=U_ZERO_ERROR; 1743 status=U_ZERO_ERROR;
1746 UEnumeration *uten = uenum_openFromStringEnumeration(newTen, &status); 1744 UEnumeration *uten = uenum_openFromStringEnumeration(newTen, &status);
1747 if (uten==NULL || U_FAILURE(status)) { 1745 if (uten==NULL || U_FAILURE(status)) {
1748 errln("fail at file %s, line %d, UErrorCode is %s\n", __FILE__, __LINE__ , u_errorName(status)); 1746 errln("fail at file %s, line %d, UErrorCode is %s\n", __FILE__, __LINE__ , u_errorName(status));
1749 return; 1747 return;
1750 } 1748 }
1751 1749
1752 // test uenum_next() 1750 // test uenum_next()
1753 for(i=0; i<LENGTHOF(testEnumStrings); ++i) { 1751 for(i=0; i<UPRV_LENGTHOF(testEnumStrings); ++i) {
1754 status=U_ZERO_ERROR; 1752 status=U_ZERO_ERROR;
1755 pc=uenum_next(uten, &length, &status); 1753 pc=uenum_next(uten, &length, &status);
1756 if(U_FAILURE(status) || pc==NULL || strcmp(pc, testEnumStrings[i]) != 0) { 1754 if(U_FAILURE(status) || pc==NULL || strcmp(pc, testEnumStrings[i]) != 0) {
1757 errln("File %s, line %d, StringEnumeration.next(%d) failed", __FILE_ _, __LINE__, i); 1755 errln("File %s, line %d, StringEnumeration.next(%d) failed", __FILE_ _, __LINE__, i);
1758 } 1756 }
1759 } 1757 }
1760 status=U_ZERO_ERROR; 1758 status=U_ZERO_ERROR;
1761 if(uenum_next(uten, &length, &status)!=NULL) { 1759 if(uenum_next(uten, &length, &status)!=NULL) {
1762 errln("File %s, line %d, uenum_next(done)!=NULL"); 1760 errln("File %s, line %d, uenum_next(done)!=NULL");
1763 } 1761 }
1764 1762
1765 // test the uenum_unext() 1763 // test the uenum_unext()
1766 uenum_reset(uten, &status); 1764 uenum_reset(uten, &status);
1767 for(i=0; i<LENGTHOF(testEnumStrings); ++i) { 1765 for(i=0; i<UPRV_LENGTHOF(testEnumStrings); ++i) {
1768 status=U_ZERO_ERROR; 1766 status=U_ZERO_ERROR;
1769 pu=uenum_unext(uten, &length, &status); 1767 pu=uenum_unext(uten, &length, &status);
1770 s=UnicodeString(testEnumStrings[i], ""); 1768 s=UnicodeString(testEnumStrings[i], "");
1771 if(U_FAILURE(status) || pu==NULL || length!=s.length() || UnicodeString( TRUE, pu, length)!=s) { 1769 if(U_FAILURE(status) || pu==NULL || length!=s.length() || UnicodeString( TRUE, pu, length)!=s) {
1772 errln("File %s, Line %d, uenum_unext(%d) failed", __FILE__, __LINE__ , i); 1770 errln("File %s, Line %d, uenum_unext(%d) failed", __FILE__, __LINE__ , i);
1773 } 1771 }
1774 } 1772 }
1775 status=U_ZERO_ERROR; 1773 status=U_ZERO_ERROR;
1776 if(uenum_unext(uten, &length, &status)!=NULL) { 1774 if(uenum_unext(uten, &length, &status)!=NULL) {
1777 errln("File %s, Line %d, uenum_unext(done)!=NULL" __FILE__, __LINE__); 1775 errln("File %s, Line %d, uenum_unext(done)!=NULL" __FILE__, __LINE__);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1822 // Input string length US_STACKBUF_SIZE to cause overflow of the 1820 // Input string length US_STACKBUF_SIZE to cause overflow of the
1823 // initially chosen fStackBuffer due to supplementary characters. 1821 // initially chosen fStackBuffer due to supplementary characters.
1824 static const UChar32 utf32[] = { 1822 static const UChar32 utf32[] = {
1825 0x41, 0xd900, 0x61, 0xdc00, -1, 0x110000, 0x5a, 0x50000, 0x7a, 1823 0x41, 0xd900, 0x61, 0xdc00, -1, 0x110000, 0x5a, 0x50000, 0x7a,
1826 0x10000, 0x20000, 0xe0000, 0x10ffff 1824 0x10000, 0x20000, 0xe0000, 0x10ffff
1827 }; 1825 };
1828 static const UChar expected_utf16[] = { 1826 static const UChar expected_utf16[] = {
1829 0x41, 0xfffd, 0x61, 0xfffd, 0xfffd, 0xfffd, 0x5a, 0xd900, 0xdc00, 0x7a, 1827 0x41, 0xfffd, 0x61, 0xfffd, 0xfffd, 0xfffd, 0x5a, 0xd900, 0xdc00, 0x7a,
1830 0xd800, 0xdc00, 0xd840, 0xdc00, 0xdb40, 0xdc00, 0xdbff, 0xdfff 1828 0xd800, 0xdc00, 0xd840, 0xdc00, 0xdb40, 0xdc00, 0xdbff, 0xdfff
1831 }; 1829 };
1832 UnicodeString from32 = UnicodeString::fromUTF32(utf32, LENGTHOF(utf32)); 1830 UnicodeString from32 = UnicodeString::fromUTF32(utf32, UPRV_LENGTHOF(utf32)) ;
1833 UnicodeString expected(FALSE, expected_utf16, LENGTHOF(expected_utf16)); 1831 UnicodeString expected(FALSE, expected_utf16, UPRV_LENGTHOF(expected_utf16)) ;
1834 if(from32 != expected) { 1832 if(from32 != expected) {
1835 errln("UnicodeString::fromUTF32() did not create the expected string."); 1833 errln("UnicodeString::fromUTF32() did not create the expected string.");
1836 } 1834 }
1837 1835
1838 static const UChar utf16[] = { 1836 static const UChar utf16[] = {
1839 0x41, 0xd900, 0x61, 0xdc00, 0x5a, 0xd900, 0xdc00, 0x7a, 0xd800, 0xdc00, 0xdbff, 0xdfff 1837 0x41, 0xd900, 0x61, 0xdc00, 0x5a, 0xd900, 0xdc00, 0x7a, 0xd800, 0xdc00, 0xdbff, 0xdfff
1840 }; 1838 };
1841 static const UChar32 expected_utf32[] = { 1839 static const UChar32 expected_utf32[] = {
1842 0x41, 0xfffd, 0x61, 0xfffd, 0x5a, 0x50000, 0x7a, 0x10000, 0x10ffff 1840 0x41, 0xfffd, 0x61, 0xfffd, 0x5a, 0x50000, 0x7a, 0x10000, 0x10ffff
1843 }; 1841 };
1844 UChar32 result32[16]; 1842 UChar32 result32[16];
1845 UErrorCode errorCode = U_ZERO_ERROR; 1843 UErrorCode errorCode = U_ZERO_ERROR;
1846 int32_t length32 = 1844 int32_t length32 =
1847 UnicodeString(FALSE, utf16, LENGTHOF(utf16)). 1845 UnicodeString(FALSE, utf16, UPRV_LENGTHOF(utf16)).
1848 toUTF32(result32, LENGTHOF(result32), errorCode); 1846 toUTF32(result32, UPRV_LENGTHOF(result32), errorCode);
1849 if( length32 != LENGTHOF(expected_utf32) || 1847 if( length32 != UPRV_LENGTHOF(expected_utf32) ||
1850 0 != uprv_memcmp(result32, expected_utf32, length32*4) || 1848 0 != uprv_memcmp(result32, expected_utf32, length32*4) ||
1851 result32[length32] != 0 1849 result32[length32] != 0
1852 ) { 1850 ) {
1853 errln("UnicodeString::toUTF32() did not create the expected string."); 1851 errln("UnicodeString::toUTF32() did not create the expected string.");
1854 } 1852 }
1855 } 1853 }
1856 1854
1857 class TestCheckedArrayByteSink : public CheckedArrayByteSink { 1855 class TestCheckedArrayByteSink : public CheckedArrayByteSink {
1858 public: 1856 public:
1859 TestCheckedArrayByteSink(char* outbuf, int32_t capacity) 1857 TestCheckedArrayByteSink(char* outbuf, int32_t capacity)
(...skipping 21 matching lines...) Expand all
1881 }; 1879 };
1882 static const UChar expected_utf16[] = { 1880 static const UChar expected_utf16[] = {
1883 0x41, 0xfffd, 1881 0x41, 0xfffd,
1884 0x61, 0xfffd, 1882 0x61, 0xfffd,
1885 0xfffd, 0x5a, 1883 0xfffd, 0x5a,
1886 0xd900, 0xdc00, 0x7a, 1884 0xd900, 0xdc00, 0x7a,
1887 0xd800, 0xdc00, 0xd840, 0xdc00, 1885 0xd800, 0xdc00, 0xd840, 0xdc00,
1888 0xdb40, 0xdc00, 0xdbff, 0xdfff 1886 0xdb40, 0xdc00, 0xdbff, 0xdfff
1889 }; 1887 };
1890 UnicodeString from8 = UnicodeString::fromUTF8(StringPiece((const char *)utf8 , (int32_t)sizeof(utf8))); 1888 UnicodeString from8 = UnicodeString::fromUTF8(StringPiece((const char *)utf8 , (int32_t)sizeof(utf8)));
1891 UnicodeString expected(FALSE, expected_utf16, LENGTHOF(expected_utf16)); 1889 UnicodeString expected(FALSE, expected_utf16, UPRV_LENGTHOF(expected_utf16)) ;
1892 1890
1893 if(from8 != expected) { 1891 if(from8 != expected) {
1894 errln("UnicodeString::fromUTF8(StringPiece) did not create the expected string."); 1892 errln("UnicodeString::fromUTF8(StringPiece) did not create the expected string.");
1895 } 1893 }
1896 #if U_HAVE_STD_STRING 1894 #if U_HAVE_STD_STRING
1897 std::string utf8_string((const char *)utf8, sizeof(utf8)); 1895 std::string utf8_string((const char *)utf8, sizeof(utf8));
1898 UnicodeString from8b = UnicodeString::fromUTF8(utf8_string); 1896 UnicodeString from8b = UnicodeString::fromUTF8(utf8_string);
1899 if(from8b != expected) { 1897 if(from8b != expected) {
1900 errln("UnicodeString::fromUTF8(std::string) did not create the expected string."); 1898 errln("UnicodeString::fromUTF8(std::string) did not create the expected string.");
1901 } 1899 }
1902 #endif 1900 #endif
1903 1901
1904 static const UChar utf16[] = { 1902 static const UChar utf16[] = {
1905 0x41, 0xd900, 0x61, 0xdc00, 0x5a, 0xd900, 0xdc00, 0x7a, 0xd800, 0xdc00, 0xdbff, 0xdfff 1903 0x41, 0xd900, 0x61, 0xdc00, 0x5a, 0xd900, 0xdc00, 0x7a, 0xd800, 0xdc00, 0xdbff, 0xdfff
1906 }; 1904 };
1907 static const uint8_t expected_utf8[] = { 1905 static const uint8_t expected_utf8[] = {
1908 0x41, 0xef, 0xbf, 0xbd, 0x61, 0xef, 0xbf, 0xbd, 0x5a, 0xf1, 0x90, 0x80, 0x80, 0x7a, 1906 0x41, 0xef, 0xbf, 0xbd, 0x61, 0xef, 0xbf, 0xbd, 0x5a, 0xf1, 0x90, 0x80, 0x80, 0x7a,
1909 0xf0, 0x90, 0x80, 0x80, 0xf4, 0x8f, 0xbf, 0xbf 1907 0xf0, 0x90, 0x80, 0x80, 0xf4, 0x8f, 0xbf, 0xbf
1910 }; 1908 };
1911 UnicodeString us(FALSE, utf16, LENGTHOF(utf16)); 1909 UnicodeString us(FALSE, utf16, UPRV_LENGTHOF(utf16));
1912 1910
1913 char buffer[64]; 1911 char buffer[64];
1914 TestCheckedArrayByteSink sink(buffer, (int32_t)sizeof(buffer)); 1912 TestCheckedArrayByteSink sink(buffer, (int32_t)sizeof(buffer));
1915 us.toUTF8(sink); 1913 us.toUTF8(sink);
1916 if( sink.NumberOfBytesWritten() != (int32_t)sizeof(expected_utf8) || 1914 if( sink.NumberOfBytesWritten() != (int32_t)sizeof(expected_utf8) ||
1917 0 != uprv_memcmp(buffer, expected_utf8, sizeof(expected_utf8)) 1915 0 != uprv_memcmp(buffer, expected_utf8, sizeof(expected_utf8))
1918 ) { 1916 ) {
1919 errln("UnicodeString::toUTF8() did not create the expected string."); 1917 errln("UnicodeString::toUTF8() did not create the expected string.");
1920 } 1918 }
1921 if(!sink.calledFlush) { 1919 if(!sink.calledFlush) {
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
2110 expected=40; 2108 expected=40;
2111 break; 2109 break;
2112 default: 2110 default:
2113 logln("This platform has neither 32-bit nor 64-bit pointers."); 2111 logln("This platform has neither 32-bit nor 64-bit pointers.");
2114 return; 2112 return;
2115 } 2113 }
2116 if(expected!=sizeofUniStr) { 2114 if(expected!=sizeofUniStr) {
2117 errln("sizeof(UnicodeString)=%d, expected %d", (int)sizeofUniStr, (int)e xpected); 2115 errln("sizeof(UnicodeString)=%d, expected %d", (int)sizeofUniStr, (int)e xpected);
2118 } 2116 }
2119 } 2117 }
OLDNEW
« no previous file with comments | « source/test/intltest/usettest.cpp ('k') | source/test/intltest/uts46test.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698