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

« back to all changes in this revision

Viewing changes to srctest/org/jaudiotagger/tag/id3/FrameCOMMTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2011-04-28 23:52:43 UTC
  • mfrom: (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110428235243-pzalvw6lncis3ukf
Tags: 2.0.3-1
* d/control: Drop Depends on default-jre per Debian Java Policy as its
  a library package.
* d/watch: Fix to directly monitor SVN tags.
* Switch to 3.0 (quilt) format.
* Bump Standards-Version to 3.9.2 (no changes needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.jaudiotagger.tag.id3;
2
 
 
3
 
import org.jaudiotagger.AbstractTestCase;
4
 
import org.jaudiotagger.audio.mp3.MP3File;
5
 
import org.jaudiotagger.tag.id3.framebody.FrameBodyCOMM;
6
 
 
7
 
import java.io.File;
8
 
 
9
 
/**
10
 
 * Test POPMFrameBody
11
 
 */
12
 
public class FrameCOMMTest extends AbstractTestCase
13
 
{
14
 
    /**
15
 
     * Should run without throwing Runtime excception, although COMMFrame wont be loaded and will
16
 
     * throwe invalid size exception
17
 
     */
18
 
    public void testReadFileContainingInvalidSizeCOMMFrame() throws Exception
19
 
    {
20
 
        Exception e = null;
21
 
        try
22
 
        {
23
 
            File testFile = AbstractTestCase.copyAudioToTmp("Issue77.id3", "testV1.mp3");
24
 
            MP3File mp3File = new MP3File(testFile);
25
 
        }
26
 
        catch (Exception ie)
27
 
        {
28
 
            e = ie;
29
 
        }
30
 
        assertNull(e);
31
 
    }
32
 
 
33
 
    /**
34
 
     * Should run without throwing Runtime excception, although COMMFrame wont be loaded and will
35
 
     * throwe invalid datatype exception
36
 
     */
37
 
    public void testReadFileContainingInvalidTextEncodingCOMMFrame() throws Exception
38
 
    {
39
 
        Exception e = null;
40
 
        try
41
 
        {
42
 
            File testFile = AbstractTestCase.copyAudioToTmp("Issue80.id3", "testV1.mp3");
43
 
            MP3File mp3File = new MP3File(testFile);
44
 
        }
45
 
        catch (Exception ie)
46
 
        {
47
 
            e = ie;
48
 
        }
49
 
        assertNull(e);
50
 
    }
51
 
 
52
 
    /**
53
 
     * Can read file containing a language code that does not actually map to a code , and write it back
54
 
     * In this real example the language code has been held as three space characters
55
 
     */
56
 
    public void testreadFrameContainingInvalidlanguageCodeCOMMFrame() throws Exception
57
 
    {
58
 
        final String INVALID_LANG_CODE = "   ";
59
 
        Exception e = null;
60
 
        try
61
 
        {
62
 
            File testFile = AbstractTestCase.copyAudioToTmp("Issue108.id3", "testV1.mp3");
63
 
            MP3File mp3File = new MP3File(testFile);
64
 
 
65
 
            assertTrue(mp3File.getID3v2Tag().hasFrame("COMM"));
66
 
 
67
 
            ID3v24Frame commFrame = (ID3v24Frame) mp3File.getID3v2Tag().getFrame("COMM");
68
 
            FrameBodyCOMM frameBody = (FrameBodyCOMM) commFrame.getBody();
69
 
 
70
 
            assertEquals(INVALID_LANG_CODE, frameBody.getLanguage());
71
 
        }
72
 
        catch (Exception ie)
73
 
        {
74
 
            ie.printStackTrace();
75
 
            e = ie;
76
 
        }
77
 
        assertNull(e);
78
 
    }
79
 
 
80
 
    /**
81
 
     * Can write file containing a COMM Frame with null language code
82
 
     */
83
 
    public void testsaveFileContainingNullLanguageCodeCOMMFrame() throws Exception
84
 
    {
85
 
        final String SAFE_LANG_CODE = "   ";
86
 
        final String SAFE_LONGER_LANG_CODE = "aa ";
87
 
        final String SAFE_SHORTER_LANG_CODE = "aaa";
88
 
        Exception e = null;
89
 
        try
90
 
        {
91
 
            //Read tag
92
 
            File testFile = AbstractTestCase.copyAudioToTmp("Issue108.id3", "testV1.mp3");
93
 
            MP3File mp3File = new MP3File(testFile);
94
 
            ID3v24Frame commFrame = (ID3v24Frame) mp3File.getID3v2Tag().getFrame("COMM");
95
 
            FrameBodyCOMM frameBody = (FrameBodyCOMM) commFrame.getBody();
96
 
 
97
 
            //Set language to null, this is common problem for new frames might null lang codes
98
 
            frameBody.setLanguage(null);
99
 
            mp3File.save();
100
 
            mp3File = new MP3File(testFile);
101
 
            commFrame = (ID3v24Frame) mp3File.getID3v2Tag().getFrame("COMM");
102
 
            frameBody = (FrameBodyCOMM) commFrame.getBody();
103
 
            assertEquals(SAFE_LANG_CODE, frameBody.getLanguage());
104
 
 
105
 
            //Set language to too short a value
106
 
            frameBody.setLanguage("aa");
107
 
            mp3File.save();
108
 
            mp3File = new MP3File(testFile);
109
 
            commFrame = (ID3v24Frame) mp3File.getID3v2Tag().getFrame("COMM");
110
 
            frameBody = (FrameBodyCOMM) commFrame.getBody();
111
 
            assertEquals(SAFE_LONGER_LANG_CODE, frameBody.getLanguage());
112
 
 
113
 
            //Set language to too long a value
114
 
            frameBody.setLanguage("aaaaaaa");
115
 
            mp3File.save();
116
 
            mp3File = new MP3File(testFile);
117
 
            commFrame = (ID3v24Frame) mp3File.getID3v2Tag().getFrame("COMM");
118
 
            frameBody = (FrameBodyCOMM) commFrame.getBody();
119
 
            assertEquals(SAFE_SHORTER_LANG_CODE, frameBody.getLanguage());
120
 
 
121
 
        }
122
 
        catch (Exception ie)
123
 
        {
124
 
            ie.printStackTrace();
125
 
            e = ie;
126
 
        }
127
 
        assertNull(e);
128
 
    }
129
 
}
 
1
package org.jaudiotagger.tag.id3;
 
2
 
 
3
import org.jaudiotagger.AbstractTestCase;
 
4
import org.jaudiotagger.audio.mp3.MP3File;
 
5
import org.jaudiotagger.tag.id3.framebody.FrameBodyCOMM;
 
6
 
 
7
import java.io.File;
 
8
 
 
9
/**
 
10
 * Test POPMFrameBody
 
11
 */
 
12
public class FrameCOMMTest extends AbstractTestCase
 
13
{
 
14
    /**
 
15
     * Should run without throwing Runtime excception, although COMMFrame wont be loaded and will
 
16
     * throwe invalid size exception
 
17
     */
 
18
    public void testReadFileContainingInvalidSizeCOMMFrame() throws Exception
 
19
    {
 
20
        Exception e = null;
 
21
        try
 
22
        {
 
23
            File testFile = AbstractTestCase.copyAudioToTmp("Issue77.id3", "testV1.mp3");
 
24
            MP3File mp3File = new MP3File(testFile);
 
25
        }
 
26
        catch (Exception ie)
 
27
        {
 
28
            e = ie;
 
29
        }
 
30
        assertNull(e);
 
31
    }
 
32
 
 
33
    /**
 
34
     * Should run without throwing Runtime excception, although COMMFrame wont be loaded and will
 
35
     * throwe invalid datatype exception
 
36
     */
 
37
    public void testReadFileContainingInvalidTextEncodingCOMMFrame() throws Exception
 
38
    {
 
39
        Exception e = null;
 
40
        try
 
41
        {
 
42
            File testFile = AbstractTestCase.copyAudioToTmp("Issue80.id3", "testV1.mp3");
 
43
            MP3File mp3File = new MP3File(testFile);
 
44
        }
 
45
        catch (Exception ie)
 
46
        {
 
47
            e = ie;
 
48
        }
 
49
        assertNull(e);
 
50
    }
 
51
 
 
52
    /**
 
53
     * Can read file containing a language code that does not actually map to a code , and write it back
 
54
     * In this real example the language code has been held as three space characters
 
55
     */
 
56
    public void testreadFrameContainingInvalidlanguageCodeCOMMFrame() throws Exception
 
57
    {
 
58
        final String INVALID_LANG_CODE = "   ";
 
59
        Exception e = null;
 
60
        try
 
61
        {
 
62
            File testFile = AbstractTestCase.copyAudioToTmp("Issue108.id3", "testV1.mp3");
 
63
            MP3File mp3File = new MP3File(testFile);
 
64
 
 
65
            assertTrue(mp3File.getID3v2Tag().hasFrame("COMM"));
 
66
 
 
67
            ID3v24Frame commFrame = (ID3v24Frame) mp3File.getID3v2Tag().getFrame("COMM");
 
68
            FrameBodyCOMM frameBody = (FrameBodyCOMM) commFrame.getBody();
 
69
 
 
70
            assertEquals(INVALID_LANG_CODE, frameBody.getLanguage());
 
71
        }
 
72
        catch (Exception ie)
 
73
        {
 
74
            ie.printStackTrace();
 
75
            e = ie;
 
76
        }
 
77
        assertNull(e);
 
78
    }
 
79
 
 
80
    /**
 
81
     * Can write file containing a COMM Frame with null language code
 
82
     */
 
83
    public void testsaveFileContainingNullLanguageCodeCOMMFrame() throws Exception
 
84
    {
 
85
        final String SAFE_LANG_CODE = "   ";
 
86
        final String SAFE_LONGER_LANG_CODE = "aa ";
 
87
        final String SAFE_SHORTER_LANG_CODE = "aaa";
 
88
        Exception e = null;
 
89
        try
 
90
        {
 
91
            //Read tag
 
92
            File testFile = AbstractTestCase.copyAudioToTmp("Issue108.id3", "testV1.mp3");
 
93
            MP3File mp3File = new MP3File(testFile);
 
94
            ID3v24Frame commFrame = (ID3v24Frame) mp3File.getID3v2Tag().getFrame("COMM");
 
95
            FrameBodyCOMM frameBody = (FrameBodyCOMM) commFrame.getBody();
 
96
 
 
97
            //Set language to null, this is common problem for new frames might null lang codes
 
98
            frameBody.setLanguage(null);
 
99
            mp3File.save();
 
100
            mp3File = new MP3File(testFile);
 
101
            commFrame = (ID3v24Frame) mp3File.getID3v2Tag().getFrame("COMM");
 
102
            frameBody = (FrameBodyCOMM) commFrame.getBody();
 
103
            assertEquals(SAFE_LANG_CODE, frameBody.getLanguage());
 
104
 
 
105
            //Set language to too short a value
 
106
            frameBody.setLanguage("aa");
 
107
            mp3File.save();
 
108
            mp3File = new MP3File(testFile);
 
109
            commFrame = (ID3v24Frame) mp3File.getID3v2Tag().getFrame("COMM");
 
110
            frameBody = (FrameBodyCOMM) commFrame.getBody();
 
111
            assertEquals(SAFE_LONGER_LANG_CODE, frameBody.getLanguage());
 
112
 
 
113
            //Set language to too long a value
 
114
            frameBody.setLanguage("aaaaaaa");
 
115
            mp3File.save();
 
116
            mp3File = new MP3File(testFile);
 
117
            commFrame = (ID3v24Frame) mp3File.getID3v2Tag().getFrame("COMM");
 
118
            frameBody = (FrameBodyCOMM) commFrame.getBody();
 
119
            assertEquals(SAFE_SHORTER_LANG_CODE, frameBody.getLanguage());
 
120
 
 
121
        }
 
122
        catch (Exception ie)
 
123
        {
 
124
            ie.printStackTrace();
 
125
            e = ie;
 
126
        }
 
127
        assertNull(e);
 
128
    }
 
129
}