LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/tools/qa/cppunit - test_reversemap.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 70 70 100.0 %
Date: 2013-07-09 Functions: 20 21 95.2 %
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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  */
      12             : 
      13             : #include <sal/types.h>
      14             : #include "cppunit/TestAssert.h"
      15             : #include "cppunit/TestFixture.h"
      16             : #include "cppunit/extensions/HelperMacros.h"
      17             : #include "cppunit/plugin/TestPlugIn.h"
      18             : #include <rtl/ustring.hxx>
      19             : #include <vector>
      20             : 
      21             : #include "tools/tenccvt.hxx"
      22             : 
      23             : //Tests for getBestMSEncodingByChar
      24             : 
      25             : namespace
      26             : {
      27             : 
      28          30 :     class Test: public CppUnit::TestFixture
      29             :     {
      30             :     public:
      31             :         void testEncoding(rtl_TextEncoding eEncoding);
      32             : 
      33             :         void test1258();
      34             :         void test1257();
      35             :         void test1256();
      36             :         void test1255();
      37             :         void test1254();
      38             :         void test1253();
      39             :         void test1252();
      40             :         void test1251();
      41             :         void test1250();
      42             :         void test874();
      43             : 
      44           2 :         CPPUNIT_TEST_SUITE(Test);
      45           1 :         CPPUNIT_TEST(test1258);
      46           1 :         CPPUNIT_TEST(test1257);
      47           1 :         CPPUNIT_TEST(test1256);
      48           1 :         CPPUNIT_TEST(test1255);
      49           1 :         CPPUNIT_TEST(test1254);
      50           1 :         CPPUNIT_TEST(test1253);
      51           1 :         CPPUNIT_TEST(test1252);
      52           1 :         CPPUNIT_TEST(test1251);
      53           1 :         CPPUNIT_TEST(test1250);
      54           1 :         CPPUNIT_TEST(test874);
      55           2 :         CPPUNIT_TEST_SUITE_END();
      56             :     };
      57             : 
      58          10 :     void Test::testEncoding(rtl_TextEncoding eEncoding)
      59             :     {
      60             :         //Taking the single byte legacy encodings, fill in all possible values
      61          10 :         std::vector<sal_Char> aAllChars(255);
      62        2560 :         for (int i = 1; i <= 255; ++i)
      63        2550 :             aAllChars[i-1] = static_cast<sal_Char>(i);
      64             : 
      65             :         //Some slots are unused, so don't map to private, just set them to 'X'
      66          10 :         sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS ^ RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MAPTOPRIVATE;
      67          20 :         OUString sOrigText(&aAllChars[0], aAllChars.size(), eEncoding, convertFlags);
      68          10 :         sOrigText = sOrigText.replace( 0xfffd, 'X' );
      69             : 
      70             :         //Should clearly be equal
      71          10 :         sal_Int32 nLength = aAllChars.size();
      72          10 :         CPPUNIT_ASSERT_EQUAL(sOrigText.getLength(), nLength);
      73             : 
      74          20 :         OUString sFinalText;
      75             : 
      76             :         //Split up in chunks of the same encoding returned by
      77             :         //getBestMSEncodingByChar, convert to it, and back
      78          10 :         rtl_TextEncoding ePrevEncoding = RTL_TEXTENCODING_DONTKNOW;
      79          10 :         const sal_Unicode *pStr = sOrigText.getStr();
      80          10 :         sal_Int32 nChunkStart=0;
      81        2560 :         for (int i = 0; i < 255; ++i)
      82             :         {
      83        2550 :             rtl_TextEncoding eCurrEncoding = getBestMSEncodingByChar(pStr[i]);
      84        2550 :             if (eCurrEncoding != ePrevEncoding)
      85             :             {
      86         337 :                 OString aChunk(pStr+nChunkStart, i-nChunkStart, ePrevEncoding);
      87         337 :                 sFinalText += OStringToOUString(aChunk, ePrevEncoding);
      88         337 :                 nChunkStart = i;
      89             :             }
      90        2550 :             ePrevEncoding = eCurrEncoding;
      91             :         }
      92          10 :         if (nChunkStart < 255)
      93             :         {
      94          10 :             OString aChunk(pStr+nChunkStart, 255-nChunkStart, ePrevEncoding);
      95          10 :             sFinalText += OStringToOUString(aChunk, ePrevEncoding);
      96             :         }
      97             : 
      98             :         //Final text should be the same as original
      99          20 :         CPPUNIT_ASSERT_EQUAL(sOrigText, sFinalText);
     100          10 :     }
     101             : 
     102           1 :     void Test::test1252()
     103             :     {
     104           1 :         testEncoding(RTL_TEXTENCODING_MS_1252);
     105           1 :     }
     106             : 
     107           1 :     void Test::test874()
     108             :     {
     109           1 :         testEncoding(RTL_TEXTENCODING_MS_874);
     110           1 :     }
     111             : 
     112           1 :     void Test::test1258()
     113             :     {
     114           1 :         testEncoding(RTL_TEXTENCODING_MS_1258);
     115           1 :     }
     116             : 
     117           1 :     void Test::test1257()
     118             :     {
     119           1 :         testEncoding(RTL_TEXTENCODING_MS_1257);
     120           1 :     }
     121             : 
     122           1 :     void Test::test1256()
     123             :     {
     124           1 :         testEncoding(RTL_TEXTENCODING_MS_1256);
     125           1 :     }
     126             : 
     127           1 :     void Test::test1255()
     128             :     {
     129           1 :         testEncoding(RTL_TEXTENCODING_MS_1255);
     130           1 :     }
     131             : 
     132           1 :     void Test::test1254()
     133             :     {
     134           1 :         testEncoding(RTL_TEXTENCODING_MS_1254);
     135           1 :     }
     136             : 
     137           1 :     void Test::test1253()
     138             :     {
     139           1 :         testEncoding(RTL_TEXTENCODING_MS_1253);
     140           1 :     }
     141             : 
     142           1 :     void Test::test1251()
     143             :     {
     144           1 :         testEncoding(RTL_TEXTENCODING_MS_1251);
     145           1 :     }
     146             : 
     147           1 :     void Test::test1250()
     148             :     {
     149           1 :         testEncoding(RTL_TEXTENCODING_MS_1250);
     150           1 :     }
     151             : 
     152           1 :     CPPUNIT_TEST_SUITE_REGISTRATION(Test);
     153             : }
     154             : 
     155           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     156             : 
     157             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10