package com.ibm.emb.test.mfb;

// java stuff
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.emb.MediaBean;
import javax.emb.MediaException;
import javax.emb.MediaFormatRegistry;
import javax.emb.MediaHeader;

import org.objectweb.jonas.emb.mfb.formats.audio.WavAudioFormat;

import com.ibm.emb.junit.EMBTestRunner;
import com.ibm.emb.test.MediaHeaderTest;

public class WavHeaderTest extends MediaHeaderTest {

    /**
     * constructor
     */
    public WavHeaderTest(String name) throws MediaException {
        super(name);
    }

    /**
     * main method
     */
    public static void main(String args[]) {
        EMBTestRunner.run(WavHeaderTest.class);
    }

    /**
     * do initialisation here
     */
    protected void setUp() {
    }

    /**
     * freeup resources
     */
    protected void tearDown() {
    }

    /**
     * creates an instance of WavHeader with the given Parameters used in super
     * class of WavHeaderTest
     */
    public MediaHeader createMediaHeader() throws MediaException, IOException {

        // register media format
        MediaFormatRegistry formatRegistry = MediaFormatRegistry.SINGLETON;
        formatRegistry.rebind("wav", new WavAudioFormat());

        // full path of the wav audio sample
        String mediaWavFullPath = embTestConfig.getMediaDir() + File.separator + embTestConfig.getWavSoundName1();

        // creates media bean
        File mediaWavFile = new File(mediaWavFullPath);
        MediaBean mediaBean = new MediaBean(mediaWavFile, "wav");

        // creates Wav format
        InputStream mediaWavInputStream = new FileInputStream(mediaWavFile);
        WavAudioFormat wavFormat = new WavAudioFormat();
        MediaHeader wavHeader = wavFormat.extractHeader(mediaWavInputStream);
        mediaWavInputStream.close();
        return wavHeader;
    }

    /**
     * <pre>
     *
     *      Testcase Name: getField(String)
     *      Testcase Number: TEMB0078SBA
     *
     *      Test 1:
     *      iterate over fieldnames, check for these results:
     *      bandwidth: 44100
     *      blockAlignment: 2
     *      formatChunkSize: 16
     *      formatTag: 1
     *      numberOfChannels: 1
     *      sampleRate: 22050
     *      sampleSize: 16
     *      waveChunkSize: 22136
     *
     *
     * </pre>
     */
    public void testTEMB0078SBA() throws MediaException, IOException {

        //TODO : wavHeader does not exist any more
//        WavHeader testInstance;
//        testInstance = (WavHeader) createMediaHeader();
//
//        //
//        // test 1
//        //
//
//        assertTrue("test1 : ", testInstance.getField("bandwidth").toString().equals("44100")
//                && testInstance.getField("blockAlignment").toString().equals("2")
//                && testInstance.getField("formatChunkSize").toString().equals("16")
//                && testInstance.getField("formatTag").toString().equals("1")
//                && testInstance.getField("numberOfChannels").toString().equals("1")
//                && testInstance.getField("sampleRate").toString().equals("22050")
//                && testInstance.getField("sampleSize").toString().equals("16")
//                && testInstance.getField("waveChunkSize").toString().equals("22136"));

        testTrace("test 1 passed");

        succeed();
    }

}