add a test

This commit is contained in:
David Renshaw 2014-05-24 21:39:59 -04:00
parent afb56982a7
commit ba0c18000a
4 changed files with 43 additions and 3 deletions

View file

@ -13,4 +13,7 @@ install:
- export CC=gcc-4.8 - export CC=gcc-4.8
- export CXX=g++-4.8 - export CXX=g++-4.8
- cd capnproto-c++-0.4.1 && ./configure && make -j5 && sudo make install && cd .. - 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

View file

@ -60,8 +60,10 @@ object Build extends sbt.Build {
object Shared { object Shared {
val testDeps = Seq( val testDeps = Seq(
"org.scalatest" %% "scalatest" % "2.1.6" % "it,test", // "org.scalatest" %% "scalatest" % "2.1.6" % "it,test",
"org.scalacheck" %% "scalacheck" % "1.11.4" % "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( val settings = Seq(

View file

@ -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) { public final PointerReader getPointerField(int ptrIndex) {
if (ptrIndex < this.pointerCount) { if (ptrIndex < this.pointerCount) {
return new PointerReader(this.segment, return new PointerReader(this.segment,

View 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));
}
}