add a test
This commit is contained in:
parent
afb56982a7
commit
ba0c18000a
4 changed files with 43 additions and 3 deletions
|
@ -13,4 +13,7 @@ install:
|
|||
- export CC=gcc-4.8
|
||||
- export CXX=g++-4.8
|
||||
- cd capnproto-c++-0.4.1 && ./configure && make -j5 && sudo make install && cd ..
|
||||
script: make CXX=g++-4.8 CXX_FLAGS="-std=c++11 -I/usr/local/include -L/usr/local/lib -lcapnp -lkj"
|
||||
script:
|
||||
- sbt compile
|
||||
- sbt test
|
||||
|
||||
|
|
|
@ -60,8 +60,10 @@ object Build extends sbt.Build {
|
|||
object Shared {
|
||||
|
||||
val testDeps = Seq(
|
||||
"org.scalatest" %% "scalatest" % "2.1.6" % "it,test",
|
||||
"org.scalacheck" %% "scalacheck" % "1.11.4" % "it,test"
|
||||
// "org.scalatest" %% "scalatest" % "2.1.6" % "it,test",
|
||||
// "org.scalacheck" %% "scalacheck" % "1.11.4" % "it,test",
|
||||
"com.novocode" % "junit-interface" % "0.10" % "test",
|
||||
"junit" % "junit" % "4.11" % "test"
|
||||
)
|
||||
|
||||
val settings = Seq(
|
||||
|
|
|
@ -58,6 +58,14 @@ public final class StructReader {
|
|||
}
|
||||
}
|
||||
|
||||
public final long getLongField(int offset) {
|
||||
if ((offset + 1) * 64 <= this.dataSize) {
|
||||
return this.segment.buffer.getLong(this.data + offset * 8);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public final PointerReader getPointerField(int ptrIndex) {
|
||||
if (ptrIndex < this.pointerCount) {
|
||||
return new PointerReader(this.segment,
|
||||
|
|
27
runtime/src/test/java/org/capnproto/LayoutTest.java
Normal file
27
runtime/src/test/java/org/capnproto/LayoutTest.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package org.capnproto;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class LayoutTest {
|
||||
|
||||
@Test
|
||||
public void simpleRawDataStruct() {
|
||||
byte[] data = {0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x01, 0x23, 0x45, 0x67,
|
||||
(byte)(0x89 & 0xff), (byte)(0xab & 0xff),
|
||||
(byte)(0xcd & 0xff), (byte)(0xef & 0xff)};
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||
buffer.order(java.nio.ByteOrder.LITTLE_ENDIAN);
|
||||
PointerReader pointerReader = new PointerReader(new SegmentReader(buffer), 0, 0x7fffffff);
|
||||
StructReader reader = pointerReader.getStruct();
|
||||
|
||||
assertThat(reader.getLongField(0), equalTo(0xefcdab8967452301L));
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue