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.FileOutputStream;
007: import java.io.IOException;
008:
009: import javax.emb.MediaBean;
010: import javax.emb.MediaConverter;
011: import javax.emb.MediaConverterSpec;
012: import javax.emb.MediaException;
013: import javax.emb.MediaFormatRegistry;
014:
015: import mfb.converters.BmpToJpegConverterSpec;
016: import mfb.converters.JpegToBmpConverterSpec;
017:
018: import org.objectweb.jonas.emb.mfb.converter.image.ImageConverter;
019: import org.objectweb.jonas.emb.mfb.converter.image.ImageResizeConverterSpec;
020: import org.objectweb.jonas.emb.mfb.formats.image.JpegFormat;
021:
022: import com.ibm.emb.junit.EMBTestRunner;
023: import com.ibm.emb.test.MediaConverterTest;
024:
025: public class ImageConverterTest extends MediaConverterTest {
026:
027: /**
028: * constructor
029: */
030: public ImageConverterTest(String name) throws MediaException {
031: super (name);
032: }
033:
034: /**
035: * main method
036: */
037: public static void main(String args[]) {
038: EMBTestRunner.run(ImageConverterTest.class);
039: }
040:
041: /**
042: * do initialisation here
043: */
044: protected void setUp() {
045: }
046:
047: /**
048: * freeup resources
049: */
050: protected void tearDown() {
051: }
052:
053: /**
054: * creates an instance of ImageConverter with the given Parameters used in
055: * super class of ImageConverterTest
056: */
057: public MediaConverter createMediaConverter() throws MediaException {
058:
059: // creates BmpToJpegConverterSpec
060: MediaConverterSpec converterSpec = new BmpToJpegConverterSpec();
061: // returns an ImageConverter
062: return converterSpec.getConverter();
063: }
064:
065: /**
066: * <pre>
067: *
068: *
069: *
070: * Testcase Name: convert(InputStream)
071: * Testcase Number: TEMB0100SBA
072: *
073: * Test 1:
074: *
075: * create BmpToJpegConverterSpec
076: * query converter instance from converter spec using getConverter()
077: * call convert(InputStream) of converter passing FileInputStream on a bmp media
078: * create MediaBean with conversion result
079: * close FileInputStream and result stream
080: * --> check for no exceptions
081: * --> call getHeader() on media bean and check for no exceptions to verify format
082: *
083: *
084: * Test 2:
085: * iterate over possible BMP color depths: 32, 24, 16, 8, 4, 1 {
086: * create JpegToBmpConverterSpec, specify color depth
087: * query converter instance from converter spec using getConverter()
088: * call convert(InputStream) of converter passing FileInputStream on a jpg media file
089: * create MediaBean with conversion result
090: * close FileInputStream and result stream
091: * --> check for no exceptions
092: * --> call getHeader() on media bean and check for no exceptions to verify format
093: *
094: * Test 3:
095: * iterate over crop factors (0.4, 1.0, 2.5) and input files ( test.bmp , test.jpg ) {
096: *
097: * create ImageResizeConverterSpec, pass crop factor
098: * query converter instance from converter spec using getConverter()
099: * call convert(InputStream) of converter passing FileInputStream on input file
100: * create MediaBean with conversion result
101: * close FileInputStream and result stream
102: * --> check for no exceptions
103: * --> call getHeader() on media bean and check for no exceptions to verify format
104: *
105: * Test 4:
106: * iterate over crop factor pairs (0.4/2.5, 1.0/1.0, 2.5/0.4) and input files (test.bmp, test.jpg ) {
107: *
108: * create ImageResizeConverterSpec, pass crop factor pair (horizontal/vertical)
109: * query converter instance from converter spec using getConverter()
110: * call convert(InputStream) of converter passing FileInputStream on input file
111: * create MediaBean with conversion result
112: * close FileInputStream and result stream
113: * --> check for no exceptions
114: * --> call getHeader() on media bean and check for no exceptions to verify format
115: * }
116: *
117: *
118: * }
119: *
120: *
121: *
122: *
123: * </pre>
124: */
125: public void testTEMB0100SBA() throws MediaException, IOException {
126: // register media format
127: MediaFormatRegistry formatRegistry = MediaFormatRegistry.SINGLETON;
128: formatRegistry.rebind("jpg", new JpegFormat());
129:
130: // testinstance
131: ImageConverter testInstance;
132:
133: // converter specs
134: JpegToBmpConverterSpec converterSpec;
135: ImageResizeConverterSpec resizeConverterSpec;
136:
137: // full path of the bmp sample
138: String mediaBmpFullPath = embTestConfig.getMediaDir()
139: + File.separator + embTestConfig.getBmpPictureName1();
140:
141: // full path of the jpg sample
142: String mediaJpegFullPath = embTestConfig.getMediaDir()
143: + File.separator + embTestConfig.getJpgPictureName1();
144:
145: // bmp input stream
146: FileInputStream bmpInputStream;
147:
148: // jpeg input stream
149: FileInputStream jpegInputStream;
150:
151: // test media
152: MediaBean testMedia;
153:
154: //
155: // test 1
156: //
157:
158: /*
159: * try { // stream bmpInputStream = new
160: * FileInputStream(mediaBmpFullPath); // creates image converter
161: * testInstance = (ImageConverter) createMediaConverter(); // creates
162: * media bean with the result of conversion testMedia = new
163: * MediaBean(testInstance.process(bmpInputStream), "jpg", "testJpg");
164: * bmpInputStream.close(); JpegHeader testJpegHeader = (JpegHeader)
165: * testMedia.getHeader(); testTrace("test 1 passed"); succeed(); } catch
166: * (Exception e) { fail("test 1 : no exception expected, this is thrown : " +
167: * e.toString()); }
168: */
169: //
170: // test 2
171: //
172: byte[] colorDepth = { 32, 24, 16, 8, 4, 1 };
173:
174: try {
175: for (int i = 0; i < colorDepth.length; i++) {
176:
177: // creates image converter
178: converterSpec = new JpegToBmpConverterSpec(
179: colorDepth[i]);
180: testInstance = (ImageConverter) converterSpec
181: .getConverter();
182:
183: // creates stream
184: jpegInputStream = new FileInputStream(mediaJpegFullPath);
185:
186: // creates media bean with the result of conversion
187: testMedia = new MediaBean(testInstance
188: .process(jpegInputStream), "bmp", "testBmp");
189:
190: // close stream stream
191: jpegInputStream.close();
192: }
193: testTrace("test 2 passed");
194: succeed();
195: } catch (IllegalArgumentException e) {
196: fail("test 2 , thrown exception : " + e.toString());
197: }
198:
199: //
200: // test 3
201: //
202:
203: double[] cropFactor = { 0.4, 1.0, 2.5 };
204:
205: try {
206: for (int i = 0; i < cropFactor.length; i++) {
207:
208: // creates image converter
209: resizeConverterSpec = new ImageResizeConverterSpec(
210: cropFactor[i]);
211: testInstance = (ImageConverter) resizeConverterSpec
212: .getConverter();
213:
214: // create input streams
215: bmpInputStream = new FileInputStream(mediaBmpFullPath);
216: jpegInputStream = new FileInputStream(mediaJpegFullPath);
217:
218: // creates media bean with the result of conversion - BMP
219: testMedia = new MediaBean(testInstance
220: .process(jpegInputStream), "bmp", "testBmp");
221:
222: // error report
223: logProductError("consequence of a reported error PEMB0052RMD");
224:
225: // creates media bean with the result of conversion - JPEG
226: testMedia = new MediaBean(testInstance
227: .process(bmpInputStream), "jpg", "testJpeg");
228:
229: // close stream
230: jpegInputStream.close();
231: bmpInputStream.close();
232: }
233: testTrace("test 3 passed");
234: succeed();
235: } catch (IllegalArgumentException e) {
236: fail("test 3 , thrown exception : " + e.toString());
237: }
238:
239: //
240: // test 4
241: //
242:
243: double[][] cropFactor2 = { { 0.4, 2.5 }, { 1.0, 1.0 },
244: { 2.5, 0.4 } };
245:
246: try {
247: for (int i = 0; i < cropFactor.length; i++) {
248:
249: // creates image converter
250: resizeConverterSpec = new ImageResizeConverterSpec(
251: cropFactor2[i][0], cropFactor2[i][1]);
252: testInstance = (ImageConverter) resizeConverterSpec
253: .getConverter();
254:
255: // create input streams
256: bmpInputStream = new FileInputStream(mediaBmpFullPath);
257: jpegInputStream = new FileInputStream(mediaJpegFullPath);
258:
259: // creates media bean with the result of conversion - BMP
260: testMedia = new MediaBean(testInstance
261: .process(jpegInputStream), "bmp", "testBmp");
262:
263: // creates media bean with the result of conversion - JPEG
264: testMedia = new MediaBean(testInstance
265: .process(bmpInputStream), "jpg", "testJpeg");
266:
267: // close stream
268: jpegInputStream.close();
269: bmpInputStream.close();
270: }
271: testTrace("test 3 passed");
272: succeed();
273: } catch (IllegalArgumentException e) {
274: fail("test 3 , thrown exception : " + e.toString());
275: }
276:
277: }
278:
279: /**
280: * <pre>
281: *
282: *
283: *
284: * Testcase Name: convert(InputStream, OutputStream)
285: * Testcase Number: TEMB0101SBA
286: *
287: * Test 1:
288: *
289: * create BmpToJpegConverterSpec
290: * query converter instance from converter spec using getConverter()
291: * call convert(InputStream) of converter passing FileInputStream on test.bmp, FileOutputStream on temporary file
292: * close FileInputStream and FileOutputStream
293: * create MediaBean with temporary file
294: * --> check for no exceptions
295: * --> call getHeader() on media bean and check for no exceptions to verify format
296: *
297: *
298: * Test 2:
299: * iterate over possible BMP color depths: 32, 24, 16, 8, 4, 1 {
300: * create JpegToBmpConverterSpec, specify color depth
301: * query converter instance from converter spec using getConverter()
302: * call convert(InputStream) of converter passing FileInputStream on test.jpg, OutputStream on temporary file
303: * close FileInputStream and FileOutputStream
304: * create MediaBean with temporary file
305: * --> check for no exceptions
306: * --> call getHeader() on media bean and check for no exceptions to verify format
307: * }
308: *
309: *
310: * Test 3:
311: * iterate over crop factors (0.4, 1.0, 2.5) and input files (test.bmp, test.jpg) {
312: *
313: * create ImageResizeConverterSpec, pass crop factor
314: * query converter instance from converter spec using getConverter()
315: * call convert(InputStream) of converter passing FileInputStream on input file, OutputStream on temporary file
316: * close FileInputStream and FileOutputStream
317: * create MediaBean with temporary file
318: * --> check for no exceptions
319: * --> call getHeader() on media bean and check for no exceptions to verify format
320: * }
321: *
322: *
323: * Test 4:
324: * iterate over crop factor pairs (0.4/2.5, 1.0/1.0, 2.5/0.4) and input files (test.bmp,test.jpg) {
325: *
326: * create ImageResizeConverterSpec, pass crop factor pair (horizontal/vertical)
327: * query converter instance from converter spec using getConverter()
328: * call convert(InputStream) of converter passing FileInputStream on input file, OutputStream on temporary file
329: * close FileInputStream and FileOutputStream
330: * create MediaBean with temporary file
331: * --> check for no exceptions
332: * --> call getHeader() on media bean and check for no exceptions to verify format
333: * }
334: *
335: *
336: *
337: *
338: * </pre>
339: */
340: public void testTEMB0101SBA() throws MediaException, IOException {
341:
342: // register media format
343: MediaFormatRegistry formatRegistry = MediaFormatRegistry.SINGLETON;
344: formatRegistry.rebind("jpg", new JpegFormat());
345:
346: // testinstance
347: ImageConverter testInstance;
348:
349: // converter specs
350: JpegToBmpConverterSpec converterSpec;
351: ImageResizeConverterSpec resizeConverterSpec;
352:
353: // full path of the bmp sample
354: String mediaBmpFullPath = embTestConfig.getMediaDir()
355: + File.separator + embTestConfig.getBmpPictureName1();
356:
357: // full path of the jpg sample
358: String mediaJpegFullPath = embTestConfig.getMediaDir()
359: + File.separator + embTestConfig.getJpgPictureName1();
360:
361: // temporary file
362: File tempFile;
363: File tempFile1;
364:
365: // bmp input stream
366: FileInputStream bmpInputStream;
367:
368: // jpeg input stream
369: FileInputStream jpegInputStream;
370:
371: // temp output stream
372: FileOutputStream tempOutputStream;
373: FileOutputStream tempOutputStream1;
374:
375: // test media
376: MediaBean testMedia;
377:
378: //
379: // test 1
380: //
381:
382: // error report
383: logProductError("consequence of a reported error PEMB0052RMD");
384:
385: try {
386: // input stream
387: bmpInputStream = new FileInputStream(mediaBmpFullPath);
388:
389: // creates temp file
390: tempFile = File.createTempFile("test", "tmp");
391:
392: // creates output stream
393: tempOutputStream = new FileOutputStream(tempFile);
394:
395: // creates image converter
396: testInstance = (ImageConverter) createMediaConverter();
397:
398: // process conversion
399: testInstance.process(bmpInputStream, tempOutputStream);
400:
401: // close streams
402: tempOutputStream.close();
403: bmpInputStream.close();
404:
405: // creates media bean with the result of conversion
406: testMedia = new MediaBean(tempFile, "jpg");
407:
408: // JpegHeader testJpegHeader = (JpegHeader) testMedia.getHeader();
409:
410: // deletes temp file
411: tempFile.delete();
412:
413: testTrace("test 1 passed");
414: succeed();
415: } catch (Exception e) {
416: fail("test 1 : no exception expected, this is thrown : "
417: + e.toString());
418: }
419:
420: //
421: // test 2
422: //
423:
424: byte[] colorDepth = { 32, 24, 16, 8, 4, 1 };
425:
426: try {
427: for (int i = 0; i < colorDepth.length; i++) {
428:
429: // creates image converter
430: converterSpec = new JpegToBmpConverterSpec(
431: colorDepth[i]);
432: testInstance = (ImageConverter) converterSpec
433: .getConverter();
434:
435: // creates temp file
436: tempFile = File.createTempFile("test", "tmp");
437:
438: // creates input stream
439: jpegInputStream = new FileInputStream(mediaJpegFullPath);
440:
441: // creates output stream
442: tempOutputStream = new FileOutputStream(tempFile);
443:
444: // process conversion
445: testInstance.process(jpegInputStream, tempOutputStream);
446:
447: // close streams
448: tempOutputStream.close();
449: jpegInputStream.close();
450:
451: // creates media bean with the result of conversion
452: testMedia = new MediaBean(tempFile, "bmp");
453:
454: // deletes temp file
455: tempFile.delete();
456: }
457:
458: testTrace("test 2 passed");
459: succeed();
460: } catch (IllegalArgumentException e) {
461: fail("test 2 , thrown exception : " + e.toString());
462: }
463:
464: //
465: // test 3
466: //
467:
468: double[] cropFactor = { 0.4, 1.0, 2.5 };
469:
470: try {
471: for (int i = 0; i < cropFactor.length; i++) {
472:
473: // creates image converter
474: resizeConverterSpec = new ImageResizeConverterSpec(
475: cropFactor[i]);
476: testInstance = (ImageConverter) resizeConverterSpec
477: .getConverter();
478:
479: // creates temp files
480: tempFile = File.createTempFile("test", "tmp");
481: tempFile1 = File.createTempFile("test", "tmp");
482:
483: // create input streams
484: bmpInputStream = new FileInputStream(mediaBmpFullPath);
485: jpegInputStream = new FileInputStream(mediaJpegFullPath);
486:
487: // creates output streams
488: tempOutputStream = new FileOutputStream(tempFile);
489: tempOutputStream1 = new FileOutputStream(tempFile1);
490:
491: // makes conversion and creates media bean with the result of
492: // conversion - bmp temp file
493: testInstance.process(jpegInputStream, tempOutputStream);
494:
495: tempOutputStream.close();
496: jpegInputStream.close();
497:
498: testMedia = new MediaBean(tempFile, "bmp");
499: tempFile.delete();
500:
501: // makes conversion and creates media bean with the result of
502: // conversion - jpeg temp file
503: testInstance.process(bmpInputStream, tempOutputStream1);
504:
505: tempOutputStream1.close();
506: bmpInputStream.close();
507:
508: testMedia = new MediaBean(tempFile1, "jpg");
509: tempFile1.delete();
510: }
511:
512: testTrace("test 3 passed");
513: succeed();
514: } catch (IllegalArgumentException e) {
515: fail("test 3 , thrown exception : " + e.toString());
516: }
517:
518: //
519: // test 4
520: //
521:
522: double[][] cropFactor2 = { { 0.4, 2.5 }, { 1.0, 1.0 },
523: { 2.5, 0.4 } };
524:
525: try {
526: for (int i = 0; i < cropFactor.length; i++) {
527:
528: // creates image converter
529: resizeConverterSpec = new ImageResizeConverterSpec(
530: cropFactor2[i][0], cropFactor2[i][1]);
531: testInstance = (ImageConverter) resizeConverterSpec
532: .getConverter();
533:
534: // creates temp files
535: tempFile = File.createTempFile("test", "tmp");
536: tempFile1 = File.createTempFile("test", "tmp");
537:
538: // create input streams
539: bmpInputStream = new FileInputStream(mediaBmpFullPath);
540: jpegInputStream = new FileInputStream(mediaJpegFullPath);
541:
542: // creates output streams
543: tempOutputStream = new FileOutputStream(tempFile);
544: tempOutputStream1 = new FileOutputStream(tempFile1);
545:
546: // makes conversion and creates media bean with the result of
547: // conversion - bmp temp file
548: testInstance.process(jpegInputStream, tempOutputStream);
549:
550: tempOutputStream.close();
551: jpegInputStream.close();
552:
553: testMedia = new MediaBean(tempFile, "bmp");
554: tempFile.delete();
555:
556: // makes conversion and creates media bean with the result of
557: // conversion - jpeg temp file
558: testInstance.process(bmpInputStream, tempOutputStream1);
559:
560: tempOutputStream1.close();
561: bmpInputStream.close();
562:
563: testMedia = new MediaBean(tempFile1, "jpg");
564: tempFile1.delete();
565: }
566:
567: testTrace("test 4 passed");
568: succeed();
569: } catch (IllegalArgumentException e) {
570: fail("test 4 , thrown exception : " + e.toString());
571: }
572:
573: }
574:
575: }
|