xspf 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,196 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+
3
+ require 'xspf'
4
+ require 'test/unit'
5
+
6
+ class TestGeneratePlaylistWithDefaults < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @playlist = XSPF::Playlist.new
10
+ end
11
+
12
+ def test_class
13
+ assert_instance_of(XSPF::Playlist, @playlist)
14
+ end
15
+
16
+ def test_version
17
+ assert_equal("1", @playlist.version)
18
+ end
19
+
20
+ def test_xmlns
21
+ assert_equal("http://xspf.org/ns/0/", @playlist.xmlns)
22
+ end
23
+
24
+ end
25
+
26
+ class TestGeneratePlaylistWithParameters < Test::Unit::TestCase
27
+
28
+ def setup
29
+ @playlist = XSPF::Playlist.new( {:xmlns => 'http://xspf.org/ns/0/', :title => 'Tout est calme', :creator => 'Yann Tiersen', :license => 'Redistribution or sharing not allowed', :info => 'http://www.yanntiersen.com/' } )
30
+ end
31
+
32
+ def test_class
33
+ assert_instance_of(XSPF::Playlist, @playlist)
34
+ end
35
+
36
+ def test_version
37
+ assert_equal('1', @playlist.version)
38
+ end
39
+
40
+ def test_xmlns
41
+ assert_equal('http://xspf.org/ns/0/', @playlist.xmlns)
42
+ end
43
+
44
+ def test_title
45
+ assert_equal('Tout est calme', @playlist.title)
46
+ end
47
+
48
+ def test_creator
49
+ assert_equal('Yann Tiersen', @playlist.creator)
50
+ end
51
+
52
+ def test_license
53
+ assert_equal('Redistribution or sharing not allowed', @playlist.license)
54
+ end
55
+
56
+ def test_info
57
+ assert_equal('http://www.yanntiersen.com/', @playlist.info)
58
+ end
59
+
60
+ def test_tracklist
61
+
62
+ track1 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file1.ogg', :identifier => 'http://musicbrainz.org/track/9f342af1-982d-4c26-9f61-3ac258957a83', :title => 'Plus au sud', :creator => 'Yann Tiersen', :tracknum => '1', :album => 'Tout est calme' } )
63
+
64
+ track2 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file2.ogg', :identifier => 'http://musicbrainz.org/track/eba1a9a9-1810-41f1-8cc9-2a00dda0a68c', :title => 'Les Grandes Marées', :creator => 'Yann Tiersen', :tracknum => '2', :album => 'Tout est calme' } )
65
+
66
+ track3 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file3.ogg', :identifier => 'http://musicbrainz.org/track/0c18ef8c-04fa-47d5-b078-66ab6a819a83', :title => 'La Crise', :creator => 'Yann Tiersen', :tracknum => '3', :album => 'Tout est calme' } )
67
+
68
+ track4 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file4.ogg', :identifier => ' http://musicbrainz.org/track/0f66dd52-bda0-4526-979d-af95ac637cc4', :title => 'Tout est calme', :creator => 'Yann Tiersen', :tracknum => '4', :album => 'Tout est calme' } )
69
+
70
+ track5 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file5.ogg', :identifier => ' http://musicbrainz.org/track/a06ef58e-019e-409a-bf72-9bd080012ac3', :title => 'La Rupture', :creator => 'Yann Tiersen', :tracknum => '5', :album => 'Tout est calme' } )
71
+
72
+ track6 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file6.ogg', :identifier => 'http://musicbrainz.org/track/f82c0a06-d4a8-41a5-9238-029e38fa9d7c', :title => 'La Relève', :creator => 'Yann Tiersen', :tracknum => '6', :album => 'Tout est calme' } )
73
+
74
+ track7 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file7.ogg', :identifier => 'http://musicbrainz.org/track/97591e2b-967e-47eb-b2b3-9a450cd33352', :title => 'La Pharmacie', :creator => 'Yann Tiersen', :tracknum => '7', :album => 'Tout est calme' } )
75
+
76
+ track8 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file8.ogg', :identifier => 'http://musicbrainz.org/track/ae7f8502-778d-4f5e-9dba-6fc5d553ad0e', :title => 'La Terrasse', :creator => 'Yann Tiersen', :tracknum => '8', :album => 'Tout est calme' } )
77
+
78
+ track9 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file9.ogg', :identifier => 'http://musicbrainz.org/track/6e937503-9d01-428c-84b5-1200bab9d1c6', :title => "L''Étal", :creator => 'Yann Tiersen', :tracknum => '9', :album => 'Tout est calme' } )
79
+
80
+ track10 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file10.ogg', :identifier => 'http://musicbrainz.org/track/2c4c845c-907a-4d96-940a-bbe8b2d0f126', :title => 'La Découverte', :creator => 'Yann Tiersen', :tracknum => '10', :album => 'Tout est calme' } )
81
+
82
+ tracklist = XSPF::Tracklist.new
83
+
84
+ tracklist << track1
85
+ tracklist << track2
86
+ tracklist << track3
87
+ tracklist << track4
88
+ tracklist << track5
89
+ tracklist << track6
90
+ tracklist << track7
91
+ tracklist << track8
92
+ tracklist << track9
93
+ tracklist << track10
94
+
95
+ @playlist.tracklist = tracklist
96
+
97
+ assert_instance_of(XSPF::Tracklist, @playlist.tracklist)
98
+ assert_equal(tracklist, @playlist.tracklist)
99
+ end
100
+
101
+ def test_nil
102
+ assert_nil(@playlist.image)
103
+ end
104
+
105
+ def test_error
106
+ assert_raise(NoMethodError) { @playlist.inexistent_method }
107
+ end
108
+
109
+ end
110
+
111
+ class TestGeneratePlaylistWithTracklist < Test::Unit::TestCase
112
+
113
+ def setup
114
+ track1 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file1.ogg', :identifier => 'http://musicbrainz.org/track/9f342af1-982d-4c26-9f61-3ac258957a83', :title => 'Plus au sud', :creator => 'Yann Tiersen', :tracknum => '1', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
115
+
116
+ track2 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file2.ogg', :identifier => 'http://musicbrainz.org/track/eba1a9a9-1810-41f1-8cc9-2a00dda0a68c', :title => 'Les Grandes Marées', :creator => 'Yann Tiersen', :tracknum => '2', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
117
+
118
+ track3 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file3.ogg', :identifier => 'http://musicbrainz.org/track/0c18ef8c-04fa-47d5-b078-66ab6a819a83', :title => 'La Crise', :creator => 'Yann Tiersen', :tracknum => '3', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
119
+
120
+ track4 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file4.ogg', :identifier => ' http://musicbrainz.org/track/0f66dd52-bda0-4526-979d-af95ac637cc4', :title => 'Tout est calme', :creator => 'Yann Tiersen', :tracknum => '4', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
121
+
122
+ track5 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file5.ogg', :identifier => ' http://musicbrainz.org/track/a06ef58e-019e-409a-bf72-9bd080012ac3', :title => 'La Rupture', :creator => 'Yann Tiersen', :tracknum => '5', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
123
+
124
+ track6 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file6.ogg', :identifier => 'http://musicbrainz.org/track/f82c0a06-d4a8-41a5-9238-029e38fa9d7c', :title => 'La Relève', :creator => 'Yann Tiersen', :tracknum => '6', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
125
+
126
+ track7 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file7.ogg', :identifier => 'http://musicbrainz.org/track/97591e2b-967e-47eb-b2b3-9a450cd33352', :title => 'La Pharmacie', :creator => 'Yann Tiersen', :tracknum => '7', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
127
+
128
+ track8 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file8.ogg', :identifier => 'http://musicbrainz.org/track/ae7f8502-778d-4f5e-9dba-6fc5d553ad0e', :title => 'La Terrasse', :creator => 'Yann Tiersen', :tracknum => '8', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
129
+
130
+ track9 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file9.ogg', :identifier => 'http://musicbrainz.org/track/6e937503-9d01-428c-84b5-1200bab9d1c6', :title => "L''Étal", :creator => 'Yann Tiersen', :tracknum => '9', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
131
+
132
+ track10 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file10.ogg', :identifier => 'http://musicbrainz.org/track/2c4c845c-907a-4d96-940a-bbe8b2d0f126', :title => 'La Découverte', :creator => 'Yann Tiersen', :tracknum => '10', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
133
+
134
+ tracklist = XSPF::Tracklist.new
135
+
136
+ tracklist << track1
137
+ tracklist << track2
138
+ tracklist << track3
139
+ tracklist << track4
140
+ tracklist << track5
141
+ tracklist << track6
142
+ tracklist << track7
143
+ tracklist << track8
144
+ tracklist << track9
145
+ tracklist << track10
146
+
147
+ @playlist = XSPF::Playlist.new( {:xmlns => 'http://xspf.org/ns/0/', :title => 'Tout est calme', :creator => 'Yann Tiersen', :license => 'Redistribution or sharing not allowed', :info => 'http://www.yanntiersen.com/', :tracklist => tracklist, :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
148
+ end
149
+
150
+ def test_class
151
+ assert_instance_of(XSPF::Playlist, @playlist)
152
+ end
153
+
154
+ def test_tracklist_class
155
+ assert_instance_of(XSPF::Tracklist, @playlist.tracklist)
156
+ end
157
+
158
+ def test_xmlns
159
+ assert_equal('http://xspf.org/ns/0/', @playlist.xmlns)
160
+ end
161
+
162
+ def test_title
163
+ assert_equal('Tout est calme', @playlist.title)
164
+ end
165
+
166
+ def test_creator
167
+ assert_equal('Yann Tiersen', @playlist.creator)
168
+ end
169
+
170
+ def test_license
171
+ assert_equal('Redistribution or sharing not allowed', @playlist.license)
172
+ end
173
+
174
+ def test_info
175
+ assert_equal('http://www.yanntiersen.com/', @playlist.info)
176
+ end
177
+
178
+ def test_nil
179
+ assert_nil(@playlist.image)
180
+ end
181
+
182
+ def test_error
183
+ assert_raise(NoMethodError) { @playlist.inexistent_method }
184
+ end
185
+
186
+ def test_meta
187
+ assert_equal('http://www.example.org/key', @playlist.meta_rel)
188
+ assert_equal('value', @playlist.meta_content)
189
+ end
190
+
191
+ def test_to_xml
192
+ xml = "<playlist version='1' xmlns='http://xspf.org/ns/0/'><title>Tout est calme</title><creator>Yann Tiersen</creator><info>http://www.yanntiersen.com/</info><license>Redistribution or sharing not allowed</license><meta rel='http://www.example.org/key'>value</meta><trackList><track><location>http://some.nifty.locati.on/file1.ogg</location><identifier>http://musicbrainz.org/track/9f342af1-982d-4c26-9f61-3ac258957a83</identifier><title>Plus au sud</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>1</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file2.ogg</location><identifier>http://musicbrainz.org/track/eba1a9a9-1810-41f1-8cc9-2a00dda0a68c</identifier><title>Les Grandes Marées</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>2</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file3.ogg</location><identifier>http://musicbrainz.org/track/0c18ef8c-04fa-47d5-b078-66ab6a819a83</identifier><title>La Crise</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>3</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file4.ogg</location><identifier> http://musicbrainz.org/track/0f66dd52-bda0-4526-979d-af95ac637cc4</identifier><title>Tout est calme</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>4</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file5.ogg</location><identifier> http://musicbrainz.org/track/a06ef58e-019e-409a-bf72-9bd080012ac3</identifier><title>La Rupture</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>5</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file6.ogg</location><identifier>http://musicbrainz.org/track/f82c0a06-d4a8-41a5-9238-029e38fa9d7c</identifier><title>La Relève</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>6</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file7.ogg</location><identifier>http://musicbrainz.org/track/97591e2b-967e-47eb-b2b3-9a450cd33352</identifier><title>La Pharmacie</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>7</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file8.ogg</location><identifier>http://musicbrainz.org/track/ae7f8502-778d-4f5e-9dba-6fc5d553ad0e</identifier><title>La Terrasse</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>8</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file9.ogg</location><identifier>http://musicbrainz.org/track/6e937503-9d01-428c-84b5-1200bab9d1c6</identifier><title>L\303\211tal</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>9</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file10.ogg</location><identifier>http://musicbrainz.org/track/2c4c845c-907a-4d96-940a-bbe8b2d0f126</identifier><title>La Découverte</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>10</trackNum><meta rel='http://www.example.org/key'>value</meta></track></trackList></playlist>"
193
+ assert_equal(xml, @playlist.to_xml)
194
+ end
195
+
196
+ end
@@ -0,0 +1,38 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+
3
+ require 'xspf'
4
+ require 'test/unit'
5
+
6
+ class TestGenerateTrack < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @track = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file.ogg', :identifier => 'http://musicbrainz.org/track/860287b7-ff56-4c12-a346-da2722414aed', :title => 'Democracy', :creator => 'Leonard Cohen', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
10
+ end
11
+
12
+ def test_class
13
+ assert_instance_of(XSPF::Track, @track)
14
+ end
15
+
16
+ def test_creation_with_arguments
17
+ assert_equal('http://musicbrainz.org/track/860287b7-ff56-4c12-a346-da2722414aed', @track.identifier)
18
+ assert_equal('http://some.nifty.locati.on/file.ogg', @track.location)
19
+ assert_equal('Leonard Cohen', @track.creator)
20
+ assert_equal('Democracy', @track.title)
21
+ end
22
+
23
+ def test_to_xml
24
+
25
+ xml = "<track><location>http://some.nifty.locati.on/file.ogg</location><identifier>http://musicbrainz.org/track/860287b7-ff56-4c12-a346-da2722414aed</identifier><title>Democracy</title><creator>Leonard Cohen</creator><meta rel='http://www.example.org/key'>value</meta></track>"
26
+
27
+ assert_equal(xml, @track.to_xml)
28
+ end
29
+
30
+ def test_nil
31
+ assert_nil(@track.album)
32
+ end
33
+
34
+ def test_error
35
+ assert_raise(NoMethodError) { @track.inexistent_method }
36
+ end
37
+
38
+ end
@@ -0,0 +1,72 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+
3
+ require 'xspf'
4
+ require 'test/unit'
5
+
6
+ class TestGenerateTracklist < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @track1 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file1.ogg', :identifier => 'http://musicbrainz.org/track/9f342af1-982d-4c26-9f61-3ac258957a83', :title => 'Plus au sud', :creator => 'Yann Tiersen', :tracknum => '1', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
10
+
11
+ @track2 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file2.ogg', :identifier => 'http://musicbrainz.org/track/eba1a9a9-1810-41f1-8cc9-2a00dda0a68c', :title => 'Les Grandes Marées', :creator => 'Yann Tiersen', :tracknum => '2', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
12
+
13
+ @track3 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file3.ogg', :identifier => 'http://musicbrainz.org/track/0c18ef8c-04fa-47d5-b078-66ab6a819a83', :title => 'La Crise', :creator => 'Yann Tiersen', :tracknum => '3', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
14
+
15
+ @track4 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file4.ogg', :identifier => ' http://musicbrainz.org/track/0f66dd52-bda0-4526-979d-af95ac637cc4', :title => 'Tout est calme', :creator => 'Yann Tiersen', :tracknum => '4', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
16
+
17
+ @track5 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file5.ogg', :identifier => ' http://musicbrainz.org/track/a06ef58e-019e-409a-bf72-9bd080012ac3', :title => 'La Rupture', :creator => 'Yann Tiersen', :tracknum => '5', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
18
+
19
+ @track6 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file6.ogg', :identifier => 'http://musicbrainz.org/track/f82c0a06-d4a8-41a5-9238-029e38fa9d7c', :title => 'La Relève', :creator => 'Yann Tiersen', :tracknum => '6', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
20
+
21
+ @track7 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file7.ogg', :identifier => 'http://musicbrainz.org/track/97591e2b-967e-47eb-b2b3-9a450cd33352', :title => 'La Pharmacie', :creator => 'Yann Tiersen', :tracknum => '7', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
22
+
23
+ @track8 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file8.ogg', :identifier => 'http://musicbrainz.org/track/ae7f8502-778d-4f5e-9dba-6fc5d553ad0e', :title => 'La Terrasse', :creator => 'Yann Tiersen', :tracknum => '8', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
24
+
25
+ @track9 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file9.ogg', :identifier => 'http://musicbrainz.org/track/6e937503-9d01-428c-84b5-1200bab9d1c6', :title => "L''Étal", :creator => 'Yann Tiersen', :tracknum => '9', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
26
+
27
+ @track10 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file10.ogg', :identifier => 'http://musicbrainz.org/track/2c4c845c-907a-4d96-940a-bbe8b2d0f126', :title => 'La Découverte', :creator => 'Yann Tiersen', :tracknum => '10', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
28
+
29
+ @tracklist = XSPF::Tracklist.new({})
30
+
31
+ @tracklist << @track1
32
+ @tracklist << @track2
33
+ @tracklist << @track3
34
+ @tracklist << @track4
35
+ @tracklist << @track5
36
+ @tracklist << @track6
37
+ @tracklist << @track7
38
+ @tracklist << @track8
39
+ @tracklist << @track9
40
+ @tracklist << @track10
41
+
42
+ end
43
+
44
+ def test_tracklist_class
45
+ assert_instance_of(XSPF::Tracklist, @tracklist)
46
+ end
47
+
48
+ def test_tracklist_creation_from_nil
49
+ tl = XSPF::Tracklist.new
50
+ assert_instance_of(XSPF::Tracklist, tl)
51
+ end
52
+
53
+ def test_number_of_tracks
54
+ assert_equal(@tracklist.tracks.size, 10)
55
+ end
56
+
57
+ def test_track_class
58
+ @tracklist.tracks.each do |t|
59
+ assert_instance_of(XSPF::Track, t)
60
+ end
61
+ end
62
+
63
+ def test_error
64
+ assert_raise(NoMethodError) { @tracklist.inexistent_method }
65
+ end
66
+
67
+ def test_to_xml
68
+ xml = "<trackList><track><location>http://some.nifty.locati.on/file1.ogg</location><identifier>http://musicbrainz.org/track/9f342af1-982d-4c26-9f61-3ac258957a83</identifier><title>Plus au sud</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>1</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file2.ogg</location><identifier>http://musicbrainz.org/track/eba1a9a9-1810-41f1-8cc9-2a00dda0a68c</identifier><title>Les Grandes Mar\303\251es</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>2</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file3.ogg</location><identifier>http://musicbrainz.org/track/0c18ef8c-04fa-47d5-b078-66ab6a819a83</identifier><title>La Crise</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>3</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file4.ogg</location><identifier> http://musicbrainz.org/track/0f66dd52-bda0-4526-979d-af95ac637cc4</identifier><title>Tout est calme</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>4</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file5.ogg</location><identifier> http://musicbrainz.org/track/a06ef58e-019e-409a-bf72-9bd080012ac3</identifier><title>La Rupture</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>5</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file6.ogg</location><identifier>http://musicbrainz.org/track/f82c0a06-d4a8-41a5-9238-029e38fa9d7c</identifier><title>La Rel\303\250ve</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>6</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file7.ogg</location><identifier>http://musicbrainz.org/track/97591e2b-967e-47eb-b2b3-9a450cd33352</identifier><title>La Pharmacie</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>7</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file8.ogg</location><identifier>http://musicbrainz.org/track/ae7f8502-778d-4f5e-9dba-6fc5d553ad0e</identifier><title>La Terrasse</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>8</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file9.ogg</location><identifier>http://musicbrainz.org/track/6e937503-9d01-428c-84b5-1200bab9d1c6</identifier><title>L\303\211tal</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>9</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file10.ogg</location><identifier>http://musicbrainz.org/track/2c4c845c-907a-4d96-940a-bbe8b2d0f126</identifier><title>La D\303\251couverte</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>10</trackNum><meta rel='http://www.example.org/key'>value</meta></track></trackList>"
69
+ assert_equal( xml, @tracklist.to_xml )
70
+ end
71
+
72
+ end
@@ -0,0 +1,90 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+
3
+ require 'xspf'
4
+ require 'test/unit'
5
+
6
+ class TestGenerateXSPF < Test::Unit::TestCase
7
+
8
+ def test_defaults
9
+ xspf = XSPF.new
10
+ assert_instance_of(XSPF, xspf)
11
+ assert_equal('1.0', xspf.version)
12
+ assert_equal('UTF-8', xspf.encoding)
13
+ end
14
+
15
+ def test_custom_encoding
16
+ xspf = XSPF.new( { :encoding => 'ASCII' } )
17
+ assert_equal('1.0', xspf.version)
18
+ assert_equal('ASCII', xspf.encoding)
19
+ end
20
+
21
+ def test_custom_version
22
+ xspf = XSPF.new( { :version => '1.1' } )
23
+ assert_equal('1.1', xspf.version)
24
+ assert_equal('UTF-8', xspf.encoding)
25
+ end
26
+
27
+ def test_error
28
+ xspf = XSPF.new
29
+ assert_raise(NoMethodError) {xspf.inexistent_method }
30
+ end
31
+
32
+ def test_xml_generation_empty_xspf
33
+ xspf = XSPF.new
34
+ assert_equal("<?xml version='1.0' encoding='UTF-8'?>", xspf.to_xml)
35
+ end
36
+
37
+ def test_xml_generation_valid_xspf
38
+
39
+ xspf_document = "<?xml version='1.0' encoding='UTF-8'?><playlist version='1' xmlns='http://xspf.org/ns/0/'><title>Tout est calme</title><creator>Yann Tiersen</creator><info>http://www.yanntiersen.com/</info><license>Redistribution or sharing not allowed</license><meta rel='http://www.example.org/key'>value</meta><trackList><track><location>http://some.nifty.locati.on/file1.ogg</location><identifier>http://musicbrainz.org/track/9f342af1-982d-4c26-9f61-3ac258957a83</identifier><title>Plus au sud</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>1</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file2.ogg</location><identifier>http://musicbrainz.org/track/eba1a9a9-1810-41f1-8cc9-2a00dda0a68c</identifier><title>Les Grandes Marées</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>2</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file3.ogg</location><identifier>http://musicbrainz.org/track/0c18ef8c-04fa-47d5-b078-66ab6a819a83</identifier><title>La Crise</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>3</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file4.ogg</location><identifier> http://musicbrainz.org/track/0f66dd52-bda0-4526-979d-af95ac637cc4</identifier><title>Tout est calme</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>4</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file5.ogg</location><identifier> http://musicbrainz.org/track/a06ef58e-019e-409a-bf72-9bd080012ac3</identifier><title>La Rupture</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>5</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file6.ogg</location><identifier>http://musicbrainz.org/track/f82c0a06-d4a8-41a5-9238-029e38fa9d7c</identifier><title>La Relève</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>6</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file7.ogg</location><identifier>http://musicbrainz.org/track/97591e2b-967e-47eb-b2b3-9a450cd33352</identifier><title>La Pharmacie</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>7</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file8.ogg</location><identifier>http://musicbrainz.org/track/ae7f8502-778d-4f5e-9dba-6fc5d553ad0e</identifier><title>La Terrasse</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>8</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file9.ogg</location><identifier>http://musicbrainz.org/track/6e937503-9d01-428c-84b5-1200bab9d1c6</identifier><title>L\303\211tal</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>9</trackNum><meta rel='http://www.example.org/key'>value</meta></track><track><location>http://some.nifty.locati.on/file10.ogg</location><identifier>http://musicbrainz.org/track/2c4c845c-907a-4d96-940a-bbe8b2d0f126</identifier><title>La Découverte</title><creator>Yann Tiersen</creator><album>Tout est calme</album><trackNum>10</trackNum><meta rel='http://www.example.org/key'>value</meta></track></trackList></playlist>"
40
+
41
+ track1 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file1.ogg', :identifier => 'http://musicbrainz.org/track/9f342af1-982d-4c26-9f61-3ac258957a83', :title => 'Plus au sud', :creator => 'Yann Tiersen', :tracknum => '1', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
42
+
43
+ track2 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file2.ogg', :identifier => 'http://musicbrainz.org/track/eba1a9a9-1810-41f1-8cc9-2a00dda0a68c', :title => 'Les Grandes Marées', :creator => 'Yann Tiersen', :tracknum => '2', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
44
+
45
+ track3 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file3.ogg', :identifier => 'http://musicbrainz.org/track/0c18ef8c-04fa-47d5-b078-66ab6a819a83', :title => 'La Crise', :creator => 'Yann Tiersen', :tracknum => '3', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
46
+
47
+ track4 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file4.ogg', :identifier => ' http://musicbrainz.org/track/0f66dd52-bda0-4526-979d-af95ac637cc4', :title => 'Tout est calme', :creator => 'Yann Tiersen', :tracknum => '4', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
48
+
49
+ track5 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file5.ogg', :identifier => ' http://musicbrainz.org/track/a06ef58e-019e-409a-bf72-9bd080012ac3', :title => 'La Rupture', :creator => 'Yann Tiersen', :tracknum => '5', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
50
+
51
+ track6 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file6.ogg', :identifier => 'http://musicbrainz.org/track/f82c0a06-d4a8-41a5-9238-029e38fa9d7c', :title => 'La Relève', :creator => 'Yann Tiersen', :tracknum => '6', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
52
+
53
+ track7 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file7.ogg', :identifier => 'http://musicbrainz.org/track/97591e2b-967e-47eb-b2b3-9a450cd33352', :title => 'La Pharmacie', :creator => 'Yann Tiersen', :tracknum => '7', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
54
+
55
+ track8 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file8.ogg', :identifier => 'http://musicbrainz.org/track/ae7f8502-778d-4f5e-9dba-6fc5d553ad0e', :title => 'La Terrasse', :creator => 'Yann Tiersen', :tracknum => '8', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
56
+
57
+ track9 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file9.ogg', :identifier => 'http://musicbrainz.org/track/6e937503-9d01-428c-84b5-1200bab9d1c6', :title => "L''Étal", :creator => 'Yann Tiersen', :tracknum => '9', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
58
+
59
+ track10 = XSPF::Track.new( { :location => 'http://some.nifty.locati.on/file10.ogg', :identifier => 'http://musicbrainz.org/track/2c4c845c-907a-4d96-940a-bbe8b2d0f126', :title => 'La Découverte', :creator => 'Yann Tiersen', :tracknum => '10', :album => 'Tout est calme', :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
60
+
61
+ tracklist = XSPF::Tracklist.new
62
+
63
+ tracklist << track1
64
+ tracklist << track2
65
+ tracklist << track3
66
+ tracklist << track4
67
+ tracklist << track5
68
+ tracklist << track6
69
+ tracklist << track7
70
+ tracklist << track8
71
+ tracklist << track9
72
+ tracklist << track10
73
+
74
+ playlist = XSPF::Playlist.new( {:xmlns => 'http://xspf.org/ns/0/', :title => 'Tout est calme', :creator => 'Yann Tiersen', :license => 'Redistribution or sharing not allowed', :info => 'http://www.yanntiersen.com/', :tracklist => tracklist, :meta_rel => 'http://www.example.org/key', :meta_content => 'value' } )
75
+
76
+ xspf = XSPF.new( { :playlist => playlist } )
77
+
78
+ assert_equal(xspf_document, xspf.to_xml)
79
+ assert_instance_of(XSPF::Playlist, xspf.playlist)
80
+ assert_raise(TypeError) { xspf.playlist = 'error' }
81
+ assert_nothing_raised(Exception) { xspf.playlist = playlist }
82
+ end
83
+
84
+ def test_error_on_xspf_creation
85
+ ary = Array.new(3) { |i| i*i }
86
+ assert_raise(TypeError) { XSPF.new( { :playlist => ary } ) }
87
+ assert_raise(TypeError) { XSPF.new(ary) }
88
+ end
89
+
90
+ end
@@ -3,7 +3,7 @@ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
3
3
  require 'xspf'
4
4
  require 'test/unit'
5
5
 
6
- class TestXSPF < Test::Unit::TestCase
6
+ class TestOuputFormats < Test::Unit::TestCase
7
7
 
8
8
  def setup
9
9
  @playlist_document = <<END_OF_PLAYLIST
@@ -52,6 +52,7 @@ END_OF_PLAYLIST
52
52
  </smil>
53
53
  END_OF_SMIL
54
54
 
55
+ # This @expected_html_ouput is not 100% correct because we do not parse the <attribution> element, therefore XSPF for Ruby does not generate the same HTML xsltproc does.
55
56
  @expected_html_ouput = <<END_OF_HTML
56
57
  <html xmlns:xspf="http://xspf.org/ns/0/">
57
58
  <head>
@@ -126,10 +127,7 @@ dl {
126
127
  <dt class="identifier">identifier</dt>
127
128
  <dd class="identifier">http://mayhem-chaos.net/xspf/xspf_it_up/1.0</dd>
128
129
  <dt class="attribution">attribution</dt>
129
- <dd class="attribution"><ol><li>
130
- <dt class="location">location</dt>
131
- <dd class="location"><a href="http://mayhem-chaos.net/xspf/xspf_it_up.html">http://mayhem-chaos.net/xspf/xspf_it_up.html</a></dd>
132
- </li></ol></dd>
130
+ <dd class="attribution"><ol></ol></dd>
133
131
  <dt class="trackList">trackList</dt>
134
132
  <dd class="trackList"><ol>
135
133
  <li><dl class="track">
@@ -168,6 +166,123 @@ dl {
168
166
  </html>
169
167
  END_OF_HTML
170
168
 
169
+ # This @expected_html_output is the output of xsltproc and is 100% correct. This should be the @expected_html_output in the future, when XSPF for Ruby will parse the <attribution> element.
170
+ # @expected_html_ouput = <<END_OF_HTML
171
+ # <html xmlns:xspf="http://xspf.org/ns/0/">
172
+ # <head>
173
+ # <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
174
+ # <title>XSPlF it up!</title>
175
+ # <link href="http://www.w3.org/StyleSheets/Core/Modernist" rel="stylesheet" type="text/css" media="screen">
176
+ # <style type="text/css">
177
+ # dl {
178
+ # margin-bottom: 5px;
179
+ # }
180
+ #
181
+ # .track {
182
+ # }
183
+ #
184
+ # .location {
185
+ # }
186
+ #
187
+ # .creator {
188
+ # }
189
+ #
190
+ # .top {
191
+ # }
192
+ #
193
+ # .duration {
194
+ # }
195
+ #
196
+ # .trackList {
197
+ # }
198
+ #
199
+ # .info {
200
+ # }
201
+ #
202
+ # .annotation {
203
+ # }
204
+ #
205
+ # .attribution {
206
+ # }
207
+ #
208
+ # .image {
209
+ # }
210
+ #
211
+ # .meta {
212
+ # }
213
+ #
214
+ # .license {
215
+ # }
216
+ #
217
+ # .trackNum {
218
+ # }
219
+ #
220
+ # .date {
221
+ # }
222
+ #
223
+ # .identifier {
224
+ # }
225
+ #
226
+ # .link {
227
+ # }
228
+ #
229
+ #
230
+ # </style>
231
+ # </head>
232
+ # <body>
233
+ # <h1>XSPlF it up!</h1>
234
+ # <dl class="top">
235
+ # <dt class="creator">creator</dt>
236
+ # <dd class="creator">Mayhem &amp; Chaos Coordinator</dd>
237
+ # <dt class="annotation">annotation</dt>
238
+ # <dd class="annotation">Just a few songs to enjoy while you XSPlF it up!</dd>
239
+ # <dt class="info">info</dt>
240
+ # <dd class="info"><a href="http://mayhem-chaos.net/xspf/xspf_it_up.html">http://mayhem-chaos.net/xspf/xspf_it_up.html</a></dd>
241
+ # <dt class="identifier">identifier</dt>
242
+ # <dd class="identifier">http://mayhem-chaos.net/xspf/xspf_it_up/1.0</dd>
243
+ # <dt class="attribution">attribution</dt>
244
+ # <dd class="attribution"><ol><li>
245
+ # <dt class="location">location</dt>
246
+ # <dd class="location"><a href="http://mayhem-chaos.net/xspf/xspf_it_up.html">http://mayhem-chaos.net/xspf/xspf_it_up.html</a></dd>
247
+ # </li></ol></dd>
248
+ # <dt class="trackList">trackList</dt>
249
+ # <dd class="trackList"><ol>
250
+ # <li><dl class="track">
251
+ # <dt class="identifier">identifier</dt>
252
+ # <dd class="identifier">http://musicbrainz.org/track/bdab6db0-2fd6-4166-a5fa-fbf2ff213793</dd>
253
+ # <dt class="creator">creator</dt>
254
+ # <dd class="creator">Cypress Hill</dd>
255
+ # <dt class="duration">duration</dt>
256
+ # <dd class="duration">174613</dd>
257
+ # <dt class="meta">meta</dt>
258
+ # <dd class="meta"><a href="http://musicbrainz.org/mm-2.1/track/bdab6db0-2fd6-4166-a5fa-fbf2ff213793">http://musicbrainz.org/mm-2.1/track/bdab6db0-2fd6-4166-a5fa-fbf2ff213793</a></dd>
259
+ # </dl></li>
260
+ # <li><dl class="track">
261
+ # <dt class="identifier">identifier</dt>
262
+ # <dd class="identifier">bdc846e7-6c26-4193-82a6-8d1b5a4d3429</dd>
263
+ # <dt class="creator">creator</dt>
264
+ # <dd class="creator">Sublime</dd>
265
+ # <dt class="duration">duration</dt>
266
+ # <dd class="duration">175466</dd>
267
+ # <dt class="meta">meta</dt>
268
+ # <dd class="meta"><a href="http://musicbrainz.org/mm-2.1/track/bdc846e7-6c26-4193-82a6-8d1b5a4d3429">http://musicbrainz.org/mm-2.1/track/bdc846e7-6c26-4193-82a6-8d1b5a4d3429</a></dd>
269
+ # </dl></li>
270
+ # <li><dl class="track">
271
+ # <dt class="identifier">identifier</dt>
272
+ # <dd class="identifier">http://musicbrainz.org/track/7d9776f7-d428-40dc-a425-3c6e3dce4d58</dd>
273
+ # <dt class="creator">creator</dt>
274
+ # <dd class="creator">Weezer</dd>
275
+ # <dt class="duration">duration</dt>
276
+ # <dd class="duration">186533</dd>
277
+ # <dt class="meta">meta</dt>
278
+ # <dd class="meta"><a href="http://musicbrainz.org/mm-2.1/track/7d9776f7-d428-40dc-a425-3c6e3dce4d58">http://musicbrainz.org/mm-2.1/track/7d9776f7-d428-40dc-a425-3c6e3dce4d58</a></dd>
279
+ # </dl></li>
280
+ # </ol></dd>
281
+ # </dl>
282
+ # </body>
283
+ # </html>
284
+ # END_OF_HTML
285
+
171
286
  @expected_soundblox_ouput = <<END_OF_SOUNDBLOX
172
287
  <?xml version="1.0"?>
173
288
  <soundbloxdata xmlns:xspf="http://xspf.org/ns/0/">
@@ -188,18 +303,18 @@ END_OF_SOUNDBLOX
188
303
  end
189
304
 
190
305
  def test_smil
191
- assert_equal(@xspf.to_smil, @expected_smil_output)
306
+ assert_equal(@expected_smil_output, @xspf.to_smil)
192
307
  end
193
308
 
194
309
  def test_html
195
- assert_equal(@xspf.to_html, @expected_html_ouput)
310
+ assert_equal(@expected_html_ouput, @xspf.to_html)
196
311
  end
197
312
 
198
313
  def test_soundblox
199
- assert_equal(@xspf.to_soundblox, @expected_soundblox_ouput)
314
+ assert_equal(@expected_soundblox_ouput, @xspf.to_soundblox)
200
315
  end
201
316
 
202
317
  def test_error
203
- assert_raise(NoMethodError) {@xspf.to_other_format }
318
+ assert_raise(NoMethodError) { @xspf.to_other_format }
204
319
  end
205
320
  end