7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift/*
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * CDDL HEADER START
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift *
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * The contents of this file are subject to the terms of the
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * Common Development and Distribution License, Version 1.0 only
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * (the "License"). You may not use this file except in compliance
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * with the License.
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift *
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac * or http://forgerock.org/license/CDDLv1.0.html.
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * See the License for the specific language governing permissions
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * and limitations under the License.
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift *
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * When distributing Covered Code, include this CDDL HEADER in each
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac * file and include the License file at legal-notices/CDDLv1_0.txt.
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac * If applicable, add the following below this CDDL HEADER, with the
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac * fields enclosed by brackets "[]" replaced with your own identifying
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac * information:
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * Portions Copyright [yyyy] [name of copyright owner]
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift *
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * CDDL HEADER END
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift *
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift *
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * Copyright 2009 Sun Microsystems, Inc.
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthew * Portions copyright 2012 ForgeRock AS.
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift */
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swiftpackage org.opends.server.types;
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swiftimport org.testng.annotations.Test;
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swiftimport org.testng.annotations.DataProvider;
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swiftimport org.testng.Assert;
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swiftimport java.util.Arrays;
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swiftimport java.io.ByteArrayOutputStream;
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthewimport java.io.IOException;
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swiftimport java.io.UnsupportedEncodingException;
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthewimport java.nio.ByteBuffer;
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthewimport java.nio.channels.WritableByteChannel;
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift/**
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * Abstract test case for the ByteSequence interface.
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift */
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swiftpublic abstract class ByteSequenceTest extends TypesTestCase
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift{
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift /**
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * ByteSequence data provider that gets the ByteSequence implementation
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * from the abstract method.
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift *
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift * @return The array of ByteStrings and the bytes it should contain.
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift */
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift @DataProvider(name = "byteSequenceProvider")
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public Object[][] concreteByteSequenceProvider() throws Exception
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift return byteSequenceProvider();
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift protected abstract Object[][] byteSequenceProvider() throws Exception;
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift @Test(dataProvider = "byteSequenceProvider")
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public void testByteAt(ByteSequence bs, byte[] ba)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift for(int i = 0; i < ba.length; i++)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift Assert.assertEquals(bs.byteAt(i),ba[i]);
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift @Test(dataProvider = "byteSequenceProvider",
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift expectedExceptions = IndexOutOfBoundsException.class)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public void testByteAtBadIndex1(ByteSequence bs, byte[] ba)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift bs.byteAt(ba.length);
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift @Test(dataProvider = "byteSequenceProvider",
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift expectedExceptions = IndexOutOfBoundsException.class)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public void testByteAtBadIndex2(ByteSequence bs, byte[] ba)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift bs.byteAt(-1);
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift @Test(dataProvider = "byteSequenceProvider")
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public void testCopyTo(ByteSequence bs, byte[] ba)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift byte[] newBa = new byte[ba.length];
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift bs.copyTo(newBa);
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift Assert.assertTrue(Arrays.equals(newBa, ba));
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift @Test(dataProvider = "byteSequenceProvider")
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public void testCopyToWithOffset(ByteSequence bs, byte[] ba)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift for(int i = 0; i < ba.length * 2; i++)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift byte[] newBa = new byte[ba.length * 2];
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift bs.copyTo(newBa, i);
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift byte[] resultBa = new byte[ba.length * 2];
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift System.arraycopy(ba, 0, resultBa, i,
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift Math.min(ba.length, ba.length * 2 - i));
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift Assert.assertTrue(Arrays.equals(newBa, resultBa));
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift @Test(dataProvider = "byteSequenceProvider",
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift expectedExceptions = IndexOutOfBoundsException.class)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public void testCopyToWithBadOffset(ByteSequence bs, byte[] ba)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift bs.copyTo(new byte[0], -1);
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift @Test(dataProvider = "byteSequenceProvider")
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public void testCopyToByteSequenceBuilder(ByteSequence bs, byte[] ba)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift ByteStringBuilder builder = new ByteStringBuilder();
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift bs.copyTo(builder);
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift Assert.assertTrue(Arrays.equals(builder.toByteArray(), ba));
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift @Test(dataProvider = "byteSequenceProvider")
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public void testCopyToOutputStream(ByteSequence bs, byte[] ba) throws Exception
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift ByteArrayOutputStream stream = new ByteArrayOutputStream();
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift bs.copyTo(stream);
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift Assert.assertTrue(Arrays.equals(stream.toByteArray(), ba));
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthew @Test(dataProvider = "byteSequenceProvider")
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthew public void testCopyToWritableByteChannel(ByteSequence bs, byte[] ba) throws Exception
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthew {
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthew final ByteStringBuilder dst = new ByteStringBuilder();
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthew WritableByteChannel channel = new WritableByteChannel()
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthew {
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthew public boolean isOpen() { return true; }
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthew public void close() throws IOException { }
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthew public int write(ByteBuffer src) throws IOException
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthew {
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthew dst.append(src, src.remaining());
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthew return dst.length();
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthew }
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthew };
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthew bs.copyTo(channel);
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthew Assert.assertEquals(bs, dst);
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthew }
38f8d2aab0fa25da1d5f7cc6f44b5270d270c0afmatthew
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift @Test(dataProvider = "byteSequenceProvider")
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public void testEquals(ByteSequence bs, byte[] ba) throws Exception
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift Assert.assertTrue(bs.equals(ByteString.wrap(ba)));
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift @Test(dataProvider = "byteSequenceProvider")
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public void testLength(ByteSequence bs, byte[] ba) throws Exception
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift Assert.assertEquals(bs.length(), ba.length);
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift @Test(dataProvider = "byteSequenceProvider")
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public void testSubSequence(ByteSequence bs, byte[] ba)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift ByteSequence bsSub = bs.subSequence(0, bs.length()/2);
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift byte[] baSub = new byte[ba.length/2];
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift System.arraycopy(ba, 0, baSub, 0, baSub.length);
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift Assert.assertTrue(Arrays.equals(bsSub.toByteArray(), baSub));
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift bsSub = bs.subSequence(ba.length/4, (bs.length()/4)*3);
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift baSub = new byte[(bs.length()/4)*3 - ba.length/4];
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift System.arraycopy(ba, ba.length/4, baSub, 0, baSub.length);
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift Assert.assertTrue(Arrays.equals(bsSub.toByteArray(), baSub));
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift bsSub = bs.subSequence(ba.length/2, bs.length());
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift baSub = new byte[bs.length() - ba.length/2];
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift System.arraycopy(ba, ba.length/2, baSub, 0, baSub.length);
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift Assert.assertTrue(Arrays.equals(bsSub.toByteArray(), baSub));
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift bsSub = bs.subSequence(0, bs.length());
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift Assert.assertTrue(Arrays.equals(bsSub.toByteArray(), ba));
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift @Test(dataProvider = "byteSequenceProvider",
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift expectedExceptions = IndexOutOfBoundsException.class)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public void testSubSequenceBadStartEnd1(ByteSequence bs, byte[] ba)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift bs.subSequence(-1, bs.length());
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift @Test(dataProvider = "byteSequenceProvider",
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift expectedExceptions = IndexOutOfBoundsException.class)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public void testSubSequenceBadStartEnd2(ByteSequence bs, byte[] ba)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift bs.subSequence(0, bs.length()+1);
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift @Test(dataProvider = "byteSequenceProvider",
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift expectedExceptions = IndexOutOfBoundsException.class)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public void testSubSequenceBadStartEnd3(ByteSequence bs, byte[] ba)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift bs.subSequence(-1, bs.length()+1);
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift @Test(dataProvider = "byteSequenceProvider")
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public void testToByteArray(ByteSequence bs, byte[] ba)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift Assert.assertTrue(Arrays.equals(bs.toByteArray(), ba));
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift @Test(dataProvider = "byteSequenceProvider")
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public void testToByteSequence(ByteSequence bs, byte[] ba)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift Assert.assertTrue(Arrays.equals(bs.toByteString().toByteArray(), ba));
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift @Test(dataProvider = "byteSequenceProvider")
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift public void testToString(ByteSequence bs, byte[] ba)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift String str;
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift try
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift str = new String(ba, "UTF-8");
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift catch(UnsupportedEncodingException uee)
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift {
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift str = new String(ba);
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift Assert.assertTrue(bs.toString().equals(str));
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift }
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift
7185b49f58c4cdb16d035ecc45e38ec9b1cd9bd0matthew_swift}