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 java.io.File;
27 import java.net.MalformedURLException;
28 import java.net.URL;
29 
30 import org.junit.Test;
31 import static org.junit.Assert.*;
32 
33 public final class NativeLibraryLoader_Test {
34     @Test
testEncoded()35     public void testEncoded() throws MalformedURLException {
36         File dir = new File(System.getProperty("user.dir"));
37         File subdir = new File(dir, "with space");
38         File file1 = new File(subdir, "file");
39 
40         String fileUrl = dir.toURL().toString();
41         if (!fileUrl.endsWith("/")) {
42             fileUrl += "/";
43         }
44         fileUrl += "with%20space/file";
45         final URL url = new URL(fileUrl);
46 
47         File file2 = NativeLibraryLoader.getResource(
48             new ClassLoader() {
49                 public URL getResource(String name) {
50                     return url;
51                 }
52             },
53             "dummy");
54         assertTrue("Files are equal", file2.equals(file1));
55     }
56 
57     @Test
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         assertTrue("Files are equal", file2.equals(file1));
78     }
79 }
80