VCDiffCodeTableReader { public void init(ByteBuffer instructions_and_sizes) { instructionsAndSizes = instructions_and_sizes; lastInstructionStart = -1; pendingSecondInstruction = NO_OPCODE; lastPendingSecondInstruction = NO_OPCODE; } VCDiffCodeTableReader();  VCDiffCodeTableReader(VCDiffCodeTableData codeTableData, short maxMode); void init(ByteBuffer instructions_and_sizes); byte getNextInstruction(AtomicInteger size, AtomicInteger mode); void unGetInstruction();  }
@Test public void ExerciseCodeTableReaderTest() throws IOException { for (int opcode = 0; opcode < VCDiffCodeTableData.kCodeTableSize; ++opcode) { instructions_and_sizes_ptr_.put((byte) opcode); if ((g_exercise_code_table_.inst1[opcode] != VCDiffCodeTableData.VCD_NOOP) && (g_exercise_code_table_.size1[opcode] == 0)) { int startPos = instructions_and_sizes_ptr_.position(); VarInt.putInt(instructions_and_sizes_ptr_, 1000 + opcode); Assert.assertTrue(startPos < instructions_and_sizes_ptr_.position()); } if ((g_exercise_code_table_.inst2[opcode] != VCDiffCodeTableData.VCD_NOOP) && (g_exercise_code_table_.size2[opcode] == 0)) { int startPos = instructions_and_sizes_ptr_.position(); VarInt.putInt(instructions_and_sizes_ptr_, 1000 + opcode); Assert.assertTrue(startPos < instructions_and_sizes_ptr_.position()); } } instructions_and_sizes_ptr_.flip(); reader_ = new VCDiffCodeTableReader(g_exercise_code_table_, kLastExerciseMode); reader_.init(instructions_and_sizes_ptr_); int opcode = 0; for (byte inst_mode1 = 0; inst_mode1 <= VCDiffCodeTableData.VCD_LAST_INSTRUCTION_TYPE + kLastExerciseMode; ++inst_mode1) { byte inst1 = inst_mode1; byte mode1 = 0; if (inst_mode1 > VCDiffCodeTableData.VCD_COPY) { inst1 = VCDiffCodeTableData.VCD_COPY; mode1 = (byte) (inst_mode1 - VCDiffCodeTableData.VCD_COPY); } for (byte inst_mode2 = 0; inst_mode2 <= VCDiffCodeTableData.VCD_LAST_INSTRUCTION_TYPE + kLastExerciseMode; ++inst_mode2) { byte inst2 = inst_mode2; byte mode2 = 0; if (inst_mode2 > VCDiffCodeTableData.VCD_COPY) { inst2 = VCDiffCodeTableData.VCD_COPY; mode2 = (byte) (inst_mode2 - VCDiffCodeTableData.VCD_COPY); } VerifyInstModeSize1(inst1, mode1, (byte) 0, (byte) opcode); VerifyInstModeSize2(inst2, mode2, (byte) 0, (byte) opcode); ++opcode; VerifyInstModeSize1(inst1, mode1, (byte) 0, (byte) opcode); VerifyInstModeSize2(inst2, mode2, (byte) 255, (byte) opcode); ++opcode; VerifyInstModeSize1(inst1, mode1, (byte) 255, (byte) opcode); VerifyInstModeSize2(inst2, mode2, (byte) 0, (byte) opcode); ++opcode; VerifyInstModeSize1(inst1, mode1, (byte) 255, (byte) opcode); VerifyInstModeSize2(inst2, mode2, (byte) 255, (byte) opcode); ++opcode; } } assertEquals(VCDiffCodeTableData.kCodeTableSize, opcode); }