annotate test/org/tmatesoft/hg/test/TestInflaterDataAccess.java @ 575:8bf184c9d733

Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 16 Apr 2013 16:59:59 +0200
parents
children 3c4db86e8c1f
rev   line source
575
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2013 TMate Software Ltd
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.test;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import java.io.ByteArrayOutputStream;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import java.io.IOException;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.nio.ByteBuffer;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.util.zip.DeflaterOutputStream;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import java.util.zip.Inflater;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import org.junit.Test;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import org.tmatesoft.hg.internal.ByteArrayDataAccess;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import org.tmatesoft.hg.internal.DataAccess;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import org.tmatesoft.hg.internal.InflaterDataAccess;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 /**
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 *
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 * @author Artem Tikhomirov
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 * @author TMate Software Ltd.
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 */
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 public class TestInflaterDataAccess {
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 private final ErrorCollectorExt errorCollector = new ErrorCollectorExt();
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 private final byte[] testContent1 = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.".getBytes();
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 private DataAccess zip(byte[] source) throws IOException {
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 ByteArrayOutputStream bos = new ByteArrayOutputStream();
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 DeflaterOutputStream dos = new DeflaterOutputStream(bos);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 dos.write(source);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 dos.flush();
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 dos.close();
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 return new ByteArrayDataAccess(bos.toByteArray());
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 }
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 @Test
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50 public void testSeek() throws Exception {
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 DataAccess zip = zip(testContent1);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 InflaterDataAccess ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25]);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 ida.seek(20);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 final int bufferCapacity = 10;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 ByteBuffer chunk1 = ByteBuffer.allocate(bufferCapacity);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 ida.readBytes(chunk1);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 errorCollector.assertTrue(new ByteArraySlice(testContent1, 20, bufferCapacity).equalsTo(chunk1.array()));
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 ida.skip(-bufferCapacity);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 ByteBuffer chunk2 = ByteBuffer.allocate(bufferCapacity);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 ida.readBytes(chunk2);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 errorCollector.assertEquals(chunk1, chunk2);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 }
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 @Test
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 public void testLength() throws Exception {
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 DataAccess zip = zip(testContent1);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 InflaterDataAccess ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25]);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 errorCollector.assertEquals("Plain #length()", testContent1.length, ida.length());
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69 //
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25]);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 byte[] dummy = new byte[30];
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 ida.readBytes(dummy, 0, dummy.length);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 int lll = ida.length();
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74 errorCollector.assertEquals("#length() after readBytes()", testContent1.length, ida.length());
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 //
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25]);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 // consume most of the stream, so that all original compressed data is already read
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 ida.readBytes(ByteBuffer.allocate(testContent1.length - 1));
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 errorCollector.assertEquals("#length() after origin was completely read", testContent1.length, ida.length());
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 }
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 @Test
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 public void testReadBytes() throws Exception {
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 DataAccess zip = zip(testContent1);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 InflaterDataAccess ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25]);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 ida.skip(10);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87 byte[] chunk1 = new byte[22];
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 ida.readBytes(chunk1, 0, 20);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
89 chunk1[20] = ida.readByte();
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
90 chunk1[21] = ida.readByte();
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
91 ida.skip(5);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 byte[] chunk2 = new byte[12];
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 chunk2[0] = ida.readByte();
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 chunk2[1] = ida.readByte();
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 ida.readBytes(chunk2, 2, 10);
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
96 errorCollector.assertTrue(new ByteArraySlice(testContent1, 10, 22).equalsTo(chunk1));
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 errorCollector.assertTrue(new ByteArraySlice(testContent1, 10+22+5, 12).equalsTo(chunk2));
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 }
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 private static class ByteArraySlice {
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101 public final byte[] array;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 public final int offset, length;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 public ByteArraySlice(byte[] array, int offset, int length) {
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105 this.array = array;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 this.offset = offset;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 this.length = length;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108 }
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 public boolean equalsTo(byte[] another) {
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 if (another == null || another.length != length) {
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 return false;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 }
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 for (int i = 0; i < length; i++) {
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115 if (array[offset + i] != another[i]) {
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 return false;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
117 }
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
118 }
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 return true;
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
120 }
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 }
8bf184c9d733 Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122 }