|
15 | 15 | import org.epics.vtype.Display; |
16 | 16 | import org.epics.vtype.EnumDisplay; |
17 | 17 | import org.epics.vtype.Time; |
| 18 | +import org.epics.vtype.VByte; |
18 | 19 | import org.epics.vtype.VDouble; |
19 | 20 | import org.epics.vtype.VEnum; |
| 21 | +import org.epics.vtype.VFloat; |
| 22 | +import org.epics.vtype.VInt; |
20 | 23 | import org.epics.vtype.VIntArray; |
21 | 24 | import org.epics.vtype.VLong; |
22 | 25 | import org.epics.vtype.VNumberArray; |
| 26 | +import org.epics.vtype.VShort; |
23 | 27 | import org.epics.vtype.VString; |
24 | 28 | import org.epics.vtype.VStringArray; |
25 | 29 | import org.epics.vtype.VType; |
| 30 | +import org.epics.vtype.VUByte; |
| 31 | +import org.epics.vtype.VUInt; |
| 32 | +import org.epics.vtype.VULong; |
| 33 | +import org.epics.vtype.VUShort; |
26 | 34 | import org.junit.jupiter.api.Test; |
27 | 35 |
|
28 | 36 | import java.text.DecimalFormat; |
@@ -167,19 +175,245 @@ public void testEngineering() |
167 | 175 | @Test |
168 | 176 | public void testHexFormat() |
169 | 177 | { |
170 | | - VType number = VDouble.of(65535.0, Alarm.none(), Time.now(), display); |
171 | | - |
172 | | - String text = FormatOptionHandler.format(number, FormatOption.HEX, 4, true); |
173 | | - System.out.println(text); |
174 | | - assertThat(text, equalTo("0xFFFF V")); |
175 | | - |
176 | | - text = FormatOptionHandler.format(number, FormatOption.HEX, 8, true); |
177 | | - System.out.println(text); |
178 | | - assertThat(text, equalTo("0x0000FFFF V")); |
179 | | - |
180 | | - text = FormatOptionHandler.format(number, FormatOption.HEX, 16, true); |
181 | | - System.out.println(text); |
182 | | - assertThat(text, equalTo("0x000000000000FFFF V")); |
| 178 | + { |
| 179 | + VType number = VDouble.of(65535.0, Alarm.none(), Time.now(), display); |
| 180 | + |
| 181 | + String text = FormatOptionHandler.format(number, FormatOption.HEX, 4, true); |
| 182 | + System.out.println(text); |
| 183 | + assertThat(text, equalTo("0xFFFF V")); |
| 184 | + |
| 185 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 8, true); |
| 186 | + System.out.println(text); |
| 187 | + assertThat(text, equalTo("0x0000FFFF V")); |
| 188 | + |
| 189 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 16, true); |
| 190 | + System.out.println(text); |
| 191 | + assertThat(text, equalTo("0x000000000000FFFF V")); |
| 192 | + } |
| 193 | + |
| 194 | + { |
| 195 | + // Test with VDouble representing 0xFFFFFFFF |
| 196 | + VType number = VDouble.of(4294967295.0, Alarm.none(), Time.now(), display); |
| 197 | + |
| 198 | + String text = FormatOptionHandler.format(number, FormatOption.HEX, 4, true); |
| 199 | + System.out.println(text); |
| 200 | + assertThat(text, equalTo("0xFFFFFFFF V")); |
| 201 | + |
| 202 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 8, true); |
| 203 | + System.out.println(text); |
| 204 | + assertThat(text, equalTo("0xFFFFFFFF V")); |
| 205 | + |
| 206 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 16, true); |
| 207 | + System.out.println(text); |
| 208 | + assertThat(text, equalTo("0x00000000FFFFFFFF V")); |
| 209 | + } |
| 210 | + |
| 211 | + { |
| 212 | + // Test with VFloat representing 0xFFFF |
| 213 | + VType number = VFloat.of(65535.0, Alarm.none(), Time.now(), display); |
| 214 | + |
| 215 | + String text = FormatOptionHandler.format(number, FormatOption.HEX, 4, true); |
| 216 | + System.out.println(text); |
| 217 | + assertThat(text, equalTo("0xFFFF V")); |
| 218 | + |
| 219 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 8, true); |
| 220 | + System.out.println(text); |
| 221 | + assertThat(text, equalTo("0x0000FFFF V")); |
| 222 | + |
| 223 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 16, true); |
| 224 | + System.out.println(text); |
| 225 | + assertThat(text, equalTo("0x000000000000FFFF V")); |
| 226 | + } |
| 227 | + |
| 228 | + { |
| 229 | + // Test with VInt representing 0x00 |
| 230 | + VType number = VInt.of(0x00, Alarm.none(), Time.now(), display); |
| 231 | + |
| 232 | + String text = FormatOptionHandler.format(number, FormatOption.HEX, 4, true); |
| 233 | + System.out.println(text); |
| 234 | + assertThat(text, equalTo("0x0000 V")); |
| 235 | + |
| 236 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 8, true); |
| 237 | + System.out.println(text); |
| 238 | + assertThat(text, equalTo("0x00000000 V")); |
| 239 | + |
| 240 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 16, true); |
| 241 | + System.out.println(text); |
| 242 | + assertThat(text, equalTo("0x0000000000000000 V")); |
| 243 | + } |
| 244 | + |
| 245 | + { |
| 246 | + // Test with VByte representing 0xFF |
| 247 | + VType number = VByte.of(0xFF, Alarm.none(), Time.now(), display); |
| 248 | + |
| 249 | + String text = FormatOptionHandler.format(number, FormatOption.HEX, 2, true); |
| 250 | + System.out.println(text); |
| 251 | + assertThat(text, equalTo("0xFF V")); |
| 252 | + |
| 253 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 4, true); |
| 254 | + System.out.println(text); |
| 255 | + assertThat(text, equalTo("0x00FF V")); |
| 256 | + |
| 257 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 8, true); |
| 258 | + System.out.println(text); |
| 259 | + assertThat(text, equalTo("0x000000FF V")); |
| 260 | + |
| 261 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 16, true); |
| 262 | + System.out.println(text); |
| 263 | + assertThat(text, equalTo("0x00000000000000FF V")); |
| 264 | + } |
| 265 | + |
| 266 | + { |
| 267 | + // Test with VByte representing 0xFF |
| 268 | + VType number = VUByte.of(0xFF, Alarm.none(), Time.now(), display); |
| 269 | + |
| 270 | + String text = FormatOptionHandler.format(number, FormatOption.HEX, 2, true); |
| 271 | + System.out.println(text); |
| 272 | + assertThat(text, equalTo("0xFF V")); |
| 273 | + |
| 274 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 4, true); |
| 275 | + System.out.println(text); |
| 276 | + assertThat(text, equalTo("0x00FF V")); |
| 277 | + |
| 278 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 8, true); |
| 279 | + System.out.println(text); |
| 280 | + assertThat(text, equalTo("0x000000FF V")); |
| 281 | + |
| 282 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 16, true); |
| 283 | + System.out.println(text); |
| 284 | + assertThat(text, equalTo("0x00000000000000FF V")); |
| 285 | + } |
| 286 | + |
| 287 | + { |
| 288 | + // Test with VShort representing 0xFFAA |
| 289 | + VType number = VShort.of(0xFFAA, Alarm.none(), Time.now(), display); |
| 290 | + |
| 291 | + String text = FormatOptionHandler.format(number, FormatOption.HEX, 2, true); |
| 292 | + System.out.println(text); |
| 293 | + assertThat(text, equalTo("0xFFAA V")); |
| 294 | + |
| 295 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 4, true); |
| 296 | + System.out.println(text); |
| 297 | + assertThat(text, equalTo("0xFFAA V")); |
| 298 | + |
| 299 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 8, true); |
| 300 | + System.out.println(text); |
| 301 | + assertThat(text, equalTo("0x0000FFAA V")); |
| 302 | + |
| 303 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 16, true); |
| 304 | + System.out.println(text); |
| 305 | + assertThat(text, equalTo("0x000000000000FFAA V")); |
| 306 | + } |
| 307 | + |
| 308 | + { |
| 309 | + // Test with VUShort representing 0xFFAA |
| 310 | + VType number = VUShort.of(0xFFAA, Alarm.none(), Time.now(), display); |
| 311 | + |
| 312 | + String text = FormatOptionHandler.format(number, FormatOption.HEX, 2, true); |
| 313 | + System.out.println(text); |
| 314 | + assertThat(text, equalTo("0xFFAA V")); |
| 315 | + |
| 316 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 4, true); |
| 317 | + System.out.println(text); |
| 318 | + assertThat(text, equalTo("0xFFAA V")); |
| 319 | + |
| 320 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 8, true); |
| 321 | + System.out.println(text); |
| 322 | + assertThat(text, equalTo("0x0000FFAA V")); |
| 323 | + |
| 324 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 16, true); |
| 325 | + System.out.println(text); |
| 326 | + assertThat(text, equalTo("0x000000000000FFAA V")); |
| 327 | + } |
| 328 | + |
| 329 | + { |
| 330 | + // Test with VInt representing 0xFF |
| 331 | + VType number = VInt.of(0xFF, Alarm.none(), Time.now(), display); |
| 332 | + |
| 333 | + String text = FormatOptionHandler.format(number, FormatOption.HEX, 2, true); |
| 334 | + System.out.println(text); |
| 335 | + assertThat(text, equalTo("0xFF V")); |
| 336 | + |
| 337 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 4, true); |
| 338 | + System.out.println(text); |
| 339 | + assertThat(text, equalTo("0x00FF V")); |
| 340 | + |
| 341 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 8, true); |
| 342 | + System.out.println(text); |
| 343 | + assertThat(text, equalTo("0x000000FF V")); |
| 344 | + |
| 345 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 16, true); |
| 346 | + System.out.println(text); |
| 347 | + assertThat(text, equalTo("0x00000000000000FF V")); |
| 348 | + } |
| 349 | + |
| 350 | + { |
| 351 | + // Test with VInt representing 0xFFFFFFAA |
| 352 | + VType number = VInt.of(0xFFFFFFAA, Alarm.none(), Time.now(), display); |
| 353 | + |
| 354 | + String text = FormatOptionHandler.format(number, FormatOption.HEX, 4, true); |
| 355 | + System.out.println(text); |
| 356 | + assertThat(text, equalTo("0xFFFFFFAA V")); |
| 357 | + |
| 358 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 8, true); |
| 359 | + System.out.println(text); |
| 360 | + assertThat(text, equalTo("0xFFFFFFAA V")); |
| 361 | + |
| 362 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 16, true); |
| 363 | + System.out.println(text); |
| 364 | + assertThat(text, equalTo("0x00000000FFFFFFAA V")); |
| 365 | + } |
| 366 | + |
| 367 | + { |
| 368 | + // Test with VUInt representing 0xFFFFFFAA |
| 369 | + VType number = VUInt.of(0xFFFFFFAA, Alarm.none(), Time.now(), display); |
| 370 | + |
| 371 | + String text = FormatOptionHandler.format(number, FormatOption.HEX, 4, true); |
| 372 | + System.out.println(text); |
| 373 | + assertThat(text, equalTo("0xFFFFFFAA V")); |
| 374 | + |
| 375 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 8, true); |
| 376 | + System.out.println(text); |
| 377 | + assertThat(text, equalTo("0xFFFFFFAA V")); |
| 378 | + |
| 379 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 16, true); |
| 380 | + System.out.println(text); |
| 381 | + assertThat(text, equalTo("0x00000000FFFFFFAA V")); |
| 382 | + } |
| 383 | + |
| 384 | + { |
| 385 | + // Test with VLong representing 0xFFFFFFAA |
| 386 | + VType number = VLong.of(0xFFFFFFFFFFFFFFAAL, Alarm.none(), Time.now(), display); |
| 387 | + |
| 388 | + String text = FormatOptionHandler.format(number, FormatOption.HEX, 4, true); |
| 389 | + System.out.println(text); |
| 390 | + assertThat(text, equalTo("0xFFFFFFFFFFFFFFAA V")); |
| 391 | + |
| 392 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 8, true); |
| 393 | + System.out.println(text); |
| 394 | + assertThat(text, equalTo("0xFFFFFFFFFFFFFFAA V")); |
| 395 | + |
| 396 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 16, true); |
| 397 | + System.out.println(text); |
| 398 | + assertThat(text, equalTo("0xFFFFFFFFFFFFFFAA V")); |
| 399 | + } |
| 400 | + |
| 401 | + { |
| 402 | + // Test with VULong representing 0xFFFFFFAA |
| 403 | + VType number = VULong.of(0xFFFFFFFFFFFFFFAAL, Alarm.none(), Time.now(), display); |
| 404 | + |
| 405 | + String text = FormatOptionHandler.format(number, FormatOption.HEX, 4, true); |
| 406 | + System.out.println(text); |
| 407 | + assertThat(text, equalTo("0xFFFFFFFFFFFFFFAA V")); |
| 408 | + |
| 409 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 8, true); |
| 410 | + System.out.println(text); |
| 411 | + assertThat(text, equalTo("0xFFFFFFFFFFFFFFAA V")); |
| 412 | + |
| 413 | + text = FormatOptionHandler.format(number, FormatOption.HEX, 16, true); |
| 414 | + System.out.println(text); |
| 415 | + assertThat(text, equalTo("0xFFFFFFFFFFFFFFAA V")); |
| 416 | + } |
183 | 417 | } |
184 | 418 |
|
185 | 419 | @Test |
|
0 commit comments