LCOV - code coverage report
Current view: top level - sal/qa/rtl/strings - test_oustring_endswith.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 31 31 100.0 %
Date: 2012-08-25 Functions: 10 10 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 47 90 52.2 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <sal/types.h>
      30                 :            : #include <cppunit/TestFixture.h>
      31                 :            : #include <cppunit/extensions/HelperMacros.h>
      32                 :            : #include "rtl/strbuf.hxx"
      33                 :            : #include "rtl/string.h"
      34                 :            : #include "rtl/string.hxx"
      35                 :            : #include "rtl/textenc.h"
      36                 :            : #include "rtl/ustring.hxx"
      37                 :            : #include "sal/types.h"
      38                 :            : #include <sal/macros.h>
      39                 :            : 
      40                 :            : namespace test { namespace oustring {
      41                 :            : 
      42         [ -  + ]:         15 : class EndsWith: public CppUnit::TestFixture
      43                 :            : {
      44                 :            : private:
      45                 :            :     void endsWith();
      46                 :            : 
      47 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE(EndsWith);
         [ +  - ][ +  - ]
                 [ #  # ]
      48 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(endsWith);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      49 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE_END();
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      50                 :            : };
      51                 :            : 
      52                 :            : } }
      53                 :            : 
      54                 :          5 : CPPUNIT_TEST_SUITE_REGISTRATION(test::oustring::EndsWith);
      55                 :            : 
      56                 :            : namespace {
      57                 :            : 
      58                 :         80 : void appendString(rtl::OStringBuffer & buffer, rtl::OString const & string)
      59                 :            : {
      60                 :         80 :     buffer.append('"');
      61         [ +  + ]:        280 :     for (int i = 0; i < string.getLength(); ++i) {
      62                 :        200 :         char c = string[i];
      63 [ +  - ][ +  - ]:        200 :         if (c < ' ' || c == '"' || c == '\\' || c > '~') {
         [ -  + ][ +  + ]
      64                 :         25 :             buffer.append('\\');
      65                 :            :             sal_Int32 n = static_cast< sal_Int32 >(
      66                 :         25 :                 static_cast< unsigned char >(c));
      67         [ +  - ]:         25 :             if (n < 16) {
      68                 :         25 :                 buffer.append('0');
      69                 :            :             }
      70                 :         25 :             buffer.append(n, 16);
      71                 :            :         } else {
      72                 :        175 :             buffer.append(c);
      73                 :            :         }
      74                 :            :     }
      75                 :         80 :     buffer.append('"');
      76                 :         80 : }
      77                 :            : 
      78                 :            : }
      79                 :            : 
      80                 :          5 : void test::oustring::EndsWith::endsWith()
      81                 :            : {
      82                 :            :     struct Data {
      83                 :            :         char const * str1;
      84                 :            :         sal_Int32 str1Len;
      85                 :            :         char const * str2;
      86                 :            :         sal_Int32 str2Len;
      87                 :            :         bool endsWith;
      88                 :            :     };
      89                 :            :     Data const data[] = {
      90                 :            :         { RTL_CONSTASCII_STRINGPARAM(""), RTL_CONSTASCII_STRINGPARAM(""),
      91                 :            :           true },
      92                 :            :         { RTL_CONSTASCII_STRINGPARAM("abc"), RTL_CONSTASCII_STRINGPARAM(""),
      93                 :            :           true },
      94                 :            :         { RTL_CONSTASCII_STRINGPARAM(""), RTL_CONSTASCII_STRINGPARAM("abc"),
      95                 :            :           false },
      96                 :            :         { RTL_CONSTASCII_STRINGPARAM("ABC"), RTL_CONSTASCII_STRINGPARAM("abc"),
      97                 :            :           true },
      98                 :            :         { RTL_CONSTASCII_STRINGPARAM("abcd"), RTL_CONSTASCII_STRINGPARAM("bcd"),
      99                 :            :           true },
     100                 :            :         { RTL_CONSTASCII_STRINGPARAM("bcd"), RTL_CONSTASCII_STRINGPARAM("abcd"),
     101                 :            :           false },
     102                 :            :         { RTL_CONSTASCII_STRINGPARAM("a\0b\0c"),
     103                 :            :           RTL_CONSTASCII_STRINGPARAM("b\0c"), true },
     104                 :            :         { RTL_CONSTASCII_STRINGPARAM("a\0b\0c"),
     105                 :          5 :           RTL_CONSTASCII_STRINGPARAM("b"), false } };
     106         [ +  + ]:         45 :     for (size_t i = 0; i < SAL_N_ELEMENTS(data); ++i) {
     107                 :         40 :         rtl::OStringBuffer msg;
     108         [ +  - ]:         40 :         appendString(msg, rtl::OString(data[i].str1, data[i].str1Len));
     109                 :            :         msg.append(
     110         [ +  - ]:         40 :             RTL_CONSTASCII_STRINGPARAM(".endsWithIgnoreAsciiCaseAsciiL("));
     111         [ +  - ]:         40 :         appendString(msg, rtl::OString(data[i].str2, data[i].str2Len));
     112         [ +  - ]:         40 :         msg.append(RTL_CONSTASCII_STRINGPARAM(") == "));
     113         [ +  - ]:         40 :         msg.append(static_cast< sal_Bool >(data[i].endsWith));
     114 [ +  - ][ +  - ]:         80 :         CPPUNIT_ASSERT_MESSAGE(
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     115                 :            :             msg.getStr(),
     116                 :            :             rtl::OUString(
     117                 :            :                 data[i].str1, data[i].str1Len,
     118                 :            :                 RTL_TEXTENCODING_ASCII_US).endsWithIgnoreAsciiCaseAsciiL(
     119                 :            :                     data[i].str2, data[i].str2Len)
     120         [ +  - ]:         40 :             == data[i].endsWith);
     121                 :         40 :     }
     122 [ +  - ][ +  - ]:         20 : }
     123                 :            : 
     124                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10