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

Generated by: LCOV version 1.10