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

Generated by: LCOV version 1.11