001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.text;
034:
035: import junit.framework.*;
036:
037: import org.apache.oro.text.*;
038: import org.apache.oro.text.regex.*;
039:
040: public class TestMaximumCapacityPatternCache extends TestCase {
041: PatternCache cache;
042:
043: protected void setUp() throws Exception {
044: cache = new MaximumCapacityPatternCache();
045: }
046:
047: public void testCapacity() {
048: assertEquals(20, cache.capacity());
049: }
050:
051: public void testSize() throws MalformedPatternException {
052: assertEquals("empty", 0, cache.size());
053:
054: cache.addPattern("/foo/");
055:
056: assertEquals("add one", 1, cache.size());
057:
058: cache.addPattern("/foo/");
059:
060: assertEquals("add same again", 1, cache.size());
061:
062: cache.addPattern("/bar/");
063:
064: assertEquals("add another", 2, cache.size());
065: }
066:
067: public void testAddPattern() throws MalformedPatternException {
068: Object pattern1 = cache.addPattern("/foo/");
069: assertNotNull("add returns null", pattern1);
070:
071: Object pattern2 = cache.addPattern("/foo/");
072: assertSame("add twice returns different", pattern1, pattern2);
073: }
074:
075: public void testAddPatternWithOption()
076: throws MalformedPatternException {
077: Object pattern = cache.addPattern("/foo/",
078: Perl5Compiler.CASE_INSENSITIVE_MASK);
079: assertNotNull("add returns null", pattern);
080: }
081:
082: public void testAddMalformedPattern()
083: throws MalformedPatternException {
084: try {
085: cache.addPattern("foo(");
086: fail("Added a malformed pattern");
087: } catch (MalformedPatternException e) {
088: // expected
089: }
090: }
091:
092: public void testAddMalformedPatternWithOption()
093: throws MalformedPatternException {
094: try {
095: cache.addPattern("foo(",
096: Perl5Compiler.CASE_INSENSITIVE_MASK);
097: fail("Added a malformed pattern");
098: } catch (MalformedPatternException e) {
099: // expected
100: }
101: }
102:
103: public void testGetPattern() throws MalformedCachePatternException {
104: Object pattern1 = cache.getPattern("/foo/");
105: assertNotNull("get returns null", pattern1);
106:
107: Object pattern2 = cache.getPattern("/foo/");
108: assertSame("get twice returns different", pattern1, pattern2);
109: }
110:
111: public void testGetPatternWithOption()
112: throws MalformedCachePatternException {
113: Object pattern = cache.getPattern("/foo/",
114: Perl5Compiler.CASE_INSENSITIVE_MASK);
115: assertNotNull("get returns null", pattern);
116: }
117:
118: public void testGetMalformedPattern()
119: throws MalformedCachePatternException {
120: try {
121: cache.getPattern("foo(");
122: fail("Got malformed pattern");
123: } catch (MalformedCachePatternException e) {
124: // Expected
125: }
126: }
127:
128: public void testGetMalformedPatternWithOption()
129: throws MalformedCachePatternException {
130: try {
131: cache.getPattern("foo(",
132: Perl5Compiler.CASE_INSENSITIVE_MASK);
133: fail("Got malformed pattern");
134: } catch (MalformedCachePatternException e) {
135: // Expected
136: }
137: }
138: }
|