1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <rtl/ustring.hxx>
24 #define TEST_VOLUME ""
26 #define TEST_VOLUME "Z:/"
29 #include <cppunit/TestFixture.h>
30 #include <cppunit/extensions/HelperMacros.h>
34 namespace osl_test_file
37 class oldtestfile
: public CppUnit::TestFixture
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( );
51 const std::pair
<OUString
, OUString
> aSource1
[] = {
52 { u
"a", u
"file:///" TEST_VOLUME
"bla/a" },
53 ///TODO: check if last slash must be omitted in resolved path.
54 // { u"a/", u"file:///" TEST_VOLUME "bla/a" },
55 { u
"../a", u
"file:///" TEST_VOLUME
"a" },
56 { u
"a/..", u
"file:///" TEST_VOLUME
"bla/" },
57 { u
"a/../b", u
"file:///" TEST_VOLUME
"bla/b" },
58 { u
"..", u
"file:///" TEST_VOLUME
"" },
59 { u
"a/b/c/d", u
"file:///" TEST_VOLUME
"bla/a/b/c/d" },
60 { u
"a/./c", u
"file:///" TEST_VOLUME
"bla/a/c" },
61 { u
"a/././c", u
"file:///" TEST_VOLUME
"bla/a/c" },
62 { u
"file:///" TEST_VOLUME
"bla1/blub", u
"file:///" TEST_VOLUME
"bla1/blub" },
65 const std::pair
<OUString
, OUString
> aSource2
[] = {
66 { u
"a", u
"file:///" TEST_VOLUME
"bla/blubs/schnubbel/a" },
67 ///TODO: check if last slash must be omitted in resolved path.
68 // { u"a/", u"file:///" TEST_VOLUME "bla/blubs/schnubbel/a" },
69 { u
"../a", u
"file:///" TEST_VOLUME
"bla/blubs/a" },
70 { u
"../../a", u
"file:///" TEST_VOLUME
"bla/a" },
71 { u
"../../../a", u
"file:///" TEST_VOLUME
"a" },
72 { u
"../../../a/b/c/d", u
"file:///" TEST_VOLUME
"a/b/c/d" },
75 void oldtestfile::test_file_001()
77 OUString
base1( "file:///" TEST_VOLUME
"bla" );
78 for (const auto& [rel
, expected
] : aSource1
)
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
);
87 void oldtestfile::test_file_002()
89 OUString
base2( "file:///" TEST_VOLUME
"bla/blubs/schnubbel" );
90 for (const auto& [rel
, expected
] : aSource2
)
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
);
99 void oldtestfile::test_file_004()
101 OUString
base4( "file:///" TEST_VOLUME
"bla/" );
102 for (const auto& [rel
, expected
] : aSource1
)
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
);
111 } // namespace osl_test_file
113 CPPUNIT_TEST_SUITE_REGISTRATION( osl_test_file::oldtestfile
);
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */