You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2006/06/01 10:38:28 UTC
svn commit: r410791 - in /cocoon/branches/BRANCH_2_1_X/src:
java/org/apache/cocoon/matching/helpers/WildcardHelper.java
test/org/apache/cocoon/matching/helpers/
test/org/apache/cocoon/matching/helpers/WildcardHelperTestCase.java
Author: cziegeler
Date: Thu Jun 1 01:38:28 2006
New Revision: 410791
URL: http://svn.apache.org/viewvc?rev=410791&view=rev
Log:
Add test case that directly tests the wildcard helper class
Remove unused/unreachable code from WildcardHelper
Added:
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/matching/helpers/
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/matching/helpers/WildcardHelperTestCase.java (with props)
Modified:
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/matching/helpers/WildcardHelper.java
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/matching/helpers/WildcardHelper.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/matching/helpers/WildcardHelper.java?rev=410791&r1=410790&r2=410791&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/matching/helpers/WildcardHelper.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/matching/helpers/WildcardHelper.java Thu Jun 1 01:38:28 2006
@@ -15,7 +15,7 @@
*/
package org.apache.cocoon.matching.helpers;
-import java.util.HashMap;
+import java.util.Map;
/**
* This class is an utility class that perform wilcard-patterns matching and
@@ -37,9 +37,7 @@
/** The int representing begin in the pattern <code>int []</code>. */
protected static final int MATCH_BEGIN = -4;
/** The int representing end in pattern <code>int []</code>. */
- protected static final int MATCH_THEEND = -5;
- /** The int value that terminates the pattern <code>int []</code>. */
- protected static final int MATCH_END = -3;
+ protected static final int MATCH_END = -5;
/**
@@ -125,7 +123,7 @@
}
// Must match end at the end
- expr[y] = MATCH_THEEND;
+ expr[y] = MATCH_END;
return expr;
}
@@ -133,7 +131,7 @@
* match a pattern agains a string and isolates wildcard replacement into a
* <code>Stack</code>.
*/
- public static boolean match (HashMap map, String data, int[] expr)
+ public static boolean match (Map map, String data, int[] expr)
throws NullPointerException {
if (data == null) {
throw new NullPointerException ("No data provided");
@@ -184,38 +182,35 @@
// Check if the data in the expression array before the current
// expression character matches the data in the input buffer
if (matchBegin) {
- if (!matchArray(expr, exprpos, charpos, buff, buffpos))
- return (false);
+ if (!matchArray(expr, exprpos, charpos, buff, buffpos)) {
+ return false;
+ }
matchBegin = false;
} else {
- offset = indexOfArray (expr, exprpos, charpos, buff,
- buffpos);
- if (offset < 0)
- return (false);
+ offset = indexOfArray (expr, exprpos, charpos, buff, buffpos);
+ if (offset < 0) {
+ return false;
+ }
}
+ // This code can never be reached, so it's commented out now!
// Check for MATCH_BEGIN
- if (matchBegin) {
- if (offset != 0)
- return (false);
- matchBegin = false;
- }
+ //if (matchBegin) {
+ // if (offset != 0)
+ // return false;
+ // matchBegin = false;
+ //}
// Advance buffpos
buffpos += (charpos - exprpos);
// Check for END's
if (exprchr == MATCH_END) {
- if (rsltpos > 0 && map != null) {
- map.put(Integer.toString(++mcount),new String(rslt, 0, rsltpos));
- }
- // Don't care about rest of input buffer
- return (true);
- } else if (exprchr == MATCH_THEEND) {
if (rsltpos > 0 && map != null ) {
map.put (Integer.toString(++mcount),new String(rslt, 0, rsltpos));
}
// Check that we reach buffer's end
+ // FIXME - if (buffpos != buff.length) then we have to search the expr again!
return (buffpos == buff.length);
}
Added: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/matching/helpers/WildcardHelperTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/matching/helpers/WildcardHelperTestCase.java?rev=410791&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/matching/helpers/WildcardHelperTestCase.java (added)
+++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/matching/helpers/WildcardHelperTestCase.java Thu Jun 1 01:38:28 2006
@@ -0,0 +1,71 @@
+/*
+* Copyright 1999-2006 The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.cocoon.matching.helpers;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+/**
+ * Testcase for the WildcardHelper class.
+ * @version $Id$
+ */
+public class WildcardHelperTestCase extends TestCase {
+
+ public void testWildcardURIMatch() throws Exception {
+ final Map resultMap = new HashMap();
+ final String uri = "test/foo/bla/end";
+ final String pattern = "**";
+ int[] expr = WildcardHelper.compilePattern(pattern);
+ boolean result = WildcardHelper.match(resultMap, uri, expr);
+ assertTrue("Test if url matches: " + uri + " - " + pattern, result);
+ assertEquals("Test if result matches for {0}", uri, resultMap.get("0"));
+ assertEquals("Test if result matches for {1}", uri, resultMap.get("1"));
+
+ resultMap.clear();
+ final String pattern2 = "**/bla/*";
+ int[] expr2 = WildcardHelper.compilePattern(pattern2);
+ boolean result2 = WildcardHelper.match(resultMap, uri, expr2);
+ assertTrue("Test if url matches: " + uri + " - " + pattern2, result2);
+ assertEquals("Test if result matches for {0}", uri, resultMap.get("0"));
+ assertEquals("Test if result matches for {1}", "test/foo", resultMap.get("1"));
+ assertEquals("Test if result matches for {2}", "end", resultMap.get("2"));
+ }
+
+ public void testWildcardURIMatchSimplePattern() throws Exception {
+ final Map resultMap = new HashMap();
+ final String uri = "test";
+ final String pattern = "*";
+ int[] expr = WildcardHelper.compilePattern(pattern);
+ boolean result = WildcardHelper.match(resultMap, uri, expr);
+ assertTrue("Test if url matches: " + uri + " - " + pattern, result);
+ assertEquals("Test if result matches for {0}", uri, resultMap.get("0"));
+ assertEquals("Test if result matches for {1}", uri, resultMap.get("1"));
+ }
+
+ public void testWildcardURIMatchDoublePattern() throws Exception {
+ final Map resultMap = new HashMap();
+ final String uri = "test/something.xmlbla.xml";
+ final String pattern = "*/*.xml";
+ int[] expr = WildcardHelper.compilePattern(pattern);
+ boolean result = WildcardHelper.match(resultMap, uri, expr);
+ assertTrue("Test if url matches: " + uri + " - " + pattern, result);
+ assertEquals("Test if result matches for {0}", uri, resultMap.get("0"));
+ assertEquals("Test if result matches for {1}", "test", resultMap.get("1"));
+ assertEquals("Test if result matches for {2}", "something.xmlbla", resultMap.get("2"));
+ }
+}
Propchange: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/matching/helpers/WildcardHelperTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/matching/helpers/WildcardHelperTestCase.java
------------------------------------------------------------------------------
svn:keywords = Id