コード例 #1
0
 @Test
 public void testDiscardReadBytes3() {
   ByteBuf a, b;
   a = wrappedBuffer(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}).order(order);
   b =
       freeLater(
           wrappedBuffer(
               wrappedBuffer(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 0, 5).order(order),
               wrappedBuffer(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 5, 5).order(order)));
   a.skipBytes(6);
   a.markReaderIndex();
   b.skipBytes(6);
   b.markReaderIndex();
   assertEquals(a.readerIndex(), b.readerIndex());
   a.readerIndex(a.readerIndex() - 1);
   b.readerIndex(b.readerIndex() - 1);
   assertEquals(a.readerIndex(), b.readerIndex());
   a.writerIndex(a.writerIndex() - 1);
   a.markWriterIndex();
   b.writerIndex(b.writerIndex() - 1);
   b.markWriterIndex();
   assertEquals(a.writerIndex(), b.writerIndex());
   a.writerIndex(a.writerIndex() + 1);
   b.writerIndex(b.writerIndex() + 1);
   assertEquals(a.writerIndex(), b.writerIndex());
   assertTrue(ByteBufUtil.equals(a, b));
   // now discard
   a.discardReadBytes();
   b.discardReadBytes();
   assertEquals(a.readerIndex(), b.readerIndex());
   assertEquals(a.writerIndex(), b.writerIndex());
   assertTrue(ByteBufUtil.equals(a, b));
   a.resetReaderIndex();
   b.resetReaderIndex();
   assertEquals(a.readerIndex(), b.readerIndex());
   a.resetWriterIndex();
   b.resetWriterIndex();
   assertEquals(a.writerIndex(), b.writerIndex());
   assertTrue(ByteBufUtil.equals(a, b));
 }
コード例 #2
0
  @Test
  public void testWrittenBuffersEquals() {
    // XXX Same tests than testEquals with written AggregateChannelBuffers
    ByteBuf a, b;
    // Different length.
    a = wrappedBuffer(new byte[] {1}).order(order);
    b = wrappedBuffer(wrappedBuffer(new byte[] {1}, new byte[1]).order(order));
    // to enable writeBytes
    b.writerIndex(b.writerIndex() - 1);
    b.writeBytes(wrappedBuffer(new byte[] {2}).order(order));
    assertFalse(ByteBufUtil.equals(a, b));

    // Same content, same firstIndex, short length.
    a = wrappedBuffer(new byte[] {1, 2, 3}).order(order);
    b = wrappedBuffer(wrappedBuffer(new byte[] {1}, new byte[2]).order(order));
    // to enable writeBytes
    b.writerIndex(b.writerIndex() - 2);
    b.writeBytes(wrappedBuffer(new byte[] {2}).order(order));
    b.writeBytes(wrappedBuffer(new byte[] {3}).order(order));
    assertTrue(ByteBufUtil.equals(a, b));

    // Same content, different firstIndex, short length.
    a = wrappedBuffer(new byte[] {1, 2, 3}).order(order);
    b = wrappedBuffer(wrappedBuffer(new byte[] {0, 1, 2, 3, 4}, 1, 3).order(order));
    // to enable writeBytes
    b.writerIndex(b.writerIndex() - 1);
    b.writeBytes(wrappedBuffer(new byte[] {0, 1, 2, 3, 4}, 3, 1).order(order));
    assertTrue(ByteBufUtil.equals(a, b));

    // Different content, same firstIndex, short length.
    a = wrappedBuffer(new byte[] {1, 2, 3}).order(order);
    b = freeLater(wrappedBuffer(wrappedBuffer(new byte[] {1, 2}, new byte[1]).order(order)));
    // to enable writeBytes
    b.writerIndex(b.writerIndex() - 1);
    b.writeBytes(wrappedBuffer(new byte[] {4}).order(order));
    assertFalse(ByteBufUtil.equals(a, b));

    // Different content, different firstIndex, short length.
    a = wrappedBuffer(new byte[] {1, 2, 3}).order(order);
    b = wrappedBuffer(wrappedBuffer(new byte[] {0, 1, 2, 4, 5}, 1, 3).order(order));
    // to enable writeBytes
    b.writerIndex(b.writerIndex() - 1);
    b.writeBytes(wrappedBuffer(new byte[] {0, 1, 2, 4, 5}, 3, 1).order(order));
    assertFalse(ByteBufUtil.equals(a, b));

    // Same content, same firstIndex, long length.
    a = wrappedBuffer(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}).order(order);
    b = freeLater(wrappedBuffer(wrappedBuffer(new byte[] {1, 2, 3}, new byte[7])).order(order));
    // to enable writeBytes
    b.writerIndex(b.writerIndex() - 7);
    b.writeBytes(wrappedBuffer(new byte[] {4, 5, 6}).order(order));
    b.writeBytes(wrappedBuffer(new byte[] {7, 8, 9, 10}).order(order));
    assertTrue(ByteBufUtil.equals(a, b));

    // Same content, different firstIndex, long length.
    a = wrappedBuffer(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}).order(order);
    b =
        wrappedBuffer(
            wrappedBuffer(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 1, 10).order(order));
    // to enable writeBytes
    b.writerIndex(b.writerIndex() - 5);
    b.writeBytes(
        wrappedBuffer(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 6, 5).order(order));
    assertTrue(ByteBufUtil.equals(a, b));

    // Different content, same firstIndex, long length.
    a = wrappedBuffer(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}).order(order);
    b =
        freeLater(
            wrappedBuffer(wrappedBuffer(new byte[] {1, 2, 3, 4, 6}, new byte[5])).order(order));
    // to enable writeBytes
    b.writerIndex(b.writerIndex() - 5);
    b.writeBytes(wrappedBuffer(new byte[] {7, 8, 5, 9, 10}).order(order));
    assertFalse(ByteBufUtil.equals(a, b));

    // Different content, different firstIndex, long length.
    a = wrappedBuffer(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}).order(order);
    b =
        wrappedBuffer(
            wrappedBuffer(new byte[] {0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11}, 1, 10).order(order));
    // to enable writeBytes
    b.writerIndex(b.writerIndex() - 5);
    b.writeBytes(
        wrappedBuffer(new byte[] {0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11}, 6, 5).order(order));
    assertFalse(ByteBufUtil.equals(a, b));
  }
コード例 #3
0
  @Test
  public void testSeveralBuffersEquals() {
    ByteBuf a, b;
    // XXX Same tests with several buffers in wrappedCheckedBuffer
    // Different length.
    a = freeLater(wrappedBuffer(new byte[] {1}).order(order));
    b =
        freeLater(
            wrappedBuffer(
                wrappedBuffer(new byte[] {1}).order(order),
                wrappedBuffer(new byte[] {2}).order(order)));
    assertFalse(ByteBufUtil.equals(a, b));

    // Same content, same firstIndex, short length.
    a = freeLater(wrappedBuffer(new byte[] {1, 2, 3}).order(order));
    b =
        freeLater(
            wrappedBuffer(
                wrappedBuffer(new byte[] {1}).order(order),
                wrappedBuffer(new byte[] {2}).order(order),
                wrappedBuffer(new byte[] {3}).order(order)));
    assertTrue(ByteBufUtil.equals(a, b));

    // Same content, different firstIndex, short length.
    a = freeLater(wrappedBuffer(new byte[] {1, 2, 3}).order(order));
    b =
        freeLater(
            wrappedBuffer(
                wrappedBuffer(new byte[] {0, 1, 2, 3, 4}, 1, 2).order(order),
                wrappedBuffer(new byte[] {0, 1, 2, 3, 4}, 3, 1).order(order)));
    assertTrue(ByteBufUtil.equals(a, b));

    // Different content, same firstIndex, short length.
    a = freeLater(wrappedBuffer(new byte[] {1, 2, 3}).order(order));
    b =
        freeLater(
            wrappedBuffer(
                wrappedBuffer(new byte[] {1, 2}).order(order),
                wrappedBuffer(new byte[] {4}).order(order)));
    assertFalse(ByteBufUtil.equals(a, b));

    // Different content, different firstIndex, short length.
    a = freeLater(wrappedBuffer(new byte[] {1, 2, 3}).order(order));
    b =
        freeLater(
            wrappedBuffer(
                wrappedBuffer(new byte[] {0, 1, 2, 4, 5}, 1, 2).order(order),
                wrappedBuffer(new byte[] {0, 1, 2, 4, 5}, 3, 1).order(order)));
    assertFalse(ByteBufUtil.equals(a, b));

    // Same content, same firstIndex, long length.
    a = freeLater(wrappedBuffer(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}).order(order));
    b =
        freeLater(
            wrappedBuffer(
                wrappedBuffer(new byte[] {1, 2, 3}).order(order),
                wrappedBuffer(new byte[] {4, 5, 6}).order(order),
                wrappedBuffer(new byte[] {7, 8, 9, 10}).order(order)));
    assertTrue(ByteBufUtil.equals(a, b));

    // Same content, different firstIndex, long length.
    a = freeLater(wrappedBuffer(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}).order(order));
    b =
        freeLater(
            wrappedBuffer(
                wrappedBuffer(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 1, 5).order(order),
                wrappedBuffer(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 6, 5)
                    .order(order)));
    assertTrue(ByteBufUtil.equals(a, b));

    // Different content, same firstIndex, long length.
    a = freeLater(wrappedBuffer(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}).order(order));
    b =
        freeLater(
            wrappedBuffer(
                wrappedBuffer(new byte[] {1, 2, 3, 4, 6}).order(order),
                wrappedBuffer(new byte[] {7, 8, 5, 9, 10}).order(order)));
    assertFalse(ByteBufUtil.equals(a, b));

    // Different content, different firstIndex, long length.
    a = freeLater(wrappedBuffer(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}).order(order));
    b =
        freeLater(
            wrappedBuffer(
                wrappedBuffer(new byte[] {0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11}, 1, 5).order(order),
                wrappedBuffer(new byte[] {0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11}, 6, 5)
                    .order(order)));
    assertFalse(ByteBufUtil.equals(a, b));
  }