[jboss-cvs] JBoss Messaging SVN: r4419 - in trunk/tests: src/org/jboss/messaging/tests/unit/core/util and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jun 10 07:58:51 EDT 2008


Author: jmesnil
Date: 2008-06-10 07:58:51 -0400 (Tue, 10 Jun 2008)
New Revision: 4419

Added:
   trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SafeUTFTest.java
Modified:
   trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/String64KLimitTest.java
Log:
moved unit tests specific to SafeUTF in SafeUTFTest class

Modified: trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/String64KLimitTest.java
===================================================================
--- trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/String64KLimitTest.java	2008-06-10 11:57:14 UTC (rev 4418)
+++ trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/String64KLimitTest.java	2008-06-10 11:58:51 UTC (rev 4419)
@@ -21,11 +21,6 @@
   */
 package org.jboss.test.messaging.jms;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-
 import javax.jms.Connection;
 import javax.jms.MessageConsumer;
 import javax.jms.MessageProducer;
@@ -33,8 +28,6 @@
 import javax.jms.Session;
 import javax.jms.TextMessage;
 
-import org.jboss.messaging.util.SafeUTF;
-
 /**
  * 
  * There is a bug in JDK1.3, 1.4 whereby writeUTF fails if more than 64K bytes are written
@@ -66,85 +59,6 @@
    // TestCase overrides -------------------------------------------
 
    // Public --------------------------------------------------------
-   
-   public void testSafeWriteReadUTFTest1() throws Exception
-   {
-      //Make sure we hit all the edge cases
-      doTest("a", 10);
-      doTest("ab", 10);
-      doTest("abc", 10);
-      doTest("abcd", 10);
-      doTest("abcde", 10);
-      doTest("abcdef", 10);
-      doTest("abcdefg", 10);
-      doTest("abcdefgh", 10);
-      doTest("abcdefghi", 10);
-      doTest("abcdefghij", 10);
-      doTest("abcdefghijk", 10);
-      doTest("abcdefghijkl", 10);
-      doTest("abcdefghijklm", 10);
-      doTest("abcdefghijklmn", 10);
-      doTest("abcdefghijklmno", 10);
-      doTest("abcdefghijklmnop", 10);
-      doTest("abcdefghijklmnopq", 10);
-      doTest("abcdefghijklmnopqr", 10);
-      doTest("abcdefghijklmnopqrs", 10);
-      doTest("abcdefghijklmnopqrst", 10);
-      doTest("abcdefghijklmnopqrstu", 10);
-      doTest("abcdefghijklmnopqrstuv", 10);
-      doTest("abcdefghijklmnopqrstuvw", 10);
-      doTest("abcdefghijklmnopqrstuvwx", 10);
-      doTest("abcdefghijklmnopqrstuvwxy", 10);
-      doTest("abcdefghijklmnopqrstuvwxyz", 10);
-      
-      //Need to work with null too
-      doTest(null, 10);
-              
-   }
-   
-   protected void doTest(String s, int chunkSize) throws Exception
-   {
-      ByteArrayOutputStream bos = new ByteArrayOutputStream();
-      
-      DataOutputStream dos = new DataOutputStream(bos);
-      
-      SafeUTF.safeWriteUTF(dos, s);
-      
-      dos.close();
-      
-      byte[] bytes = bos.toByteArray();
-      
-      ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
-      
-      DataInputStream dis = new DataInputStream(bis);
-      
-      String s2 = SafeUTF.safeReadUTF(dis);
-      
-      assertEquals(s, s2);   
-   }
-   
-   public void testSafeWriteReadUTFTest2() throws Exception
-   {
-      ByteArrayOutputStream bos = new ByteArrayOutputStream();
-      
-      DataOutputStream dos = new DataOutputStream(bos);
-      
-      String s = "abcdefghijklmnopqrstuvwxyz";
-      
-      SafeUTF.safeWriteUTF(dos, s);
-      
-      dos.close();
-      
-      byte[] bytes = bos.toByteArray();
-      
-      ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
-      
-      DataInputStream dis = new DataInputStream(bis);
-      
-      String s2 = SafeUTF.safeReadUTF(dis);
-      
-      assertEquals(s, s2); 
-   }
          
    protected String genString(int len)
    {
@@ -158,6 +72,10 @@
    
    //Tests commented out until message chunking is complete
    //See http://jira.jboss.org/jira/browse/JBMESSAGING-379
+
+   public void testFoo() throws Exception
+   {      
+   }
    
 //   public void test64KLimitWithTextMessage() throws Exception
 //   {            

Added: trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SafeUTFTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SafeUTFTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SafeUTFTest.java	2008-06-10 11:58:51 UTC (rev 4419)
@@ -0,0 +1,152 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.messaging.tests.unit.core.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.util.SafeUTF;
+
+/**
+ * 
+ * There is a bug in JDK1.3, 1.4 whereby writeUTF fails if more than 64K bytes are written
+ * we need to work with all size of strings
+ * 
+ * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4806007
+ * http://jira.jboss.com/jira/browse/JBAS-2641
+ * 
+ * @author <a href="tim.fox at jboss.com">Tim Fox</a>
+ * 
+ * @version $Revision: 1174 $
+ */
+public class SafeUTFTest extends TestCase
+{
+   // Constants -----------------------------------------------------
+
+   // Static --------------------------------------------------------
+   
+   // Attributes ----------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public SafeUTFTest(String name)
+   {
+      super(name);
+   }
+
+   // TestCase overrides -------------------------------------------
+
+   // Public --------------------------------------------------------
+   
+   public void testSafeWriteReadUTFTest1() throws Exception
+   {
+      //Make sure we hit all the edge cases
+      doTest("a", 10);
+      doTest("ab", 10);
+      doTest("abc", 10);
+      doTest("abcd", 10);
+      doTest("abcde", 10);
+      doTest("abcdef", 10);
+      doTest("abcdefg", 10);
+      doTest("abcdefgh", 10);
+      doTest("abcdefghi", 10);
+      doTest("abcdefghij", 10);
+      doTest("abcdefghijk", 10);
+      doTest("abcdefghijkl", 10);
+      doTest("abcdefghijklm", 10);
+      doTest("abcdefghijklmn", 10);
+      doTest("abcdefghijklmno", 10);
+      doTest("abcdefghijklmnop", 10);
+      doTest("abcdefghijklmnopq", 10);
+      doTest("abcdefghijklmnopqr", 10);
+      doTest("abcdefghijklmnopqrs", 10);
+      doTest("abcdefghijklmnopqrst", 10);
+      doTest("abcdefghijklmnopqrstu", 10);
+      doTest("abcdefghijklmnopqrstuv", 10);
+      doTest("abcdefghijklmnopqrstuvw", 10);
+      doTest("abcdefghijklmnopqrstuvwx", 10);
+      doTest("abcdefghijklmnopqrstuvwxy", 10);
+      doTest("abcdefghijklmnopqrstuvwxyz", 10);
+      
+      //Need to work with null too
+      doTest(null, 10);
+              
+   }
+   
+   protected void doTest(String s, int chunkSize) throws Exception
+   {
+      ByteArrayOutputStream bos = new ByteArrayOutputStream();
+      
+      DataOutputStream dos = new DataOutputStream(bos);
+      
+      SafeUTF.safeWriteUTF(dos, s);
+      
+      dos.close();
+      
+      byte[] bytes = bos.toByteArray();
+      
+      ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
+      
+      DataInputStream dis = new DataInputStream(bis);
+      
+      String s2 = SafeUTF.safeReadUTF(dis);
+      
+      assertEquals(s, s2);   
+   }
+   
+   public void testSafeWriteReadUTFTest2() throws Exception
+   {
+      ByteArrayOutputStream bos = new ByteArrayOutputStream();
+      
+      DataOutputStream dos = new DataOutputStream(bos);
+      
+      String s = "abcdefghijklmnopqrstuvwxyz";
+      
+      SafeUTF.safeWriteUTF(dos, s);
+      
+      dos.close();
+      
+      byte[] bytes = bos.toByteArray();
+      
+      ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
+      
+      DataInputStream dis = new DataInputStream(bis);
+      
+      String s2 = SafeUTF.safeReadUTF(dis);
+      
+      assertEquals(s, s2); 
+   }
+         
+   protected String genString(int len)
+   {
+      char[] chars = new char[len];
+      for (int i = 0; i < len; i++)
+      {
+         chars[i] = (char)(65 + i % 26);
+      }
+      return new String(chars);
+   }
+}




More information about the jboss-cvs-commits mailing list