public void testConstructors() {
try
{
new IntegerField(-1);
fail("Should have caught ArrayIndexOutOfBoundsException");
}
catch (ArrayIndexOutOfBoundsException ignored_e)
{
// as expected
}
IntegerField field = new IntegerField(2);
assertEquals(0, field.get());
try
{
new IntegerField(-1, 1);
fail("Should have caught ArrayIndexOutOfBoundsException");
}
catch (ArrayIndexOutOfBoundsException ignored_e)
{
// as expected
}
field = new IntegerField(2, 0x12345678);
assertEquals(0x12345678, field.get());
byte[] array = new byte[ 6 ];
try
{
new IntegerField(-1, 1, array);
fail("Should have caught ArrayIndexOutOfBoundsException");
}
catch (ArrayIndexOutOfBoundsException ignored_e)
{
// as expected
}
field = new IntegerField(2, 0x12345678, array);
assertEquals(0x12345678, field.get());
assertEquals(( byte ) 0x78, array[ 2 ]);
assertEquals(( byte ) 0x56, array[ 3 ]);
assertEquals(( byte ) 0x34, array[ 4 ]);
assertEquals(( byte ) 0x12, array[ 5 ]);
array = new byte[ 5 ];
try
{
new IntegerField(2, 5, array);
fail("should have gotten ArrayIndexOutOfBoundsException");
}
catch (ArrayIndexOutOfBoundsException ignored_e)
{
// as expected
}
for (int j = 0; j < _test_array.length; j++)
{
array = new byte[ 4 ];
new IntegerField(0, _test_array[ j ], array);
assertEquals(_test_array[ j ], new IntegerField(0, array).get());
}
}
|