1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "sal/config.h"
25 
26 #include "com/sun/star/uno/Reference.hxx"
27 #include "com/sun/star/uno/RuntimeException.hpp"
28 #include "com/sun/star/uno/XInterface.hpp"
29 #include "osl/file.hxx"
30 #include "osl/process.h"
31 #include "rtl/ustring.hxx"
32 #include "test/toabsolutefileurl.hxx"
33 
34 namespace {
35 
36 namespace css = com::sun::star;
37 
38 }
39 
40 namespace test {
41 
toAbsoluteFileUrl(rtl::OUString const & relativePathname)42 rtl::OUString toAbsoluteFileUrl(rtl::OUString const & relativePathname) {
43     rtl::OUString cwd;
44     oslProcessError e1 = osl_getProcessWorkingDir(&cwd.pData);
45     if (e1 != osl_Process_E_None) {
46         throw css::uno::RuntimeException(
47             (rtl::OUString(
48                 RTL_CONSTASCII_USTRINGPARAM(
49                     "osl_getProcessWorkingDir failed with ")) +
50              rtl::OUString::valueOf(static_cast< sal_Int32 >(e1))),
51             css::uno::Reference< css::uno::XInterface >());
52     }
53     rtl::OUString url;
54     osl::FileBase::RC e2 = osl::FileBase::getFileURLFromSystemPath(
55         relativePathname, url);
56     if (e2 != osl::FileBase::E_None) {
57         throw css::uno::RuntimeException(
58             (rtl::OUString(
59                 RTL_CONSTASCII_USTRINGPARAM(
60                     "osl::FileBase::getFileURLFromSystemPath(")) +
61              relativePathname +
62              rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(") failed with ")) +
63              rtl::OUString::valueOf(static_cast< sal_Int32 >(e2))),
64             css::uno::Reference< css::uno::XInterface >());
65     }
66     rtl::OUString absUrl;
67     e2 = osl::FileBase::getAbsoluteFileURL(cwd, url, absUrl);
68     if (e2 != osl::FileBase::E_None) {
69         throw css::uno::RuntimeException(
70             (rtl::OUString(
71                 RTL_CONSTASCII_USTRINGPARAM(
72                     "osl::FileBase::getAbsoluteFileURL(")) +
73              cwd + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(", ")) + url +
74              rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(") failed with ")) +
75              rtl::OUString::valueOf(static_cast< sal_Int32 >(e2))),
76             css::uno::Reference< css::uno::XInterface >());
77     }
78     return absUrl;
79 }
80 
81 }
82