Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2010 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.osgi.tests.bundles; |
12 |
|
13 |
import java.util.Enumeration; |
14 |
import junit.framework.Test; |
15 |
import junit.framework.TestSuite; |
16 |
import org.eclipse.core.tests.harness.CoreTest; |
17 |
import org.eclipse.osgi.tests.OSGiTestsActivator; |
18 |
import org.osgi.framework.*; |
19 |
|
20 |
public class BundleResourceTests extends CoreTest { |
21 |
private BundleInstaller installer; |
22 |
|
23 |
protected void setUp() throws Exception { |
24 |
try { |
25 |
installer = new BundleInstaller(OSGiTestsActivator.TEST_FILES_ROOT + "resourcetests/bundles", OSGiTestsActivator.getContext()); //$NON-NLS-1$ |
26 |
} catch (InvalidSyntaxException e) { |
27 |
fail("Failed to create bundle installer", e); //$NON-NLS-1$ |
28 |
} |
29 |
} |
30 |
|
31 |
protected void tearDown() throws Exception { |
32 |
installer.shutdown(); |
33 |
} |
34 |
|
35 |
public static Test suite() { |
36 |
return new TestSuite(BundleResourceTests.class); |
37 |
} |
38 |
|
39 |
public void testBug328795() throws BundleException { |
40 |
Bundle bundle = installer.installBundle("test"); //$NON-NLS-1$ |
41 |
checkEntries(bundle, "notFound\\", 0); // this results in invalid syntax exception which is logged because of trailing escape |
42 |
checkEntries(bundle, "notFound\\\\", 0); // test escaped escape "notFound\" |
43 |
checkEntries(bundle, "notFound(", 0); // test unescaped trailing ( |
44 |
checkEntries(bundle, "notFound\\(", 0); // test escaped trailing ( |
45 |
checkEntries(bundle, "notFound)", 0); // test unescaped trailing ) |
46 |
checkEntries(bundle, "notFound\\)", 0); // test escaped trailing ) |
47 |
checkEntries(bundle, "notFound*", 0); // test trailing unescaped * |
48 |
checkEntries(bundle, "notFound\\*", 0); // test trailing escaped * |
49 |
checkEntries(bundle, "paren(.txt", 1); // test unescaped ( -> should find one |
50 |
checkEntries(bundle, "paren\\(.txt", 1); // test escaped ( -> should find one |
51 |
checkEntries(bundle, "paren\\\\(.txt", 0); // test escaped escape before unescaped ( -> should find none; looks for paren\(.txt file |
52 |
checkEntries(bundle, "paren).txt", 1); // test unescaped ) -> should find one |
53 |
checkEntries(bundle, "paren\\).txt", 1); // test escaped ) -> should find one |
54 |
checkEntries(bundle, "paren\\\\).txt", 0); // test escaped escape before unescaped ) -> should find none; looks for paren\).txt file |
55 |
checkEntries(bundle, "paren(", 1); // test unescaped trailing ( -> should find one |
56 |
checkEntries(bundle, "paren\\(", 1); // test escaped trailing ( -> should find one |
57 |
checkEntries(bundle, "paren\\\\(", 0); // test escaped escape before ( -> should find none; looks for paren\( |
58 |
checkEntries(bundle, "paren)", 1); // test unescaped trailing ( -> should find one |
59 |
checkEntries(bundle, "paren\\)", 1); // test escaped trailing ( -> should find one |
60 |
checkEntries(bundle, "paren\\\\)", 0); // test escaped escape before ) -> should find none; looks for paren\) |
61 |
checkEntries(bundle, "paren*", 4); // test trailing wild cards |
62 |
checkEntries(bundle, "paren*.txt", 2); // test middle wild cards |
63 |
checkEntries(bundle, "paren\\*", 0); // test escaped wild card -> should find none; looks for paren* |
64 |
checkEntries(bundle, "paren\\\\*", 0); // test escaped escape before wild card -> should find none; looks for paren\* |
65 |
checkEntries(bundle, "p*r*n*", 4); // test multiple wild cards |
66 |
checkEntries(bundle, "p*r*n*.txt", 2); // test multiple wild cards |
67 |
checkEntries(bundle, "*)*", 2); |
68 |
checkEntries(bundle, "*(*", 2); |
69 |
checkEntries(bundle, "*\\)*", 2); |
70 |
checkEntries(bundle, "*\\(*", 2); |
71 |
} |
72 |
|
73 |
private void checkEntries(Bundle bundle, String filePattern, int expectedNumber) { |
74 |
Enumeration entries = bundle.findEntries("folder", filePattern, false); |
75 |
if (expectedNumber == 0) { |
76 |
assertNull("Expected nothing here.", entries); |
77 |
return; |
78 |
} |
79 |
int i = 0; |
80 |
while (entries.hasMoreElements()) { |
81 |
entries.nextElement(); |
82 |
i++; |
83 |
} |
84 |
assertEquals("Unexpected number of entries", expectedNumber, i); |
85 |
} |
86 |
} |