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