1 64 65 package com.jcorporate.expresso.core.misc.tests; 66 67 import com.jcorporate.expresso.core.misc.CookieBase64; 68 import com.jcorporate.expresso.services.test.CommandLineParser; 69 import com.jcorporate.expresso.services.test.ExpressoTestCase; 70 import junit.framework.TestSuite; 71 72 73 79 public class CookieBase64Test 80 extends ExpressoTestCase { 81 final String [] testString = { 82 "a", "ab", "abc", "abcd", "abcde", "ABC", "ABCDE", "abcdef", "abcdefg", 83 "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ!@", 84 "#$%^&*()_+1234567890<>,.:\"\\" 85 }; 86 final byte[] test3 = { 87 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, 120, 54, -125, 30, (byte) 0xFF 88 }; 89 90 public CookieBase64Test(String testName) 91 throws Exception { 92 super(testName); 93 } 94 95 public static void main(String [] args) 96 throws Exception { 97 98 CommandLineParser.parseCommandLine(args); 100 junit.textui.TestRunner.run(suite()); 101 } 102 103 106 public static junit.framework.Test suite() 107 throws Exception { 108 return new TestSuite(CookieBase64Test.class); 109 } 110 111 114 public void testCookieBase64() { 115 int i; 116 117 for (i = 0; i < testString.length; i++) { 118 String arrayPartEncode = CookieBase64.encodeNoPadding(testString[i].getBytes()); 119 String arrayPartDecode = new String (CookieBase64.decodeNoPadding(arrayPartEncode)); 120 assertTrue("CookieBase64 Test: Test Data " + testString[i], 121 arrayPartDecode.equals(testString[i])); 122 assertTrue("Greater Than Zero Length Return " + testString[i], 123 arrayPartEncode.length() > 0); 124 assertTrue("No Padding", arrayPartEncode.indexOf('=') == -1); 125 } 126 127 String encode3 = CookieBase64.encodeNoPadding(test3); 129 byte[] decode3 = CookieBase64.decodeNoPadding(encode3); 130 131 for (i = 0; i < decode3.length; i++) { 132 assertTrue("Binary Input Data i=" + Integer.toString(i), 133 test3[i] == decode3[i]); 134 } 135 } 136 } | Popular Tags |