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 package com.sun.star.lib.util; 25 26 import complexlib.ComplexTestCase; 27 import java.io.File; 28 import java.net.MalformedURLException; 29 import java.net.URL; 30 31 public final class NativeLibraryLoader_Test extends ComplexTestCase { getTestMethodNames()32 public String[] getTestMethodNames() { 33 return new String[] { "testEncoded", "testUnencoded" }; 34 } 35 testEncoded()36 public void testEncoded() throws MalformedURLException { 37 File dir = new File(System.getProperty("user.dir")); 38 File subdir = new File(dir, "with space"); 39 File file1 = new File(subdir, "file"); 40 41 String fileUrl = dir.toURL().toString(); 42 if (!fileUrl.endsWith("/")) { 43 fileUrl += "/"; 44 } 45 fileUrl += "with%20space/file"; 46 final URL url = new URL(fileUrl); 47 48 File file2 = NativeLibraryLoader.getResource( 49 new ClassLoader() { 50 public URL getResource(String name) { 51 return url; 52 } 53 }, 54 "dummy"); 55 assure("Files are equal", file2.equals(file1)); 56 } 57 testUnencoded()58 public void testUnencoded() throws MalformedURLException { 59 File dir = new File(System.getProperty("user.dir")); 60 File subdir = new File(dir, "with space"); 61 File file1 = new File(subdir, "file"); 62 63 String fileUrl = dir.toURL().toString(); 64 if (!fileUrl.endsWith("/")) { 65 fileUrl += "/"; 66 } 67 fileUrl += "with space/file"; 68 final URL url = new URL(fileUrl); 69 70 File file2 = NativeLibraryLoader.getResource( 71 new ClassLoader() { 72 public URL getResource(String name) { 73 return url; 74 } 75 }, 76 "dummy"); 77 assure("Files are equal", file2.equals(file1)); 78 } 79 } 80