001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.midp.io.j2me.socket;
028:
029: import java.io.*;
030: import javax.microedition.io.*;
031: import javax.microedition.midlet.MIDlet;
032: import com.sun.midp.i3test.*;
033: import com.sun.midp.io.j2me.push.*;
034:
035: /**
036: * Test of SocketConnection function that unblocks a pending read
037: * when the connection is closed.
038: */
039: public class TestPushRegistry extends TestCase {
040: boolean exceptionThrownAsExpected;
041: String negativeFilters[] = { "", "...", "?.?.?", ".1.2.3",
042: "1.2.3.", "*.*.*.*.*" };
043: String positiveFilters[] = { "1.2.3.4", "?.?.?.?", "1.1.1.1",
044: "1.1.1.*", "1.1.1.**", "1.**.1.**", "1.1.1.1*", "1.1.1.*1",
045: "1.1.1.*1", "1.1.1.*1", "1.1.1.*?1", "1.1.1.*??",
046: "1.1.1.*1?", "1.1.*.1", "1.1.1*.1", "1.1.*1.1", "1.1.*1.1",
047: "1.1.*1.1", "1.1.*?1.1", "1.1.*??.1", "1.1.*1?.1",
048: "1.1.*.*", "1.1.1*.1*", "1.1.*1.*1", "1.1.*1.*1",
049: "1.1.*1.*1", "1.1.*?1.*1", "1.1.*??.1??", "1.1.*1?.*1?",
050: "*1?.1.1.1", "*1?.1.1.*1?", "1.*.?1.1", "*" };
051: String connection = "socket://:1223";
052:
053: void testPushFilters() {
054: ProtocolPushImpl pushImpl = null;
055: int i = 0;
056:
057: exceptionThrownAsExpected = true;
058:
059: try {
060: pushImpl = (ProtocolPushImpl) ProtocolPush
061: .getInstance(connection);
062: } catch (Exception cce) {
063: exceptionThrownAsExpected = false;
064: }
065:
066: if (exceptionThrownAsExpected) {
067: for (i = negativeFilters.length; --i >= 0
068: && exceptionThrownAsExpected;) {
069: exceptionThrownAsExpected = false;
070: try {
071: pushImpl
072: .checkRegistration(
073: connection,
074: "com.sun.midp.io.j2me.socket.TestPushRegistry.MyTestMIDlet",
075: negativeFilters[i]);
076: System.err.println("failed with no exception at "
077: + negativeFilters[i]);
078: } catch (IllegalArgumentException iae) {
079: exceptionThrownAsExpected = true;
080: } catch (Exception ex) {
081: System.err.println("failed with " + ex + " at "
082: + negativeFilters[i]);
083: }
084: }
085: }
086:
087: if (exceptionThrownAsExpected) {
088: try {
089: for (i = positiveFilters.length; --i >= 0
090: && exceptionThrownAsExpected;) {
091: pushImpl
092: .checkRegistration(
093: connection,
094: "com.sun.midp.io.j2me.socket.TestPushRegistry.MyTestMIDlet",
095: positiveFilters[i]);
096: }
097: } catch (Exception ex) {
098: System.err.println("failed with " + ex + " at "
099: + positiveFilters[i]);
100: exceptionThrownAsExpected = false;
101: }
102: }
103:
104: assertTrue("Verify PushRegistry for socket connection",
105: exceptionThrownAsExpected);
106: }
107:
108: /**
109: * Start PushRegistry tests for socket connection
110: */
111: public void runTests() {
112: declare("Test PushRegistry for socket connection");
113:
114: testPushFilters();
115: }
116:
117: }
|