public void unpack (ISOComponent c, InputStream in) throws IOException, ISOException { BitSet bmap = ISOUtil.byte2BitSet (new BitSet (64), readBytes (in, 8), 0); if (getLength() > 8 && bmap.get (1)) { ISOUtil.byte2BitSet (bmap, readBytes (in, 8), 64); } if (getLength() > 16 && bmap.get (65)) { ISOUtil.byte2BitSet (bmap, readBytes (in, 8), 128); } c.setValue(bmap); } public int getMaxPackedLength() {
@Test(expected = NullPointerException.class) public void testByte2BitSetThrowsNullPointerException1() throws Throwable { byte[] b = new byte[4]; b[2] = (byte) 127; ISOUtil.byte2BitSet(null, b, 100); }
@Test public void testByte2BitSet() throws Throwable { byte[] b = new byte[9]; BitSet result = ISOUtil.byte2BitSet(b, 0, true); assertEquals("result.size()", 64, result.size()); }
@Test public void testByte2BitSet1() throws Throwable { byte[] b = new byte[9]; b[4] = (byte) 1; BitSet result = ISOUtil.byte2BitSet(b, 0, true); assertEquals("result.size()", 64, result.size()); }
@Test public void testByte2BitSet9() throws Throwable { byte[] b = new byte[10]; BitSet result = ISOUtil.byte2BitSet(b, 0, 100); assertEquals("result.size()", 64, result.size()); }
@Test public void testByte2BitSet5() throws Throwable { byte[] b = new byte[1]; BitSet result = ISOUtil.byte2BitSet(null, b, 100); assertNull("result", result); }
@Test public void testByte2BitSet6() throws Throwable { byte[] b = new byte[0]; BitSet result = ISOUtil.byte2BitSet(null, b, 100); assertNull("result", result); }
@Test public void testBitSetByteHexInteroperability() throws Throwable { BitSet bs = new BitSet(); bs.set(1); bs.set(63); bs.set(127); bs.set(191); byte[] b = ISOUtil.bitSet2byte(bs); BitSet bs1 = ISOUtil.byte2BitSet(b, 0, 192); BitSet bs2 = ISOUtil.hex2BitSet(ISOUtil.hexString(b).getBytes(), 0, 192); assertEquals("BitSets should be equal", bs1, bs2); }
@Test public void testByte2BitSetThrowsArrayIndexOutOfBoundsException13() throws Throwable { byte[] b = new byte[1]; try { ISOUtil.byte2BitSet(b, 0, false); fail("Expected ArrayIndexOutOfBoundsException to be thrown"); } catch (ArrayIndexOutOfBoundsException ex) { assertEquals("ex.getMessage()", "1", ex.getMessage()); } }
@Test public void testByte2BitSetThrowsArrayIndexOutOfBoundsException9() throws Throwable { byte[] b = new byte[1]; try { ISOUtil.byte2BitSet(b, 0, 129); fail("Expected ArrayIndexOutOfBoundsException to be thrown"); } catch (ArrayIndexOutOfBoundsException ex) { assertEquals("ex.getMessage()", "1", ex.getMessage()); } }
@Test public void testByte2BitSetThrowsArrayIndexOutOfBoundsException19() throws Throwable { byte[] b = new byte[2]; b[1] = (byte) 59; try { ISOUtil.byte2BitSet(b, 0, 128); fail("Expected ArrayIndexOutOfBoundsException to be thrown"); } catch (ArrayIndexOutOfBoundsException ex) { assertEquals("ex.getMessage()", "2", ex.getMessage()); } }
@Test public void testByte2BitSetThrowsArrayIndexOutOfBoundsException14() throws Throwable { byte[] b = new byte[1]; try { ISOUtil.byte2BitSet(b, 0, true); fail("Expected ArrayIndexOutOfBoundsException to be thrown"); } catch (ArrayIndexOutOfBoundsException ex) { assertEquals("ex.getMessage()", "1", ex.getMessage()); } }
@Test public void testByte2BitSetThrowsArrayIndexOutOfBoundsException18() throws Throwable { byte[] b = new byte[12]; b[1] = (byte) -63; b[9] = (byte) -128; try { ISOUtil.byte2BitSet(b, 1, 1000); fail("Expected ArrayIndexOutOfBoundsException to be thrown"); } catch (ArrayIndexOutOfBoundsException ex) { assertEquals("ex.getMessage()", "12", ex.getMessage()); } }
@Test public void testByte2BitSetThrowsArrayIndexOutOfBoundsException8() throws Throwable { byte[] b = new byte[1]; try { ISOUtil.byte2BitSet(b, 0, 63); fail("Expected ArrayIndexOutOfBoundsException to be thrown"); } catch (ArrayIndexOutOfBoundsException ex) { assertEquals("ex.getMessage()", "1", ex.getMessage()); } }
@Test public void testByte2BitSetThrowsArrayIndexOutOfBoundsException10() throws Throwable { byte[] b = new byte[3]; try { ISOUtil.byte2BitSet(b, 100, 64); fail("Expected ArrayIndexOutOfBoundsException to be thrown"); } catch (ArrayIndexOutOfBoundsException ex) { assertEquals("ex.getMessage()", "100", ex.getMessage()); } }
@Test public void testByte2BitSetThrowsArrayIndexOutOfBoundsException2() throws Throwable { byte[] b = new byte[2]; b[1] = (byte) -1; try { ISOUtil.byte2BitSet(b, 1, 129); fail("Expected ArrayIndexOutOfBoundsException to be thrown"); } catch (ArrayIndexOutOfBoundsException ex) { assertEquals("ex.getMessage()", "2", ex.getMessage()); } }
@Test public void testByte2BitSetThrowsArrayIndexOutOfBoundsException5() throws Throwable { byte[] b = new byte[1]; b[0] = (byte) 3; try { ISOUtil.byte2BitSet(b, 0, 129); fail("Expected ArrayIndexOutOfBoundsException to be thrown"); } catch (ArrayIndexOutOfBoundsException ex) { assertEquals("ex.getMessage()", "1", ex.getMessage()); } }
@Test public void testThirdBitmapPack() throws Exception { byte[] b = ISOUtil.hex2byte("F23C04800AE00000"+"8000000000000108"+"63BC780000000010"); BitSet bs1 = ISOUtil.byte2BitSet(b, 0, 192); ISOBitMap bmap = new ISOBitMap(-1); bmap.setValue(bs1); IFA_BITMAP ifa = new IFA_BITMAP(24, "BITMAP"); byte[] b1 = ifa.pack(bmap); assertEquals ("Pack should be equal to unpack", ISOUtil.hexString(b), new String(b1)); } }
@Test public void testBitSetByteHexInteroperability3() throws Throwable { byte[] b = ISOUtil.hex2byte("F23C04800AE00000800000000000010863BC780000000010"); BitSet bs1 = ISOUtil.byte2BitSet(b, 0, 192); BitSet bs2 = ISOUtil.hex2BitSet (ISOUtil.hexString(b).getBytes(), 0, 192); assertEquals("BitSets should be equal", bs1, bs2); assertEquals("Image matches", ISOUtil.hexString(b), ISOUtil.hexString(ISOUtil.bitSet2byte(bs1))); }
@Test public void testThirdBitmapPack() throws Exception { byte[] b = ISOUtil.hex2byte("F23C04800AE00000800000000000010863BC780000000010"); BitSet bs1 = ISOUtil.byte2BitSet(b, 0, 192); ISOBitMap bmap = new ISOBitMap(-1); bmap.setValue(bs1); IFB_BITMAP ifb = new IFB_BITMAP(24, "BITMAP"); byte[] b1 = ifb.pack(bmap); assertEquals ("Pack should be equal to unpack", ISOUtil.hexString(b), ISOUtil.hexString(b1)); } }