LCOV - code coverage report
Current view: top level - sal/qa/rtl/oustringbuffer - test_oustringbuffer_utf32.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 67 68 98.5 %
Date: 2014-11-03 Functions: 12 12 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      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"
      28             : 
      29             : namespace test { namespace oustringbuffer {
      30             : 
      31          12 : class Utf32: public CppUnit::TestFixture {
      32             : private:
      33             :     void appendUtf32();
      34             : 
      35             :     void insertUtf32();
      36             : 
      37           4 :     CPPUNIT_TEST_SUITE(Utf32);
      38           2 :     CPPUNIT_TEST(appendUtf32);
      39           2 :     CPPUNIT_TEST(insertUtf32);
      40           4 :     CPPUNIT_TEST_SUITE_END();
      41             : };
      42             : 
      43             : } }
      44             : 
      45           2 : CPPUNIT_TEST_SUITE_REGISTRATION(test::oustringbuffer::Utf32);
      46             : 
      47             : namespace {
      48             : 
      49          16 : void appendString(rtl::OStringBuffer & buffer, rtl::OUString const & string) {
      50          16 :     buffer.append('"');
      51          96 :     for (int i = 0; i < string.getLength(); ++i) {
      52          80 :         buffer.append(RTL_CONSTASCII_STRINGPARAM("\\u"));
      53          80 :         sal_Unicode c = string[i];
      54          80 :         if (c < 0x1000) {
      55          64 :             buffer.append('0');
      56          64 :             if (c < 0x100) {
      57          64 :                 buffer.append('0');
      58          64 :                 if (c < 0x10) {
      59           0 :                     buffer.append('0');
      60             :                 }
      61             :             }
      62             :         }
      63             :         buffer.append(
      64          80 :             static_cast< sal_Int32 >(c), static_cast< sal_Int16 >(16));
      65             :     }
      66          16 :     buffer.append('"');
      67          16 : }
      68             : 
      69           8 : void createMessage(
      70             :     rtl::OStringBuffer & message, rtl::OUString const & string1,
      71             :     rtl::OUString const & string2)
      72             : {
      73           8 :     message.setLength(0);
      74           8 :     appendString(message, string1);
      75           8 :     message.append(RTL_CONSTASCII_STRINGPARAM(" vs. "));
      76           8 :     appendString(message, string2);
      77           8 : }
      78             : 
      79             : }
      80             : 
      81           2 : void test::oustringbuffer::Utf32::appendUtf32() {
      82           2 :     int const str1Len = 3;
      83           2 :     sal_Unicode const str1[str1Len] = { 'a', 'b', 'c' };
      84           2 :     int const str2Len = 4;
      85           2 :     sal_Unicode const str2[str2Len] = { 'a', 'b', 'c', 'd' };
      86           2 :     int const str3Len = 6;
      87           2 :     sal_Unicode const str3[str3Len] = { 'a', 'b', 'c', 'd', 0xD800, 0xDC00 };
      88           2 :     rtl::OStringBuffer message;
      89           4 :     rtl::OUStringBuffer buf1(rtl::OUString(str1, str1Len));
      90           2 :     buf1.appendUtf32('d');
      91           4 :     rtl::OUString res1(buf1.makeStringAndClear());
      92           2 :     createMessage(message, res1, rtl::OUString(str2, str2Len));
      93           4 :     CPPUNIT_ASSERT_MESSAGE(
      94           2 :         (const char *) message.getStr(), res1 == rtl::OUString(str2, str2Len));
      95           4 :     rtl::OUStringBuffer buf2(rtl::OUString(str2, str2Len));
      96           2 :     buf2.appendUtf32(0x10000);
      97           4 :     rtl::OUString res2(buf2.makeStringAndClear());
      98           2 :     createMessage(message, res2, rtl::OUString(str3, str3Len));
      99           4 :     CPPUNIT_ASSERT_MESSAGE(
     100           4 :         (const char *)message.getStr(), res2 == rtl::OUString(str3, str3Len));
     101           2 : }
     102             : 
     103           2 : void test::oustringbuffer::Utf32::insertUtf32() {
     104           2 :     int const str1Len = 3;
     105           2 :     sal_Unicode const str1[str1Len] = { 'a', 'b', 'c' };
     106           2 :     int const str2Len = 4;
     107           2 :     sal_Unicode const str2[str2Len] = { 'a', 'b', 'd', 'c' };
     108           2 :     int const str3Len = 6;
     109           2 :     sal_Unicode const str3[str3Len] = { 'a', 'b', 0xDBFF, 0xDFFF, 'd', 'c' };
     110           2 :     rtl::OStringBuffer message;
     111           4 :     rtl::OUStringBuffer buf1(rtl::OUString(str1, str1Len));
     112           2 :     buf1.insertUtf32(2, 'd');
     113           4 :     rtl::OUString res1(buf1.makeStringAndClear());
     114           2 :     createMessage(message, res1, rtl::OUString(str2, str2Len));
     115           4 :     CPPUNIT_ASSERT_MESSAGE(
     116           2 :         (const char *) message.getStr(), res1 == rtl::OUString(str2, str2Len));
     117           4 :     rtl::OUStringBuffer buf2(rtl::OUString(str2, str2Len));
     118           2 :     buf2.insertUtf32(2, 0x10FFFF);
     119           4 :     rtl::OUString res2(buf2.makeStringAndClear());
     120           2 :     createMessage(message, res2, rtl::OUString(str3, str3Len));
     121           4 :     CPPUNIT_ASSERT_MESSAGE(
     122           4 :         (const char *) message.getStr(), res2 == rtl::OUString(str3, str3Len));
     123           8 : }
     124             : 
     125             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10