@Test(groups = "fast") public void testCombiningTimesError() throws Exception { final byte[] times1 = Hex.decodeHex("ff10000001fe0310ff1000011bfe0310".toCharArray()); final byte[] times2 = Hex.decodeHex("ff10000160".toCharArray()); final List<byte[]> timesList = new ArrayList<byte[]>(); timesList.add(times1); timesList.add(times2); final byte[] combinedTimes = timelineCoder.combineTimelines(timesList, null); final String hexCombinedTimes = new String(Hex.encodeHex(combinedTimes)); //System.out.printf("Combined times: %s\n", hexCombinedTimes); Assert.assertEquals(hexCombinedTimes, "ff10000001fe0310eafe031015"); }
@Test(groups = "fast") public void testCombiningShortFragments() throws Exception { final byte[] fragment0 = new byte[]{(byte) -1, (byte) 0, (byte) 15, (byte) 66, (byte) 84, (byte) 20}; final byte[] fragment1 = new byte[]{(byte) -1, (byte) 0, (byte) 15, (byte) 66, (byte) -122, (byte) 30}; final byte[] fragment2 = new byte[]{(byte) -1, (byte) 0, (byte) 15, (byte) 66, (byte) -62, (byte) 30}; final byte[] fragment3 = new byte[]{(byte) -1, (byte) 0, (byte) 15, (byte) 66, (byte) -2, (byte) 30}; final byte[][] fragmentArray = new byte[][]{fragment0, fragment1, fragment2, fragment3}; final byte[] combined = timelineCoder.combineTimelines(Arrays.asList(fragmentArray), null); final List<DateTime> restoredTimes = timelineCoder.decompressDateTimes(combined); final List<List<DateTime>> fragmentIntTimes = new ArrayList<List<DateTime>>(); final List<DateTime> allFragmentTimes = new ArrayList<DateTime>(); int totalLength = 0; for (final byte[] aFragmentArray : fragmentArray) { final List<DateTime> fragmentTimes = timelineCoder.decompressDateTimes(aFragmentArray); fragmentIntTimes.add(fragmentTimes); totalLength += fragmentTimes.size(); for (final DateTime time : fragmentTimes) { allFragmentTimes.add(time); } } Assert.assertEquals(restoredTimes.size(), totalLength); for (int i = 0; i < totalLength; i++) { Assert.assertEquals(restoredTimes.get(i), allFragmentTimes.get(i)); } }
timelineChunkIds.add(timelineChunk.getChunkId()); final byte[] combinedTimeBytes = timelineCoder.combineTimelines(timeParts, sampleCount); final byte[] combinedSampleBytes = sampleCoder.combineSampleBytes(sampleParts); final int timeBytesLength = combinedTimeBytes.length;
timesList.add(compressedTimes1); timesList.add(compressedTimes2); final byte[] combinedTimes = timelineCoder.combineTimelines(timesList, null); Assert.assertEquals(combinedTimes.length, 9); Assert.assertEquals(combinedTimes[0] & 0xff, TimelineOpcode.FULL_TIME.getOpcodeIndex());
fragments.add(timelineCoder.compressDateTimes(fragment)); final byte[] combined = timelineCoder.combineTimelines(fragments, null); final List<DateTime> restoredDateTimes = timelineCoder.decompressDateTimes(combined);
timesList.add(compressedTimes1); timesList.add(compressedTimes2); final byte[] combinedTimes = timelineCoder.combineTimelines(timesList, null); Assert.assertEquals(combinedTimes.length, 8); Assert.assertEquals(combinedTimes[0] & 0xff, TimelineOpcode.FULL_TIME.getOpcodeIndex());
private void checkCombinedTimelines(final String... timelines) throws Exception { final List<byte[]> timeParts = new ArrayList<byte[]>(); for (final String timeline : timelines) { timeParts.add(Hex.decodeHex(timeline.toCharArray())); } int sampleCount = 0; int byteCount = 0; for (final byte[] timePart : timeParts) { byteCount += timePart.length; sampleCount += timelineCoder.countTimeBytesSamples(timePart); } final byte[] concatedTimes = new byte[byteCount]; int offset = 0; for (final byte[] timePart : timeParts) { final int length = timePart.length; System.arraycopy(timePart, 0, concatedTimes, offset, length); offset += length; } final byte[] newCombined = timelineCoder.combineTimelines(timeParts, null); final int newCombinedLength = timelineCoder.countTimeBytesSamples(newCombined); final DefaultTimelineCursor concatedCursor = new DefaultTimelineCursor(concatedTimes, sampleCount); final DefaultTimelineCursor combinedCursor = new DefaultTimelineCursor(newCombined, sampleCount); for (int i = 0; i < sampleCount; i++) { final DateTime concatedTime = concatedCursor.getNextTime(); final DateTime combinedTime = combinedCursor.getNextTime(); Assert.assertEquals(combinedTime, concatedTime); } Assert.assertEquals(newCombinedLength, sampleCount); } }