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: TestByteSourceSink.java,v 1.5 2003/01/21 22:43:12 michaelh Exp $ 20 */ 21 22 package test.juju.reattore.io.impl; 23 24 import junit.framework.*; 25 import juju.reattore.io.impl.ByteSourceSink; 26 import juju.reattore.io.Source; 27 28 public class TestByteSourceSink 29 extends TestCase { 30 31 private ByteSourceSink ss = new ByteSourceSink(); 32 33 /*** Tests that put stores the correct set of bytes */ 34 public void testPut() { 35 ss.put(1); 36 ss.put(2); 37 ss.put(-15); 38 39 assertTrue(ss.compareTo(new byte[] { 1, 2, -15 }) == 0); 40 41 ss.put(123); 42 ss.put(45); 43 ss.put(-126); 44 assertTrue(ss.compareTo(new byte[] { 1, 2, -15, 123, 45, -126 }) == 0); 45 } 46 47 /*** Tests the compareTo method */ 48 public void testCompareTo() { 49 byte[] seed = new byte[] { 1, 2, 3, 4 }; 50 ss.put(seed, 0, seed.length); 51 52 assertEquals(ss.compareTo(seed), 0); 53 assertTrue(ss.compareTo(new byte[] { }) > 0); 54 assertTrue(ss.compareTo(new byte[] { 1, 2, 3, 4, 5, 6, 7 }) < 0); 55 assertTrue(ss.compareTo(new byte[] { 8, 8, 8, 8, 8, 8, 8 }) < 0); 56 57 assertTrue(ss.compareTo(new byte[] { 1, 2, 3, 4 }) == 0); 58 assertTrue(ss.compareTo(new byte[] { 1, 2, 4, 4 }) < 0); 59 assertTrue(ss.compareTo(new byte[] { 1, -17, 3, 4 }) > 0); 60 } 61 62 /*** Tests bulk put and sequential get */ 63 public void testGet() { 64 byte[] seed = new byte[] { 1, 2, 4, 5, -1 }; 65 ss.put(seed, 0, seed.length); 66 67 assertEquals(1, ss.get()); 68 assertEquals(2, ss.get()); 69 assertEquals(4, ss.get()); 70 assertEquals(5, ss.get()); 71 assertEquals(-1, ss.get()); 72 assertEquals(Source.EOF, ss.get()); 73 assertEquals(Source.EOF, ss.get()); 74 } 75 76 /*** Tests mark() and reset() */ 77 public void testMarkReset() { 78 byte[] seed = new byte[] { 1, 2, 4, 5, -1 }; 79 ss.put(seed, 0, seed.length); 80 81 assertEquals(1, ss.get()); 82 assertEquals(2, ss.get()); 83 assertEquals(4, ss.get()); 84 assertEquals(5, ss.get()); 85 assertEquals(-1, ss.get()); 86 assertEquals(Source.EOF, ss.get()); 87 88 ss.reset(); 89 90 assertEquals(1, ss.get()); 91 assertEquals(2, ss.get()); 92 assertEquals(4, ss.get()); 93 ss.mark(); 94 assertEquals(5, ss.get()); 95 assertEquals(-1, ss.get()); 96 assertEquals(Source.EOF, ss.get()); 97 98 99 ss.reset(); 100 assertEquals(5, ss.get()); 101 assertEquals(-1, ss.get()); 102 assertEquals(Source.EOF, ss.get()); 103 104 ss.reset(); 105 assertEquals(5, ss.get()); 106 assertEquals(-1, ss.get()); 107 assertEquals(Source.EOF, ss.get()); 108 } 109 110 /*** Tests rewind() */ 111 public void testRewind() { 112 byte[] seed = new byte[] { 20, -25, 30, -40, 60 }; 113 ss.put(seed, 0, seed.length); 114 115 assertEquals(20, ss.get()); 116 assertEquals(-25, ss.get()); 117 assertEquals(30, ss.get()); 118 119 ss.mark(); 120 assertEquals(-40, ss.get()); 121 assertEquals(60, ss.get()); 122 123 ss.rewind(); 124 125 assertEquals(20, ss.get()); 126 assertEquals(-25, ss.get()); 127 assertEquals(30, ss.get()); 128 assertEquals(-40, ss.get()); 129 assertEquals(60, ss.get()); 130 131 ss.reset(); 132 assertEquals(-40, ss.get()); 133 134 ss.rewind(); 135 assertEquals(20, ss.get()); 136 } 137 138 /*** Tests compact() */ 139 public void testCompact() { 140 byte[] seed = new byte[] { 1, 2, 3 }; 141 ss.put(seed, 0, seed.length); 142 143 ss.compact(); 144 assertTrue(ss.array().length == 3); 145 146 assertEquals(1, ss.array()[0]); 147 assertEquals(2, ss.array()[1]); 148 assertEquals(3, ss.array()[2]); 149 } 150 151 public void testGrow() { 152 ss.put(new byte[128], 0, 128); 153 ss.put('a'); 154 } 155 156 public void testCreate() { 157 ss = new ByteSourceSink(new byte[] { 1, 2, 3 }); 158 assertEquals(3, ss.remaining()); 159 160 assertEquals(1, ss.get()); 161 assertEquals(2, ss.get()); 162 assertEquals(3, ss.get()); 163 assertEquals(Source.EOF, ss.get()); 164 } 165 166 /*** @see TestSuite */ 167 public static Test suite() { 168 return new TestSuite(TestByteSourceSink.class); 169 } 170 }

This page was automatically generated by Maven