01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package com.sun.midp.i3test;
28:
29: public class TestCompWildcard extends TestCase {
30:
31: /**
32: * Compare the filter and source address.
33: * @param filter The filter string to be used
34: * @param src The incoming address to be tested by the filter
35: * @return <tt>true</tt> if the comparison is successful,
36: * <tt>false</tt> if it fails
37: */
38: private native boolean cmpWildCard(String filter, String src);
39:
40: /**
41: * Runs all the tests.
42: */
43: public void runTests() {
44: declare("Compare * 1.2.3.4");
45: assertTrue("Wrong compare", cmpWildCard("*", "1.2.3.4"));
46: declare("Compare 1.* 1.2.3.4");
47: assertTrue("Wrong compare", cmpWildCard("1.*", "1.2.3.4"));
48: declare("Compare 1.** 1.2.3.4");
49: assertTrue("Wrong compare", cmpWildCard("1.**", "1.2.3.4"));
50: declare("Compare *4 1.2.3.4");
51: assertTrue("Wrong compare", cmpWildCard("*4", "1.2.3.4"));
52: declare("Compare 1.?.3.4 1.2.3.4");
53: assertTrue("Wrong compare", cmpWildCard("1.?.3.4", "1.2.3.4"));
54: declare("Compare ?*? 1.2.3.4");
55: assertTrue("Wrong compare", cmpWildCard("?*?", "1.2.3.4"));
56: declare("Compare ?**?3?*4 1.2.3.4");
57: assertTrue("Wrong compare", cmpWildCard("?**?3?*4", "1.2.3.4"));
58: declare("Compare *5* 1.2.3.4");
59: assertTrue("Wrong compare", !cmpWildCard("*5*", "1.2.3.4"));
60: declare("Compare 1.2.3.?? 1.2.3.4");
61: assertTrue("Wrong compare", !cmpWildCard("1.2.3.??", "1.2.3.4"));
62: declare("Compare *.??.* 1.2.3.4");
63: assertTrue("Wrong compare", !cmpWildCard("*.??.*", "1.2.3.4"));
64: declare("Compare *ab* axab");
65: assertTrue("Wrong compare", cmpWildCard("*ab*", "axab"));
66: declare("Compare *aab aaab");
67: assertTrue("Wrong compare", cmpWildCard("*aab", "aaab"));
68: declare("Compare *abcde*aab uuabcdeuuauuabcdeuuaab");
69: assertTrue("Wrong compare", cmpWildCard("*abcde*aab",
70: "uuabcdeuuauuabcdeuuaab"));
71: }
72:
73: }
|