~ubuntu-branches/ubuntu/utopic/libjaudiotagger-java/utopic

« back to all changes in this revision

Viewing changes to srctest/org/jaudiotagger/tag/wma/WmaDescriptionLocationTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath, Damien Raude-Morvan, Varun Hiremath
  • Date: 2009-04-01 19:17:56 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090401191756-bygniim270guy7o1
Tags: 1.0.9-1
[ Damien Raude-Morvan ]
* New upstream release
* debian/watch: Use java.net repository (which contains new releases!)
* debian/control:
  - Build-Depends on default-jdk-builddep
  - Bump Standards-Version to 3.8.1 (no changes needed)
  - Change section to "java"
* debian/rules: use default-java as JAVA_HOME
* debina/orig-tar.{sh|excludes}: strip audio and others binary files from ZIP
* debian/build.xml:
  - compile with "nowarn" to keep build log readable
  - exclude LogFormatter from build (use com.sun classes)
* debian/ant.properties: new source directory is "src" in orig.tar.gz
* Add myself as Uploaders

[ Varun Hiremath ]
* Accept changes made by Damien Raude-Morvan (Closes: #522130)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.jaudiotagger.tag.wma;
 
2
 
 
3
import org.jaudiotagger.audio.asf.io.AsfStreamer;
 
4
 
 
5
import org.jaudiotagger.audio.asf.io.AsfExtHeaderModifier;
 
6
 
 
7
import org.jaudiotagger.audio.asf.io.ChunkModifier;
 
8
 
 
9
import org.jaudiotagger.audio.asf.data.ExtendedContentDescription;
 
10
 
 
11
import org.jaudiotagger.audio.asf.io.WriteableChunkModifer;
 
12
import org.jaudiotagger.audio.asf.util.TagConverter;
 
13
 
 
14
import org.jaudiotagger.audio.asf.data.AsfHeader;
 
15
 
 
16
import org.jaudiotagger.audio.asf.io.AsfHeaderReader;
 
17
 
 
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;
 
22
 
 
23
import java.io.File;
 
24
import java.io.FileInputStream;
 
25
import java.io.FileOutputStream;
 
26
import java.util.ArrayList;
 
27
import java.util.List;
 
28
 
 
29
/**
 
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.
 
32
 * 
 
33
 * @author Christian Laireiter
 
34
 */
 
35
public class WmaDescriptionLocationTest extends WmaTestCase
 
36
{
 
37
 
 
38
    /**
 
39
     * Test file to use as source.
 
40
     */
 
41
    public final static String TEST_FILE = "test1.wma"; //$NON-NLS-1$
 
42
 
 
43
    /**
 
44
     * Will hold a tag instance for writing some values.
 
45
     */
 
46
    private final AsfTag testTag;
 
47
 
 
48
    /**
 
49
     * Creates an instance.
 
50
     */
 
51
    public WmaDescriptionLocationTest()   throws Exception
 
52
    {
 
53
        super(TEST_FILE);
 
54
        this.testTag = new AsfTag(true);
 
55
        this.testTag.setArtist("TheArtist");
 
56
        this.testTag.set(this.testTag.createTagField(AsfFieldKey.ISVBR, Boolean.TRUE.toString()));
 
57
    }
 
58
 
 
59
 
 
60
    /**
 
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.
 
69
     */
 
70
    private void applyTag(File testFile, boolean hcd, boolean hecd) throws Exception
 
71
    {
 
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>();
 
86
        if (hcd)
 
87
        {
 
88
            headerMods.add(cdCreator);
 
89
        }
 
90
        else
 
91
        {
 
92
            extHeaderMods.add(cdCreator);
 
93
        }
 
94
        if (hecd)
 
95
        {
 
96
            headerMods.add(ecdCreator);
 
97
        }
 
98
        else
 
99
        {
 
100
            extHeaderMods.add(ecdCreator);
 
101
        }
 
102
        headerMods.add(new AsfExtHeaderModifier(extHeaderMods));
 
103
        File destination = prepareTestFile("chunkloc.wma");
 
104
        new AsfStreamer()
 
105
                        .createModifiedCopy(new FileInputStream(testFile), new FileOutputStream(destination), headerMods);
 
106
        checkExcpectations(destination, hcd, hecd, !hcd, !hecd);
 
107
 
 
108
    }
 
109
 
 
110
    /**
 
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
 
120
     */
 
121
    private void checkExcpectations(File testFile, boolean hcd, boolean hecd, boolean ehcd, boolean ehecd) throws Exception
 
122
    {
 
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);
 
135
    }
 
136
 
 
137
    /**
 
138
     * Tests the locations of the content descriptor object and the extended content descriptor object, upon
 
139
     * some deep ASF manipulations.
 
140
     * 
 
141
     * @throws Exception On I/O Errors
 
142
     */
 
143
    public void testChunkLocations() throws Exception
 
144
    {
 
145
        File testFile = prepareTestFile(null);
 
146
        AudioFile read = AudioFileIO.read(testFile);
 
147
        AudioFileIO.delete(read);
 
148
        read.setTag(testTag);
 
149
        read.commit();
 
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);
 
155
    }
 
156
 
 
157
}