1
package org.jaudiotagger.tag.wma;
3
import org.jaudiotagger.audio.asf.io.AsfStreamer;
5
import org.jaudiotagger.audio.asf.io.AsfExtHeaderModifier;
7
import org.jaudiotagger.audio.asf.io.ChunkModifier;
9
import org.jaudiotagger.audio.asf.data.ExtendedContentDescription;
11
import org.jaudiotagger.audio.asf.io.WriteableChunkModifer;
12
import org.jaudiotagger.audio.asf.util.TagConverter;
14
import org.jaudiotagger.audio.asf.data.AsfHeader;
16
import org.jaudiotagger.audio.asf.io.AsfHeaderReader;
18
import org.jaudiotagger.audio.AudioFile;
19
import org.jaudiotagger.audio.AudioFileIO;
20
import org.jaudiotagger.audio.asf.tag.AsfFieldKey;
21
import org.jaudiotagger.audio.asf.tag.AsfTag;
24
import java.io.FileInputStream;
25
import java.io.FileOutputStream;
26
import java.util.ArrayList;
27
import java.util.List;
30
* This testcase tests the ability to read the content description and extended content description
31
* from the ASF header object and the ASF header extension object.
33
* @author Christian Laireiter
35
public class WmaDescriptionLocationTest extends WmaTestCase
39
* Test file to use as source.
41
public final static String TEST_FILE = "test1.wma"; //$NON-NLS-1$
44
* Will hold a tag instance for writing some values.
46
private final AsfTag testTag;
49
* Creates an instance.
51
public WmaDescriptionLocationTest() throws Exception
54
this.testTag = new AsfTag(true);
55
this.testTag.setArtist("TheArtist");
56
this.testTag.set(this.testTag.createTagField(AsfFieldKey.ISVBR, Boolean.TRUE.toString()));
61
* Applies {@link #testTag} to the given audio file, and allows to specify at which location the
62
* content description and extended content description are to be added.<br>
63
* @param testFile The file to work with.
64
* @param hcd <code>true</code> if the content description should be placed into the header object. if <code>false</code>
65
* it will be placed in the header extension object.
66
* @param hecd <code>true</code> if the extended content description should be placed into the header object. if <code>false</code>
67
* it will be placed in the header extension object.
68
* @throws Exception on I/O Errors.
70
private void applyTag(File testFile, boolean hcd, boolean hecd) throws Exception
72
// get an audio file instance
73
AudioFile read = AudioFileIO.read(testFile);
74
// delete all managed data
75
AudioFileIO.delete(read);
76
// create creator for the content description object (chunk)
77
WriteableChunkModifer cdCreator = new WriteableChunkModifer(TagConverter.createContentDescription(this.testTag));
78
ExtendedContentDescription ecd = new ExtendedContentDescription();
79
TagConverter.assignCommonTagValues(testTag, ecd);
80
TagConverter.assignOptionalTagValues(testTag, ecd);
81
// create creator for the extended content description object (chunk)
82
WriteableChunkModifer ecdCreator = new WriteableChunkModifer(ecd);
83
// create the modifier lists
84
List<ChunkModifier> headerMods = new ArrayList<ChunkModifier>();
85
List<ChunkModifier> extHeaderMods = new ArrayList<ChunkModifier>();
88
headerMods.add(cdCreator);
92
extHeaderMods.add(cdCreator);
96
headerMods.add(ecdCreator);
100
extHeaderMods.add(ecdCreator);
102
headerMods.add(new AsfExtHeaderModifier(extHeaderMods));
103
File destination = prepareTestFile("chunkloc.wma");
105
.createModifiedCopy(new FileInputStream(testFile), new FileOutputStream(destination), headerMods);
106
checkExcpectations(destination, hcd, hecd, !hcd, !hecd);
111
* Tests whether the audio file contains artist and variable bitrate as specified in the
112
* {@linkplain #WmaDescriptionLocationTest() constructor}, and if a content description object as well
113
* as an extended content description is available.
114
* @param testFile file to test
115
* @param hcd <code>true</code> if a content description is expected in the ASF header.
116
* @param hecd <code>true</code> if an extended content description is expected in the ASF header.
117
* @param ehcd <code>true</code> if a content description is expected in the ASF header extension.
118
* @param ehecd <code>true</code> if an extended content description is expected in the ASF header extension.
119
* @throws Exception on I/O Errors
121
private void checkExcpectations(File testFile, boolean hcd, boolean hecd, boolean ehcd, boolean ehecd) throws Exception
123
AudioFile read = AudioFileIO.read(testFile);
124
assertTrue(read.getAudioHeader().isVariableBitRate());
125
assertEquals("TheArtist", read.getTag().getFirstArtist());
126
AsfHeader readHeader = AsfHeaderReader.readHeader(testFile);
127
assertNotNull(readHeader.findContentDescription());
128
assertNotNull(readHeader.findExtendedContentDescription());
129
assertEquals(hcd, readHeader.getContentDescription() != null);
130
assertEquals(hecd, readHeader.getExtendedContentDescription() != null);
131
assertEquals(ehcd, readHeader.getExtendedHeader() != null && readHeader.getExtendedHeader()
132
.getContentDescription() != null);
133
assertEquals(ehecd, readHeader.getExtendedHeader() != null && readHeader.getExtendedHeader()
134
.getExtendedContentDescription() != null);
138
* Tests the locations of the content descriptor object and the extended content descriptor object, upon
139
* some deep ASF manipulations.
141
* @throws Exception On I/O Errors
143
public void testChunkLocations() throws Exception
145
File testFile = prepareTestFile(null);
146
AudioFile read = AudioFileIO.read(testFile);
147
AudioFileIO.delete(read);
148
read.setTag(testTag);
150
checkExcpectations(testFile, true, true, false, false);
151
applyTag(testFile, false, false);
152
applyTag(testFile, false, true);
153
applyTag(testFile, true, false);
154
applyTag(testFile, true, true);