ICU-1920 test UnicodeString::getTerminatedBuffer()

X-SVN-Rev: 8823
This commit is contained in:
Markus Scherer 2002-06-08 19:36:19 +00:00
parent 64e7f644ea
commit 712900b007

View File

@ -147,7 +147,7 @@ UnicodeStringTest::TestBasicManipulation()
}
// NUL-terminate the string buffer and test u_countChar32(length=-1)
const UChar *buffer=s.append((UChar)0).getBuffer();
const UChar *buffer=s.getTerminatedBuffer();
if(
u_countChar32(buffer, -1)!=4 ||
u_countChar32(buffer+1, -1)!=4 ||
@ -1009,6 +1009,27 @@ UnicodeStringTest::TestMiscellaneous()
errln("UnicodeString::releaseBuffer(-1 but no NUL) does not properly set the length of the UnicodeString");
}
// test getTerminatedBuffer()
test1=UnicodeString("This is another test.", "");
test2=UnicodeString("This is another test.", "");
q=test1.getTerminatedBuffer();
if(q[test1.length()]!=0 || test1!=test2 || test2.compare(q, -1)!=0) {
errln("getTerminatedBuffer()[length]!=0");
}
const UChar u[]={ 5, 6, 7, 8, 0 };
test1.setTo(FALSE, u, 3);
q=test1.getTerminatedBuffer();
if(q==u || q[0]!=5 || q[1]!=6 || q[2]!=7 || q[3]!=0) {
errln("UnicodeString(u[3]).getTerminatedBuffer() returns a bad buffer");
}
test1.setTo(TRUE, u, -1);
q=test1.getTerminatedBuffer();
if(q!=u || test1.length()!=4 || q[3]!=8 || q[4]!=0) {
errln("UnicodeString(u[-1]).getTerminatedBuffer() returns a bad buffer");
}
/*
#if U_IOSTREAM_SOURCE
logln("Testing the operator \"<<\" \n");