// Path: op1/src/main/java/com/op1/iff/Chunk.java
// public interface Chunk {
// 
//     /**
//      * Returns the ID of this chunk.
//      */
//     ID getChunkID();
// 
//     /**
//      * Returns the size in bytes of the data portion of the chunk. The count does not include the 8 bytes used by the
//      * chunk ID and chunk size. Also, please note, when the data portion of a chunk contains an odd number of bytes,
//      * chunk readers should expect to read an extra pad byte (0) which is also not included in the chunk size count.
//      */
//     SignedLong getChunkSize();
// 
//     /**
//      * Returns the actual number of bytes used to represent this Chunk. This should be equal to the value returned by
//      * getChunkSize() + 8 [+1 if getChunkSize() is odd].
//      */
//     int getPhysicalSize();
// }
// 
// Path: op1/src/main/java/com/op1/iff/types/SignedLong.java
// public class SignedLong extends DataType {
// 
// 
//     public SignedLong(byte[] bytes) {
//         super(bytes, 4);
//     }
// 
//     public int toInt() {
//         return ByteBuffer.wrap(bytes).getInt();
//     }
// 
//     public static SignedLong fromInt(int i) {
//         return new SignedLong(ByteBuffer.allocate(4).putInt(i).array());
//     }
// 
//     @Override
//     public String toString() {
//         return String.valueOf(toInt());
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
// 
//         final SignedLong that = (SignedLong) o;
// 
//         return Arrays.equals(bytes, that.bytes);
// 
//     }
// 
//     @Override
//     public int hashCode() {
//         return Arrays.hashCode(bytes);
//     }
// }


import com.op1.iff.Chunk;
import com.op1.iff.types.SignedLong;
import org.junit.Test;
import java.io.File;
import java.util.List;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
package com.op1.aiff;




public class AiffReaderTest {

    @Test
    public void canReadDrumKitFile() throws Exception {
        doReadFileTest(ExampleFile.DRUM_UTILITY.getFile());
    }

    @Test
    public void canReadAlbumFile() throws Exception {
        doReadFileTest(ExampleFile.ALBUM.getFile());
    }

    private void doReadFileTest(File file) throws Exception {

        // given
        final AiffReader aiffReader = AiffReader.newAiffReader(file);

        // when
        final Aiff aiff = aiffReader.readAiff();

        // then
        assertThat(aiff, notNullValue());
    }

    @Test
    public void canReadDrumPreset1() throws Exception {
        doCanReadDrumPreset(ExampleFile.DRUM_PRESET_1.getFile());
    }

    private void doCanReadDrumPreset(File drumPreset) throws Exception {

        // given
        final AiffReader aiffReader = AiffReader.newAiffReader(drumPreset);

        // when
        final Aiff aiff = aiffReader.readAiff();

        // then
        assertThat(aiff, notNullValue());
        assertHasApplicationChunk(aiff);
    }

    private void assertHasApplicationChunk(Aiff aiff) throws Exception {
        assertThat(aiff, notNullValue());
        final List<Chunk> applicationChunks = aiff.getChunks(ChunkType.APPLICATION.getChunkId());
        assertThat(applicationChunks.size(), equalTo(1));
        final ApplicationChunk applicationChunk = (ApplicationChunk) applicationChunks.get(0);
// Path: op1/src/main/java/com/op1/iff/Chunk.java
// public interface Chunk {
// 
//     /**
//      * Returns the ID of this chunk.
//      */
//     ID getChunkID();
// 
//     /**
//      * Returns the size in bytes of the data portion of the chunk. The count does not include the 8 bytes used by the
//      * chunk ID and chunk size. Also, please note, when the data portion of a chunk contains an odd number of bytes,
//      * chunk readers should expect to read an extra pad byte (0) which is also not included in the chunk size count.
//      */
//     SignedLong getChunkSize();
// 
//     /**
//      * Returns the actual number of bytes used to represent this Chunk. This should be equal to the value returned by
//      * getChunkSize() + 8 [+1 if getChunkSize() is odd].
//      */
//     int getPhysicalSize();
// }
// 
// Path: op1/src/main/java/com/op1/iff/types/SignedLong.java
// public class SignedLong extends DataType {
// 
// 
//     public SignedLong(byte[] bytes) {
//         super(bytes, 4);
//     }
// 
//     public int toInt() {
//         return ByteBuffer.wrap(bytes).getInt();
//     }
// 
//     public static SignedLong fromInt(int i) {
//         return new SignedLong(ByteBuffer.allocate(4).putInt(i).array());
//     }
// 
//     @Override
//     public String toString() {
//         return String.valueOf(toInt());
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
// 
//         final SignedLong that = (SignedLong) o;
// 
//         return Arrays.equals(bytes, that.bytes);
// 
//     }
// 
//     @Override
//     public int hashCode() {
//         return Arrays.hashCode(bytes);
//     }
// }


// Path: op1/src/test/java/com/op1/aiff/AiffReaderTest.java
import com.op1.iff.Chunk;
import com.op1.iff.types.SignedLong;
import org.junit.Test;
import java.io.File;
import java.util.List;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

package com.op1.aiff;




public class AiffReaderTest {

    @Test
    public void canReadDrumKitFile() throws Exception {
        doReadFileTest(ExampleFile.DRUM_UTILITY.getFile());
    }

    @Test
    public void canReadAlbumFile() throws Exception {
        doReadFileTest(ExampleFile.ALBUM.getFile());
    }

    private void doReadFileTest(File file) throws Exception {

        // given
        final AiffReader aiffReader = AiffReader.newAiffReader(file);

        // when
        final Aiff aiff = aiffReader.readAiff();

        // then
        assertThat(aiff, notNullValue());
    }

    @Test
    public void canReadDrumPreset1() throws Exception {
        doCanReadDrumPreset(ExampleFile.DRUM_PRESET_1.getFile());
    }

    private void doCanReadDrumPreset(File drumPreset) throws Exception {

        // given
        final AiffReader aiffReader = AiffReader.newAiffReader(drumPreset);

        // when
        final Aiff aiff = aiffReader.readAiff();

        // then
        assertThat(aiff, notNullValue());
        assertHasApplicationChunk(aiff);
    }

    private void assertHasApplicationChunk(Aiff aiff) throws Exception {
        assertThat(aiff, notNullValue());
        final List<Chunk> applicationChunks = aiff.getChunks(ChunkType.APPLICATION.getChunkId());
        assertThat(applicationChunks.size(), equalTo(1));
        final ApplicationChunk applicationChunk = (ApplicationChunk) applicationChunks.get(0);
        assertThat(applicationChunk.getChunkSize(), equalTo(SignedLong.fromInt(1248)));