LCOV - code coverage report
Current view: top level - libreoffice/sal/qa/rtl/strings - test_oustring_compare.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 36 36 100.0 %
Date: 2012-12-17 Functions: 11 11 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/string.h"
      24             : #include "rtl/ustring.hxx"
      25             : 
      26             : namespace test { namespace oustring {
      27             : 
      28          18 : class Compare: public CppUnit::TestFixture
      29             : {
      30             : private:
      31             :     void equalsIgnoreAsciiCaseAscii();
      32             : 
      33             :     void compareToAscii();
      34             : 
      35             :     void compareToIgnoreAsciiCase();
      36             : 
      37           4 : CPPUNIT_TEST_SUITE(Compare);
      38           2 : CPPUNIT_TEST(equalsIgnoreAsciiCaseAscii);
      39           2 : CPPUNIT_TEST(compareToAscii);
      40           2 : CPPUNIT_TEST(compareToIgnoreAsciiCase);
      41           4 : CPPUNIT_TEST_SUITE_END();
      42             : };
      43             : 
      44             : } }
      45             : 
      46           2 : CPPUNIT_TEST_SUITE_REGISTRATION(test::oustring::Compare);
      47             : 
      48           2 : void test::oustring::Compare::equalsIgnoreAsciiCaseAscii()
      49             : {
      50           2 :     CPPUNIT_ASSERT(!rtl::OUString().equalsIgnoreAsciiCaseAscii("abc"));
      51           4 :     CPPUNIT_ASSERT(!rtl::OUString().equalsIgnoreAsciiCaseAsciiL(
      52           2 :                        RTL_CONSTASCII_STRINGPARAM("abc")));
      53           4 :     CPPUNIT_ASSERT(!rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("abc")).
      54           2 :                    equalsIgnoreAsciiCaseAscii(""));
      55           4 :     CPPUNIT_ASSERT(!rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("abc")).
      56           2 :                    equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("")));
      57             : 
      58           4 :     CPPUNIT_ASSERT(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("abc")).
      59           2 :                    equalsIgnoreAsciiCaseAscii("abc"));
      60           4 :     CPPUNIT_ASSERT(!rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("abcd")).
      61           2 :                    equalsIgnoreAsciiCaseAscii("abc"));
      62           4 :     CPPUNIT_ASSERT(!rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("abc")).
      63           2 :                    equalsIgnoreAsciiCaseAscii("abcd"));
      64           2 : }
      65             : 
      66           2 : void test::oustring::Compare::compareToAscii()
      67             : {
      68             :     // The different overloads of compareToAscii exhibit potentially confusing
      69             :     // behavior:
      70           2 :     rtl::OUString abc("abc");
      71           2 :     CPPUNIT_ASSERT(abc.compareToAscii("a") > 0);
      72           4 :     CPPUNIT_ASSERT_EQUAL(
      73           4 :         sal_Int32(0), abc.compareToAscii(RTL_CONSTASCII_STRINGPARAM("a")));
      74           2 : }
      75             : 
      76           2 : void test::oustring::Compare::compareToIgnoreAsciiCase()
      77             : {
      78           4 :     CPPUNIT_ASSERT_EQUAL(
      79             :         sal_Int32(0),
      80           2 :         rtl::OUString("abc").compareToIgnoreAsciiCase(rtl::OUString("ABC")));
      81           4 :     CPPUNIT_ASSERT(
      82             :         rtl::OUString("ABC").compareToIgnoreAsciiCase(rtl::OUString("abcdef"))
      83           2 :         < 0);
      84           4 :     CPPUNIT_ASSERT(
      85           2 :         rtl::OUString("A").compareToIgnoreAsciiCase(rtl::OUString("_")) > 0);
      86           8 : }
      87             : 
      88             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10