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.MediaFormatRegistry;
012: import javax.emb.MediaHeader;
013:
014: import org.objectweb.jonas.emb.mfb.formats.image.JpegFormat;
015: import org.objectweb.jonas.emb.mfb.formats.image.JpegHeader;
016:
017: import com.ibm.emb.junit.EMBTestRunner;
018: import com.ibm.emb.test.MediaHeaderTest;
019:
020: public class JpegHeaderTest extends MediaHeaderTest {
021:
022: /**
023: * constructor
024: */
025: public JpegHeaderTest(String name) throws MediaException {
026: super (name);
027: }
028:
029: /**
030: * main method
031: */
032: public static void main(String args[]) {
033: EMBTestRunner.run(JpegHeaderTest.class);
034: }
035:
036: /**
037: * do initialisation here
038: */
039: protected void setUp() {
040: }
041:
042: /**
043: * freeup resources
044: */
045: protected void tearDown() {
046: }
047:
048: /**
049: * creates an instance of JpegHeader with the given Parameters used in super
050: * class of JpegHeaderTest
051: */
052: public MediaHeader createMediaHeader() throws MediaException,
053: IOException {
054:
055: // register media format
056: MediaFormatRegistry formatRegistry = MediaFormatRegistry.SINGLETON;
057: formatRegistry.rebind("jpg", new JpegFormat());
058:
059: // full path of the jpg sample
060: String mediaJpegFullPath = embTestConfig.getMediaDir()
061: + File.separator + embTestConfig.getJpgPictureName1();
062:
063: // creates media bean
064: File mediaJpegFile = new File(mediaJpegFullPath);
065: MediaBean mediaBean = new MediaBean(mediaJpegFile, "jpg");
066:
067: // creates jpeg format
068: InputStream mediaJpegInputStream = new FileInputStream(
069: mediaJpegFile);
070: JpegFormat jpegFormat = new JpegFormat();
071: JpegHeader jpegHeader = (JpegHeader) jpegFormat
072: .extractHeader(mediaJpegInputStream);
073: mediaJpegInputStream.close();
074: return jpegHeader;
075: }
076:
077: /**
078: * <pre>
079: *
080: * Testcase Name: getField(String)
081: * Testcase Number: TEMB0071SBA
082: *
083: * Test 1:
084: * iterate over fieldnames, check for these results:
085: * startOfImageSegment: 216
086: * applicationMarkerSegmentType: 224
087: * applicationMarkerSegmentSize: 16
088: * applicationIdentifier: "JFIF"
089: *
090: * Test 2:
091: * extract segment header using getJfifSegmentHeader();
092: * iterate over fieldnames, check for these results:
093: * identifier: "JFIF"
094: * formatRevision: "1.01"
095: * resolutionUnit: 1
096: * horizontalResolution: 96
097: * verticalResolution: 96
098: * horizontalThumbnailPixelCount: 0
099: * verticalThumbnailPixelCount: 0
100: *
101: * </pre>
102: */
103: public void testTEMB0071SBA() throws MediaException, IOException {
104:
105: JpegHeader testInstance;
106: testInstance = (JpegHeader) createMediaHeader();
107:
108: //
109: // test 1
110: //
111:
112: assertTrue("test 1", testInstance.getField(
113: "startOfImageSegment").toString().equals("216")
114: && testInstance
115: .getField("applicationMarkerSegmentType")
116: .toString().equals("224")
117: && testInstance
118: .getField("applicationMarkerSegmentSize")
119: .toString().equals("16")
120: && testInstance.getField("applicationIdentifier")
121: .toString().equals("JFIF"));
122: testTrace("test 1 passed");
123:
124: //
125: // test 2
126: //
127:
128: /*
129: * MediaHeader mediaHeader = (JpegJfifSegmentHeader)
130: * testInstance.getApplicationMarkerSegment(); assertTrue( "test 2",
131: * mediaHeader.getField("identifier").toString().equals("JFIF") &&
132: * mediaHeader.getField("formatRevision").toString().equals("1.01") &&
133: * mediaHeader.getField("resolutionUnit").toString().equals("1") &&
134: * mediaHeader.getField("horizontalResolution").toString().equals("96") &&
135: * mediaHeader.getField("verticalResolution").toString().equals("96") &&
136: * mediaHeader.getField("horizontalThumbnailPixelCount").toString().equals("0") &&
137: * mediaHeader.getField("verticalThumbnailPixelCount").toString().equals("0"));
138: * testTrace("test 2 passed");
139: */
140:
141: succeed();
142: }
143: }
|