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.video.MpegVideoFormat;

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

public class MpegVideoHeaderTest extends MediaHeaderTest {

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

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

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

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

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

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

        // full path of the mpeg video sample
        String mediaMpgFullPath = embTestConfig.getMediaDir() + File.separator + embTestConfig.getMpegMovieName1();

        // creates media bean
        File mediaMpegFile = new File(mediaMpgFullPath);
        MediaBean mediaBean = new MediaBean(mediaMpegFile, "mpg");

        // creates jpeg format
        InputStream mediaMpegInputStream = new FileInputStream(mediaMpegFile);
        MpegVideoFormat mpgFormat = new MpegVideoFormat();

        // TODO : MpegHeader does not exist any more

        MediaHeader mpgHeader = mpgFormat.extractHeader(mediaMpegInputStream);
        mediaMpegInputStream.close();
        return mpgHeader;
    }

    /**
     * <pre>
     *
     *
     *
     *        Testcase Name: getField(String)
     *        Testcase Number: TEMB0083SBA
     *
     *        Test 1:
     *        iterate over fieldnames, check for results, check system and stream headers.
     *
     *
     *
     *
     * </pre>
     */
    public void testTEMB0083SBA() throws MediaException, IOException {

//      TODO : MpegHeader does not exist any more
//        MpegVideoHeader testInstance;
//        testInstance = (MpegVideoHeader) createMediaHeader();
//
//        //
//        // test 1
//        //
//
//        // error report
//        logProductError("reported error PEMB0055RMD");
//
//        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();
    }
}