... if you can submit this to bugzilla, it will help us track that it's reviewed.
It did not occur to me to use bugzilla since the improvements, which I believe SMTPDataInputStream offers, are not necessarily fixes to bugs. The changes in behavior are arguable. I argue that the right end of data indicator to recognize is "a period alone in a line" rather than "CRLF.CRLF", but it seems that many people see it differently.
Should I use bugzilla to express my opinions about improvements needed?
> ... JUnit tests.
I did some JUnit tests, not comparing old vs. new, but only testing the new. I attach a file containing that class. Earlier I had tested the old (existing) behavior, as I reported briefly to this list in this message on June 10, <http://marc.theaimsgroup.com/?l=james-dev&m=105527214016488&w=2>.
Rich
import java.io.BufferedInputStream; import java.io.ByteArrayInputStream;
import junit.framework.TestCase; public class TestSIS extends TestCase { SMTPDataInputStream sis; public TestSIS(String whooo){ super(whooo); } static String food = ".dogs\r. sp\n" + ".\r\n" + ".\r8\r\n" + ".\r\r\no*" + " \r\n.\r\n" + "I guess we shouldn't get here.\r\n"; //test response to a challenging sequence of characters public void testFood0() throws Exception { sis=constructSIS(food, 25, 7); assertEquals((byte)sis.read(),(byte)'d'); assertEquals((byte)sis.read(),(byte)'o'); assertEquals((byte)sis.read(),(byte)'g'); assertEquals((byte)sis.read(),(byte)'s'); assertEquals((byte)sis.read(),(byte)13); assertEquals((byte)sis.read(),(byte)'.'); assertEquals((byte)sis.read(),(byte)' '); assertEquals((byte)sis.read(),(byte)'s'); assertEquals((byte)sis.read(),(byte)'p'); assertEquals((byte)sis.read(),(byte)012); assertEquals((byte)sis.read(),(byte)'.'); assertEquals((byte)sis.read(),(byte)13); assertEquals((byte)sis.read(),(byte)10); assertEquals((byte)sis.read(),(byte)13); assertEquals((byte)sis.read(),(byte)'8'); assertEquals((byte)sis.read(),(byte)13); assertEquals((byte)sis.read(),(byte)10); assertEquals((byte)sis.read(),(byte)13); assertEquals((byte)sis.read(),(byte)13); assertEquals((byte)sis.read(),(byte)10); assertEquals((byte)sis.read(),(byte)'o'); assertEquals((byte)sis.read(),(byte)'*'); assertEquals((byte)sis.read(),(byte)' '); assertEquals((byte)sis.read(),(byte)13); assertEquals((byte)sis.read(),(byte)10); assertEquals((byte)sis.read(),(byte)-1); assertEquals((byte)sis.read(),(byte)-1); assertEquals((byte)sis.read(),(byte)-1); sis.close(); } //test attempt to read beyond maxMessageSize public void testFood1() throws Exception { sis=constructSIS(food, 6, 7); assertEquals((byte)sis.read(),(byte)'d'); assertEquals((byte)sis.read(),(byte)'o'); assertEquals((byte)sis.read(),(byte)'g'); assertEquals((byte)sis.read(),(byte)'s'); assertEquals((byte)sis.read(),(byte)13); assertEquals((byte)sis.read(),(byte)'.'); Exception ex = null; try{ sis.read(); }catch (Exception e){ ex = e; } assertTrue(ex instanceof MessageSizeException); sis.close(); } //test same with different reset interval public void testFood2() throws Exception { sis=constructSIS(food, 6, 1); assertEquals((byte)sis.read(),(byte)'d'); assertEquals((byte)sis.read(),(byte)'o'); assertEquals((byte)sis.read(),(byte)'g'); assertEquals((byte)sis.read(),(byte)'s'); assertEquals((byte)sis.read(),(byte)13); assertEquals((byte)sis.read(),(byte)'.'); Exception ex = null; try{ sis.read(); }catch (Exception e){ ex = e; } assertTrue(ex instanceof MessageSizeException); sis.close(); } //test same with different reset interval public void testFood3() throws Exception { sis=constructSIS(food, 6, 6); assertEquals((byte)sis.read(),(byte)'d'); assertEquals((byte)sis.read(),(byte)'o'); assertEquals((byte)sis.read(),(byte)'g'); assertEquals((byte)sis.read(),(byte)'s'); assertEquals((byte)sis.read(),(byte)13); assertEquals((byte)sis.read(),(byte)'.'); Exception ex = null; try{ sis.read(); }catch (Exception e){ ex = e; } assertTrue(ex instanceof MessageSizeException); sis.close(); } //test same with different reset interval public void testFood4() throws Exception { sis=constructSIS(food, 6, 3); assertEquals((byte)sis.read(),(byte)'d'); assertEquals((byte)sis.read(),(byte)'o'); assertEquals((byte)sis.read(),(byte)'g'); assertEquals((byte)sis.read(),(byte)'s'); assertEquals((byte)sis.read(),(byte)13); assertEquals((byte)sis.read(),(byte)'.'); Exception ex = null; try{ sis.read(); }catch (Exception e){ ex = e; } assertTrue(ex instanceof MessageSizeException); sis.close(); } //test a set of illegal arguments to the constructor public void testFood5() throws Exception { Throwable t0 = null; try{ sis=new SMTPDataInputStream(null, 6, new WatchDog(), 3); }catch (Throwable t){ t0=t; } assertTrue(t0 instanceof IllegalArgumentException); t0 = null; try{ sis=constructSIS(food, -1, 8); }catch (Throwable t){ t0=t; } assertTrue(t0 instanceof IllegalArgumentException); t0 = null; try{ sis=constructSIS(food, 4, 0); }catch (Throwable t){ t0=t; } assertTrue(t0 instanceof IllegalArgumentException); if (sis != null) sis.close(); } //test read(byte[]) public void testFood6() throws Exception { sis=constructSIS(food, 40, 600); byte[] b = new byte[5]; assertEquals(5, sis.read(b)); assertEquals(b[0],(byte)'d'); assertEquals(b[4],(byte)13); assertEquals((byte)sis.read(),(byte)'.'); sis.close(); } //test read(byte[], int, int) public void testFood7() throws Exception { sis=constructSIS(food, 6880, 32); byte[] b = { (byte) 71, (byte) 72, (byte) 73, (byte) 74, (byte) 75, (byte) 76, (byte) 77, (byte) 78, (byte) 79, (byte) 80 }; sis.read(); sis.read(); sis.read(); sis.read(); sis.read(); sis.read(); sis.read(); sis.read(); sis.read(); sis.read(); sis.read(); sis.read(); assertEquals(4, sis.read(b, 3, 4)); assertEquals(b[0],(byte) 71); assertEquals(b[1],(byte) 72); assertEquals(b[2],(byte) 73); assertEquals(b[3],(byte)10); assertEquals(b[4],(byte)13); assertEquals(b[5],(byte)'8'); assertEquals(b[6],(byte)13); assertEquals(b[7],(byte)78); assertEquals(b[8],(byte)79); assertEquals(b[9],(byte)80); assertEquals((byte)sis.read(),(byte)10); sis.close(); } //test the exact-length end public void testExactEnd() throws Exception{ sis=constructSIS("abcdefghij\r\n.\r\n and more too", 12, 5); byte[] b = new byte[3992]; assertEquals(sis.read(b), 12); assertEquals(sis.read(b, 498, 500), -1); } //test a zero length inputStream public void testSmall() throws Exception { sis=constructSIS("", 6, 7); assertEquals((byte)sis.read(),(byte)-1); assertEquals((byte)sis.read(),(byte)-1); sis.close(); } private SMTPDataInputStream constructSIS (String food, int maxSize, int resetSize)throws Exception { return new SMTPDataInputStream( new BufferedInputStream( new ByteArrayInputStream ( food.getBytes("ASCII"))), maxSize, new WatchDog(){ void reset(){ System.out.println("Hey, I been reset"); } }, resetSize ); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]