1 package org.ninjasoft.magiccodes.logic; 2 3 import junit.framework.TestCase; 4 // JUnitDoclet begin import 5 import org.ninjasoft.magiccodes.logic.Translator; 6 // JUnitDoclet end import 7 8 /*** 9 * Generated by JUnitDoclet, a tool provided by 10 * ObjectFab GmbH under LGPL. 11 * Please see www.junitdoclet.org, www.gnu.org 12 * and www.objectfab.de for informations about 13 * the tool, the licence and the authors. 14 */ 15 16 17 public class TranslatorTest 18 // JUnitDoclet begin extends_implements 19 extends TestCase 20 // JUnitDoclet end extends_implements 21 { 22 // JUnitDoclet begin class 23 org.ninjasoft.magiccodes.logic.Translator translator = null; 24 // JUnitDoclet end class 25 26 public TranslatorTest(String name) { 27 // JUnitDoclet begin method TranslatorTest 28 super(name); 29 // JUnitDoclet end method TranslatorTest 30 } 31 32 public org.ninjasoft.magiccodes.logic.Translator createInstance() throws Exception { 33 // JUnitDoclet begin method testcase.createInstance 34 return new org.ninjasoft.magiccodes.logic.Translator(); 35 // JUnitDoclet end method testcase.createInstance 36 } 37 38 protected void setUp() throws Exception { 39 // JUnitDoclet begin method testcase.setUp 40 super.setUp(); 41 translator = createInstance(); 42 // JUnitDoclet end method testcase.setUp 43 } 44 45 protected void tearDown() throws Exception { 46 // JUnitDoclet begin method testcase.tearDown 47 translator = null; 48 super.tearDown(); 49 // JUnitDoclet end method testcase.tearDown 50 } 51 52 public void testByteToBin() throws Exception { 53 // JUnitDoclet begin method byteToBin 54 assertEquals(Translator.byteToBin(new int[] {0x01, 0x80, 0xff}), 55 "000000011000000011111111"); 56 assertEquals(Translator.byteToBin(new int[] {'A', 'B', 'C'}), 57 "010000010100001001000011"); 58 // JUnitDoclet end method byteToBin 59 } 60 61 public void testBinToByte() throws Exception { 62 // JUnitDoclet begin method binToByte 63 int[] data = Translator.binToByte("000000011000000011111111"); 64 assertEquals(data[0], 0x01); 65 assertEquals(data[1], 0x80); 66 assertEquals(data[2], 0xff); 67 data = Translator.binToByte("010000010100001001000011"); 68 assertEquals(data[0], 'A'); 69 assertEquals(data[1], 'B'); 70 assertEquals(data[2], 'C'); 71 boolean caught = false; 72 try{ 73 Translator.binToByte("1111111"); 74 }catch(Exception e){ 75 caught = true; 76 } 77 assertTrue("Check invalid input length", caught); 78 // JUnitDoclet end method binToByte 79 } 80 81 public void testByteToHex() throws Exception { 82 // JUnitDoclet begin method byteToHex 83 assertEquals(Translator.byteToHex(new int[] {0x01, 0x80, 0xff}), 84 "0180FF"); 85 assertEquals(Translator.byteToHex(new int[] {'A', 'B', 'C'}), 86 "414243"); 87 // JUnitDoclet end method byteToHex 88 } 89 90 public void testHexToByte() throws Exception { 91 // JUnitDoclet begin method hexToByte 92 int[] data = Translator.hexToByte("0180FF"); 93 assertEquals(data[0], 0x01); 94 assertEquals(data[1], 0x80); 95 assertEquals(data[2], 0xff); 96 data = Translator.hexToByte("414243"); 97 assertEquals(data[0], 'A'); 98 assertEquals(data[1], 'B'); 99 assertEquals(data[2], 'C'); 100 boolean caught = false; 101 try{ 102 Translator.binToByte("AAA"); 103 }catch(Exception e){ 104 caught = true; 105 } 106 assertTrue("Check invalid input length", caught); 107 // JUnitDoclet end method hexToByte 108 } 109 110 public void testByteToAscii() throws Exception { 111 // JUnitDoclet begin method byteToAscii 112 assertEquals(Translator.byteToAscii(new int[] {0x01, 0x80, 0xff}), 113 "" + String.valueOf((char) 0x01) + String.valueOf((char) 0x80) + String.valueOf((char) 0xff)); 114 assertEquals(Translator.byteToAscii(new int[] {'A', 'B', 'C'}), 115 "ABC"); 116 // JUnitDoclet end method byteToAscii 117 } 118 119 public void testAsciiToByte() throws Exception { 120 // JUnitDoclet begin method asciiToByte 121 int[] data = Translator.asciiToByte("" + new Character((char) 0x01) + new Character((char) 0x80) + new Character((char) 0xff)); 122 assertEquals(data[0], 0x01); 123 assertEquals(data[1], 0x80); 124 assertEquals(data[2], 0xff); 125 data = Translator.asciiToByte("ABC"); 126 assertEquals(data[0], 'A'); 127 assertEquals(data[1], 'B'); 128 assertEquals(data[2], 'C'); 129 // JUnitDoclet end method asciiToByte 130 } 131 132 public void testByteToPrintableAscii() throws Exception { 133 // JUnitDoclet begin method byteToPrintableAscii 134 // JUnitDoclet end method byteToPrintableAscii 135 } 136 137 public void testNormalizeString() throws Exception { 138 // JUnitDoclet begin method normalizeString 139 // JUnitDoclet end method normalizeString 140 } 141 142 143 144 /*** 145 * JUnitDoclet moves marker to this method, if there is not match 146 * for them in the regenerated code and if the marker is not empty. 147 * This way, no test gets lost when regenerating after renaming. 148 * Method testVault is supposed to be empty. 149 */ 150 public void testVault() throws Exception { 151 // JUnitDoclet begin method testcase.testVault 152 // JUnitDoclet end method testcase.testVault 153 } 154 155 public static void main(String[] args) { 156 // JUnitDoclet begin method testcase.main 157 junit.textui.TestRunner.run(TranslatorTest.class); 158 // JUnitDoclet end method testcase.main 159 } 160 }

This page was automatically generated by Maven