2010-10-14 08:30:07 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-19 19:45:04 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2004-02-26 12:37:11 +00:00
|
|
|
|
2012-06-27 16:05:04 +01:00
|
|
|
#include <sal/types.h>
|
2011-02-05 22:31:57 +01:00
|
|
|
#include <cppunit/TestFixture.h>
|
|
|
|
#include <cppunit/TestAssert.h>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
2011-02-07 10:17:10 +01:00
|
|
|
#include "rtl/strbuf.hxx"
|
2004-02-26 12:37:11 +00:00
|
|
|
#include "rtl/ustrbuf.hxx"
|
|
|
|
#include "rtl/ustring.h"
|
|
|
|
#include "rtl/ustring.hxx"
|
|
|
|
|
|
|
|
namespace test { namespace oustringbuffer {
|
|
|
|
|
|
|
|
class Utf32: public CppUnit::TestFixture {
|
|
|
|
private:
|
|
|
|
void appendUtf32();
|
|
|
|
|
|
|
|
void insertUtf32();
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(Utf32);
|
|
|
|
CPPUNIT_TEST(appendUtf32);
|
|
|
|
CPPUNIT_TEST(insertUtf32);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
};
|
|
|
|
|
|
|
|
} }
|
|
|
|
|
2011-02-05 22:31:57 +01:00
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(test::oustringbuffer::Utf32);
|
2004-02-26 12:37:11 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2011-02-07 10:17:10 +01:00
|
|
|
void appendString(rtl::OStringBuffer & buffer, rtl::OUString const & string) {
|
|
|
|
buffer.append('"');
|
2004-02-26 12:37:11 +00:00
|
|
|
for (int i = 0; i < string.getLength(); ++i) {
|
2017-01-11 16:39:20 +01:00
|
|
|
buffer.append("\\u");
|
2004-02-26 12:37:11 +00:00
|
|
|
sal_Unicode c = string[i];
|
|
|
|
if (c < 0x1000) {
|
2011-02-07 10:17:10 +01:00
|
|
|
buffer.append('0');
|
2004-02-26 12:37:11 +00:00
|
|
|
if (c < 0x100) {
|
2011-02-07 10:17:10 +01:00
|
|
|
buffer.append('0');
|
2004-02-26 12:37:11 +00:00
|
|
|
if (c < 0x10) {
|
2011-02-07 10:17:10 +01:00
|
|
|
buffer.append('0');
|
2004-02-26 12:37:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
buffer.append(
|
|
|
|
static_cast< sal_Int32 >(c), static_cast< sal_Int16 >(16));
|
|
|
|
}
|
2011-02-07 10:17:10 +01:00
|
|
|
buffer.append('"');
|
2004-02-26 12:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void createMessage(
|
2011-02-07 10:17:10 +01:00
|
|
|
rtl::OStringBuffer & message, rtl::OUString const & string1,
|
2004-02-26 12:37:11 +00:00
|
|
|
rtl::OUString const & string2)
|
|
|
|
{
|
|
|
|
message.setLength(0);
|
|
|
|
appendString(message, string1);
|
2017-01-11 16:39:20 +01:00
|
|
|
message.append(" vs. ");
|
2004-02-26 12:37:11 +00:00
|
|
|
appendString(message, string2);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void test::oustringbuffer::Utf32::appendUtf32() {
|
|
|
|
int const str1Len = 3;
|
|
|
|
sal_Unicode const str1[str1Len] = { 'a', 'b', 'c' };
|
|
|
|
int const str2Len = 4;
|
|
|
|
sal_Unicode const str2[str2Len] = { 'a', 'b', 'c', 'd' };
|
|
|
|
int const str3Len = 6;
|
|
|
|
sal_Unicode const str3[str3Len] = { 'a', 'b', 'c', 'd', 0xD800, 0xDC00 };
|
2011-02-07 10:17:10 +01:00
|
|
|
rtl::OStringBuffer message;
|
2004-02-26 12:37:11 +00:00
|
|
|
rtl::OUStringBuffer buf1(rtl::OUString(str1, str1Len));
|
|
|
|
buf1.appendUtf32('d');
|
|
|
|
rtl::OUString res1(buf1.makeStringAndClear());
|
|
|
|
createMessage(message, res1, rtl::OUString(str2, str2Len));
|
2016-07-13 09:18:07 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE(
|
|
|
|
message.getStr(), rtl::OUString(str2, str2Len), res1);
|
2004-02-26 12:37:11 +00:00
|
|
|
rtl::OUStringBuffer buf2(rtl::OUString(str2, str2Len));
|
|
|
|
buf2.appendUtf32(0x10000);
|
|
|
|
rtl::OUString res2(buf2.makeStringAndClear());
|
|
|
|
createMessage(message, res2, rtl::OUString(str3, str3Len));
|
2016-07-13 09:18:07 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE(
|
|
|
|
message.getStr(), rtl::OUString(str3, str3Len), res2);
|
2004-02-26 12:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void test::oustringbuffer::Utf32::insertUtf32() {
|
|
|
|
int const str1Len = 3;
|
|
|
|
sal_Unicode const str1[str1Len] = { 'a', 'b', 'c' };
|
|
|
|
int const str2Len = 4;
|
|
|
|
sal_Unicode const str2[str2Len] = { 'a', 'b', 'd', 'c' };
|
|
|
|
int const str3Len = 6;
|
|
|
|
sal_Unicode const str3[str3Len] = { 'a', 'b', 0xDBFF, 0xDFFF, 'd', 'c' };
|
2011-02-07 10:17:10 +01:00
|
|
|
rtl::OStringBuffer message;
|
2004-02-26 12:37:11 +00:00
|
|
|
rtl::OUStringBuffer buf1(rtl::OUString(str1, str1Len));
|
|
|
|
buf1.insertUtf32(2, 'd');
|
|
|
|
rtl::OUString res1(buf1.makeStringAndClear());
|
|
|
|
createMessage(message, res1, rtl::OUString(str2, str2Len));
|
2016-07-13 09:18:07 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE(
|
|
|
|
message.getStr(), rtl::OUString(str2, str2Len), res1);
|
2004-02-26 12:37:11 +00:00
|
|
|
rtl::OUStringBuffer buf2(rtl::OUString(str2, str2Len));
|
|
|
|
buf2.insertUtf32(2, 0x10FFFF);
|
|
|
|
rtl::OUString res2(buf2.makeStringAndClear());
|
|
|
|
createMessage(message, res2, rtl::OUString(str3, str3Len));
|
2016-07-13 09:18:07 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL_MESSAGE(
|
|
|
|
message.getStr(), rtl::OUString(str3, str3Len), res2);
|
2004-02-26 12:37:11 +00:00
|
|
|
}
|
2010-10-14 08:30:07 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|