KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > media > format > audio > oggvorbis > TestOggVorbisHeader


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.test.media.format.audio.oggvorbis;
9
10 import java.io.File JavaDoc;
11 import java.util.Hashtable JavaDoc;
12 import java.util.Vector JavaDoc;
13
14 import javax.emb.Media;
15 import javax.emb.MediaBean;
16 import javax.emb.MediaFormatRegistry;
17
18 import junit.framework.TestCase;
19
20 import org.jboss.logging.Logger;
21 import org.jboss.media.format.audio.oggvorbis.OggVorbisFormat;
22 import org.jboss.media.format.audio.oggvorbis.OggVorbisHeader;
23 import org.jboss.media.util.ResourceUtils;
24
25 /**
26  * Test case for parsing Ogg Vorbis headers.
27  *
28  * @version <tt>$Revision: 1.1 $</tt>
29  * @author <a HREF="mailto:ricardoarguello@users.sourceforge.net">Ricardo ArgŁello</a>
30  */

31 public class TestOggVorbisHeader extends TestCase
32 {
33    private static final Logger log =
34       Logger.getLogger(TestOggVorbisHeader.class);
35
36    private static String JavaDoc RESOURCE_DIRECTORY = "media/format/data/";
37    private static final String JavaDoc OGG_VORBIS_FILE = "jboss48k16khz.ogg";
38    private static final String JavaDoc OGG_VORBIS_MIME_TYPE = "application/ogg";
39
40    /**
41     * Constructor for TestMpegAudioHeader.
42     */

43    public TestOggVorbisHeader(String JavaDoc name)
44    {
45       super(name);
46    }
47
48    public void setUp() throws Exception JavaDoc
49    {
50       MediaFormatRegistry mediaFormatRegistry = MediaFormatRegistry.SINGLETON;
51       mediaFormatRegistry.bind("ogg", new OggVorbisFormat());
52    }
53
54    public void tearDown() throws Exception JavaDoc
55    {
56       MediaFormatRegistry mediaFormatRegistry = MediaFormatRegistry.SINGLETON;
57       mediaFormatRegistry.unbind("ogg");
58    }
59
60    public void testGetHeaders() throws Exception JavaDoc
61    {
62       File JavaDoc file =
63          ResourceUtils.getResourceFile(RESOURCE_DIRECTORY + OGG_VORBIS_FILE);
64       Media media = new MediaBean(file, OGG_VORBIS_MIME_TYPE);
65       OggVorbisHeader header = (OggVorbisHeader) media.getHeader();
66
67       String JavaDoc[] fieldNames = header.getFieldNames();
68
69       if (log.isDebugEnabled())
70       {
71          for (int i = 0; i < fieldNames.length; i++)
72          {
73             log.debug(fieldNames[i] + ": " + header.getField(fieldNames[i]));
74          }
75       }
76
77       // Test headers:
78
assertEquals(new Integer JavaDoc(1), header.getField("channels"));
79       assertEquals(new Long JavaDoc(16000), header.getField("rate"));
80       assertEquals(new Long JavaDoc(48000), header.getField("bitRate"));
81
82       // Test comments:
83
Hashtable JavaDoc comments = (Hashtable JavaDoc) header.getField("comments");
84       Vector JavaDoc tracknumber = (Vector JavaDoc) comments.get("tracknumber");
85       assertEquals("1", tracknumber.get(0));
86       Vector JavaDoc date = (Vector JavaDoc) comments.get("date");
87       assertEquals("November 22 2003", date.get(0));
88       Vector JavaDoc title = (Vector JavaDoc) comments.get("title");
89       assertEquals("JBoss Media Ogg Vorbis testing file.", title.get(0));
90    }
91 }
Popular Tags