1 package org.ninjasoft.magiccodes.logic;
2
3 import junit.framework.TestCase;
4
5 import org.ninjasoft.magiccodes.logic.Translator;
6
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
19 extends TestCase
20
21 {
22
23 org.ninjasoft.magiccodes.logic.Translator translator = null;
24
25
26 public TranslatorTest(String name) {
27
28 super(name);
29
30 }
31
32 public org.ninjasoft.magiccodes.logic.Translator createInstance() throws Exception {
33
34 return new org.ninjasoft.magiccodes.logic.Translator();
35
36 }
37
38 protected void setUp() throws Exception {
39
40 super.setUp();
41 translator = createInstance();
42
43 }
44
45 protected void tearDown() throws Exception {
46
47 translator = null;
48 super.tearDown();
49
50 }
51
52 public void testByteToBin() throws Exception {
53
54 assertEquals(Translator.byteToBin(new int[] {0x01, 0x80, 0xff}),
55 "000000011000000011111111");
56 assertEquals(Translator.byteToBin(new int[] {'A', 'B', 'C'}),
57 "010000010100001001000011");
58
59 }
60
61 public void testBinToByte() throws Exception {
62
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
79 }
80
81 public void testByteToHex() throws Exception {
82
83 assertEquals(Translator.byteToHex(new int[] {0x01, 0x80, 0xff}),
84 "0180FF");
85 assertEquals(Translator.byteToHex(new int[] {'A', 'B', 'C'}),
86 "414243");
87
88 }
89
90 public void testHexToByte() throws Exception {
91
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
108 }
109
110 public void testByteToAscii() throws Exception {
111
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
117 }
118
119 public void testAsciiToByte() throws Exception {
120
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
130 }
131
132 public void testByteToPrintableAscii() throws Exception {
133
134
135 }
136
137 public void testNormalizeString() throws Exception {
138
139
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
152
153 }
154
155 public static void main(String[] args) {
156
157 junit.textui.TestRunner.run(TranslatorTest.class);
158
159 }
160 }