gt:             byte[] threeBytes = new byte[]{-83, 59, -128};
context: /*******************************************************************************
   * Copyright (c) 2012 IBM Corporation and others.
   * All rights reserved. This program and the accompanying materials
   * are made available under the terms of the Eclipse Public License v1.0
   * which accompanies this distribution, and is available at
   * http://www.eclipse.org/legal/epl-v10.html
   *
   * Contributors:
   *     IBM Corporation - initial API and implementation
   *******************************************************************************/
  package com.ibm.ws.sib.msgstore.test.util;
  /*
   * Change activity:
   *
   *  Reason         Date     Origin   Description
   * --------------- -------- -------- ------------------------------------------
   *  SIB0048c.ms.2  02/02/07 gareth   Resolve wide XID problem
   * ============================================================================
   */
  
  import java.lang.reflect.Array;
  
  import java.util.Random;
  
  import com.ibm.ws.sib.msgstore.test.*;
  import com.ibm.ws.sib.utils.Base64Utils;
  
  import junit.framework.TestSuite;
  
  public class Base64Test extends MessageStoreTestCase
  {
      public Base64Test(String name)
      {
          super(name);
  
          //turnOnTrace();
      }
  
      /**
       * This is an Non-persitent test.
       */
      public static TestSuite suite()
      {
          TestSuite suite = new TestSuite(Base64Test.class);
  
          return suite;
      }
  
      public void testBase64EncodeDecode()
      {
          print("|-----------------------------------------------------");
          print("| Base64EncodeDecode:");
          print("|--------------------");
  
          String        encoded;
          byte[]        decoded;
          StringBuilder decodedBytes;
  
          try
          {
              byte[] allOnes = new byte[]{-1, -1, -1};
              print("|");
              print("|-----------------------------------------------------");
              print("| Encode of:               {  -1        -1       -1   }");
              print("|  - Value in bits       :  11111111 11111111 11111111");
              print("|                           ^--|-^^--|--^^--|--^^-|--^");
              print("|  - Expected characters :!    -     -      -     -");
              encoded = Base64Utils.encodeBase64(allOnes);
              print("|  - Actual characters   : "+encoded);
              if (!"!----".equals(encoded))
              {
                  print("| Characters do not match! !!!FAILED!!!");
                  fail("Ouput does not match expected string: Actual("+encoded+") Expected(----)");
              }
  
              print("|");
              print("| Decode of:              {!    -        -        -       -    }");
              print("|  - Value in bits       :  00111111 00111111 00111111 00111111");
              print("|                             ^----|----^^----|----^^----|----^");
              print("|  - Expected bytes      :        -1         -1         -1");
              decoded = Base64Utils.decodeBase64(encoded);
              decodedBytes = new StringBuilder();
              for (byte b : decoded)
              {
                  decodedBytes.append(b);
                  decodedBytes.append(" ");
              }
              print("|  - Actual bytes        : "+decodedBytes);
              print("|-----------------------------------------------------");
              if (!byteArraysEqual(allOnes, decoded))
              {
                  print("| Bytes do not match! !!!FAILED!!!");
                  fail("Output does not match expected bytes: Actual("+decodedBytes+") Expected(-1 -1 -1)");
              }
  
  
              byte[] allZeros = new byte[]{0, 0, 0};
              print("| ");
              print("|-----------------------------------------------------");
              print("| Encode of:               {   0         0        0   }");
              print("|  - Value in bits       :  00000000 00000000 00000000");
              print("|                           ^--|-^^--|--^^--|--^^-|--^");
              print("|  - Expected characters :!    A     A      A     A");
              encoded = Base64Utils.encodeBase64(allZeros);
              print("|  - Actual characters   : "+encoded);
              if (!"!AAAA".equals(encoded))
              {
                  print("| Characters do not match! !!!FAILED!!!");
                  fail("Ouput does not match expected string: Actual("+encoded+") Expected(AAAA)");
              }
  
              print("|");
              print("| Decode of:              {!    A        A        A       A    }");
              print("|  - Value in bits       :  00000000 00000000 00000000 00000000");
              print("|                             ^----|----^^----|----^^----|----^");
              print("|  - Expected bytes      :         0          0          0");
              decoded = Base64Utils.decodeBase64(encoded);
              decodedBytes = new StringBuilder();
              for (byte b : decoded)
              {
                  decodedBytes.append(b);
                  decodedBytes.append(" ");
              }
              print("|  - Actual bytes        : "+decodedBytes);
              print("|-----------------------------------------------------");
              if (!byteArraysEqual(allZeros, decoded))
              {
                  print("| Bytes do not match! !!!FAILED!!!");
                  fail("Output does not match expected bytes: Actual("+decodedBytes+") Expected(0 0 0)");
              }
  
              
              byte[] oneByte = new byte[]{65};
              print("|");
              print("|-----------------------------------------------------");
              print("| Encode of:               {   65       -         -   }");
              print("|  - Value in bits       :  01000001 -------- --------");
              print("|                           ^--|-^^--|--^^--|--^^-|--^");
              print("|  - Expected characters :!    Q     Q      =     =");
              encoded = Base64Utils.encodeBase64(oneByte);
              print("|  - Actual characters   : "+encoded);
              if (!"!QQ==".equals(encoded))
              {
                  print("| Characters do not match! !!!FAILED!!!");
                  fail("Ouput does not match expected string: Actual("+encoded+") Expected(QQ==)");
              }
  
              print("|");
              print("| Decode of:              {!    Q        Q        =       =    }");
              print("|  - Value in bits       :  00010000 00010000 -------- --------");
              print("|                             ^----|----^^----|----^^----|----^");
              print("|  - Expected bytes      :        65          -          -");
              decoded = Base64Utils.decodeBase64(encoded);
              decodedBytes = new StringBuilder();
              for (byte b : decoded)
              {
                  decodedBytes.append(b);
                  decodedBytes.append(" ");
              }
              print("|  - Actual bytes        : "+decodedBytes);
              print("|-----------------------------------------------------");
              if (!byteArraysEqual(oneByte, decoded))
              {
                  print("| Bytes do not match! !!!FAILED!!!");
                  fail("Output does not match expected bytes: Actual("+decodedBytes+") Expected(65)");
              }
  
  
              byte[] twoBytes = new byte[]{59, -83};
              print("|");
              print("|-----------------------------------------------------");
              print("| Encode of:               {   59      -83        -   }");
              print("|  - Value in bits       :  00111011 10101101 --------");
              print("|                           ^--|-^^--|--^^--|--^^-|--^");
              print("|  - Expected characters :!    O     6      0     =");
              encoded = Base64Utils.encodeBase64(twoBytes);
              print("|  - Actual characters   : "+encoded);
              if (!"!O60=".equals(encoded))
              {
                  print("| Characters do not match! !!!FAILED!!!");
                  fail("Ouput does not match expected string: Actual("+encoded+") Expected(O60=)");
              }
  
              print("|");
              print("| Decode of:              {!    O        6        0       =    }");
              print("|  - Value in bits       :  00001110 00111010 00110100 --------");
              print("|                             ^----|----^^----|----^^----|----^");
              print("|  - Expected bytes      :        59         -83         -");
              decoded = Base64Utils.decodeBase64(encoded);
              decodedBytes = new StringBuilder();
              for (byte b : decoded)
              {
                  decodedBytes.append(b);
                  decodedBytes.append(" ");
              }
              print("|  - Actual bytes        : "+decodedBytes);
              print("|-----------------------------------------------------");
              if (!byteArraysEqual(twoBytes, decoded))
              {
                  print("| Bytes do not match! !!!FAILED!!!");
                  fail("Output does not match expected bytes: Actual("+decodedBytes+") Expected(59 -83)");
              }
  
  
  