LCOV - code coverage report
Current view: top level - libreoffice/tools/qa/cppunit - test_reversemap.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 70 70 100.0 %
Date: 2012-12-27 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             :  * 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. You may obtain a copy of the License at
       8             :  * 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             :  * The Initial Developer of the Original Code is
      16             :  *        Caolán McNamara <caolanm@redhat.com> (Red Hat, Inc.)
      17             :  * Portions created by the Initial Developer are Copyright (C) 2010 the
      18             :  * Initial Developer. All Rights Reserved.
      19             :  *
      20             :  * Contributor(s): Caolán McNamara <caolanm@redhat.com>
      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             : #include <rtl/ustring.hxx>
      35             : #include <vector>
      36             : 
      37             : #include "tools/tenccvt.hxx"
      38             : 
      39             : //Tests for getBestMSEncodingByChar
      40             : 
      41             : namespace
      42             : {
      43             : 
      44          30 :     class Test: public CppUnit::TestFixture
      45             :     {
      46             :     public:
      47             :         void testEncoding(rtl_TextEncoding eEncoding);
      48             : 
      49             :         void test1258();
      50             :         void test1257();
      51             :         void test1256();
      52             :         void test1255();
      53             :         void test1254();
      54             :         void test1253();
      55             :         void test1252();
      56             :         void test1251();
      57             :         void test1250();
      58             :         void test874();
      59             : 
      60           2 :         CPPUNIT_TEST_SUITE(Test);
      61           1 :         CPPUNIT_TEST(test1258);
      62           1 :         CPPUNIT_TEST(test1257);
      63           1 :         CPPUNIT_TEST(test1256);
      64           1 :         CPPUNIT_TEST(test1255);
      65           1 :         CPPUNIT_TEST(test1254);
      66           1 :         CPPUNIT_TEST(test1253);
      67           1 :         CPPUNIT_TEST(test1252);
      68           1 :         CPPUNIT_TEST(test1251);
      69           1 :         CPPUNIT_TEST(test1250);
      70           1 :         CPPUNIT_TEST(test874);
      71           2 :         CPPUNIT_TEST_SUITE_END();
      72             :     };
      73             : 
      74          10 :     void Test::testEncoding(rtl_TextEncoding eEncoding)
      75             :     {
      76             :         //Taking the single byte legacy encodings, fill in all possible values
      77          10 :         std::vector<sal_Char> aAllChars(255);
      78        2560 :         for (int i = 1; i <= 255; ++i)
      79        2550 :             aAllChars[i-1] = static_cast<sal_Char>(i);
      80             : 
      81             :         //Some slots are unused, so don't map to private, just set them to 'X'
      82          10 :         sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS ^ RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MAPTOPRIVATE;
      83          10 :         rtl::OUString sOrigText(&aAllChars[0], aAllChars.size(), eEncoding, convertFlags);
      84          10 :         sOrigText = sOrigText.replace( 0xfffd, 'X' );
      85             : 
      86             :         //Should clearly be equal
      87          10 :         sal_Int32 nLength = aAllChars.size();
      88          10 :         CPPUNIT_ASSERT_EQUAL(sOrigText.getLength(), nLength);
      89             : 
      90          10 :         rtl::OUString sFinalText;
      91             : 
      92             :         //Split up in chunks of the same encoding returned by
      93             :         //getBestMSEncodingByChar, convert to it, and back
      94          10 :         rtl_TextEncoding ePrevEncoding = RTL_TEXTENCODING_DONTKNOW;
      95          10 :         const sal_Unicode *pStr = sOrigText.getStr();
      96          10 :         sal_Int32 nChunkStart=0;
      97        2560 :         for (int i = 0; i < 255; ++i)
      98             :         {
      99        2550 :             rtl_TextEncoding eCurrEncoding = getBestMSEncodingByChar(pStr[i]);
     100        2550 :             if (eCurrEncoding != ePrevEncoding)
     101             :             {
     102         337 :                 rtl::OString aChunk(pStr+nChunkStart, i-nChunkStart, ePrevEncoding);
     103         337 :                 sFinalText += rtl::OStringToOUString(aChunk, ePrevEncoding);
     104         337 :                 nChunkStart = i;
     105             :             }
     106        2550 :             ePrevEncoding = eCurrEncoding;
     107             :         }
     108          10 :         if (nChunkStart < 255)
     109             :         {
     110          10 :             rtl::OString aChunk(pStr+nChunkStart, 255-nChunkStart, ePrevEncoding);
     111          10 :             sFinalText += rtl::OStringToOUString(aChunk, ePrevEncoding);
     112             :         }
     113             : 
     114             :         //Final text should be the same as original
     115          10 :         CPPUNIT_ASSERT_EQUAL(sOrigText, sFinalText);
     116          10 :     }
     117             : 
     118           1 :     void Test::test1252()
     119             :     {
     120           1 :         testEncoding(RTL_TEXTENCODING_MS_1252);
     121           1 :     }
     122             : 
     123           1 :     void Test::test874()
     124             :     {
     125           1 :         testEncoding(RTL_TEXTENCODING_MS_874);
     126           1 :     }
     127             : 
     128           1 :     void Test::test1258()
     129             :     {
     130           1 :         testEncoding(RTL_TEXTENCODING_MS_1258);
     131           1 :     }
     132             : 
     133           1 :     void Test::test1257()
     134             :     {
     135           1 :         testEncoding(RTL_TEXTENCODING_MS_1257);
     136           1 :     }
     137             : 
     138           1 :     void Test::test1256()
     139             :     {
     140           1 :         testEncoding(RTL_TEXTENCODING_MS_1256);
     141           1 :     }
     142             : 
     143           1 :     void Test::test1255()
     144             :     {
     145           1 :         testEncoding(RTL_TEXTENCODING_MS_1255);
     146           1 :     }
     147             : 
     148           1 :     void Test::test1254()
     149             :     {
     150           1 :         testEncoding(RTL_TEXTENCODING_MS_1254);
     151           1 :     }
     152             : 
     153           1 :     void Test::test1253()
     154             :     {
     155           1 :         testEncoding(RTL_TEXTENCODING_MS_1253);
     156           1 :     }
     157             : 
     158           1 :     void Test::test1251()
     159             :     {
     160           1 :         testEncoding(RTL_TEXTENCODING_MS_1251);
     161           1 :     }
     162             : 
     163           1 :     void Test::test1250()
     164             :     {
     165           1 :         testEncoding(RTL_TEXTENCODING_MS_1250);
     166           1 :     }
     167             : 
     168           1 :     CPPUNIT_TEST_SUITE_REGISTRATION(Test);
     169             : }
     170             : 
     171           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     172             : 
     173             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10