[Beepcore-java-commits] CVS: beepcore-java/test/org/beepcore/beep/core TestByteOutputDataStream.java
Status: Beta
Brought to you by:
huston
From: Huston F. <hu...@us...> - 2001-11-10 21:33:32
|
Update of /cvsroot/beepcore-java/beepcore-java/test/org/beepcore/beep/core In directory usw-pr-cvs1:/tmp/cvs-serv17519/test/org/beepcore/beep/core Modified Files: TestFileDataStream.java TestInputDataStreamAdapter.java Added Files: TestByteOutputDataStream.java TestStringOutputDataStream.java Removed Files: TestByteDataStream.java TestDataStream.java TestFrameDataStream.java TestInputStreamDataStream.java TestStringDataStream.java Log Message: Rename Byte/StringDataStream to Byte/StringOutputDataStream --- NEW FILE: TestByteOutputDataStream.java --- /* * TestByteOutputDataStream.java $Revision: 1.1 $ $Date: 2001/11/10 21:33:29 $ * * Copyright (c) 2001 Invisible Worlds, Inc. All rights reserved. * Copyright (c) 2001 Huston Franklin. All rights reserved. * * The contents of this file are subject to the Blocks Public License (the * "License"); You may not use this file except in compliance with the License. * * You may obtain a copy of the License at http://www.beepcore.org/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * */ package org.beepcore.beep.core; import java.io.InputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.Enumeration; import java.util.Hashtable; import org.beepcore.beep.util.BufferSegment; import junit.framework.*; public class TestByteOutputDataStream extends TestCase { protected ByteOutputDataStream data; protected byte[] message; protected int dataOffset = 0; protected Hashtable headers = new Hashtable(); public TestByteOutputDataStream(String name) { super(name); } public static void main (String[] args) { junit.textui.TestRunner.run (suite()); } public void testGetNextSegment() { int i=0; while (data.isComplete() == false || data.availableSegment()) { BufferSegment b = data.getNextSegment(message.length); for (int j=b.getOffset(); j < b.getOffset() + b.getLength(); ++j) { assertEquals((char)message[i++], (char)(b.getData()[j])); } } } public void testGetNextSegmentFragments() { int i=0; while (data.isComplete() == false || data.availableSegment()) { BufferSegment b = data.getNextSegment(10); for (int j=b.getOffset(); j < b.getOffset() + b.getLength(); ++j) { assertEquals((char)message[i++], (char)(b.getData()[j])); } } } protected void setUp() throws UnsupportedEncodingException, BEEPException { Channel channel = new Channel("0", "0", null, null); String s = "12345678901234567890x2345678901234567890"; String EH1 = "EntityHeader1"; String h1 = "header1"; String EH2 = "EntityHeader2"; String h2 = "header2"; data = new ByteOutputDataStream(s.getBytes("UTF-8")); data.setHeaderValue(EH1, h1); data.setHeaderValue(EH2, h2); headers.put(EH1, h1); headers.put(EH2, h2); headers.put(MimeHeaders.CONTENT_TYPE, MimeHeaders.DEFAULT_CONTENT_TYPE); headers.put(MimeHeaders.CONTENT_TRANSFER_ENCODING, MimeHeaders.DEFAULT_CONTENT_TRANSFER_ENCODING); StringBuffer messageBuffer = new StringBuffer(); messageBuffer.append(serializeHeaders(data.getHeaderNames(), headers)); dataOffset = messageBuffer.length(); messageBuffer.append(s); message = messageBuffer.toString().getBytes("UTF8"); } private String serializeHeaders(Enumeration names, Hashtable headers) throws BEEPException { StringBuffer buf = new StringBuffer(); // Enumeration names = data.getHeaderNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); String value = (String) headers.get(name); if ((name.equals(MimeHeaders.CONTENT_TYPE) && value.equals(MimeHeaders.DEFAULT_CONTENT_TYPE)) || (name.equals(MimeHeaders.CONTENT_TRANSFER_ENCODING) && value.equals(MimeHeaders.DEFAULT_CONTENT_TRANSFER_ENCODING))) { // these are default values that don't need to be added // to the payload continue; } buf.append(name); buf.append(": "); buf.append(value); buf.append("\r\n"); } buf.append("\r\n"); return buf.toString(); } public static Test suite() { return new TestSuite(TestByteOutputDataStream.class); } } --- NEW FILE: TestStringOutputDataStream.java --- /* * TestStringOutputDataStream.java * $Revision: 1.1 $ $Date: 2001/11/10 21:33:29 $ * * Copyright (c) 2001 Invisible Worlds, Inc. All rights reserved. * Copyright (c) Huston Franklin. All rights reserved. * * The contents of this file are subject to the Blocks Public License (the * "License"); You may not use this file except in compliance with the License. * * You may obtain a copy of the License at http://www.beepcore.org/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * */ package org.beepcore.beep.core; import java.io.InputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.Enumeration; import java.util.Hashtable; import org.beepcore.beep.util.BufferSegment; import junit.framework.*; public class TestStringOutputDataStream extends TestCase { protected StringOutputDataStream data; protected byte[] message; protected int dataOffset = 0; protected Hashtable headers = new Hashtable(); public TestStringOutputDataStream(String name) { super(name); } public void testGetNextSegment() { int i=0; while (data.isComplete() == false || data.availableSegment()) { BufferSegment b = data.getNextSegment(message.length); for (int j=b.getOffset(); j < b.getOffset() + b.getLength(); ++j) { assertEquals((char)message[i++], (char)(b.getData()[j])); } } } public void testGetNextSegmentFragments() { int i=0; while (data.isComplete() == false || data.availableSegment()) { BufferSegment b = data.getNextSegment(10); for (int j=b.getOffset(); j < b.getOffset() + b.getLength(); ++j) { assertEquals((char)message[i++], (char)(b.getData()[j])); } } } protected void setUp() throws UnsupportedEncodingException, BEEPException { String s = "1234567890"; String EH1 = "EntityHeader1"; String h1 = "header1"; String EH2 = "EntityHeader2"; String h2 = "header2"; String te = "TransferEncoding1"; data = new StringOutputDataStream(s); data.setHeaderValue(EH1, h1); data.setHeaderValue(EH2, h2); data.setTransferEncoding(te); data.setContentType(MimeHeaders.BEEP_XML_CONTENT_TYPE); headers.put(MimeHeaders.CONTENT_TYPE, MimeHeaders.BEEP_XML_CONTENT_TYPE); headers.put(MimeHeaders.CONTENT_TRANSFER_ENCODING, te); headers.put(EH1, h1); headers.put(EH2, h2); StringBuffer messageBuffer = new StringBuffer(); messageBuffer.append(serializeHeaders(data.getHeaderNames(), headers)); dataOffset = messageBuffer.length(); messageBuffer.append(s); message = messageBuffer.toString().getBytes("UTF8"); } private String serializeHeaders(Enumeration names, Hashtable headers) throws BEEPException { StringBuffer buf = new StringBuffer(); // Enumeration names = data.getHeaderNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); String value = (String) headers.get(name); if ((name.equals(MimeHeaders.CONTENT_TYPE) && value.equals(MimeHeaders.DEFAULT_CONTENT_TYPE)) || (name.equals(MimeHeaders.CONTENT_TRANSFER_ENCODING) && value.equals(MimeHeaders.DEFAULT_CONTENT_TRANSFER_ENCODING))) { // these are default values that don't need to be added // to the payload continue; } buf.append(name); buf.append(": "); buf.append(value); buf.append("\r\n"); } buf.append("\r\n"); return buf.toString(); } public static Test suite() { return new TestSuite(TestStringOutputDataStream.class); } public static void main (String[] args) { junit.textui.TestRunner.run (suite()); } } Index: TestFileDataStream.java =================================================================== RCS file: /cvsroot/beepcore-java/beepcore-java/test/org/beepcore/beep/core/TestFileDataStream.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** TestFileDataStream.java 2001/11/08 05:51:35 1.2 --- TestFileDataStream.java 2001/11/10 21:33:29 1.3 *************** *** 26,31 **** import junit.framework.*; ! public class TestFileDataStream extends TestDataStream { ! static public String filename; --- 26,31 ---- import junit.framework.*; ! public class TestFileDataStream /*extends TestDataStream*/ { ! /* static public String filename; *************** *** 87,90 **** return new TestSuite(TestFileDataStream.class); } ! } --- 87,90 ---- return new TestSuite(TestFileDataStream.class); } ! */ } Index: TestInputDataStreamAdapter.java =================================================================== RCS file: /cvsroot/beepcore-java/beepcore-java/test/org/beepcore/beep/core/TestInputDataStreamAdapter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** TestInputDataStreamAdapter.java 2001/10/31 00:32:38 1.1 --- TestInputDataStreamAdapter.java 2001/11/10 21:33:29 1.2 *************** *** 3,6 **** --- 3,7 ---- * * Copyright (c) 2001 Invisible Worlds, Inc. All rights reserved. + * Copyright (c) 2001 Huston Franklin. All rights reserved. * * The contents of this file are subject to the Blocks Public License (the *************** *** 37,45 **** } ! public void testAvailable() throws IOException { ! InputStream is = data.getInputStream(); ! assertEquals("is.available()", ! message.length - dataOffset, is.available()); ! } public void testRead() throws IOException { --- 38,46 ---- } ! public void testAvailable() throws IOException { ! InputStream is = data.getInputStream(); ! assertEquals("is.available()", ! message.length - dataOffset, is.available()); ! } public void testRead() throws IOException { *************** *** 49,53 **** assertEquals("is.available()", is.available(), message.length - dataOffset - i); ! assertEquals(//"Byte number: " + i + " did not match", ((byte) is.read()), message[dataOffset + i]); } --- 50,54 ---- assertEquals("is.available()", is.available(), message.length - dataOffset - i); ! assertEquals(//"Byte number: " + i, ((byte) is.read()), message[dataOffset + i]); } *************** *** 75,79 **** message.length - dataOffset, count); for (int i=0; i < message.length - dataOffset; ++i) { ! assertEquals(//"Byte number: " + i + " did not match", message[dataOffset + i], b[i+5]); } --- 76,80 ---- message.length - dataOffset, count); for (int i=0; i < message.length - dataOffset; ++i) { ! assertEquals(//"Byte number: " + i, message[dataOffset + i], b[i+5]); } *************** *** 90,94 **** } for (int i=0; i < count; ++i) { ! assertEquals(//"Byte number: " + i + " did not match", message[dataOffset + i], b[i]); } --- 91,95 ---- } for (int i=0; i < count; ++i) { ! assertEquals(//"Byte number: " + i, message[dataOffset + i], b[i]); } *************** *** 108,112 **** } for (int i=0; i < b.length - dataOffset; ++i) { ! assertEquals("Byte number: " + i + " did not match", message[dataOffset + i], b[i]); } --- 109,113 ---- } for (int i=0; i < b.length - dataOffset; ++i) { ! assertEquals("Byte number: " + i, message[dataOffset + i], b[i]); } *************** *** 124,128 **** } for (int i=0; i < count - 5; ++i) { ! assertEquals(//"Byte number: " + i + " did not match", message[dataOffset + i], b[i+5]); } --- 125,129 ---- } for (int i=0; i < count - 5; ++i) { ! assertEquals(//"Byte number: " + i, message[dataOffset + i], b[i+5]); } *************** *** 143,152 **** for (int i=0; i<count; ++i) { ! assertEquals("Byte number: " + i + " did not match", (byte) is.read(), b[i]); } for (int i=0; is.available() != 0; ++i) { ! assertEquals("Byte number: " + i + " did not match", message[dataOffset + b.length + i], (byte) is.read()); --- 144,153 ---- for (int i=0; i<count; ++i) { ! assertEquals("Byte number: " + i, (byte) is.read(), b[i]); } for (int i=0; is.available() != 0; ++i) { ! assertEquals("Byte number: " + i, message[dataOffset + b.length + i], (byte) is.read()); *************** *** 162,166 **** int count = is.read(b); for (int i=0; i < count; ++i) { ! assertEquals("Byte number: " + i + " did not match", message[dataOffset + SKIP_AMOUNT + i], b[i]); } --- 163,167 ---- int count = is.read(b); for (int i=0; i < count; ++i) { ! assertEquals("Byte number: " + i, message[dataOffset + SKIP_AMOUNT + i], b[i]); } *************** *** 173,178 **** String header = data.getInputStream().getHeaderValue(name); String origHeader = (String)headers.get(name); ! assertEquals("Header: " + name + " values do not match (" + ! header + "!=" + origHeader + ")", origHeader, header); } --- 174,178 ---- String header = data.getInputStream().getHeaderValue(name); String origHeader = (String)headers.get(name); ! assertEquals("Header: " + name, origHeader, header); } --- TestByteDataStream.java DELETED --- --- TestDataStream.java DELETED --- --- TestFrameDataStream.java DELETED --- --- TestInputStreamDataStream.java DELETED --- --- TestStringDataStream.java DELETED --- |