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

Generated by: LCOV version 1.11