LCOV - code coverage report
Current view: top level - sal/qa/rtl/strings - test_oustring_endswith.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 40 40 100.0 %
Date: 2015-06-13 12:38:46 Functions: 13 13 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/extensions/HelperMacros.h>
      23             : #include "rtl/strbuf.hxx"
      24             : #include "rtl/string.h"
      25             : #include "rtl/string.hxx"
      26             : #include "rtl/textenc.h"
      27             : #include "rtl/ustring.hxx"
      28             : #include <sal/macros.h>
      29             : 
      30             : namespace test { namespace oustring {
      31             : 
      32           3 : class EndsWith: public CppUnit::TestFixture
      33             : {
      34             : private:
      35             :     void endsWith();
      36             : 
      37           2 :     CPPUNIT_TEST_SUITE(EndsWith);
      38           1 :     CPPUNIT_TEST(endsWith);
      39           5 :     CPPUNIT_TEST_SUITE_END();
      40             : };
      41             : 
      42             : } }
      43             : 
      44           1 : CPPUNIT_TEST_SUITE_REGISTRATION(test::oustring::EndsWith);
      45             : 
      46             : namespace {
      47             : 
      48          16 : void appendString(rtl::OStringBuffer & buffer, rtl::OString const & string)
      49             : {
      50          16 :     buffer.append('"');
      51          56 :     for (int i = 0; i < string.getLength(); ++i) {
      52          40 :         char c = string[i];
      53          40 :         if (c < ' ' || c == '"' || c == '\\' || c > '~') {
      54           5 :             buffer.append('\\');
      55             :             sal_Int32 n = static_cast< sal_Int32 >(
      56           5 :                 static_cast< unsigned char >(c));
      57           5 :             if (n < 16) {
      58           5 :                 buffer.append('0');
      59             :             }
      60           5 :             buffer.append(n, 16);
      61             :         } else {
      62          35 :             buffer.append(c);
      63             :         }
      64             :     }
      65          16 :     buffer.append('"');
      66          16 : }
      67             : 
      68             : }
      69             : 
      70           1 : void test::oustring::EndsWith::endsWith()
      71             : {
      72             :     struct Data {
      73             :         char const * str1;
      74             :         sal_Int32 str1Len;
      75             :         char const * str2;
      76             :         sal_Int32 str2Len;
      77             :         bool endsWith;
      78             :     };
      79             :     Data const data[] = {
      80           2 :         { RTL_CONSTASCII_STRINGPARAM(""), RTL_CONSTASCII_STRINGPARAM(""),
      81             :           true },
      82           2 :         { RTL_CONSTASCII_STRINGPARAM("abc"), RTL_CONSTASCII_STRINGPARAM(""),
      83             :           true },
      84           2 :         { RTL_CONSTASCII_STRINGPARAM(""), RTL_CONSTASCII_STRINGPARAM("abc"),
      85             :           false },
      86           2 :         { RTL_CONSTASCII_STRINGPARAM("ABC"), RTL_CONSTASCII_STRINGPARAM("abc"),
      87             :           true },
      88           2 :         { RTL_CONSTASCII_STRINGPARAM("abcd"), RTL_CONSTASCII_STRINGPARAM("bcd"),
      89             :           true },
      90           2 :         { RTL_CONSTASCII_STRINGPARAM("bcd"), RTL_CONSTASCII_STRINGPARAM("abcd"),
      91             :           false },
      92           1 :         { RTL_CONSTASCII_STRINGPARAM("a\0b\0c"),
      93           1 :           RTL_CONSTASCII_STRINGPARAM("b\0c"), true },
      94           1 :         { RTL_CONSTASCII_STRINGPARAM("a\0b\0c"),
      95          16 :           RTL_CONSTASCII_STRINGPARAM("b"), false } };
      96           9 :     for (size_t i = 0; i < SAL_N_ELEMENTS(data); ++i) {
      97           8 :         rtl::OStringBuffer msg;
      98           8 :         appendString(msg, rtl::OString(data[i].str1, data[i].str1Len));
      99             :         msg.append(
     100           8 :             RTL_CONSTASCII_STRINGPARAM(".endsWithIgnoreAsciiCaseAsciiL("));
     101           8 :         appendString(msg, rtl::OString(data[i].str2, data[i].str2Len));
     102           8 :         msg.append(RTL_CONSTASCII_STRINGPARAM(") == "));
     103           8 :         msg.append(data[i].endsWith);
     104          16 :         CPPUNIT_ASSERT_MESSAGE(
     105             :             msg.getStr(),
     106             :             rtl::OUString(
     107             :                 data[i].str1, data[i].str1Len,
     108             :                 RTL_TEXTENCODING_ASCII_US).endsWithIgnoreAsciiCaseAsciiL(
     109             :                     data[i].str2, data[i].str2Len)
     110           8 :             == data[i].endsWith);
     111           8 :     }
     112           4 : }
     113             : 
     114             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11