Author: sebb
Date: Wed Nov 5 10:32:32 2008
New Revision: 711649
URL: http://svn.apache.org/viewvc?rev=711649&view=rev
Log:
Add error tests and round-trip
Modified:
jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/tcp/sampler/BinaryTCPClientImplTest.java
Modified:
jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/tcp/sampler/BinaryTCPClientImplTest.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/tcp/sampler/BinaryTCPClientImplTest.java?rev=711649&r1=711648&r2=711649&view=diff
==============================================================================
---
jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/tcp/sampler/BinaryTCPClientImplTest.java
(original)
+++
jakarta/jmeter/trunk/test/src/org/apache/jmeter/protocol/tcp/sampler/BinaryTCPClientImplTest.java
Wed Nov 5 10:32:32 2008
@@ -22,10 +22,14 @@
*/
package org.apache.jmeter.protocol.tcp.sampler;
-import org.apache.jorphan.util.JOrphanUtils;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
import junit.framework.TestCase;
+import org.apache.jorphan.util.JOrphanUtils;
+
public class BinaryTCPClientImplTest extends TestCase {
public void testHexStringToByteArray() throws Exception {
@@ -37,7 +41,7 @@
assertEquals(1, ba.length);
assertEquals(0, ba[0]);
- ba = BinaryTCPClientImpl.hexStringToByteArray("0f107f8081ff");
+ ba = BinaryTCPClientImpl.hexStringToByteArray("0f107F8081ff");
assertEquals(6, ba.length);
assertEquals(15, ba[0]);
assertEquals(16, ba[1]);
@@ -45,11 +49,38 @@
assertEquals(-128, ba[3]);
assertEquals(-127, ba[4]);
assertEquals(-1, ba[5]);
-
+ try {
+ ba = BinaryTCPClientImpl.hexStringToByteArray("0f107f8081ff1");//
odd chars
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException expected){
+ // ignored
+ }
+ try {
+ ba = BinaryTCPClientImpl.hexStringToByteArray("0f107xxf8081ff");
// invalid
+ fail("Expected IllegalArgumentException");
+ } catch (IllegalArgumentException expected){
+ // ignored
+ }
}
public void testLoopBack() throws Exception {
assertEquals("0f107f8081ff",
JOrphanUtils.baToHexString(BinaryTCPClientImpl.hexStringToByteArray("0f107f8081ff")));
}
+ public void testRoundTrip() throws Exception {
+ BinaryTCPClientImpl bi = new BinaryTCPClientImpl();
+ InputStream is = null;
+ try {
+ bi.write(null, is);
+ fail("Expected UnsupportedOperationException");
+ } catch (UnsupportedOperationException expected) {
+ // ignored
+ }
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ bi.write(os, "3132333435"); // '12345'
+ os.close();
+ assertEquals("12345",os.toString());
+ ByteArrayInputStream bis = new ByteArrayInputStream(os.toByteArray());
+ assertEquals("3132333435",bi.read(bis));
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]