xref: /AOO41X/main/jurt/test/com/sun/star/lib/util/NativeLibraryLoader_Test.java (revision 2be432768a66cc90838f6a32e76ec156f587e741)
1*2be43276SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2be43276SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2be43276SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2be43276SAndrew Rist  * distributed with this work for additional information
6*2be43276SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2be43276SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2be43276SAndrew Rist  * "License"); you may not use this file except in compliance
9*2be43276SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*2be43276SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*2be43276SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2be43276SAndrew Rist  * software distributed under the License is distributed on an
15*2be43276SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2be43276SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2be43276SAndrew Rist  * specific language governing permissions and limitations
18*2be43276SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*2be43276SAndrew Rist  *************************************************************/
21*2be43276SAndrew Rist 
22*2be43276SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package com.sun.star.lib.util;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import complexlib.ComplexTestCase;
27cdf0e10cSrcweir import java.io.File;
28cdf0e10cSrcweir import java.net.MalformedURLException;
29cdf0e10cSrcweir import java.net.URL;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir public final class NativeLibraryLoader_Test extends ComplexTestCase {
getTestMethodNames()32cdf0e10cSrcweir     public String[] getTestMethodNames() {
33cdf0e10cSrcweir         return new String[] { "testEncoded", "testUnencoded" };
34cdf0e10cSrcweir     }
35cdf0e10cSrcweir 
testEncoded()36cdf0e10cSrcweir     public void testEncoded() throws MalformedURLException {
37cdf0e10cSrcweir         File dir = new File(System.getProperty("user.dir"));
38cdf0e10cSrcweir         File subdir = new File(dir, "with space");
39cdf0e10cSrcweir         File file1 = new File(subdir, "file");
40cdf0e10cSrcweir 
41cdf0e10cSrcweir         String fileUrl = dir.toURL().toString();
42cdf0e10cSrcweir         if (!fileUrl.endsWith("/")) {
43cdf0e10cSrcweir             fileUrl += "/";
44cdf0e10cSrcweir         }
45cdf0e10cSrcweir         fileUrl += "with%20space/file";
46cdf0e10cSrcweir         final URL url = new URL(fileUrl);
47cdf0e10cSrcweir 
48cdf0e10cSrcweir         File file2 = NativeLibraryLoader.getResource(
49cdf0e10cSrcweir             new ClassLoader() {
50cdf0e10cSrcweir                 public URL getResource(String name) {
51cdf0e10cSrcweir                     return url;
52cdf0e10cSrcweir                 }
53cdf0e10cSrcweir             },
54cdf0e10cSrcweir             "dummy");
55cdf0e10cSrcweir         assure("Files are equal", file2.equals(file1));
56cdf0e10cSrcweir     }
57cdf0e10cSrcweir 
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");
77cdf0e10cSrcweir         assure("Files are equal", file2.equals(file1));
78cdf0e10cSrcweir     }
79cdf0e10cSrcweir }
80