LCOV - code coverage report
Current view: top level - sal/qa/rtl/uri - rtl_Uri.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 24 24 100.0 %
Date: 2014-04-11 Functions: 12 13 92.3 %
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             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <stdlib.h>
      21             : #include <rtl/strbuf.hxx>
      22             : #include <rtl/uri.hxx>
      23             : #include <osl/thread.h>
      24             : #include <osl/file.hxx>
      25             : 
      26             : #include <cppunit/TestFixture.h>
      27             : #include <cppunit/extensions/HelperMacros.h>
      28             : #include <cppunit/plugin/TestPlugIn.h>
      29             : 
      30             : namespace Stringtest
      31             : {
      32             : 
      33           3 :     class Convert : public CppUnit::TestFixture
      34             :     {
      35             :         rtl::OUString m_aStr;
      36             :     public:
      37           2 :         rtl::OString convertToOString(rtl::OUString const& _suStr)
      38             :             {
      39           2 :                 return rtl::OUStringToOString(_suStr, osl_getThreadTextEncoding()/*RTL_TEXTENCODING_ASCII_US*/);
      40             :             }
      41             : 
      42           2 :         void showContent(rtl::OUString const& _suStr)
      43             :             {
      44           2 :                 rtl::OString sStr = convertToOString(_suStr);
      45           2 :                 printf("%s\n", sStr.getStr());
      46           2 :             }
      47             : 
      48           1 :         void test_FromUTF8_001()
      49             :             {
      50             :                 // string --> ustring
      51           1 :                 rtl::OString sStrUTF8("h%C3%A4llo");
      52           2 :                 rtl::OUString suStrUTF8 = rtl::OStringToOUString(sStrUTF8, RTL_TEXTENCODING_ASCII_US);
      53             : 
      54             :                 // UTF8 --> real ustring
      55           2 :                 rtl::OUString suStr_UriDecodeToIuri      = rtl::Uri::decode(suStrUTF8, rtl_UriDecodeToIuri, RTL_TEXTENCODING_UTF8);
      56           1 :                 showContent(suStr_UriDecodeToIuri);
      57             : 
      58             :                 // string --> ustring
      59           2 :                 rtl::OString sStr("h\xE4llo", strlen("h\xE4llo"));
      60           2 :                 rtl::OUString suString = rtl::OStringToOUString(sStr, RTL_TEXTENCODING_ISO_8859_15);
      61             : 
      62           1 :                 CPPUNIT_ASSERT_MESSAGE("Strings must be equal", suString.equals(suStr_UriDecodeToIuri));
      63             : 
      64             :                 // ustring --> ustring (UTF8)
      65           2 :                 rtl::OUString suStr2 = rtl::Uri::encode(suStr_UriDecodeToIuri, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8);
      66           1 :                 showContent(suStr2);
      67             : 
      68           2 :                 CPPUNIT_ASSERT_MESSAGE("Strings must be equal", suStr2.equals(suStrUTF8));
      69             :                 // suStr should be equal to suStr2
      70           1 :             }
      71             : 
      72           2 :         CPPUNIT_TEST_SUITE( Convert );
      73           1 :         CPPUNIT_TEST( test_FromUTF8_001 );
      74           2 :         CPPUNIT_TEST_SUITE_END( );
      75             :     };
      76             : 
      77             : }
      78             : 
      79           1 : CPPUNIT_TEST_SUITE_REGISTRATION( Stringtest::Convert );
      80             : 
      81             : // LLA: doku anpassen!!!
      82             : 
      83           4 : CPPUNIT_PLUGIN_IMPLEMENT();
      84             : 
      85             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10