You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2018/02/22 10:53:40 UTC
[incubator-plc4x] branch master updated: added tests with hex
suffix to help better understand boundaries.
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
The following commit(s) were added to refs/heads/master by this push:
new 787abb6 added tests with hex suffix to help better understand boundaries.
787abb6 is described below
commit 787abb6956c4f40f778280d3259ebbca9adff56a
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Feb 22 11:53:36 2018 +0100
added tests with hex suffix to help better understand boundaries.
---
.../plc4x/java/ads/api/util/ByteValueTest.java | 60 +++++++++++++++-------
1 file changed, 42 insertions(+), 18 deletions(-)
diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/util/ByteValueTest.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/util/ByteValueTest.java
index 90202bc..b35156a 100644
--- a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/util/ByteValueTest.java
+++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/util/ByteValueTest.java
@@ -25,18 +25,18 @@ import org.junit.Test;
import java.math.BigInteger;
+import static java.util.Arrays.copyOfRange;
import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertThat;
public class ByteValueTest {
private ByteValue byteValue;
- private long upperBound = (long) Math.pow( 2, (8 * 4));
+ private long upperBound = (long) Math.pow(2, (8 * 4));
@Before
public void setUp() throws Exception {
- byteValue = new ByteValue((byte)0x1, (byte)0x2,(byte) 0x3, (byte)0x4);
+ byteValue = new ByteValue((byte) 0x1, (byte) 0x2, (byte) 0x3, (byte) 0x4);
}
@After
@@ -57,7 +57,14 @@ public class ByteValueTest {
@Test
public void checkUnsignedBoundsLong() {
ByteValue.checkUnsignedBounds(0, 4);
- ByteValue.checkUnsignedBounds(upperBound-1, 4);
+ ByteValue.checkUnsignedBounds(upperBound - 1, 4);
+ }
+
+ @Test
+ public void checkUnsignedBoundsLongHex() {
+ // Hex representation to visualize valid bounds in bytes
+ ByteValue.checkUnsignedBounds(0x0_00_00, 2);
+ ByteValue.checkUnsignedBounds(0x0_FF_FF, 2);
}
@Test(expected = IllegalArgumentException.class)
@@ -70,10 +77,21 @@ public class ByteValueTest {
ByteValue.checkUnsignedBounds(upperBound, 4);
}
+ @Test(expected = IllegalArgumentException.class)
+ public void checkUnsignedBoundsLongTooBigHex() {
+ ByteValue.checkUnsignedBounds(0x1_FF_FF, 2);
+ }
+
@Test
public void checkUnsignedBoundsBig() {
ByteValue.checkUnsignedBounds(new BigInteger("0"), 4);
- ByteValue.checkUnsignedBounds(new BigInteger(Long.toString(upperBound-1)), 4);
+ ByteValue.checkUnsignedBounds(new BigInteger(Long.toString(upperBound - 1)), 4);
+ }
+
+ @Test
+ public void checkUnsignedBoundsBigHex() {
+ ByteValue.checkUnsignedBounds(BigInteger.valueOf(0x0_00_00), 2);
+ ByteValue.checkUnsignedBounds(BigInteger.valueOf(0x0_FF_FF), 2);
}
@Test(expected = IllegalArgumentException.class)
@@ -86,37 +104,43 @@ public class ByteValueTest {
ByteValue.checkUnsignedBounds(new BigInteger(Long.toString(upperBound)).add(BigInteger.ONE), 4);
}
+ @Test(expected = IllegalArgumentException.class)
+ public void checkUnsignedBoundsBigTooBigHex() {
+ ByteValue.checkUnsignedBounds(BigInteger.valueOf(0x1_FF_FF), 2);
+ }
+
@Test
public void getBytes() {
- byte[] correct = {(byte)0x1, (byte)0x2, (byte)0x3, (byte)0x4};
+ byte[] correct = {(byte) 0x1, (byte) 0x2, (byte) 0x3, (byte) 0x4};
assertThat(byteValue.getBytes(), is(correct));
}
@Test
public void getByteBuf() {
- byte[] correct = {(byte)0x1, (byte)0x2, (byte)0x3, (byte)0x4};
+ byte[] correct = {(byte) 0x1, (byte) 0x2, (byte) 0x3, (byte) 0x4};
ByteBuf data = byteValue.getByteBuf();
assertThat(data.readableBytes(), is(4));
- assertThat(data.readByte(), is((byte)0x1));
- assertThat(data.readByte(), is((byte)0x2));
- assertThat(data.readByte(), is((byte)0x3));
- assertThat(data.readByte(), is((byte)0x4));
+ assertThat(data.readByte(), is((byte) 0x1));
+ assertThat(data.readByte(), is((byte) 0x2));
+ assertThat(data.readByte(), is((byte) 0x3));
+ assertThat(data.readByte(), is((byte) 0x4));
+ assertThat(copyOfRange(data.array(), 0, 4), is(correct));
}
@Test
public void equals() {
- ByteValue a = new ByteValue(((byte)0x1));
- ByteValue b = new ByteValue(((byte)0x1));
- ByteValue c = new ByteValue(((byte)0x2));
- byte array[] = {(byte)0x1};
+ ByteValue a = new ByteValue(((byte) 0x1));
+ ByteValue b = new ByteValue(((byte) 0x1));
+ ByteValue c = new ByteValue(((byte) 0x2));
+ byte array[] = {(byte) 0x1};
assertThat(a.equals(a), is(true));
assertThat(a.equals(b), is(true));
assertThat(a.equals(c), is(false));
assertThat(a.equals(1), is(false));
- assertThat(a.equals((byte)1), is(false));
+ assertThat(a.equals((byte) 1), is(false));
assertThat(a.equals(array), is(false));
}
-
+
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
sruehl@apache.org.