LCOV - code coverage report
Current view: top level - sal/qa/osl/file - osl_old_test_file.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 49 49 100.0 %
Date: 2012-08-25 Functions: 12 13 92.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 113 224 50.4 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : // LLA:
      30                 :            : // this file is converted to use with testshl2
      31                 :            : // original was placed in sal/test/textenc.cxx
      32                 :            : 
      33                 :            : #include <stdio.h>
      34                 :            : 
      35                 :            : #include <osl/file.h>
      36                 :            : #include <osl/process.h>
      37                 :            : #include <rtl/ustring.hxx>
      38                 :            : #ifdef SAL_UNX
      39                 :            : #include <unistd.h>
      40                 :            : #include <limits.h>
      41                 :            : #include <string.h>
      42                 :            : #include <sys/stat.h>
      43                 :            : #define TEST_VOLUME ""
      44                 :            : #else
      45                 :            : // WINDOWS
      46                 :            : #define TEST_VOLUME "c:/"
      47                 :            : #endif
      48                 :            : 
      49                 :            : #include <cppunit/TestFixture.h>
      50                 :            : #include <cppunit/extensions/HelperMacros.h>
      51                 :            : #include <cppunit/plugin/TestPlugIn.h>
      52                 :            : 
      53                 :            : namespace osl_test_file
      54                 :            : {
      55                 :            : 
      56                 :            : // -----------------------------------------------------------------------------
      57                 :            : 
      58         [ -  + ]:         45 : class oldtestfile : public CppUnit::TestFixture
      59                 :            : {
      60                 :            : public:
      61                 :            :     void test_file_001();
      62                 :            :     void test_file_002();
      63                 :            :     void test_file_004();
      64                 :            : 
      65 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE( oldtestfile );
         [ +  - ][ +  - ]
                 [ #  # ]
      66 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST( test_file_001 );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      67 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST( test_file_002 );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      68 [ +  - ][ +  - ]:          5 :     CPPUNIT_TEST( test_file_004 );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      69 [ +  - ][ +  - ]:         10 :     CPPUNIT_TEST_SUITE_END( );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
      70                 :            : };
      71                 :            : 
      72                 :            : const char * const aSource1[] =
      73                 :            : {
      74                 :            :     "a"    , "file:///" TEST_VOLUME "bla/a",
      75                 :            :     ///TODO: check if last slash must be omitted in resolved path.
      76                 :            : //    "a/"   , "file:///" TEST_VOLUME "bla/a",
      77                 :            :     "../a" , "file:///" TEST_VOLUME "a" ,
      78                 :            :     "a/.." , "file:///" TEST_VOLUME "bla/",
      79                 :            :     "a/../b" , "file:///" TEST_VOLUME "bla/b",
      80                 :            :     ".."   , "file:///" TEST_VOLUME "",
      81                 :            :     "a/b/c/d"   , "file:///" TEST_VOLUME "bla/a/b/c/d",
      82                 :            :     "a/./c"   , "file:///" TEST_VOLUME "bla/a/c",
      83                 :            :     "file:///bla/blub", "file:///"  "bla/blub",
      84                 :            :     0 , 0
      85                 :            : };
      86                 :            : 
      87                 :            : const char * const aSource2[ ] =
      88                 :            : {
      89                 :            :     "a" , "file:///" TEST_VOLUME "bla/blubs/schnubbel/a",
      90                 :            :     ///TODO: check if last slash must be omitted in resolved path.
      91                 :            : //    "a/", "file:///" TEST_VOLUME "bla/blubs/schnubbel/a",
      92                 :            :     "../a", "file:///" TEST_VOLUME "bla/blubs/a",
      93                 :            :     "../../a", "file:///" TEST_VOLUME "bla/a",
      94                 :            :     "../../../a", "file:///" TEST_VOLUME "a",
      95                 :            :     "../../../a/b/c/d", "file:///" TEST_VOLUME "a/b/c/d",
      96                 :            :     0,0
      97                 :            : };
      98                 :            : 
      99                 :            : const char * const aSource3[ ] =
     100                 :            : {
     101                 :            :     ".." , "/a",
     102                 :            :     "../a" , "/a/a",
     103                 :            :     "e/f" , "/c/e/f",
     104                 :            :     "../..", "",
     105                 :            :     0,0
     106                 :            : };
     107                 :            : 
     108                 :            : using ::rtl::OUString;
     109                 :            : using ::rtl::OUStringToOString;
     110                 :            : using ::rtl::OString;
     111                 :            : 
     112                 :          5 : void oldtestfile::test_file_001()
     113                 :            : {
     114                 :            : #ifndef WIN32
     115         [ +  - ]:          5 :     OUString base1( RTL_CONSTASCII_USTRINGPARAM( "file:///" TEST_VOLUME "bla" ) );
     116                 :            :     int i;
     117         [ +  + ]:         45 :     for( i = 0 ; aSource1[i] ; i +=2 )
     118                 :            :     {
     119                 :         40 :         OUString target;
     120                 :         40 :         OUString rel = OUString::createFromAscii( aSource1[i] );
     121         [ +  - ]:         40 :         oslFileError e = osl_getAbsoluteFileURL( base1.pData, rel.pData , &target.pData );
     122                 :            :         //fprintf(stderr, "%d : %s -- %s -- %s\n", i, aSource1[i], aSource1[i+1], OUStringToOString(target , RTL_TEXTENCODING_ASCII_US ).getStr() );
     123 [ +  - ][ +  - ]:         40 :         CPPUNIT_ASSERT_MESSAGE("failure #1",  osl_File_E_None == e );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     124         [ +  - ]:         40 :         if( osl_File_E_None == e )
     125                 :            :         {
     126 [ +  - ][ +  - ]:         40 :             CPPUNIT_ASSERT_MESSAGE("failure #1.1",  target.equalsAscii( aSource1[i+1] ) );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     127                 :            :         }
     128         [ +  - ]:         40 :         OString o = OUStringToOString( target , RTL_TEXTENCODING_ASCII_US );
     129         [ +  - ]:         40 :         OString obase = OUStringToOString( base1 , RTL_TEXTENCODING_ASCII_US );
     130                 :            :         // fprintf( stderr, "%d %s + %s = %s\n" ,e, obase.getStr(), aSource1[i], o.pData->buffer );
     131                 :         40 :     }
     132                 :            : 
     133         [ +  - ]:          5 :     OUString err1( RTL_CONSTASCII_USTRINGPARAM( "../.." ) );
     134                 :          5 :     OUString target;
     135                 :            :     // CPPUNIT_ASSERT_MESSAGE("failure #11",  osl_File_E_None != osl_getAbsoluteFileURL( base1.pData , err1.pData , &target.pData ) );
     136                 :            : #endif
     137                 :          5 : }
     138                 :            : 
     139                 :          5 : void oldtestfile::test_file_002()
     140                 :            : {
     141                 :            : #ifndef WIN32
     142         [ +  - ]:          5 :     OUString base2( RTL_CONSTASCII_USTRINGPARAM( "file:///" TEST_VOLUME "bla/blubs/schnubbel" ) );
     143                 :            :     int i;
     144         [ +  + ]:         30 :     for(  i = 0 ; aSource2[i] ; i +=2 )
     145                 :            :     {
     146                 :         25 :         OUString target;
     147                 :         25 :         OUString rel = OUString::createFromAscii( aSource2[i] );
     148         [ +  - ]:         25 :         oslFileError e = osl_getAbsoluteFileURL( base2.pData, rel.pData , &target.pData );
     149                 :            :         //fprintf(stderr, "%d : %s -- %s -- %s\n", i, aSource2[i], aSource2[i+1], OUStringToOString(target , RTL_TEXTENCODING_ASCII_US ).getStr() );
     150 [ +  - ][ +  - ]:         25 :         CPPUNIT_ASSERT_MESSAGE("failure #2",  osl_File_E_None == e );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     151         [ +  - ]:         25 :         if( osl_File_E_None == e )
     152                 :            :         {
     153 [ +  - ][ +  - ]:         25 :             CPPUNIT_ASSERT_MESSAGE("failure #2.1",  target.equalsAscii( aSource2[i+1] ) );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     154                 :            :         }
     155         [ +  - ]:         25 :         OString o = OUStringToOString( target , RTL_TEXTENCODING_ASCII_US );
     156         [ +  - ]:         25 :         OString obase = OUStringToOString( base2 , RTL_TEXTENCODING_ASCII_US );
     157                 :         30 :     }
     158                 :            : #endif
     159                 :          5 : }
     160                 :            : 
     161                 :          5 : void oldtestfile::test_file_004()
     162                 :            : {
     163                 :            : #ifndef WIN32
     164         [ +  - ]:          5 :     OUString base4( RTL_CONSTASCII_USTRINGPARAM( "file:///" TEST_VOLUME "bla/" ) );
     165                 :            :     int i;
     166         [ +  + ]:         45 :     for( i = 0 ; aSource1[i] ; i +=2 )
     167                 :            :     {
     168                 :         40 :         OUString target;
     169                 :         40 :         OUString rel = OUString::createFromAscii( aSource1[i] );
     170         [ +  - ]:         40 :         oslFileError e = osl_getAbsoluteFileURL( base4.pData, rel.pData , &target.pData );
     171 [ +  - ][ +  - ]:         40 :         CPPUNIT_ASSERT_MESSAGE("failure #10",  osl_File_E_None == e );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     172         [ +  - ]:         40 :         if( osl_File_E_None == e )
     173                 :            :         {
     174 [ +  - ][ +  - ]:         40 :             CPPUNIT_ASSERT_MESSAGE("failure #10.1",  target.equalsAscii( aSource1[i+1] ) );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     175                 :            :         }
     176         [ +  - ]:         40 :         OString o = OUStringToOString( target , RTL_TEXTENCODING_ASCII_US );
     177         [ +  - ]:         40 :         OString obase = OUStringToOString( base4 , RTL_TEXTENCODING_ASCII_US );
     178                 :            :         //fprintf( stderr, "%d %s + %s = %s\n" ,e, obase.getStr(), aSource1[i], o.pData->buffer );
     179                 :         45 :     }
     180                 :            : #endif
     181                 :          5 : }
     182                 :            : 
     183                 :            : } // namespace osl_test_file
     184                 :            : 
     185                 :            : // -----------------------------------------------------------------------------
     186                 :          5 : CPPUNIT_TEST_SUITE_REGISTRATION( osl_test_file::oldtestfile);
     187                 :            : 
     188                 :            : // -----------------------------------------------------------------------------
     189 [ +  - ][ +  - ]:         20 : CPPUNIT_PLUGIN_IMPLEMENT();
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
     190                 :            : 
     191                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10