01: package test.it.unimi.dsi.mg4j.index.payload;
02:
03: import it.unimi.dsi.mg4j.index.payload.Payload;
04: import it.unimi.dsi.fastutil.io.FastByteArrayOutputStream;
05: import it.unimi.dsi.io.InputBitStream;
06: import it.unimi.dsi.io.OutputBitStream;
07:
08: import java.io.IOException;
09:
10: import junit.framework.TestCase;
11:
12: public abstract class PayloadTestCase extends TestCase {
13: /** Checks that a given payload serialises correctly.
14: *
15: * @param payload a payload containing a current value.
16: */
17: public static void testWriteAndRead(Payload payload)
18: throws IOException {
19: final FastByteArrayOutputStream fbos = new FastByteArrayOutputStream();
20: final OutputBitStream obs = new OutputBitStream(fbos);
21: Object o = payload.get();
22: payload.write(obs);
23: obs.flush();
24: final InputBitStream ibs = new InputBitStream(fbos.array);
25: payload.read(ibs);
26: assertEquals(o, payload.get());
27: }
28:
29: }
|