-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestVariableRepresentation.java
More file actions
290 lines (243 loc) · 13.3 KB
/
TestVariableRepresentation.java
File metadata and controls
290 lines (243 loc) · 13.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
import java.util.*;
public class TestVariableRepresentation {
public static String runTest() {
String header = "TestVariableRepresentation results:" + System.lineSeparator();
String errors = "";
String result = "";
VariableRepresentation rep = new VariableRepresentation("FAFB");
if (!rep.getValue(true).equals("FAFB"))
errors += " VALUE ERROR 1: Value is [" + rep.getValue(true) + "]" + System.lineSeparator();
if (!rep.getValue(false).equals("FBFA"))
errors += " VALUE ERROR 2: Value is [" + rep.getValue(false) + "]" + System.lineSeparator();
// CHAR
result = rep.clampValue(VariableType.UNSIGNED_CHAR, "-50");
if (!result.equals("255"))
errors += " CLAMP ERROR 3: Clamp is [" + result + "]" + System.lineSeparator();
result = rep.clampValue(VariableType.UNSIGNED_CHAR, "300");
if (!result.equals("0"))
errors += " CLAMP ERROR 4: Clamp is [" + result + "]" + System.lineSeparator();
result = rep.clampValue(VariableType.SIGNED_CHAR, "-300");
if (!result.equals("127"))
errors += " CLAMP ERROR 5: Clamp is [" + result + "]" + System.lineSeparator();
result = rep.clampValue(VariableType.SIGNED_CHAR, "300");
if (!result.equals("-128"))
errors += " CLAMP ERROR 6: Clamp is [" + result + "]" + System.lineSeparator();
// SHORT
result = rep.clampValue(VariableType.UNSIGNED_SHORT, "-50");
if (!result.equals("65535"))
errors += " CLAMP ERROR 7: Clamp is [" + result + "]" + System.lineSeparator();
result = rep.clampValue(VariableType.UNSIGNED_SHORT, "70000");
if (!result.equals("0"))
errors += " CLAMP ERROR 8: Clamp is [" + result + "]" + System.lineSeparator();
result = rep.clampValue(VariableType.SIGNED_SHORT, "-40000");
if (!result.equals("32767"))
errors += " CLAMP ERROR 9: Clamp is [" + result + "]" + System.lineSeparator();
result = rep.clampValue(VariableType.SIGNED_SHORT, "40000");
if (!result.equals("-32768"))
errors += " CLAMP ERROR 10: Clamp is [" + result + "]" + System.lineSeparator();
// INT
result = rep.clampValue(VariableType.UNSIGNED_INT, "-50");
if (!result.equals("4294967295"))
errors += " CLAMP ERROR 11: Clamp is [" + result + "]" + System.lineSeparator();
result = rep.clampValue(VariableType.UNSIGNED_INT, "5294967295");
if (!result.equals("0"))
errors += " CLAMP ERROR 12: Clamp is [" + result + "]" + System.lineSeparator();
result = rep.clampValue(VariableType.SIGNED_INT, "-3147483648");
if (!result.equals("2147483647"))
errors += " CLAMP ERROR 13: Clamp is [" + result + "]" + System.lineSeparator();
result = rep.clampValue(VariableType.SIGNED_INT, "3147483648");
if (!result.equals("-2147483648"))
errors += " CLAMP ERROR 14: Clamp is [" + result + "]" + System.lineSeparator();
// LONG
UIUtils.architecture = 64;
result = rep.clampValue(VariableType.UNSIGNED_LONG, "-50");
if (!result.equals("18446744073709551615"))
errors += " CLAMP ERROR 15: Clamp is [" + result + "]" + System.lineSeparator();
result = rep.clampValue(VariableType.UNSIGNED_LONG, "28446744073709551615");
if (!result.equals("0"))
errors += " CLAMP ERROR 16: Clamp is [" + result + "]" + System.lineSeparator();
result = rep.clampValue(VariableType.SIGNED_LONG, "-9923372036854775807");
if (!result.equals("9223372036854775807"))
errors += " CLAMP ERROR 17: Clamp is [" + result + "]" + System.lineSeparator();
result = rep.clampValue(VariableType.SIGNED_LONG, "9923372036854775807");
if (!result.equals("-9223372036854775808"))
errors += " CLAMP ERROR 18: Clamp is [" + result + "]" + System.lineSeparator();
UIUtils.architecture = 32;
result = rep.clampValue(VariableType.UNSIGNED_LONG, "-50");
if (!result.equals("4294967295"))
errors += " CLAMP ERROR 19: Clamp is [" + result + "]" + System.lineSeparator();
result = rep.clampValue(VariableType.UNSIGNED_LONG, "5294967295");
if (!result.equals("0"))
errors += " CLAMP ERROR 20: Clamp is [" + result + "]" + System.lineSeparator();
result = rep.clampValue(VariableType.SIGNED_LONG, "-3147483648");
if (!result.equals("2147483647"))
errors += " CLAMP ERROR 21: Clamp is [" + result + "]" + System.lineSeparator();
result = rep.clampValue(VariableType.SIGNED_LONG, "3147483648");
if (!result.equals("-2147483648"))
errors += " CLAMP ERROR 22: Clamp is [" + result + "]" + System.lineSeparator();
// Check hex values we get back when feeding in decimal values of various variable types
// CHAR
rep.setValueFromDecimal("201", VariableType.UNSIGNED_CHAR);
result = rep.getValue(true);
if (!result.equals("C9"))
errors += " HEX ERROR 23: Hex is [" + result + "]" + System.lineSeparator();
result = rep.getValue(false);
if (!result.equals("C9"))
errors += " HEX ERROR 24: Hex is [" + result + "]" + System.lineSeparator();
rep.setValueFromDecimal("-99", VariableType.SIGNED_CHAR);
result = rep.getValue(true);
if (!result.equals("9D"))
errors += " HEX ERROR 25: Hex is [" + result + "]" + System.lineSeparator();
result = rep.getValue(false);
if (!result.equals("9D"))
errors += " HEX ERROR 26: Hex is [" + result + "]" + System.lineSeparator();
// SHORT
rep.setValueFromDecimal("201", VariableType.UNSIGNED_SHORT);
result = rep.getValue(true);
if (!result.equals("00C9"))
errors += " HEX ERROR 27: Hex is [" + result + "]" + System.lineSeparator();
result = rep.getValue(false);
if (!result.equals("C900"))
errors += " HEX ERROR 28: Hex is [" + result + "]" + System.lineSeparator();
rep.setValueFromDecimal("65246", VariableType.UNSIGNED_SHORT);
result = rep.getValue(true);
if (!result.equals("FEDE"))
errors += " HEX ERROR 29: Hex is [" + result + "]" + System.lineSeparator();
result = rep.getValue(false);
if (!result.equals("DEFE"))
errors += " HEX ERROR 30: Hex is [" + result + "]" + System.lineSeparator();
rep.setValueFromDecimal("-99", VariableType.SIGNED_SHORT);
result = rep.getValue(true);
if (!result.equals("FF9D"))
errors += " HEX ERROR 31: Hex is [" + result + "]" + System.lineSeparator();
result = rep.getValue(false);
if (!result.equals("9DFF"))
errors += " HEX ERROR 32: Hex is [" + result + "]" + System.lineSeparator();
rep.setValueFromDecimal("-32111", VariableType.SIGNED_SHORT);
result = rep.getValue(true);
if (!result.equals("8291"))
errors += " HEX ERROR 33: Hex is [" + result + "]" + System.lineSeparator();
result = rep.getValue(false);
if (!result.equals("9182"))
errors += " HEX ERROR 34: Hex is [" + result + "]" + System.lineSeparator();
rep.setValueFromDecimal("-32111", VariableType.SIGNED_SHORT);
result = rep.getValue(true);
if (!result.equals("8291"))
errors += " HEX ERROR 33: Hex is [" + result + "]" + System.lineSeparator();
result = rep.getValue(false);
if (!result.equals("9182"))
errors += " HEX ERROR 34: Hex is [" + result + "]" + System.lineSeparator();
rep.setValueFromDecimal("129000", VariableType.SIGNED_SHORT);
result = rep.getValue(true);
if (!result.equals("F7E8"))
errors += " HEX ERROR 35: Hex is [" + result + "]" + System.lineSeparator();
result = rep.getValue(false);
if (!result.equals("E8F7"))
errors += " HEX ERROR 36: Hex is [" + result + "]" + System.lineSeparator();
// INTEGER
rep.setValueFromDecimal("201", VariableType.UNSIGNED_INT);
result = rep.getValue(true);
if (!result.equals("000000C9"))
errors += " HEX ERROR 37: Hex is [" + result + "]" + System.lineSeparator();
result = rep.getValue(false);
if (!result.equals("C9000000"))
errors += " HEX ERROR 38: Hex is [" + result + "]" + System.lineSeparator();
rep.setValueFromDecimal("4100050301", VariableType.UNSIGNED_INT);
result = rep.getValue(true);
if (!result.equals("F461CD7D"))
errors += " HEX ERROR 39: Hex is [" + result + "]" + System.lineSeparator();
result = rep.getValue(false);
if (!result.equals("7DCD61F4"))
errors += " HEX ERROR 40: Hex is [" + result + "]" + System.lineSeparator();
rep.setValueFromDecimal("-99", VariableType.SIGNED_INT);
result = rep.getValue(true);
if (!result.equals("FFFFFF9D"))
errors += " HEX ERROR 41: Hex is [" + result + "]" + System.lineSeparator();
result = rep.getValue(false);
if (!result.equals("9DFFFFFF"))
errors += " HEX ERROR 42: Hex is [" + result + "]" + System.lineSeparator();
rep.setValueFromDecimal("-2100050301", VariableType.SIGNED_INT);
result = rep.getValue(true);
if (!result.equals("82D3C683"))
errors += " HEX ERROR 43: Hex is [" + result + "]" + System.lineSeparator();
result = rep.getValue(false);
if (!result.equals("83C6D382"))
errors += " HEX ERROR 44: Hex is [" + result + "]" + System.lineSeparator();
rep.setValueFromDecimal("-6100050301", VariableType.SIGNED_INT);
result = rep.getValue(true);
if (!result.equals("94689E83"))
errors += " HEX ERROR 45: Hex is [" + result + "]" + System.lineSeparator();
result = rep.getValue(false);
if (!result.equals("839E6894"))
errors += " HEX ERROR 46: Hex is [" + result + "]" + System.lineSeparator();
rep.setValueFromDecimal("7100050301", VariableType.SIGNED_INT);
result = rep.getValue(true);
if (!result.equals("A7322B7D"))
errors += " HEX ERROR 47: Hex is [" + result + "]" + System.lineSeparator();
result = rep.getValue(false);
if (!result.equals("7D2B32A7"))
errors += " HEX ERROR 48: Hex is [" + result + "]" + System.lineSeparator();
// LONGS
// I'm going to skip 64-bit longs because my own code is the only way I know of
// to verify values that large (except the extremely tedious process of converting
// by hand, not happening), which makes testing kind of pointless.
// I will test longs on 32-bit architecture however to make sure they're
// behaving the same as ints in that case.
UIUtils.architecture = 32;
rep.setValueFromDecimal("201", VariableType.UNSIGNED_LONG);
result = rep.getValue(true);
if (!result.equals("000000C9"))
errors += " HEX ERROR 49: Hex is [" + result + "]" + System.lineSeparator();
result = rep.getValue(false);
if (!result.equals("C9000000"))
errors += " HEX ERROR 50: Hex is [" + result + "]" + System.lineSeparator();
rep.setValueFromDecimal("4100050301", VariableType.UNSIGNED_LONG);
result = rep.getValue(true);
if (!result.equals("F461CD7D"))
errors += " HEX ERROR 51: Hex is [" + result + "]" + System.lineSeparator();
result = rep.getValue(false);
if (!result.equals("7DCD61F4"))
errors += " HEX ERROR 52: Hex is [" + result + "]" + System.lineSeparator();
rep.setValueFromDecimal("-99", VariableType.SIGNED_LONG);
result = rep.getValue(true);
if (!result.equals("FFFFFF9D"))
errors += " HEX ERROR 53: Hex is [" + result + "]" + System.lineSeparator();
result = rep.getValue(false);
if (!result.equals("9DFFFFFF"))
errors += " HEX ERROR 54: Hex is [" + result + "]" + System.lineSeparator();
rep.setValueFromDecimal("-2100050301", VariableType.SIGNED_LONG);
result = rep.getValue(true);
if (!result.equals("82D3C683"))
errors += " HEX ERROR 55: Hex is [" + result + "]" + System.lineSeparator();
result = rep.getValue(false);
if (!result.equals("83C6D382"))
errors += " HEX ERROR 56: Hex is [" + result + "]" + System.lineSeparator();
rep.setValueFromDecimal("-6100050301", VariableType.SIGNED_LONG);
result = rep.getValue(true);
if (!result.equals("94689E83"))
errors += " HEX ERROR 57: Hex is [" + result + "]" + System.lineSeparator();
result = rep.getValue(false);
if (!result.equals("839E6894"))
errors += " HEX ERROR 58: Hex is [" + result + "]" + System.lineSeparator();
rep.setValueFromDecimal("7100050301", VariableType.SIGNED_LONG);
result = rep.getValue(true);
if (!result.equals("A7322B7D"))
errors += " HEX ERROR 59: Hex is [" + result + "]" + System.lineSeparator();
result = rep.getValue(false);
if (!result.equals("7D2B32A7"))
errors += " HEX ERROR 60: Hex is [" + result + "]" + System.lineSeparator();
// Actually, I'll do a LITTLE bit of 64-bit testing just to make sure the hex
// is the right length, but I'll be taking its word for it on the values.
UIUtils.architecture = 64;
rep.setValueFromDecimal("18416744073109551616", VariableType.UNSIGNED_LONG);
result = rep.getValue(true);
if (!result.equals("FF956B288CF9BA00"))
errors += " HEX ERROR 61: Hex is [" + result + "]" + System.lineSeparator();
// Make sure we get the same decimal number back out
result = rep.convertHexToDecimal(result, VariableType.UNSIGNED_LONG);
if (!result.equals("18416744073109551616"))
errors += " DEC ERROR 62: Decimal is [" + result + "]" + System.lineSeparator();
if (errors.isEmpty()) errors = " All tests passed!" + System.lineSeparator();
return (header + errors);
} // runTest()
} // TestVariableRepresentation class