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