1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: test_oustringbuffer_utf32.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sal.hxx"
34 #include "cppunit/simpleheader.hxx"
35 #include "rtl/ustrbuf.hxx"
36 #include "rtl/ustring.h"
37 #include "rtl/ustring.hxx"
39 namespace test
{ namespace oustringbuffer
{
41 class Utf32
: public CppUnit::TestFixture
{
47 CPPUNIT_TEST_SUITE(Utf32
);
48 CPPUNIT_TEST(appendUtf32
);
49 CPPUNIT_TEST(insertUtf32
);
50 CPPUNIT_TEST_SUITE_END();
55 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(test::oustringbuffer::Utf32
, "alltest");
59 void appendString(rtl::OUStringBuffer
& buffer
, rtl::OUString
const & string
) {
60 buffer
.append(static_cast< sal_Unicode
>('"'));
61 for (int i
= 0; i
< string
.getLength(); ++i
) {
62 buffer
.appendAscii(RTL_CONSTASCII_STRINGPARAM("\\u"));
63 sal_Unicode c
= string
[i
];
65 buffer
.append(static_cast< sal_Unicode
>('0'));
67 buffer
.append(static_cast< sal_Unicode
>('0'));
69 buffer
.append(static_cast< sal_Unicode
>('0'));
74 static_cast< sal_Int32
>(c
), static_cast< sal_Int16
>(16));
76 buffer
.append(static_cast< sal_Unicode
>('"'));
80 rtl::OUStringBuffer
& message
, rtl::OUString
const & string1
,
81 rtl::OUString
const & string2
)
84 appendString(message
, string1
);
85 message
.appendAscii(RTL_CONSTASCII_STRINGPARAM(" vs. "));
86 appendString(message
, string2
);
91 void test::oustringbuffer::Utf32::appendUtf32() {
92 int const str1Len
= 3;
93 sal_Unicode
const str1
[str1Len
] = { 'a', 'b', 'c' };
94 int const str2Len
= 4;
95 sal_Unicode
const str2
[str2Len
] = { 'a', 'b', 'c', 'd' };
96 int const str3Len
= 6;
97 sal_Unicode
const str3
[str3Len
] = { 'a', 'b', 'c', 'd', 0xD800, 0xDC00 };
98 rtl::OUStringBuffer message
;
99 rtl::OUStringBuffer
buf1(rtl::OUString(str1
, str1Len
));
100 buf1
.appendUtf32('d');
101 rtl::OUString
res1(buf1
.makeStringAndClear());
102 createMessage(message
, res1
, rtl::OUString(str2
, str2Len
));
103 CPPUNIT_ASSERT_MESSAGE(
104 message
.getStr(), res1
== rtl::OUString(str2
, str2Len
));
105 rtl::OUStringBuffer
buf2(rtl::OUString(str2
, str2Len
));
106 buf2
.appendUtf32(0x10000);
107 rtl::OUString
res2(buf2
.makeStringAndClear());
108 createMessage(message
, res2
, rtl::OUString(str3
, str3Len
));
109 CPPUNIT_ASSERT_MESSAGE(
110 message
.getStr(), res2
== rtl::OUString(str3
, str3Len
));
113 void test::oustringbuffer::Utf32::insertUtf32() {
114 int const str1Len
= 3;
115 sal_Unicode
const str1
[str1Len
] = { 'a', 'b', 'c' };
116 int const str2Len
= 4;
117 sal_Unicode
const str2
[str2Len
] = { 'a', 'b', 'd', 'c' };
118 int const str3Len
= 6;
119 sal_Unicode
const str3
[str3Len
] = { 'a', 'b', 0xDBFF, 0xDFFF, 'd', 'c' };
120 rtl::OUStringBuffer message
;
121 rtl::OUStringBuffer
buf1(rtl::OUString(str1
, str1Len
));
122 buf1
.insertUtf32(2, 'd');
123 rtl::OUString
res1(buf1
.makeStringAndClear());
124 createMessage(message
, res1
, rtl::OUString(str2
, str2Len
));
125 CPPUNIT_ASSERT_MESSAGE(
126 message
.getStr(), res1
== rtl::OUString(str2
, str2Len
));
127 rtl::OUStringBuffer
buf2(rtl::OUString(str2
, str2Len
));
128 buf2
.insertUtf32(2, 0x10FFFF);
129 rtl::OUString
res2(buf2
.makeStringAndClear());
130 createMessage(message
, res2
, rtl::OUString(str3
, str3Len
));
131 CPPUNIT_ASSERT_MESSAGE(
132 message
.getStr(), res2
== rtl::OUString(str3
, str3Len
));