changeset 731:435c0834e124

unit tests for r729
author Devel 1
date Mon, 04 Dec 2017 12:50:58 +0100
parents 8e04c0095608
children f1fb6cf53868
files stress-tester/src/test/java/com/passus/st/reader/nc/NcDataHelperTest.java
diffstat 1 files changed, 41 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/test/java/com/passus/st/reader/nc/NcDataHelperTest.java	Mon Dec 04 12:27:22 2017 +0100
+++ b/stress-tester/src/test/java/com/passus/st/reader/nc/NcDataHelperTest.java	Mon Dec 04 12:50:58 2017 +0100
@@ -2,10 +2,13 @@
 
 import com.passus.commons.AsciiUtils;
 import com.passus.data.ByteBuff;
+import com.passus.data.ByteString;
 import com.passus.data.HeapByteBuff;
 import java.nio.ByteBuffer;
+import org.apache.commons.lang3.mutable.Mutable;
 import org.apache.commons.lang3.mutable.MutableInt;
 import org.apache.commons.lang3.mutable.MutableLong;
+import org.apache.commons.lang3.mutable.MutableObject;
 import static org.testng.AssertJUnit.*;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
@@ -108,6 +111,44 @@
     }
 
     @Test
+    public void testReadByteString_bytes() {
+        byte[] bytes = {'x', 'v', 'a', 'l', 'u', 'e', AsciiUtils.NUL};
+        Mutable<ByteString> result = new MutableObject<>();
+        int read = helper.readByteStringNullTerminated(bytes, 1, result);
+        assertEquals(6, read);
+        assertEquals("value", result.getValue().toString());
+    }
+
+    @Test
+    public void testWriteByteString_bytes() {
+        ByteString value = ByteString.create("value");
+        byte[] bytes = {1, 1, 1, 1, 1, 1, 1, 1};
+        int written = helper.writeByteStringNullTerminated(bytes, 1, bytes.length, value, true);
+        byte[] expected = {1, 'v', 'a', 'l', 'u', 'e', AsciiUtils.NUL, 1};
+        assertEquals(expected, bytes);
+        assertEquals(6, written);
+    }
+
+    @Test
+    public void testReadString_bytes() {
+        byte[] bytes = {'x', 'v', 'a', 'l', 'u', 'e', AsciiUtils.NUL};
+        Mutable<String> result = new MutableObject<>();
+        int read = helper.readStringNullTerminated(bytes, 1, result);
+        assertEquals(6, read);
+        assertEquals("value", result.getValue());
+    }
+
+    @Test
+    public void testWriteString_bytes() {
+        String value = "value";
+        byte[] bytes = {1, 1, 1, 1, 1, 1, 1, 1};
+        int written = helper.writeStringNullTerminated(bytes, 1, bytes.length, value);
+        byte[] expected = {1, 'v', 'a', 'l', 'u', 'e', AsciiUtils.NUL, 1};
+        assertEquals(expected, bytes);
+        assertEquals(6, written);
+    }
+
+    @Test
     public void testWriteStringNullTerminated() {
         ByteBuffer buffer = ByteBuffer.allocate(256);