1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/types.h>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/TestAssert.h>
23 #include <cppunit/extensions/HelperMacros.h>
24 #include "rtl/strbuf.hxx"
25 #include "rtl/ustrbuf.hxx"
26 #include "rtl/ustring.h"
27 #include "rtl/ustring.hxx"
29 namespace test
{ namespace oustringbuffer
{
31 class Utf32
: public CppUnit::TestFixture
{
37 CPPUNIT_TEST_SUITE(Utf32
);
38 CPPUNIT_TEST(appendUtf32
);
39 CPPUNIT_TEST(insertUtf32
);
40 CPPUNIT_TEST_SUITE_END();
45 CPPUNIT_TEST_SUITE_REGISTRATION(test::oustringbuffer::Utf32
);
49 void appendString(rtl::OStringBuffer
& buffer
, rtl::OUString
const & string
) {
51 for (int i
= 0; i
< string
.getLength(); ++i
) {
52 buffer
.append(RTL_CONSTASCII_STRINGPARAM("\\u"));
53 sal_Unicode c
= string
[i
];
64 static_cast< sal_Int32
>(c
), static_cast< sal_Int16
>(16));
70 rtl::OStringBuffer
& message
, rtl::OUString
const & string1
,
71 rtl::OUString
const & string2
)
74 appendString(message
, string1
);
75 message
.append(RTL_CONSTASCII_STRINGPARAM(" vs. "));
76 appendString(message
, string2
);
81 void test::oustringbuffer::Utf32::appendUtf32() {
82 int const str1Len
= 3;
83 sal_Unicode
const str1
[str1Len
] = { 'a', 'b', 'c' };
84 int const str2Len
= 4;
85 sal_Unicode
const str2
[str2Len
] = { 'a', 'b', 'c', 'd' };
86 int const str3Len
= 6;
87 sal_Unicode
const str3
[str3Len
] = { 'a', 'b', 'c', 'd', 0xD800, 0xDC00 };
88 rtl::OStringBuffer message
;
89 rtl::OUStringBuffer
buf1(rtl::OUString(str1
, str1Len
));
90 buf1
.appendUtf32('d');
91 rtl::OUString
res1(buf1
.makeStringAndClear());
92 createMessage(message
, res1
, rtl::OUString(str2
, str2Len
));
93 CPPUNIT_ASSERT_MESSAGE(
94 (const char *) message
.getStr(), res1
== rtl::OUString(str2
, str2Len
));
95 rtl::OUStringBuffer
buf2(rtl::OUString(str2
, str2Len
));
96 buf2
.appendUtf32(0x10000);
97 rtl::OUString
res2(buf2
.makeStringAndClear());
98 createMessage(message
, res2
, rtl::OUString(str3
, str3Len
));
99 CPPUNIT_ASSERT_MESSAGE(
100 (const char *)message
.getStr(), res2
== rtl::OUString(str3
, str3Len
));
103 void test::oustringbuffer::Utf32::insertUtf32() {
104 int const str1Len
= 3;
105 sal_Unicode
const str1
[str1Len
] = { 'a', 'b', 'c' };
106 int const str2Len
= 4;
107 sal_Unicode
const str2
[str2Len
] = { 'a', 'b', 'd', 'c' };
108 int const str3Len
= 6;
109 sal_Unicode
const str3
[str3Len
] = { 'a', 'b', 0xDBFF, 0xDFFF, 'd', 'c' };
110 rtl::OStringBuffer message
;
111 rtl::OUStringBuffer
buf1(rtl::OUString(str1
, str1Len
));
112 buf1
.insertUtf32(2, 'd');
113 rtl::OUString
res1(buf1
.makeStringAndClear());
114 createMessage(message
, res1
, rtl::OUString(str2
, str2Len
));
115 CPPUNIT_ASSERT_MESSAGE(
116 (const char *) message
.getStr(), res1
== rtl::OUString(str2
, str2Len
));
117 rtl::OUStringBuffer
buf2(rtl::OUString(str2
, str2Len
));
118 buf2
.insertUtf32(2, 0x10FFFF);
119 rtl::OUString
res2(buf2
.makeStringAndClear());
120 createMessage(message
, res2
, rtl::OUString(str3
, str3Len
));
121 CPPUNIT_ASSERT_MESSAGE(
122 (const char *) message
.getStr(), res2
== rtl::OUString(str3
, str3Len
));
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */