FileDocCategorySizeDatePackage
AbstractSampleEncryptionBoxTest.javaAPI Docmp4parser 1.0-RC-177655Wed Dec 19 20:10:22 GMT 2012com.googlecode.mp4parser.boxes

AbstractSampleEncryptionBoxTest

public abstract class AbstractSampleEncryptionBoxTest extends Object
Created by IntelliJ IDEA. User: sannies Date: 11/19/11 Time: 4:06 PM To change this template use File | Settings | File Templates.

Fields Summary
protected AbstractSampleEncryptionBox
senc
Constructors Summary
Methods Summary
public voidsetUp()


    
public voidtestRoundTripFlagsOne()

        senc.setOverrideTrackEncryptionBoxParameters(true);
        senc.setAlgorithmId(0x333333);
        senc.setIvSize(8);
        senc.setKid(UUIDConverter.convert(UUID.randomUUID()));

        List<AbstractSampleEncryptionBox.Entry> entries = new LinkedList<AbstractSampleEncryptionBox.Entry>();
        AbstractSampleEncryptionBox.Entry entry = senc.createEntry();
        entry.iv = new byte[]{1, 2, 3, 4, 5, 6, 7, 8};
        entries.add(entry);

        senc.setEntries(entries);
        long sizeBeforeWrite = senc.getSize();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        senc.getBox(Channels.newChannel(baos));
        Assert.assertEquals(baos.size(), senc.getSize());
        Assert.assertEquals(sizeBeforeWrite, senc.getSize());
        IsoFile iso = new IsoFile(new ByteBufferByteChannel(ByteBuffer.wrap(baos.toByteArray())));

        Assert.assertTrue(iso.getBoxes().get(0) instanceof AbstractSampleEncryptionBox);
        AbstractSampleEncryptionBox senc2 = (AbstractSampleEncryptionBox) iso.getBoxes().get(0);
        Assert.assertEquals(1, senc2.getFlags());
        Assert.assertTrue(senc.equals(senc2));
        Assert.assertTrue(senc2.equals(senc));
    
public voidtestRoundTripFlagsThree()

        senc.setSubSampleEncryption(true);
        senc.setOverrideTrackEncryptionBoxParameters(true);
        senc.setAlgorithmId(0x333333);
        senc.setIvSize(8);
        senc.setKid(UUIDConverter.convert(UUID.randomUUID()));
        List<AbstractSampleEncryptionBox.Entry> entries = new LinkedList<AbstractSampleEncryptionBox.Entry>();
        AbstractSampleEncryptionBox.Entry entry = senc.createEntry();
        entry.iv = new byte[]{1, 2, 3, 4, 5, 6, 7, 8};
        entry.pairs = new LinkedList<AbstractSampleEncryptionBox.Entry.Pair>();
        entry.pairs.add(entry.createPair(5, 15));
        entry.pairs.add(entry.createPair(5, 16));
        entry.pairs.add(entry.createPair(5, 17));
        entry.pairs.add(entry.createPair(5, 18));
        entry.pairs.add(entry.createPair(5, 19));
        entries.add(entry);
        entries.add(entry);
        entries.add(entry);
        entries.add(entry);

        senc.setEntries(entries);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        senc.getBox(Channels.newChannel(baos));

        Assert.assertEquals(baos.size(), senc.getSize());

        IsoFile iso = new IsoFile(new ByteBufferByteChannel(ByteBuffer.wrap(baos.toByteArray())));

        Assert.assertTrue(iso.getBoxes().get(0) instanceof AbstractSampleEncryptionBox);
        AbstractSampleEncryptionBox senc2 = (AbstractSampleEncryptionBox) iso.getBoxes().get(0);
        Assert.assertEquals(3, senc2.getFlags());
        Assert.assertTrue(senc.equals(senc2));
        Assert.assertTrue(senc2.equals(senc));
    
public voidtestRoundTripFlagsTwo()

        senc.setSubSampleEncryption(true);
        List<AbstractSampleEncryptionBox.Entry> entries = new LinkedList<AbstractSampleEncryptionBox.Entry>();
        AbstractSampleEncryptionBox.Entry entry = senc.createEntry();
        entry.iv = new byte[]{1, 2, 3, 4, 5, 6, 7, 8};
        entry.pairs = new LinkedList<AbstractSampleEncryptionBox.Entry.Pair>();
        entry.pairs.add(entry.createPair(5, 15));
        entry.pairs.add(entry.createPair(5, 16));
        entry.pairs.add(entry.createPair(5, 17));
        entry.pairs.add(entry.createPair(5, 18));
        entry.pairs.add(entry.createPair(5, 19));
        entries.add(entry);


        senc.setEntries(entries);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        senc.getBox(Channels.newChannel(baos));
        Assert.assertEquals(baos.size(), senc.getSize());
        IsoFile iso = new IsoFile(new ByteBufferByteChannel(ByteBuffer.wrap(baos.toByteArray())));

        Assert.assertTrue(iso.getBoxes().get(0) instanceof AbstractSampleEncryptionBox);
        AbstractSampleEncryptionBox senc2 = (AbstractSampleEncryptionBox) iso.getBoxes().get(0);
        Assert.assertEquals(2, senc2.getFlags());
        Assert.assertTrue(senc.equals(senc2));
        Assert.assertTrue(senc2.equals(senc));

    
public voidtestRoundTripFlagsZero()

        List<AbstractSampleEncryptionBox.Entry> entries = new LinkedList<AbstractSampleEncryptionBox.Entry>();

        AbstractSampleEncryptionBox.Entry entry = senc.createEntry();
        entry.iv = new byte[]{1, 2, 3, 4, 5, 6, 7, 8};
        entries.add(entry);

        senc.setEntries(entries);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        long sizeBeforeWrite = senc.getSize();
        senc.getBox(Channels.newChannel(baos));
        Assert.assertEquals(baos.size(), senc.getSize());
        Assert.assertEquals(baos.size(), sizeBeforeWrite);
        IsoFile iso = new IsoFile(new ByteBufferByteChannel(ByteBuffer.wrap(baos.toByteArray())));


        Assert.assertTrue(iso.getBoxes().get(0) instanceof AbstractSampleEncryptionBox);
        AbstractSampleEncryptionBox senc2 = (AbstractSampleEncryptionBox) iso.getBoxes().get(0);
        Assert.assertEquals(0, senc2.getFlags());
        Assert.assertTrue(senc.equals(senc2));
        Assert.assertTrue(senc2.equals(senc));

    
public voidtestRoundTripSmallIV()

        List<AbstractSampleEncryptionBox.Entry> entries = new LinkedList<AbstractSampleEncryptionBox.Entry>();
        senc.setOverrideTrackEncryptionBoxParameters(true);
        senc.setAlgorithmId(1);
        senc.setIvSize(8);
        senc.setKid(UUIDConverter.convert(UUID.randomUUID()));
        AbstractSampleEncryptionBox.Entry entry = senc.createEntry();
        entry.iv = new byte[]{1, 2, 3, 5, 6, 7, 8};
        entries.add(entry);
        entry = senc.createEntry();
        entry.iv = new byte[]{1, 2, 3, 5, 6, 7, 9};
        entries.add(entry);
        entry = senc.createEntry();
        entry.iv = new byte[]{1, 2, 3, 5, 6, 7, 10};
        entries.add(entry);

        senc.setEntries(entries);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        long sizeBeforeWrite = senc.getSize();
        senc.getBox(Channels.newChannel(baos));
        Assert.assertEquals(baos.size(), senc.getSize());
        Assert.assertEquals(baos.size(), sizeBeforeWrite);
        IsoFile iso = new IsoFile(new ByteBufferByteChannel(ByteBuffer.wrap(baos.toByteArray())));


        Assert.assertTrue(iso.getBoxes().get(0) instanceof AbstractSampleEncryptionBox);
        AbstractSampleEncryptionBox senc2 = (AbstractSampleEncryptionBox) iso.getBoxes().get(0);
        Assert.assertEquals(senc.getFlags(), senc2.getFlags());
        Assert.assertTrue(senc.equals(senc2));
        Assert.assertTrue(senc2.equals(senc));