You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by bl...@apache.org on 2004/02/21 03:06:40 UTC

cvs commit: xml-security/src_unitTests/org/apache/xml/security/test/utils Base64Test.java

blautenb    2004/02/20 18:06:40

  Modified:    src_unitTests/org/apache/xml/security/test/utils
                        Base64Test.java
  Log:
  Added unit tests for some Base64 encoding conditions
  
  Revision  Changes    Path
  1.8       +45 -4     xml-security/src_unitTests/org/apache/xml/security/test/utils/Base64Test.java
  
  Index: Base64Test.java
  ===================================================================
  RCS file: /home/cvs/xml-security/src_unitTests/org/apache/xml/security/test/utils/Base64Test.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Base64Test.java	8 Feb 2004 06:08:22 -0000	1.7
  +++ Base64Test.java	21 Feb 2004 02:06:40 -0000	1.8
  @@ -24,6 +24,7 @@
   import junit.framework.TestSuite;
   
   import org.apache.xml.security.exceptions.Base64DecodingException;
  +import org.apache.xml.security.utils.Base64;
   
   
   /**
  @@ -76,17 +77,57 @@
      public static void testA1() throws java.io.UnsupportedEncodingException, Base64DecodingException {
   
         String textData = "Hallo";
  -      String result0 =
  -         org.apache.xml.security.utils.Base64
  -            .encode(textData.getBytes("UTF-8"));
  +      String result0 = Base64.encode(textData.getBytes("UTF-8"));
   
         assertNotNull("Result of encoding result0", result0);
   
  -      byte resultBytes[] = org.apache.xml.security.utils.Base64.decode(result0);
  +      byte resultBytes[] = Base64.decode(result0);
         String resultStr = new String(resultBytes, "UTF-8");
   
         assertEquals("Result of decoding", 0, textData.compareTo(resultStr));
      }
  +
  +   /**
  +    * Method testWrap1
  +    *
  +	* Test for correct line wrapping at end of an exactly 76 char string
  +	*
  +    * @throws java.io.UnsupportedEncodingException
  +    */
  +
  +	public static void testWrap1() 
  +		throws java.io.UnsupportedEncodingException, Base64DecodingException {
  +
  +		String inputData = "The quick brown fox jumps over the lazy dog and some extr";
  +		String expectedResult = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZyBhbmQgc29tZSBleHRy";
  +		String result = Base64.encode(inputData.getBytes("UTF-8"));
  +		assertEquals("Result of encoding", result, expectedResult);
  +
  +		String result2 = new String(Base64.decode(result), "UTF-8");
  +		assertEquals("Result of encoding", result2, inputData);
  +
  +	}
  +
  +   /**
  +    * Method testWrap2
  +    *
  +	* Test for correct line wrapping after more than 76 characters
  +	*
  +    * @throws java.io.UnsupportedEncodingException
  +    */
  +
  +	public static void testWrap2() 
  +		throws java.io.UnsupportedEncodingException, Base64DecodingException {
  +
  +		String inputData = "The quick brown fox jumps over the lazy dog and some extra text that will cause a line wrap";
  +		String expectedResult = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZyBhbmQgc29tZSBleHRy\nYSB0ZXh0IHRoYXQgd2lsbCBjYXVzZSBhIGxpbmUgd3JhcA==";
  +		String result = Base64.encode(inputData.getBytes("UTF-8"));
  +		assertEquals("Result of encoding", result, expectedResult);
  +
  +		String result2 = new String(Base64.decode(result), "UTF-8");
  +		assertEquals("Result of encoding", result2, inputData);
  +
  +	}
   
      static {
         org.apache.xml.security.Init.init();