LCOV - code coverage report
Current view: top level - libreoffice/svl/qa/unit - test_lngmisc.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 103 103 100.0 %
Date: 2012-12-17 Functions: 13 14 92.9 %
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             :  * 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          24 :   class LngMiscTest : public CppUnit::TestFixture
      42             :   {
      43             :   private:
      44             :     void testRemoveHyphens();
      45             :     void testRemoveControlChars();
      46             :     void testReplaceControlChars();
      47             :     void testGetThesaurusReplaceText();
      48             : 
      49           4 :     CPPUNIT_TEST_SUITE(LngMiscTest);
      50             : 
      51           2 :     CPPUNIT_TEST(testRemoveHyphens);
      52           2 :     CPPUNIT_TEST(testRemoveControlChars);
      53           2 :     CPPUNIT_TEST(testReplaceControlChars);
      54           2 :     CPPUNIT_TEST(testGetThesaurusReplaceText);
      55             : 
      56           4 :     CPPUNIT_TEST_SUITE_END();
      57             :   };
      58             : 
      59           2 :   void LngMiscTest::testRemoveHyphens()
      60             :   {
      61           2 :     ::rtl::OUString str1("");
      62           2 :     ::rtl::OUString str2("a-b--c---");
      63             : 
      64           2 :     ::rtl::OUStringBuffer str3Buf;
      65           2 :     str3Buf.append(SVT_SOFT_HYPHEN);
      66           2 :     str3Buf.append(SVT_HARD_HYPHEN);
      67           2 :     str3Buf.append(SVT_HARD_HYPHEN);
      68           2 :     ::rtl::OUString str3(str3Buf.makeStringAndClear());
      69             : 
      70           2 :     ::rtl::OUString str4("asdf");
      71             : 
      72           2 :     bool bModified = linguistic::RemoveHyphens(str1);
      73           2 :     CPPUNIT_ASSERT(!bModified);
      74           2 :     CPPUNIT_ASSERT(str1.isEmpty());
      75             : 
      76             :     // Note that '-' isn't a hyphen to RemoveHyphens.
      77           2 :     bModified = linguistic::RemoveHyphens(str2);
      78           2 :     CPPUNIT_ASSERT(!bModified);
      79           2 :     CPPUNIT_ASSERT( str2 == "a-b--c---" );
      80             : 
      81           2 :     bModified = linguistic::RemoveHyphens(str3);
      82           2 :     CPPUNIT_ASSERT(bModified);
      83           2 :     CPPUNIT_ASSERT(str3.isEmpty());
      84             : 
      85           2 :     bModified = linguistic::RemoveHyphens(str4);
      86           2 :     CPPUNIT_ASSERT(!bModified);
      87           2 :     CPPUNIT_ASSERT( str4 == "asdf" );
      88           2 :   }
      89             : 
      90           2 :   void LngMiscTest::testRemoveControlChars()
      91             :   {
      92           2 :     ::rtl::OUString str1("");
      93           2 :     ::rtl::OUString str2("asdf");
      94           2 :     ::rtl::OUString str3("asdf\nasdf");
      95             : 
      96           2 :     ::rtl::OUStringBuffer str4Buf(33);
      97           2 :     str4Buf.setLength(33);
      98          68 :     for(int i = 0; i < 33; i++)
      99          66 :       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           2 :     ::rtl::OUString str4(str4Buf.makeStringAndClear());
     103             : 
     104           2 :     bool bModified = linguistic::RemoveControlChars(str1);
     105           2 :     CPPUNIT_ASSERT(!bModified);
     106           2 :     CPPUNIT_ASSERT(str1.isEmpty());
     107             : 
     108           2 :     bModified = linguistic::RemoveControlChars(str2);
     109           2 :     CPPUNIT_ASSERT(!bModified);
     110           2 :     CPPUNIT_ASSERT( str2 == "asdf" );
     111             : 
     112           2 :     bModified = linguistic::RemoveControlChars(str3);
     113           2 :     CPPUNIT_ASSERT(bModified);
     114           2 :     CPPUNIT_ASSERT( str3 == "asdfasdf" );
     115             : 
     116           2 :     bModified = linguistic::RemoveControlChars(str4);
     117           2 :     CPPUNIT_ASSERT(bModified);
     118           2 :     CPPUNIT_ASSERT( str4 == " " );
     119           2 :   }
     120             : 
     121           2 :   void LngMiscTest::testReplaceControlChars()
     122             :   {
     123           2 :     ::rtl::OUString str1("");
     124           2 :     ::rtl::OUString str2("asdf");
     125           2 :     ::rtl::OUString str3("asdf\nasdf");
     126             : 
     127           2 :     ::rtl::OUStringBuffer str4Buf(33);
     128           2 :     str4Buf.setLength(33);
     129          68 :     for(int i = 0; i < 33; i++)
     130          66 :       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           2 :     ::rtl::OUString str4(str4Buf.makeStringAndClear());
     134             : 
     135           2 :     bool bModified = linguistic::ReplaceControlChars(str1);
     136           2 :     CPPUNIT_ASSERT(!bModified);
     137           2 :     CPPUNIT_ASSERT(str1.isEmpty());
     138             : 
     139           2 :     bModified = linguistic::ReplaceControlChars(str2);
     140           2 :     CPPUNIT_ASSERT(!bModified);
     141           2 :     CPPUNIT_ASSERT( str2 == "asdf" );
     142             : 
     143           2 :     bModified = linguistic::ReplaceControlChars(str3);
     144           2 :     CPPUNIT_ASSERT(bModified);
     145           2 :     CPPUNIT_ASSERT( str3 == "asdf asdf" );
     146             : 
     147           2 :     bModified = linguistic::ReplaceControlChars(str4);
     148           2 :     CPPUNIT_ASSERT(bModified);
     149           2 :     CPPUNIT_ASSERT(str4.getLength() == 32);
     150          66 :     for(int i = 0; i < 32; i++)
     151          66 :       CPPUNIT_ASSERT(str4[i] == ' ');
     152           2 :   }
     153             : 
     154           2 :   void LngMiscTest::testGetThesaurusReplaceText()
     155             :   {
     156           2 :     const ::rtl::OUString str1("");
     157           2 :     const ::rtl::OUString str2("asdf");
     158           2 :     const ::rtl::OUString str3("asdf (abc)");
     159           2 :     const ::rtl::OUString str4("asdf*");
     160           2 :     const ::rtl::OUString str5("asdf * ");
     161           2 :     const ::rtl::OUString str6("asdf (abc) *");
     162           2 :     const ::rtl::OUString str7("asdf asdf * (abc)");
     163           2 :     const ::rtl::OUString str8(" * (abc) asdf *");
     164             : 
     165           2 :     ::rtl::OUString r = linguistic::GetThesaurusReplaceText(str1);
     166           2 :     CPPUNIT_ASSERT(r.isEmpty());
     167             : 
     168           2 :     r = linguistic::GetThesaurusReplaceText(str2);
     169           2 :     CPPUNIT_ASSERT(r == str2);
     170             : 
     171           2 :     r = linguistic::GetThesaurusReplaceText(str3);
     172           2 :     CPPUNIT_ASSERT(r == str2);
     173             : 
     174           2 :     r = linguistic::GetThesaurusReplaceText(str4);
     175           2 :     CPPUNIT_ASSERT(r == str2);
     176             : 
     177           2 :     r = linguistic::GetThesaurusReplaceText(str5);
     178           2 :     CPPUNIT_ASSERT(r == str2);
     179             : 
     180           2 :     r = linguistic::GetThesaurusReplaceText(str6);
     181           2 :     CPPUNIT_ASSERT(r == str2);
     182             : 
     183           2 :     r = linguistic::GetThesaurusReplaceText(str7);
     184           2 :     CPPUNIT_ASSERT(r == "asdf asdf");
     185             : 
     186           2 :     r = linguistic::GetThesaurusReplaceText(str8);
     187           2 :     CPPUNIT_ASSERT(r.isEmpty());
     188           2 :   }
     189             : 
     190           2 :   CPPUNIT_TEST_SUITE_REGISTRATION(LngMiscTest);
     191             : }
     192           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     193             : 
     194             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10