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

Generated by: LCOV version 1.10