12be43276SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32be43276SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42be43276SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52be43276SAndrew Rist  * distributed with this work for additional information
62be43276SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72be43276SAndrew Rist  * to you under the Apache License, Version 2.0 (the
82be43276SAndrew Rist  * "License"); you may not use this file except in compliance
92be43276SAndrew Rist  * with the License.  You may obtain a copy of the License at
102be43276SAndrew Rist  *
112be43276SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
122be43276SAndrew Rist  *
132be43276SAndrew Rist  * Unless required by applicable law or agreed to in writing,
142be43276SAndrew Rist  * software distributed under the License is distributed on an
152be43276SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162be43276SAndrew Rist  * KIND, either express or implied.  See the License for the
172be43276SAndrew Rist  * specific language governing permissions and limitations
182be43276SAndrew Rist  * under the License.
192be43276SAndrew Rist  *
202be43276SAndrew Rist  *************************************************************/
212be43276SAndrew Rist 
222be43276SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package com.sun.star.lib.util;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import java.io.File;
27cdf0e10cSrcweir import java.net.MalformedURLException;
28cdf0e10cSrcweir import java.net.URL;
29cdf0e10cSrcweir 
30*9cbd97ceSDamjan Jovanovic import org.junit.Test;
31*9cbd97ceSDamjan Jovanovic import static org.junit.Assert.*;
32cdf0e10cSrcweir 
33*9cbd97ceSDamjan Jovanovic public final class NativeLibraryLoader_Test {
34*9cbd97ceSDamjan Jovanovic     @Test
testEncoded()35cdf0e10cSrcweir     public void testEncoded() throws MalformedURLException {
36cdf0e10cSrcweir         File dir = new File(System.getProperty("user.dir"));
37cdf0e10cSrcweir         File subdir = new File(dir, "with space");
38cdf0e10cSrcweir         File file1 = new File(subdir, "file");
39cdf0e10cSrcweir 
40cdf0e10cSrcweir         String fileUrl = dir.toURL().toString();
41cdf0e10cSrcweir         if (!fileUrl.endsWith("/")) {
42cdf0e10cSrcweir             fileUrl += "/";
43cdf0e10cSrcweir         }
44cdf0e10cSrcweir         fileUrl += "with%20space/file";
45cdf0e10cSrcweir         final URL url = new URL(fileUrl);
46cdf0e10cSrcweir 
47cdf0e10cSrcweir         File file2 = NativeLibraryLoader.getResource(
48cdf0e10cSrcweir             new ClassLoader() {
49cdf0e10cSrcweir                 public URL getResource(String name) {
50cdf0e10cSrcweir                     return url;
51cdf0e10cSrcweir                 }
52cdf0e10cSrcweir             },
53cdf0e10cSrcweir             "dummy");
54*9cbd97ceSDamjan Jovanovic         assertTrue("Files are equal", file2.equals(file1));
55cdf0e10cSrcweir     }
56cdf0e10cSrcweir 
57*9cbd97ceSDamjan Jovanovic     @Test
testUnencoded()58cdf0e10cSrcweir     public void testUnencoded() throws MalformedURLException {
59cdf0e10cSrcweir         File dir = new File(System.getProperty("user.dir"));
60cdf0e10cSrcweir         File subdir = new File(dir, "with space");
61cdf0e10cSrcweir         File file1 = new File(subdir, "file");
62cdf0e10cSrcweir 
63cdf0e10cSrcweir         String fileUrl = dir.toURL().toString();
64cdf0e10cSrcweir         if (!fileUrl.endsWith("/")) {
65cdf0e10cSrcweir             fileUrl += "/";
66cdf0e10cSrcweir         }
67cdf0e10cSrcweir         fileUrl += "with space/file";
68cdf0e10cSrcweir         final URL url = new URL(fileUrl);
69cdf0e10cSrcweir 
70cdf0e10cSrcweir         File file2 = NativeLibraryLoader.getResource(
71cdf0e10cSrcweir             new ClassLoader() {
72cdf0e10cSrcweir                 public URL getResource(String name) {
73cdf0e10cSrcweir                     return url;
74cdf0e10cSrcweir                 }
75cdf0e10cSrcweir             },
76cdf0e10cSrcweir             "dummy");
77*9cbd97ceSDamjan Jovanovic         assertTrue("Files are equal", file2.equals(file1));
78cdf0e10cSrcweir     }
79cdf0e10cSrcweir }
80