| 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 <rtl/ustring.hxx> |
| 22 |
|
| 23 |
#ifdef SAL_UNX |
| 24 |
#define TEST_VOLUME "" |
| 25 |
#elif defined _WIN32 |
| 26 |
#define TEST_VOLUME "Z:/" |
| 27 |
#endif |
| 28 |
|
| 29 |
#include <cppunit/TestFixture.h> |
| 30 |
#include <cppunit/extensions/HelperMacros.h> |
| 31 |
|
| 32 |
#include <utility> |
| 33 |
|
| 34 |
namespace osl_test_file |
| 35 |
{ |
| 36 |
|
| 37 |
class oldtestfile : public CppUnit::TestFixture |
| 38 |
{ |
| 39 |
public: |
| 40 |
void test_file_001(); |
| 41 |
void test_file_002(); |
| 42 |
void test_file_004(); |
| 43 |
|
| 44 |
CPPUNIT_TEST_SUITE( oldtestfile ); |
| 45 |
CPPUNIT_TEST( test_file_001 ); |
| 46 |
CPPUNIT_TEST( test_file_002 ); |
| 47 |
CPPUNIT_TEST( test_file_004 ); |
| 48 |
CPPUNIT_TEST_SUITE_END( ); |
| 49 |
}; |
| 50 |
|
| 51 |
const std::pair<OUString, OUString> aSource1[] = { |
| 52 |
{ u"a"_ustr, u"file:///" TEST_VOLUME "bla/a"_ustr }, |
| 53 |
///TODO: check if last slash must be omitted in resolved path. |
| 54 |
// { u"a/"_ustr, u"file:///" TEST_VOLUME "bla/a"_ustr }, |
| 55 |
{ u"../a"_ustr, u"file:///" TEST_VOLUME "a"_ustr }, |
| 56 |
{ u"a/.."_ustr, u"file:///" TEST_VOLUME "bla/"_ustr }, |
| 57 |
{ u"a/../b"_ustr, u"file:///" TEST_VOLUME "bla/b"_ustr }, |
| 58 |
{ u".."_ustr, u"file:///" TEST_VOLUME ""_ustr }, |
| 59 |
{ u"a/b/c/d"_ustr, u"file:///" TEST_VOLUME "bla/a/b/c/d"_ustr }, |
| 60 |
{ u"a/./c"_ustr, u"file:///" TEST_VOLUME "bla/a/c"_ustr }, |
| 61 |
{ u"a/././c"_ustr, u"file:///" TEST_VOLUME "bla/a/c"_ustr }, |
| 62 |
{ u"file:///" TEST_VOLUME "bla1/blub"_ustr, u"file:///" TEST_VOLUME "bla1/blub"_ustr }, |
| 63 |
}; |
| 64 |
|
| 65 |
const std::pair<OUString, OUString> aSource2[] = { |
| 66 |
{ u"a"_ustr, u"file:///" TEST_VOLUME "bla/blubs/schnubbel/a"_ustr }, |
| 67 |
///TODO: check if last slash must be omitted in resolved path. |
| 68 |
// { u"a/"_ustr, u"file:///" TEST_VOLUME "bla/blubs/schnubbel/a"_ustr }, |
| 69 |
{ u"../a"_ustr, u"file:///" TEST_VOLUME "bla/blubs/a"_ustr }, |
| 70 |
{ u"../../a"_ustr, u"file:///" TEST_VOLUME "bla/a"_ustr }, |
| 71 |
{ u"../../../a"_ustr, u"file:///" TEST_VOLUME "a"_ustr }, |
| 72 |
{ u"../../../a/b/c/d"_ustr, u"file:///" TEST_VOLUME "a/b/c/d"_ustr }, |
| 73 |
}; |
| 74 |
|
| 75 |
void oldtestfile::test_file_001() |
| 76 |
{ |
| 77 |
OUString base1( u"file:///" TEST_VOLUME "bla"_ustr ); |
| 78 |
for (const auto& [rel, expected] : aSource1) |
| 79 |
{ |
| 80 |
OUString target; |
| 81 |
oslFileError e = osl_getAbsoluteFileURL( base1.pData, rel.pData , &target.pData ); |
| 82 |
CPPUNIT_ASSERT_EQUAL_MESSAGE("failure #1", osl_File_E_None, e ); |
| 83 |
CPPUNIT_ASSERT_EQUAL_MESSAGE("failure #1.1", expected, target); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
void oldtestfile::test_file_002() |
| 88 |
{ |
| 89 |
OUString base2( u"file:///" TEST_VOLUME "bla/blubs/schnubbel"_ustr ); |
| 90 |
for (const auto& [rel, expected] : aSource2) |
| 91 |
{ |
| 92 |
OUString target; |
| 93 |
oslFileError e = osl_getAbsoluteFileURL( base2.pData, rel.pData , &target.pData ); |
| 94 |
CPPUNIT_ASSERT_EQUAL_MESSAGE("failure #2", osl_File_E_None, e ); |
| 95 |
CPPUNIT_ASSERT_EQUAL_MESSAGE("failure #2.1", expected, target); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
void oldtestfile::test_file_004() |
| 100 |
{ |
| 101 |
OUString base4( u"file:///" TEST_VOLUME "bla/"_ustr ); |
| 102 |
for (const auto& [rel, expected] : aSource1) |
| 103 |
{ |
| 104 |
OUString target; |
| 105 |
oslFileError e = osl_getAbsoluteFileURL( base4.pData, rel.pData , &target.pData ); |
| 106 |
CPPUNIT_ASSERT_EQUAL_MESSAGE("failure #10", osl_File_E_None, e ); |
| 107 |
CPPUNIT_ASSERT_EQUAL_MESSAGE("failure #10.1", expected, target); |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
} // namespace osl_test_file |
| 112 |
|
| 113 |
CPPUNIT_TEST_SUITE_REGISTRATION( osl_test_file::oldtestfile); |
| 114 |
|
| 115 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |