LCOV - code coverage report
Current view: top level - sal/qa/osl/file - osl_old_test_file.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 41 41 100.0 %
Date: 2014-11-03 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 <osl/file.h>
      21             : #include <osl/process.h>
      22             : #include <rtl/ustring.hxx>
      23             : #ifdef SAL_UNX
      24             : #include <unistd.h>
      25             : #include <limits.h>
      26             : #include <string.h>
      27             : #include <sys/stat.h>
      28             : #define TEST_VOLUME ""
      29             : #else
      30             : // WINDOWS
      31             : #define TEST_VOLUME "c:/"
      32             : #endif
      33             : 
      34             : #include <cppunit/TestFixture.h>
      35             : #include <cppunit/extensions/HelperMacros.h>
      36             : #include <cppunit/plugin/TestPlugIn.h>
      37             : 
      38             : namespace osl_test_file
      39             : {
      40             : 
      41          18 : class oldtestfile : public CppUnit::TestFixture
      42             : {
      43             : public:
      44             :     void test_file_001();
      45             :     void test_file_002();
      46             :     void test_file_004();
      47             : 
      48           4 :     CPPUNIT_TEST_SUITE( oldtestfile );
      49           2 :     CPPUNIT_TEST( test_file_001 );
      50           2 :     CPPUNIT_TEST( test_file_002 );
      51           2 :     CPPUNIT_TEST( test_file_004 );
      52           4 :     CPPUNIT_TEST_SUITE_END( );
      53             : };
      54             : 
      55             : const char * const aSource1[] =
      56             : {
      57             :     "a"    , "file:///" TEST_VOLUME "bla/a",
      58             :     ///TODO: check if last slash must be omitted in resolved path.
      59             : //    "a/"   , "file:///" TEST_VOLUME "bla/a",
      60             :     "../a" , "file:///" TEST_VOLUME "a" ,
      61             :     "a/.." , "file:///" TEST_VOLUME "bla/",
      62             :     "a/../b" , "file:///" TEST_VOLUME "bla/b",
      63             :     ".."   , "file:///" TEST_VOLUME "",
      64             :     "a/b/c/d"   , "file:///" TEST_VOLUME "bla/a/b/c/d",
      65             :     "a/./c"   , "file:///" TEST_VOLUME "bla/a/c",
      66             :     "file:///bla/blub", "file:///"  "bla/blub",
      67             :     0 , 0
      68             : };
      69             : 
      70             : const char * const aSource2[ ] =
      71             : {
      72             :     "a" , "file:///" TEST_VOLUME "bla/blubs/schnubbel/a",
      73             :     ///TODO: check if last slash must be omitted in resolved path.
      74             : //    "a/", "file:///" TEST_VOLUME "bla/blubs/schnubbel/a",
      75             :     "../a", "file:///" TEST_VOLUME "bla/blubs/a",
      76             :     "../../a", "file:///" TEST_VOLUME "bla/a",
      77             :     "../../../a", "file:///" TEST_VOLUME "a",
      78             :     "../../../a/b/c/d", "file:///" TEST_VOLUME "a/b/c/d",
      79             :     0,0
      80             : };
      81             : 
      82             : using ::rtl::OUString;
      83             : using ::rtl::OUStringToOString;
      84             : using ::rtl::OString;
      85             : 
      86           2 : void oldtestfile::test_file_001()
      87             : {
      88             : #ifndef WIN32
      89           2 :     OUString base1( "file:///" TEST_VOLUME "bla" );
      90             :     int i;
      91          18 :     for( i = 0 ; aSource1[i] ; i +=2 )
      92             :     {
      93          16 :         OUString target;
      94          32 :         OUString rel = OUString::createFromAscii( aSource1[i] );
      95          16 :         oslFileError e = osl_getAbsoluteFileURL( base1.pData, rel.pData , &target.pData );
      96          16 :         CPPUNIT_ASSERT_MESSAGE("failure #1",  osl_File_E_None == e );
      97          16 :         if( osl_File_E_None == e )
      98             :         {
      99          16 :             CPPUNIT_ASSERT_MESSAGE("failure #1.1",  target.equalsAscii( aSource1[i+1] ) );
     100             :         }
     101          18 :     }
     102             : #endif
     103           2 : }
     104             : 
     105           2 : void oldtestfile::test_file_002()
     106             : {
     107             : #ifndef WIN32
     108           2 :     OUString base2( "file:///" TEST_VOLUME "bla/blubs/schnubbel" );
     109             :     int i;
     110          12 :     for(  i = 0 ; aSource2[i] ; i +=2 )
     111             :     {
     112          10 :         OUString target;
     113          20 :         OUString rel = OUString::createFromAscii( aSource2[i] );
     114          10 :         oslFileError e = osl_getAbsoluteFileURL( base2.pData, rel.pData , &target.pData );
     115          10 :         CPPUNIT_ASSERT_MESSAGE("failure #2",  osl_File_E_None == e );
     116          10 :         if( osl_File_E_None == e )
     117             :         {
     118          10 :             CPPUNIT_ASSERT_MESSAGE("failure #2.1",  target.equalsAscii( aSource2[i+1] ) );
     119             :         }
     120          12 :     }
     121             : #endif
     122           2 : }
     123             : 
     124           2 : void oldtestfile::test_file_004()
     125             : {
     126             : #ifndef WIN32
     127           2 :     OUString base4( "file:///" TEST_VOLUME "bla/" );
     128             :     int i;
     129          18 :     for( i = 0 ; aSource1[i] ; i +=2 )
     130             :     {
     131          16 :         OUString target;
     132          32 :         OUString rel = OUString::createFromAscii( aSource1[i] );
     133          16 :         oslFileError e = osl_getAbsoluteFileURL( base4.pData, rel.pData , &target.pData );
     134          16 :         CPPUNIT_ASSERT_MESSAGE("failure #10",  osl_File_E_None == e );
     135          16 :         if( osl_File_E_None == e )
     136             :         {
     137          16 :             CPPUNIT_ASSERT_MESSAGE("failure #10.1",  target.equalsAscii( aSource1[i+1] ) );
     138             :         }
     139          18 :     }
     140             : #endif
     141           2 : }
     142             : 
     143             : } // namespace osl_test_file
     144             : 
     145           2 : CPPUNIT_TEST_SUITE_REGISTRATION( osl_test_file::oldtestfile);
     146             : 
     147           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     148             : 
     149             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10