diff options
author | Jesse Wilson <jessewilson@google.com> | 2011-05-25 16:36:17 -0700 |
---|---|---|
committer | Jesse Wilson <jessewilson@google.com> | 2011-05-25 16:36:17 -0700 |
commit | 0eefc54c2ae7a461cb28a8f117b515071df19f1e (patch) | |
tree | 2893ce0c11796280932ee66d503c19b5fc8fe757 | |
parent | 5a4ecd15a879353ab17c7910a445ab25c6462484 (diff) | |
download | apache-harmony-0eefc54c2ae7a461cb28a8f117b515071df19f1e.tar.gz |
Cleanup URI normalize test.
Used to test I9e0b86bd1e7ab8e5e71c46f1efcf4aeb218e66b2.
Change-Id: I4a635d36c7afcd9b0e54e06aa60b252e8209fe69
http://b/2753295
-rw-r--r-- | luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URITest.java | 124 |
1 files changed, 67 insertions, 57 deletions
diff --git a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URITest.java b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URITest.java index e7be391..9029b04 100644 --- a/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URITest.java +++ b/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/URITest.java @@ -20,9 +20,7 @@ package org.apache.harmony.luni.tests.java.net; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; - import junit.framework.TestCase; - import org.apache.harmony.testframework.serialization.SerializationTest; public class URITest extends TestCase { @@ -1326,61 +1324,73 @@ public class URITest extends TestCase { * @tests java.net.URI#normalize() */ public void test_normalize() throws Exception { + // normal + testNormalize("/", "/"); + testNormalize("/a", "/a"); + testNormalize("/a/b", "/a/b"); + testNormalize("/a/b/c", "/a/b/c"); + // single, '.' + testNormalize("/.", "/"); + testNormalize("/./", "/"); + testNormalize("/./.", "/"); + testNormalize("/././", "/"); + testNormalize("/./a", "/a"); + testNormalize("/./a/", "/a/"); + testNormalize("/././a", "/a"); + testNormalize("/././a/", "/a/"); + testNormalize("/a/.", "/a/"); + testNormalize("/a/./", "/a/"); + testNormalize("/a/./.", "/a/"); + testNormalize("/a/./b", "/a/b"); + // double, '..' + testNormalize("/a/..", "/"); + testNormalize("/a/../", "/"); + testNormalize("/a/../b", "/b"); + testNormalize("/a/../b/..", "/"); + testNormalize("/a/../b/../", "/"); + testNormalize("/a/../b/../c", "/c"); + testNormalize("/..", "/.."); + testNormalize("/../", "/../"); + testNormalize("/../..", "/../.."); + testNormalize("/../../", "/../../"); + testNormalize("/../a", "/../a"); + testNormalize("/../a/", "/../a/"); + testNormalize("/../../a", "/../../a"); + testNormalize("/../../a/", "/../../a/"); + testNormalize("/a/b/../../c", "/c"); + testNormalize("/a/b/../..", "/"); + testNormalize("/a/b/../../", "/"); + testNormalize("/a/b/../../c", "/c"); + testNormalize("/a/b/c/../../../d", "/d"); + testNormalize("/a/b/..", "/a/"); + testNormalize("/a/b/../", "/a/"); + testNormalize("/a/b/../c", "/a/c"); + // miscellaneous + testNormalize("/a/b/.././../../c/./d/../e", "/../c/e"); + testNormalize("/a/../../.c././../././c/d/../g/..", "/../c/"); + // '.' in the middle of segments + testNormalize("/a./b", "/a./b"); + testNormalize("/.a/b", "/.a/b"); + testNormalize("/a.b/c", "/a.b/c"); + testNormalize("/a/b../c", "/a/b../c"); + testNormalize("/a/..b/c", "/a/..b/c"); + testNormalize("/a/b..c/d", "/a/b..c/d"); + // no leading slash, miscellaneous + testNormalize("", ""); + testNormalize("a", "a"); + testNormalize("a/b", "a/b"); + testNormalize("a/b/c", "a/b/c"); + testNormalize("../", "../"); + testNormalize(".", ""); + testNormalize("..", ".."); + testNormalize("../g", "../g"); + testNormalize("g/a/../../b/c/./g", "b/c/g"); + testNormalize("a/b/.././../../c/./d/../e", "../c/e"); + testNormalize("a/../../.c././../././c/d/../g/..", "../c/"); + } - String[] normalizeData = new String[] { - // normal - "/", - "/a", - "/a/b", - "/a/b/c", - // single, '.' - "/.", "/./", "/./.", "/././", - "/./a", - "/./a/", - "/././a", - "/././a/", - "/a/.", - "/a/./", - "/a/./.", - "/a/./b", - // double, '..' - "/a/..", "/a/../", "/a/../b", "/a/../b/..", "/a/../b/../", - "/a/../b/../c", "/..", "/../", "/../..", "/../../", "/../a", - "/../a/", "/../../a", "/../../a/", "/a/b/../../c", - "/a/b/../..", - "/a/b/../../", - "/a/b/../../c", - "/a/b/c/../../../d", - "/a/b/..", - "/a/b/../", - "/a/b/../c", - // miscellaneous - "/a/b/.././../../c/./d/../e", - "/a/../../.c././../././c/d/../g/..", - // '.' in the middle of segments - "/a./b", "/.a/b", "/a.b/c", "/a/b../c", - "/a/..b/c", - "/a/b..c/d", - // no leading slash, miscellaneous - "", "a", "a/b", "a/b/c", "../", ".", "..", "../g", - "g/a/../../b/c/./g", "a/b/.././../../c/./d/../e", - "a/../../.c././../././c/d/../g/..", }; - - String[] normalizeResults = new String[] { "/", "/a", "/a/b", "/a/b/c", - "/", "/", "/", "/", "/a", "/a/", "/a", "/a/", "/a/", "/a/", - "/a/", "/a/b", "/", "/", "/b", "/", "/", "/c", "/..", "/../", - "/../..", "/../../", "/../a", "/../a/", "/../../a", - "/../../a/", "/c", "/", "/", "/c", "/d", "/a/", "/a/", "/a/c", - "/../c/e", "/../c/", "/a./b", "/.a/b", "/a.b/c", "/a/b../c", - "/a/..b/c", "/a/b..c/d", "", "a", "a/b", "a/b/c", "../", "", - "..", "../g", "b/c/g", "../c/e", "../c/", }; - - for (int i = 0; i < normalizeData.length; i++) { - URI test = new URI(normalizeData[i]); - String result = test.normalize().toString(); - assertEquals("Normalized incorrectly, ", normalizeResults[i], - result.toString()); - } + private void testNormalize(String original, String expected) throws URISyntaxException { + assertEquals(expected, new URI(original).normalize().toString()); } /** @@ -1847,7 +1857,7 @@ public class URITest extends TestCase { } } } - + /** * @tests serialization/deserialization. */ |