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.MpegAudioFormat;

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

public class MpegAudioHeaderTest extends MediaHeaderTest {

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

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

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

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

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

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

        // full path of the mp3 media sample
        String mediaMp3FullPath = embTestConfig.getMediaDir() + File.separator + embTestConfig.getMp3SoundName1();

        // creates media bean
        File mediaMp3File = new File(mediaMp3FullPath);
        MediaBean mediaBean = new MediaBean(mediaMp3File, "mp3");

        // creates jpeg format
        InputStream mediaMp3InputStream = new FileInputStream(mediaMp3File);
        MpegAudioFormat mp3Format = new MpegAudioFormat();
        MediaHeader mp3Header = mp3Format.extractHeader(mediaMp3InputStream);
        mediaMp3InputStream.close();
        return mp3Header;
    }

    /**
     * <pre>
     *
     *
     *
     *        Testcase Name: getField(String)
     *        Testcase Number: TEMB0091SBA
     *
     *        Test 1:
     *        iterate over fieldnames, check results:
     *        bitrate: 128
     *        emphasisIndex: 0
     *        layer: 3
     *        modeExtensionIndex: 0
     *        modeIndex: 0
     *        samplingFrequency: 22050
     *        version: 2.0
     *
     *
     *
     * </pre>
     */
    public void testTEMB0091SBA() throws MediaException, IOException {

//        MpegAudioHeader testInstance;
//        testInstance = (MpegAudioHeader) createMediaHeader();
//
//        //
//        // test 1
//        //
//
//        assertTrue("test1 : ", testInstance.getField("bitrate").toString().equals("128")
//                && testInstance.getField("emphasisIndex").toString().equals("0")
//                && testInstance.getField("layer").toString().equals("3")
//                && testInstance.getField("modeExtensionIndex").toString().equals("0")
//                && testInstance.getField("modeIndex").toString().equals("0")
//                && testInstance.getField("samplingFrequency").toString().equals("22050")
//                && testInstance.getField("version").toString().equals("2.0"));
//        testTrace("test 1 passed");

        succeed();
    }
}