-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: improve test coverage of XdrInt
Acked-by: Paul Millar Target: master
- Loading branch information
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/xdr/XdrIntTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.dcache.oncrpc4j.xdr; | ||
|
||
import java.io.IOException; | ||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
|
||
public class XdrIntTest { | ||
|
||
|
||
@Test | ||
public void testDecode() throws IOException { | ||
|
||
int value = 17; | ||
|
||
XdrInt xInt = new XdrInt(); | ||
try(Xdr xdr = new Xdr(8)) { | ||
xdr.beginEncoding(); | ||
xdr.xdrEncodeInt(value); | ||
|
||
xdr.endEncoding(); | ||
|
||
xdr.beginDecoding(); | ||
xInt.xdrDecode(xdr); | ||
|
||
assertEquals("invalid value decode", value, xInt.intValue()); | ||
|
||
} | ||
} | ||
|
||
@Test | ||
public void testEncode() throws IOException { | ||
|
||
|
||
XdrInt xInt = new XdrInt(17); | ||
try (Xdr xdr = new Xdr(8)) { | ||
xdr.beginEncoding(); | ||
xInt.xdrEncode(xdr); | ||
|
||
xdr.endEncoding(); | ||
|
||
xdr.beginDecoding(); | ||
|
||
assertEquals("invalid value decoded", xInt.intValue(), xdr.xdrDecodeInt()); | ||
|
||
} | ||
} | ||
|
||
@Test | ||
public void testEncodeWellKnown() throws IOException { | ||
|
||
byte[] data = new byte[] { | ||
0x0, 0x0, 0x0, 0x11 // big endian encoded 17 | ||
}; | ||
|
||
XdrInt xInt = new XdrInt(17); | ||
try (Xdr xdr = new Xdr(8)) { | ||
xdr.beginEncoding(); | ||
xInt.xdrEncode(xdr); | ||
|
||
xdr.endEncoding(); | ||
assertArrayEquals(data, xdr.getBytes()); | ||
} | ||
} | ||
|
||
|
||
@Test | ||
public void testDecodeWellKnown() throws IOException { | ||
|
||
byte[] data = new byte[]{ | ||
0x0, 0x0, 0x0, 0x11 // big endian encoded 17 | ||
}; | ||
|
||
try (Xdr xdr = new Xdr(data)) { | ||
xdr.beginDecoding(); | ||
XdrInt xInt = new XdrInt(); | ||
xInt.xdrDecode(xdr); | ||
|
||
assertEquals(17, xInt.intValue()); | ||
} | ||
} | ||
|
||
} |