FileDocCategorySizeDatePackage
BoxComparator.javaAPI Docmp4parser 1.0-RC-172840Wed Dec 19 20:10:21 GMT 2012com.googlecode.mp4parser.authoring.tracks

BoxComparator

public class BoxComparator extends Object
Compares boxes for testing purposes.

Fields Summary
Constructors Summary
Methods Summary
private static voidchechBox(com.coremedia.iso.boxes.Box b1, com.coremedia.iso.boxes.Box b2, java.lang.String[] ignores)

        if (!isIgnore(b1, ignores)) {
            ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
            ByteArrayOutputStream baos2 = new ByteArrayOutputStream();

            b1.getBox(Channels.newChannel(baos1));
            b2.getBox(Channels.newChannel(baos2));

            baos1.close();
            baos2.close();

            Assert.assertArrayEquals("Box at " + Path.createPath(b1) + " differs from reference\n\n" + b1.toString() + "\n" + b2.toString(), baos1.toByteArray(), baos2.toByteArray());
        }
    
public static voidcheck(com.coremedia.iso.boxes.Box b1, com.coremedia.iso.boxes.Box b2, java.lang.String ignores)

        Assert.assertEquals(b1.getType(), b2.getType());
        if (!isIgnore(b1, ignores)) {
        //    System.err.println(b1.getType());
            Assert.assertEquals("Type differs. \ntypetrace ref : " + Path.createPath(b1) + "\ntypetrace new : " + Path.createPath(b2),
                    b1.getType(), b2.getType());
            if (b1 instanceof ContainerBox ^ !(b2 instanceof ContainerBox)) {
                if (b1 instanceof ContainerBox) {
                    checkContainer((ContainerBox) b1, (ContainerBox) b2, ignores);
                } else {
                    chechBox(b1, b2, ignores);
                }
            } else {
                Assert.fail("Either both boxes are container boxes or none");
            }
        }
    
private static voidcheckContainer(com.coremedia.iso.boxes.ContainerBox cb1, com.coremedia.iso.boxes.ContainerBox cb2, java.lang.String[] ignores)

        Iterator<Box> it1 = cb1.getBoxes().iterator();
        Iterator<Box> it2 = cb2.getBoxes().iterator();

        while (it1.hasNext() && it2.hasNext()) {
            Box b1 = it1.next();
            Box b2 = it2.next();

            check(b1, b2, ignores);
        }
        if (it1.hasNext()) {
            Assert.fail("There is a box missing in the current output of the tool: " + it1.next());
        }
        if (it2.hasNext()) {
            Assert.fail("There is a box too much in the current output of the tool: " + it2.next());
        }

    
public static booleanisIgnore(com.coremedia.iso.boxes.Box b, java.lang.String[] ignores)

        for (String ignore : ignores) {
            if (Path.isContained(b, ignore)) {
                return true;
            }
        }
        return false;