001: package com.ibm.emb.test.mfb;
002:
003: import java.io.File;
004: import java.net.MalformedURLException;
005: import java.net.URL;
006:
007: import javax.emb.FormatSyntaxException;
008: import javax.emb.MediaException;
009: import javax.emb.MediaFormat;
010: import javax.emb.MediaSegment;
011:
012: import com.ibm.emb.junit.EMBStaticHelper;
013: import com.ibm.emb.test.MediaFormatTest;
014:
015: public abstract class EmbeddedMediaFormatTest extends MediaFormatTest {
016:
017: public EmbeddedMediaFormatTest(String name) throws MediaException {
018: super (name);
019: }
020:
021: /**
022: * abstract method to create an instance of MediaFormat this method needs to
023: * be implemented in the test subclass and will create an Instance of the
024: * concrete implementation of the class under test
025: */
026: public abstract MediaFormat createMediaFormat();
027:
028: /**
029: * <pre>
030: *
031: *
032: *
033: * Testcase Name: assembleContent(URL, MediaSegment[])
034: * Testcase Number: TEMB0054SBA
035: *
036: * Test 1:
037: * create 2 element segment array
038: * call assembleContent with the segment array created and null as location
039: * ----> check for FormatSyntaxException
040: *
041: * Test 2:
042: * create 1 element segment array, fill in random content and valid random child location
043: * call assembleContent with the segment array created and null as location
044: * --->check for FormatSyntaxException
045: *
046: *
047: *
048: * </pre>
049: */
050: public void testTEMB0054SBA() throws MediaException,
051: MalformedURLException {
052: // media segment
053: MediaSegment mediaSegment1 = null;
054: MediaSegment[] testMediaSegmentArray = null;
055:
056: // test instance
057: MediaFormat testInstance = createMediaFormat();
058:
059: //
060: // test 1
061: //
062: mediaSegment1 = new MediaSegment();
063: testMediaSegmentArray = new MediaSegment[] { mediaSegment1,
064: mediaSegment1 };
065: try {
066: testInstance.assembleContent(null, testMediaSegmentArray);
067: fail("test1: should throw a FormatSyntaxException");
068: } catch (FormatSyntaxException e) {
069: testTrace("test 1 passed");
070: } catch (Exception e) {
071: fail("test 1: should throw a FormatSyntaxException but threw "
072: + e.toString());
073: }
074:
075: //
076: // test 2
077: //
078: // name of a jpg sample
079: String mediaBmp = embTestConfig.getBmpPictureName1();
080:
081: // full path of the jpg sample
082: String mediaBmpFullPath = embTestConfig.getMediaDir()
083: + File.separator + mediaBmp;
084:
085: // test URL
086: URL testURL = new URL("file", "localhost", mediaBmpFullPath);
087:
088: // media segment
089: mediaSegment1 = new MediaSegment();
090: mediaSegment1.setContent(EMBStaticHelper
091: .createRandomByteArray(1024));
092: mediaSegment1.setChildLocation(testURL);
093: testMediaSegmentArray = new MediaSegment[] { mediaSegment1 };
094: try {
095: testInstance.assembleContent(null, testMediaSegmentArray);
096: fail("test2: should throw a FormatSyntaxException");
097: } catch (FormatSyntaxException e) {
098: testTrace("test 2 passed");
099: } catch (Exception e) {
100: fail("test 2: should throw a FormatSyntaxException but threw "
101: + e.toString());
102: }
103:
104: succeed();
105: }
106:
107: /**
108: * <pre>
109: *
110: *
111: *
112: * Testcase Name: disassembleContent(URL, byte[])
113: * Testcase Number: TEMB0055SBA
114: *
115: * Test 1:
116: * call disassembleContent with random media content and null as location
117: * --->check the result to be a 1-element segment array,
118: * and the element to contain the random content created and a childLocation of null.
119: *
120: *
121: *
122: * </pre>
123: */
124: public void testTEMB0055SBA() throws MediaException,
125: MalformedURLException {
126: // media segment
127: MediaSegment mediaSegment1 = null;
128: MediaSegment[] testMediaSegmentArray = null;
129: // test array
130: byte[] testByteArray = EMBStaticHelper
131: .createRandomByteArray(1024);
132:
133: // test instance
134: MediaFormat testInstance = createMediaFormat();
135:
136: //
137: // test 1
138: //
139:
140: testMediaSegmentArray = testInstance.disassembleContent(null,
141: testByteArray);
142: assertTrue(
143: "test 1",
144: (testMediaSegmentArray.length == 1)
145: && (java.util.Arrays.equals(
146: testMediaSegmentArray[0].getContent(),
147: testByteArray))
148: && (testMediaSegmentArray[0].getChildLocation() == null));
149: testTrace("test 1 passed");
150:
151: succeed();
152: }
153:
154: /**
155: * <pre>
156: *
157: *
158: *
159: * Testcase Name: isEmbedded()
160: * Testcase Number: TEMB0059SBA
161: *
162: * Test 1:
163: * call isEmbedded
164: * --->check if result is true
165: *
166: *
167: *
168: * </pre>
169: */
170: public void testTEMB0059SBA() throws MediaException,
171: MalformedURLException {
172: // test instance
173: MediaFormat testInstance = createMediaFormat();
174: assertTrue("test 1", testInstance.isEmbedded());
175: testTrace("test 1 passed");
176:
177: succeed();
178: }
179:
180: }
|