FileDocCategorySizeDatePackage
TestPushUtils.javaAPI DocphoneME MR2 API (J2ME)5528Wed May 02 18:00:40 BST 2007javax.microedition.sip

TestPushUtils

public class TestPushUtils extends com.sun.midp.i3test.TestCase
Simple pattern matching tests to emulate native push filter handling.

Fields Summary
Constructors Summary
Methods Summary
booleanchecksender(java.lang.String buf, java.lang.String filter)

	byte[] sender = new byte[512];

	getSipFromHeaderURI(buf.getBytes(), sender, 512);
	return checksipfilter(filter.getBytes(), sender);
    
native booleanchecksipfilter(byte[] filter, byte[] sender)

native intgetSipAcceptContactType(byte[] buf, byte[] sender, int len)

native intgetSipFromHeaderURI(byte[] buf, byte[] sender, int len)

public voidrunTests()
Run the tests

        declare("Pattern tests");
        test1();
    
voidtest1()

	String buf = "abc\nFrom: <abc.com> def\ndef";
	String filter = "*";
	assertTrue("Match(" + buf + "," + filter + ")",
		   checksender(buf, filter));

	filter = "foo";
	assertTrue("Match(" + buf + "," + filter + ")",
		   !checksender(buf, filter));

	filter = "*.com";
	assertTrue("Match(" + buf + "," + filter + ")",
		   checksender(buf, filter));

	filter = "???.com";
	assertTrue("Match(" + buf + "," + filter + ")",
		   checksender(buf, filter));

	buf = "abc\nFrom:  abc.com def\ndef";
	filter = "*";
	assertTrue("Match(" + buf + "," + filter + ")",
		   checksender(buf, filter));

	filter = "foo";
	assertTrue("Match(" + buf + "," + filter + ")",
		   !checksender(buf, filter));

	filter = "*.com";
	assertTrue("Match(" + buf + "," + filter + ")",
		   !checksender(buf, filter));

	filter = "???.com";
	assertTrue("Match(" + buf + "," + filter + ")",
		   !checksender(buf, filter));

	buf = "abc\nFrom  :  <abc.com> def\ndef";
	filter = "*";
	assertTrue("Match(" + buf + "," + filter + ")",
		   checksender(buf, filter));

	filter = "foo";
	assertTrue("Match(" + buf + "," + filter + ")",
		   !checksender(buf, filter));

	filter = "*.com";
	assertTrue("Match(" + buf + "," + filter + ")",
		   checksender(buf, filter));

	filter = "???.com";
	assertTrue("Match(" + buf + "," + filter + ")",
		   checksender(buf, filter));
	

	buf = "abc\nF  :  <abc.com> def\ndef";
	filter = "*";
	assertTrue("Match(" + buf + "," + filter + ")",
		   checksender(buf, filter));

	filter = "foo";
	assertTrue("Match(" + buf + "," + filter + ")",
		   !checksender(buf, filter));

	filter = "*.com";
	assertTrue("Match(" + buf + "," + filter + ")",
		   checksender(buf, filter));

	filter = "???.com";
	assertTrue("Match(" + buf + "," + filter + ")",
		   checksender(buf, filter));


	buf = "abc\nf:  <abc.com> def\ndef";
	filter = "*";
	assertTrue("Match(" + buf + "," + filter + ")",
		   checksender(buf, filter));

	filter = "foo";
	assertTrue("Match(" + buf + "," + filter + ")",
		   !checksender(buf, filter));

	filter = "*.com";
	assertTrue("Match(" + buf + "," + filter + ")",
		   checksender(buf, filter));

	filter = "???.com";
	assertTrue("Match(" + buf + "," + filter + ")",
		   checksender(buf, filter));

	buf = "INVITE sip:sippy.tester@localhost:5090 SIP/2.0\n"
	    + "Call-ID: 467269204a-2130459815@129.145.167.130\n"
	    + "CSeq: 1 INVITE\n"
	    + "To: <sip:sippy.tester@localhost:5090>\n"
	    + "Via: SIP/2.0/UDP\n"
	    + "129.145.167.130:5090;branch=z9hG4bK3131323230353731383931393232373833313238333735343136313739333937\n"
	    + "Max-Forwards: 70\n"
	    + "From: <sip:sippy.tester@localhost>;tag=1017508678\n"
	    + " Subject: Hello...\n"
	    + "Contact: <sip:user@129.145.167.130:5090>\n"
	    + "Accept-Contact: *;type=\"application/x-chess\"\n"
	    + "Content-Type: text/plain\n"
	    + "Content-Length: 15\n"
	    + "\n"
	    + "Hello SIP-World\n";
	filter = "*";
	assertTrue("Match(" + buf + "," + filter + ")",
		   checksender(buf, filter));

	filter = "foo";
	assertTrue("Match(" + buf + "," + filter + ")",
		   !checksender(buf, filter));

	filter = "*.com";
	assertTrue("Match(" + buf + "," + filter + ")",
		   !checksender(buf, filter));

	filter = "???.com";
	assertTrue("Match(" + buf + "," + filter + ")",
		   !checksender(buf, filter));

	byte []acceptcontact_type = new byte[512];

	getSipAcceptContactType(buf.getBytes(),acceptcontact_type, 512);

	String act = new String(acceptcontact_type, 0, 7);

	assertTrue("Media type " + act + "==x-chess",
		   act.equalsIgnoreCase("x-chess"));
	assertTrue("Media type " + act + "!=x-chessbad",
		   !act.equalsIgnoreCase("x-chessbad"));
	assertTrue("Media type " + act + "!=bad",
		   !act.equalsIgnoreCase("bad"));