001: package com.ibm.emb.test.mfb;
002:
003: // java stuff
004: import java.io.File;
005: import java.io.FileInputStream;
006: import java.io.IOException;
007: import java.io.InputStream;
008:
009: import javax.emb.Media;
010: import javax.emb.MediaBean;
011: import javax.emb.MediaException;
012: import javax.emb.MediaFormat;
013: import javax.emb.MediaFormatRegistry;
014: import javax.emb.MediaHeader;
015:
016: import org.objectweb.jonas.emb.mfb.formats.audio.MpegAudioFormat;
017:
018: import com.ibm.emb.junit.EMBTestRunner;
019:
020: public class MpegAudioFormatTest extends EmbeddedMediaFormatTest {
021:
022: /**
023: * constructor
024: */
025: public MpegAudioFormatTest(String name) throws MediaException {
026: super (name);
027: }
028:
029: /**
030: * main method
031: */
032: public static void main(String args[]) {
033: EMBTestRunner.run(MpegAudioFormatTest.class);
034: }
035:
036: /**
037: * creates an instance of BmpFormat with the given Parameters used in super
038: * class of BmpFormatTest
039: */
040: public MediaFormat createMediaFormat() {
041: return new MpegAudioFormat();
042: }
043:
044: /**
045: * do initialisation here
046: */
047: protected void setUp() {
048: }
049:
050: /**
051: * freeup resources
052: */
053: protected void tearDown() {
054: }
055:
056: /**
057: * <pre>
058: *
059: *
060: *
061: * Testcase Name: extractHeader(Media)
062: * Testcase Number: TEMB0079SBA
063: *
064: * Test 1:
065: * call extractHeader passing a mp3 audio file
066: * --> check result to be an instance of com.ibm.emb.meb.MpegAudioHeader
067: *
068: *
069: *
070: * </pre>
071: */
072: public void testTEMB0079SBA() throws MediaException, IOException {
073:
074: //
075: // test 1
076: //
077:
078: // register media format
079: MediaFormatRegistry formatRegistry = MediaFormatRegistry.SINGLETON;
080: formatRegistry.rebind("mp3", new MpegAudioFormat());
081:
082: // full path of the mp3 audio sample
083: String mediaMp3FullPath = embTestConfig.getMediaDir()
084: + File.separator + embTestConfig.getMp3SoundName1();
085:
086: // creates media bean'
087: File mediaMp3File = new File(mediaMp3FullPath);
088: MediaBean mediaBean = new MediaBean(mediaMp3File, "mp3");
089:
090: // creates mpeg audio format
091: MpegAudioFormat mpegAudioFormat = new MpegAudioFormat();
092:
093: // creates mpegAudioHeader
094: InputStream mediaMp3InputStream = new FileInputStream(
095: mediaMp3File);
096: MediaHeader mpegAudioHeader = mpegAudioFormat
097: .extractHeader(mediaMp3InputStream);
098: mediaMp3InputStream.close();
099:
100: // test
101: //assertTrue("test 1", mpegAudioHeader instanceof MpegAudioHeader);
102:
103: testTrace("test 1 passed");
104:
105: succeed();
106: }
107:
108: /**
109: * <pre>
110: *
111: *
112: *
113: * Testcase Name: extractSurrogate(Media)
114: * Testcase Number: TEMB0080SBA
115: *
116: * Test 1:
117: * call extractSurrogate passing a mp3 media
118: * check result to be an instance of Media
119: * access the content of the resulting media ----> to verify it is accessible
120: *
121: *
122: *
123: * </pre>
124: */
125: public void testTEMB0080SBA() throws MediaException, IOException {
126: //
127: // test 1
128: //
129:
130: // register media format
131: MediaFormatRegistry formatRegistry = MediaFormatRegistry.SINGLETON;
132: formatRegistry.rebind("mp3", new MpegAudioFormat());
133:
134: // full path of the bmp sample
135: String mediaMp3FullPath = embTestConfig.getMediaDir()
136: + File.separator + embTestConfig.getMp3SoundName1();
137:
138: // creates media bean
139: File mediaMp3File = new File(mediaMp3FullPath);
140: MediaBean mediaBean = new MediaBean(mediaMp3File, "mp3");
141:
142: // creates jpg format
143: InputStream mediaMp3InputStream = new FileInputStream(
144: mediaMp3File);
145: MpegAudioFormat mpegAudioFormat = new MpegAudioFormat();
146: // gets surrogate
147: MediaBean mediaBeanSurrogate = (MediaBean) mpegAudioFormat
148: .extractProxy(mediaMp3InputStream);
149: mediaMp3InputStream.close();
150:
151: // check access to content and check format
152: byte[] content = mediaBeanSurrogate.getContent();
153: byte[] content_ = new byte[content.length];
154: System.arraycopy(content, 0, content_, 0, content.length);
155:
156: assertTrue("test 1", mediaBeanSurrogate instanceof Media);
157: testTrace("test 1 passed");
158:
159: succeed();
160: }
161:
162: /**
163: * <pre>
164: *
165: *
166: *
167: * Testcase Name: getDefaultMimeType()
168: * Testcase Number: TEMB0081SBA
169: *
170: * Test 1:
171: * call getDefaultMimeType
172: * --->check if result equals "audio/x-mpeg"
173: *
174: *
175: *
176: * </pre>
177: */
178: public void testTEMB0081SBA() throws MediaException {
179: //
180: // test 1
181: //
182:
183: // creates mpeg audio format
184: MpegAudioFormat mpegAudioFormat = new MpegAudioFormat();
185:
186: assertEquals("test 1: ", "audio/x-mpeg", mpegAudioFormat
187: .getDefaultMimeType());
188: testTrace("test 1 passed");
189:
190: succeed();
191: }
192:
193: /**
194: * <pre>
195: *
196: *
197: *
198: * Testcase Name: isStreamingDesirable()
199: * Testcase Number: TEMB0082SBA
200: *
201: * Test 1:
202: * call isStreamingDesirable
203: * --->check if result is true
204: *
205: *
206: *
207: * </pre>
208: */
209: public void testTEMB0082SBA() throws MediaException {
210: //
211: // test 1
212: //
213:
214: // creates mpeg audio format
215: MpegAudioFormat mpegAudioFormat = new MpegAudioFormat();
216:
217: assertTrue("test 1: ", mpegAudioFormat.isStreamingDesirable());
218: testTrace("test 1 passed");
219:
220: succeed();
221: }
222:
223: }
|