1 /* Reattore HTTP Server 2 3 Copyright (C) 2002 Michael Hope <michaelh@juju.net.nz> 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 $Id: TestPushbackByteSource.java,v 1.2 2003/02/17 04:17:28 michaelh Exp $ 20 */ 21 22 package test.juju.reattore.io.impl; 23 24 import junit.framework.*; 25 import juju.reattore.io.impl.*; 26 import juju.reattore.io.*; 27 28 public class TestPushbackByteSource 29 extends TestCase { 30 31 private PushbackByteSource pb = new PushbackByteSource(); 32 33 private void seed(byte[] seed) { 34 ByteSourceSink backing = new ByteSourceSink(); 35 backing.put(seed, 0, seed.length); 36 37 pb.seed(backing); 38 } 39 40 public void testRead() 41 throws Exception { 42 43 seed(new byte[] { 1, 2, 3, 4, 5 }); 44 45 assertEquals(1, pb.get()); 46 assertEquals(2, pb.get()); 47 assertEquals(3, pb.get()); 48 assertEquals(4, pb.get()); 49 assertEquals(5, pb.get()); 50 assertEquals(Source.EOF, pb.get()); 51 } 52 53 public void testPushback() 54 throws Exception { 55 56 seed(new byte[] { 1, 2, 3, 4, 5 }); 57 58 assertEquals(1, pb.get()); 59 assertEquals(2, pb.get()); 60 assertEquals(3, pb.get()); 61 62 pb.pushback(17); 63 assertEquals(17, pb.get()); 64 65 assertEquals(4, pb.get()); 66 67 pb.pushback(17); 68 assertEquals(17, pb.get()); 69 70 assertEquals(5, pb.get()); 71 assertEquals(Source.EOF, pb.get()); 72 } 73 74 public void testAtEOF() 75 throws Exception { 76 77 seed(new byte[] { 1, 2 }); 78 79 assertEquals(1, pb.get()); 80 assertEquals(2, pb.get()); 81 assertEquals(Source.EOF, pb.get()); 82 83 pb.pushback(17); 84 assertEquals(17, pb.get()); 85 assertEquals(Source.EOF, pb.get()); 86 } 87 88 public void testOnEmpty() 89 throws Exception { 90 91 assertEquals(Source.EOF, pb.get()); 92 } 93 94 public void testAcrossSeed() 95 throws Exception { 96 97 seed(new byte[] { 1, 2 }); 98 99 assertEquals(1, pb.get()); 100 101 pb.pushback(992); 102 103 seed(new byte[] { 12, 14 }); 104 assertEquals(992, pb.get()); 105 assertEquals(12, pb.get()); 106 assertEquals(14, pb.get()); 107 } 108 109 public static Test suite() { 110 return new TestSuite(TestPushbackByteSource.class); 111 } 112 }

This page was automatically generated by Maven