LCOV - code coverage report
Current view: top level - svl/qa/unit - test_lngmisc.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 103 103 100.0 %
Date: 2012-08-25 Functions: 13 14 92.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 341 680 50.1 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4                 :            :  *
       5                 :            :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :            :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :            :  * the License or as specified alternatively below. You may obtain a copy of
       8                 :            :  * the License at http://www.mozilla.org/MPL/
       9                 :            :  *
      10                 :            :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :            :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :            :  * for the specific language governing rights and limitations under the
      13                 :            :  * License.
      14                 :            :  *
      15                 :            :  * Major Contributor(s):
      16                 :            :  *  Copyright (C) 2011 August Sodora <augsod@gmail.com> (initial developer)
      17                 :            :  *
      18                 :            :  * All Rights Reserved.
      19                 :            :  *
      20                 :            :  * For minor contributions see the git repository.
      21                 :            :  *
      22                 :            :  * Alternatively, the contents of this file may be used under the terms of
      23                 :            :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      24                 :            :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      25                 :            :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      26                 :            :  * instead of those above.
      27                 :            :  */
      28                 :            : 
      29                 :            : #include <sal/types.h>
      30                 :            : #include "cppunit/TestAssert.h"
      31                 :            : #include "cppunit/TestFixture.h"
      32                 :            : #include "cppunit/extensions/HelperMacros.h"
      33                 :            : #include "cppunit/plugin/TestPlugIn.h"
      34                 :            : 
      35                 :            : #include "svl/lngmisc.hxx"
      36                 :            : 
      37                 :            : #include <rtl/ustrbuf.hxx>
      38                 :            : 
      39                 :            : namespace
      40                 :            : {
      41         [ -  + ]:         60 :   class LngMiscTest : public CppUnit::TestFixture
      42                 :            :   {
      43                 :            :   private:
      44                 :            :     void testRemoveHyphens();
      45                 :            :     void testRemoveControlChars();
      46                 :            :     void testReplaceControlChars();
      47                 :            :     void testGetThesaurusReplaceText();
      48                 :            : 
      49 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE(LngMiscTest);
         [ +  - ][ +  - ]
                 [ #  # ]
      50                 :            : 
      51 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(testRemoveHyphens);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      52 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(testRemoveControlChars);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      53 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(testReplaceControlChars);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      54 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST(testGetThesaurusReplaceText);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      55                 :            : 
      56 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE_END();
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      57                 :            :   };
      58                 :            : 
      59                 :          5 :   void LngMiscTest::testRemoveHyphens()
      60                 :            :   {
      61                 :          5 :     ::rtl::OUString str1("");
      62                 :          5 :     ::rtl::OUString str2("a-b--c---");
      63                 :            : 
      64                 :          5 :     ::rtl::OUStringBuffer str3Buf;
      65         [ +  - ]:          5 :     str3Buf.append(SVT_SOFT_HYPHEN);
      66         [ +  - ]:          5 :     str3Buf.append(SVT_HARD_HYPHEN);
      67         [ +  - ]:          5 :     str3Buf.append(SVT_HARD_HYPHEN);
      68         [ +  - ]:          5 :     ::rtl::OUString str3(str3Buf.makeStringAndClear());
      69                 :            : 
      70                 :          5 :     ::rtl::OUString str4("asdf");
      71                 :            : 
      72         [ +  - ]:          5 :     bool bModified = linguistic::RemoveHyphens(str1);
      73 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(!bModified);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      74 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(str1.isEmpty());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      75                 :            : 
      76                 :            :     // Note that '-' isn't a hyphen to RemoveHyphens.
      77         [ +  - ]:          5 :     bModified = linguistic::RemoveHyphens(str2);
      78 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(!bModified);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      79 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT( str2 == "a-b--c---" );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      80                 :            : 
      81         [ +  - ]:          5 :     bModified = linguistic::RemoveHyphens(str3);
      82 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(bModified);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      83 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(str3.isEmpty());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      84                 :            : 
      85         [ +  - ]:          5 :     bModified = linguistic::RemoveHyphens(str4);
      86 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(!bModified);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      87 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT( str4 == "asdf" );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      88                 :          5 :   }
      89                 :            : 
      90                 :          5 :   void LngMiscTest::testRemoveControlChars()
      91                 :            :   {
      92                 :          5 :     ::rtl::OUString str1("");
      93                 :          5 :     ::rtl::OUString str2("asdf");
      94                 :          5 :     ::rtl::OUString str3("asdf\nasdf");
      95                 :            : 
      96                 :          5 :     ::rtl::OUStringBuffer str4Buf(33);
      97         [ +  - ]:          5 :     str4Buf.setLength(33);
      98         [ +  + ]:        170 :     for(int i = 0; i < 33; i++)
      99                 :        165 :       str4Buf[i] = static_cast<sal_Unicode>(i);
     100                 :            :     //    TODO: is this a bug? shouldn't RemoveControlChars remove this?
     101                 :            :     //    str4Buf[33] = static_cast<sal_Unicode>(0x7F);
     102         [ +  - ]:          5 :     ::rtl::OUString str4(str4Buf.makeStringAndClear());
     103                 :            : 
     104         [ +  - ]:          5 :     bool bModified = linguistic::RemoveControlChars(str1);
     105 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(!bModified);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     106 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(str1.isEmpty());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     107                 :            : 
     108         [ +  - ]:          5 :     bModified = linguistic::RemoveControlChars(str2);
     109 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(!bModified);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     110 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT( str2 == "asdf" );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     111                 :            : 
     112         [ +  - ]:          5 :     bModified = linguistic::RemoveControlChars(str3);
     113 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(bModified);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     114 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT( str3 == "asdfasdf" );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     115                 :            : 
     116         [ +  - ]:          5 :     bModified = linguistic::RemoveControlChars(str4);
     117 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(bModified);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     118 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT( str4 == " " );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     119                 :          5 :   }
     120                 :            : 
     121                 :          5 :   void LngMiscTest::testReplaceControlChars()
     122                 :            :   {
     123                 :          5 :     ::rtl::OUString str1("");
     124                 :          5 :     ::rtl::OUString str2("asdf");
     125                 :          5 :     ::rtl::OUString str3("asdf\nasdf");
     126                 :            : 
     127                 :          5 :     ::rtl::OUStringBuffer str4Buf(33);
     128         [ +  - ]:          5 :     str4Buf.setLength(33);
     129         [ +  + ]:        170 :     for(int i = 0; i < 33; i++)
     130                 :        165 :       str4Buf[i] = static_cast<sal_Unicode>(i);
     131                 :            :     //    TODO: is this a bug? shouldn't RemoveControlChars remove this?
     132                 :            :     //    str4Buf[33] = static_cast<sal_Unicode>(0x7F);
     133         [ +  - ]:          5 :     ::rtl::OUString str4(str4Buf.makeStringAndClear());
     134                 :            : 
     135         [ +  - ]:          5 :     bool bModified = linguistic::ReplaceControlChars(str1);
     136 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(!bModified);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     137 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(str1.isEmpty());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     138                 :            : 
     139         [ +  - ]:          5 :     bModified = linguistic::ReplaceControlChars(str2);
     140 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(!bModified);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     141 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT( str2 == "asdf" );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     142                 :            : 
     143         [ +  - ]:          5 :     bModified = linguistic::ReplaceControlChars(str3);
     144 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(bModified);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     145 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT( str3 == "asdf asdf" );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     146                 :            : 
     147         [ +  - ]:          5 :     bModified = linguistic::ReplaceControlChars(str4);
     148 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(bModified);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     149 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(str4.getLength() == 32);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     150         [ +  + ]:        165 :     for(int i = 0; i < 32; i++)
     151 [ +  - ][ +  - ]:        165 :       CPPUNIT_ASSERT(str4[i] == ' ');
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     152                 :          5 :   }
     153                 :            : 
     154                 :          5 :   void LngMiscTest::testGetThesaurusReplaceText()
     155                 :            :   {
     156                 :          5 :     const ::rtl::OUString str1("");
     157                 :          5 :     const ::rtl::OUString str2("asdf");
     158                 :          5 :     const ::rtl::OUString str3("asdf (abc)");
     159                 :          5 :     const ::rtl::OUString str4("asdf*");
     160                 :          5 :     const ::rtl::OUString str5("asdf * ");
     161                 :          5 :     const ::rtl::OUString str6("asdf (abc) *");
     162                 :          5 :     const ::rtl::OUString str7("asdf asdf * (abc)");
     163                 :          5 :     const ::rtl::OUString str8(" * (abc) asdf *");
     164                 :            : 
     165         [ +  - ]:          5 :     ::rtl::OUString r = linguistic::GetThesaurusReplaceText(str1);
     166 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(r.isEmpty());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     167                 :            : 
     168         [ +  - ]:          5 :     r = linguistic::GetThesaurusReplaceText(str2);
     169 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(r == str2);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     170                 :            : 
     171         [ +  - ]:          5 :     r = linguistic::GetThesaurusReplaceText(str3);
     172 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(r == str2);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     173                 :            : 
     174         [ +  - ]:          5 :     r = linguistic::GetThesaurusReplaceText(str4);
     175 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(r == str2);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     176                 :            : 
     177         [ +  - ]:          5 :     r = linguistic::GetThesaurusReplaceText(str5);
     178 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(r == str2);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     179                 :            : 
     180         [ +  - ]:          5 :     r = linguistic::GetThesaurusReplaceText(str6);
     181 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(r == str2);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     182                 :            : 
     183         [ +  - ]:          5 :     r = linguistic::GetThesaurusReplaceText(str7);
     184 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(r == "asdf asdf");
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     185                 :            : 
     186         [ +  - ]:          5 :     r = linguistic::GetThesaurusReplaceText(str8);
     187 [ +  - ][ +  - ]:          5 :     CPPUNIT_ASSERT(r.isEmpty());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     188                 :          5 :   }
     189                 :            : 
     190                 :          5 :   CPPUNIT_TEST_SUITE_REGISTRATION(LngMiscTest);
     191                 :            : }
     192 [ +  - ][ +  - ]:         20 : CPPUNIT_PLUGIN_IMPLEMENT();
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
     193                 :            : 
     194                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10