LCOV - code coverage report
Current view: top level - svl/qa/unit - test_lngmisc.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 103 103 100.0 %
Date: 2014-11-03 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             :  * 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             : 
      10             : #include <sal/types.h>
      11             : #include "cppunit/TestAssert.h"
      12             : #include "cppunit/TestFixture.h"
      13             : #include "cppunit/extensions/HelperMacros.h"
      14             : #include "cppunit/plugin/TestPlugIn.h"
      15             : 
      16             : #include <svl/lngmisc.hxx>
      17             : 
      18             : #include <rtl/ustrbuf.hxx>
      19             : 
      20             : namespace
      21             : {
      22          24 :   class LngMiscTest : public CppUnit::TestFixture
      23             :   {
      24             :   private:
      25             :     void testRemoveHyphens();
      26             :     void testRemoveControlChars();
      27             :     void testReplaceControlChars();
      28             :     void testGetThesaurusReplaceText();
      29             : 
      30           4 :     CPPUNIT_TEST_SUITE(LngMiscTest);
      31             : 
      32           2 :     CPPUNIT_TEST(testRemoveHyphens);
      33           2 :     CPPUNIT_TEST(testRemoveControlChars);
      34           2 :     CPPUNIT_TEST(testReplaceControlChars);
      35           2 :     CPPUNIT_TEST(testGetThesaurusReplaceText);
      36             : 
      37           4 :     CPPUNIT_TEST_SUITE_END();
      38             :   };
      39             : 
      40           2 :   void LngMiscTest::testRemoveHyphens()
      41             :   {
      42           2 :     OUString str1("");
      43           4 :     OUString str2("a-b--c---");
      44             : 
      45           4 :     OUStringBuffer str3Buf;
      46           2 :     str3Buf.append(SVT_SOFT_HYPHEN);
      47           2 :     str3Buf.append(SVT_HARD_HYPHEN);
      48           2 :     str3Buf.append(SVT_HARD_HYPHEN);
      49           4 :     OUString str3(str3Buf.makeStringAndClear());
      50             : 
      51           4 :     OUString str4("asdf");
      52             : 
      53           2 :     bool bModified = linguistic::RemoveHyphens(str1);
      54           2 :     CPPUNIT_ASSERT(!bModified);
      55           2 :     CPPUNIT_ASSERT(str1.isEmpty());
      56             : 
      57             :     // Note that '-' isn't a hyphen to RemoveHyphens.
      58           2 :     bModified = linguistic::RemoveHyphens(str2);
      59           2 :     CPPUNIT_ASSERT(!bModified);
      60           2 :     CPPUNIT_ASSERT( str2 == "a-b--c---" );
      61             : 
      62           2 :     bModified = linguistic::RemoveHyphens(str3);
      63           2 :     CPPUNIT_ASSERT(bModified);
      64           2 :     CPPUNIT_ASSERT(str3.isEmpty());
      65             : 
      66           2 :     bModified = linguistic::RemoveHyphens(str4);
      67           2 :     CPPUNIT_ASSERT(!bModified);
      68           4 :     CPPUNIT_ASSERT( str4 == "asdf" );
      69           2 :   }
      70             : 
      71           2 :   void LngMiscTest::testRemoveControlChars()
      72             :   {
      73           2 :     OUString str1("");
      74           4 :     OUString str2("asdf");
      75           4 :     OUString str3("asdf\nasdf");
      76             : 
      77           4 :     OUStringBuffer str4Buf(33);
      78           2 :     str4Buf.setLength(33);
      79          68 :     for(int i = 0; i < 33; i++)
      80          66 :       str4Buf[i] = static_cast<sal_Unicode>(i);
      81             :     //    TODO: is this a bug? shouldn't RemoveControlChars remove this?
      82             :     //    str4Buf[33] = static_cast<sal_Unicode>(0x7F);
      83           4 :     OUString str4(str4Buf.makeStringAndClear());
      84             : 
      85           2 :     bool bModified = linguistic::RemoveControlChars(str1);
      86           2 :     CPPUNIT_ASSERT(!bModified);
      87           2 :     CPPUNIT_ASSERT(str1.isEmpty());
      88             : 
      89           2 :     bModified = linguistic::RemoveControlChars(str2);
      90           2 :     CPPUNIT_ASSERT(!bModified);
      91           2 :     CPPUNIT_ASSERT( str2 == "asdf" );
      92             : 
      93           2 :     bModified = linguistic::RemoveControlChars(str3);
      94           2 :     CPPUNIT_ASSERT(bModified);
      95           2 :     CPPUNIT_ASSERT( str3 == "asdfasdf" );
      96             : 
      97           2 :     bModified = linguistic::RemoveControlChars(str4);
      98           2 :     CPPUNIT_ASSERT(bModified);
      99           4 :     CPPUNIT_ASSERT( str4 == " " );
     100           2 :   }
     101             : 
     102           2 :   void LngMiscTest::testReplaceControlChars()
     103             :   {
     104           2 :     OUString str1("");
     105           4 :     OUString str2("asdf");
     106           4 :     OUString str3("asdf\nasdf");
     107             : 
     108           4 :     OUStringBuffer str4Buf(33);
     109           2 :     str4Buf.setLength(33);
     110          68 :     for(int i = 0; i < 33; i++)
     111          66 :       str4Buf[i] = static_cast<sal_Unicode>(i);
     112             :     //    TODO: is this a bug? shouldn't RemoveControlChars remove this?
     113             :     //    str4Buf[33] = static_cast<sal_Unicode>(0x7F);
     114           4 :     OUString str4(str4Buf.makeStringAndClear());
     115             : 
     116           2 :     bool bModified = linguistic::ReplaceControlChars(str1);
     117           2 :     CPPUNIT_ASSERT(!bModified);
     118           2 :     CPPUNIT_ASSERT(str1.isEmpty());
     119             : 
     120           2 :     bModified = linguistic::ReplaceControlChars(str2);
     121           2 :     CPPUNIT_ASSERT(!bModified);
     122           2 :     CPPUNIT_ASSERT( str2 == "asdf" );
     123             : 
     124           2 :     bModified = linguistic::ReplaceControlChars(str3);
     125           2 :     CPPUNIT_ASSERT(bModified);
     126           2 :     CPPUNIT_ASSERT( str3 == "asdf asdf" );
     127             : 
     128           2 :     bModified = linguistic::ReplaceControlChars(str4);
     129           2 :     CPPUNIT_ASSERT(bModified);
     130           2 :     CPPUNIT_ASSERT(str4.getLength() == 32);
     131          66 :     for(int i = 0; i < 32; i++)
     132          66 :       CPPUNIT_ASSERT(str4[i] == ' ');
     133           2 :   }
     134             : 
     135           2 :   void LngMiscTest::testGetThesaurusReplaceText()
     136             :   {
     137           2 :     const OUString str1("");
     138           4 :     const OUString str2("asdf");
     139           4 :     const OUString str3("asdf (abc)");
     140           4 :     const OUString str4("asdf*");
     141           4 :     const OUString str5("asdf * ");
     142           4 :     const OUString str6("asdf (abc) *");
     143           4 :     const OUString str7("asdf asdf * (abc)");
     144           4 :     const OUString str8(" * (abc) asdf *");
     145             : 
     146           4 :     OUString r = linguistic::GetThesaurusReplaceText(str1);
     147           2 :     CPPUNIT_ASSERT(r.isEmpty());
     148             : 
     149           2 :     r = linguistic::GetThesaurusReplaceText(str2);
     150           2 :     CPPUNIT_ASSERT(r == str2);
     151             : 
     152           2 :     r = linguistic::GetThesaurusReplaceText(str3);
     153           2 :     CPPUNIT_ASSERT(r == str2);
     154             : 
     155           2 :     r = linguistic::GetThesaurusReplaceText(str4);
     156           2 :     CPPUNIT_ASSERT(r == str2);
     157             : 
     158           2 :     r = linguistic::GetThesaurusReplaceText(str5);
     159           2 :     CPPUNIT_ASSERT(r == str2);
     160             : 
     161           2 :     r = linguistic::GetThesaurusReplaceText(str6);
     162           2 :     CPPUNIT_ASSERT(r == str2);
     163             : 
     164           2 :     r = linguistic::GetThesaurusReplaceText(str7);
     165           2 :     CPPUNIT_ASSERT(r == "asdf asdf");
     166             : 
     167           2 :     r = linguistic::GetThesaurusReplaceText(str8);
     168           4 :     CPPUNIT_ASSERT(r.isEmpty());
     169           2 :   }
     170             : 
     171           2 :   CPPUNIT_TEST_SUITE_REGISTRATION(LngMiscTest);
     172             : }
     173           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     174             : 
     175             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10