discid 1.0.0.rc1 → 1.0.0rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +3 -2
- data/CHANGES +4 -1
- data/{LICENSE.txt → LICENSE} +0 -0
- data/README.md +1 -1
- data/discid.gemspec +1 -0
- data/examples/{discid.rb → readdiscid.rb} +3 -3
- data/lib/discid.rb +9 -2
- data/lib/discid/disc.rb +38 -33
- data/lib/discid/lib.rb +1 -1
- data/lib/discid/track_info.rb +2 -1
- data/lib/discid/version.rb +2 -1
- data/test/test_disc.rb +87 -0
- data/test/test_discid.rb +52 -71
- data/test/test_track_info.rb +77 -0
- metadata +11 -7
- data/changelog +0 -35
data/.travis.yml
CHANGED
data/CHANGES
CHANGED
data/{LICENSE.txt → LICENSE}
RENAMED
File without changes
|
data/README.md
CHANGED
data/discid.gemspec
CHANGED
@@ -13,6 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "https://github.com/phw/ruby-discid"
|
14
14
|
spec.license = "LGPL-3"
|
15
15
|
spec.post_install_message = %q{Please make sure you have libdiscid (http://musicbrainz.org/doc/libdiscid) installed.}
|
16
|
+
spec.requirements = "libdiscid >= 0.1.0"
|
16
17
|
|
17
18
|
spec.files = `git ls-files`.split($/)
|
18
19
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
@@ -26,7 +26,7 @@ begin
|
|
26
26
|
|
27
27
|
# Instead of reading from a device we could set the TOC directly:
|
28
28
|
#disc = DiscId.put(1, 82255, [150, 16157, 35932, 57527])
|
29
|
-
rescue
|
29
|
+
rescue DiscId::DiscError => e
|
30
30
|
puts e
|
31
31
|
exit(1)
|
32
32
|
end
|
@@ -37,8 +37,8 @@ print <<EOF
|
|
37
37
|
Device : #{disc.device}
|
38
38
|
DiscID : #{disc.id}
|
39
39
|
FreeDB ID : #{disc.freedb_id}
|
40
|
-
First track : #{disc.
|
41
|
-
Last track : #{disc.
|
40
|
+
First track : #{disc.last_track_number}
|
41
|
+
Last track : #{disc.first_track_number}
|
42
42
|
Total length: #{disc.seconds} seconds
|
43
43
|
Sectors : #{disc.sectors}
|
44
44
|
EOF
|
data/lib/discid.rb
CHANGED
@@ -89,7 +89,7 @@ module DiscId
|
|
89
89
|
# supported features by version and platform.
|
90
90
|
#
|
91
91
|
# @raise [TypeError] `device` can not be converted to a String.
|
92
|
-
# @raise [
|
92
|
+
# @raise [DiscError] Error reading from `device`. `Exception#message` contains
|
93
93
|
# error details.
|
94
94
|
# @param device [String] The device identifier. If set to `nil` {default_device}
|
95
95
|
# will be used.
|
@@ -107,7 +107,7 @@ module DiscId
|
|
107
107
|
# This function may be used if the TOC has been read earlier and you want to
|
108
108
|
# calculate the disc ID afterwards, without accessing the disc drive.
|
109
109
|
#
|
110
|
-
# @raise [
|
110
|
+
# @raise [DiscError] The TOC could not be set. `Exception#message`contains
|
111
111
|
# error details.
|
112
112
|
# @param first_track [Integer] The number of the first audio track on the
|
113
113
|
# disc (usually one).
|
@@ -167,4 +167,11 @@ module DiscId
|
|
167
167
|
return (sectors.to_f / 75).round
|
168
168
|
end
|
169
169
|
|
170
|
+
# The libdiscid version.
|
171
|
+
#
|
172
|
+
# @note This will only give meaningful results for libdiscid 0.4.0
|
173
|
+
# and higher. For lower versions this constant will always have
|
174
|
+
# the value "libdiscid < 0.4.0".
|
175
|
+
LIBDISCID_VERSION = Lib.get_version_string
|
176
|
+
|
170
177
|
end
|
data/lib/discid/disc.rb
CHANGED
@@ -31,6 +31,7 @@ module DiscId
|
|
31
31
|
pointer = Lib.new
|
32
32
|
@handle = FFI::AutoPointer.new(pointer, Lib.method(:free))
|
33
33
|
@read = false
|
34
|
+
@tracks = nil
|
34
35
|
end
|
35
36
|
|
36
37
|
# @private
|
@@ -47,7 +48,7 @@ module DiscId
|
|
47
48
|
result = Lib.read @handle, @device, flags
|
48
49
|
|
49
50
|
if result == 0
|
50
|
-
raise
|
51
|
+
raise DiscError, Lib.get_error_msg(@handle)
|
51
52
|
else
|
52
53
|
@read = true
|
53
54
|
end
|
@@ -65,7 +66,7 @@ module DiscId
|
|
65
66
|
result = Lib.put @handle, first_track, last_track, p
|
66
67
|
|
67
68
|
if result == 0
|
68
|
-
raise
|
69
|
+
raise DiscError, Lib.get_error_msg(@handle)
|
69
70
|
else
|
70
71
|
@read = true
|
71
72
|
end
|
@@ -76,40 +77,35 @@ module DiscId
|
|
76
77
|
#
|
77
78
|
# @return [String] The DiscID or `nil` if no ID was yet read.
|
78
79
|
def id
|
79
|
-
return
|
80
|
-
return Lib.get_id @handle
|
80
|
+
return Lib.get_id @handle if @read
|
81
81
|
end
|
82
82
|
|
83
83
|
# The FreeDB DiscID.
|
84
84
|
#
|
85
85
|
# @return [String] The DiscID or `nil` if no ID was yet read.
|
86
86
|
def freedb_id
|
87
|
-
return
|
88
|
-
return Lib.get_freedb_id @handle
|
87
|
+
return Lib.get_freedb_id @handle if @read
|
89
88
|
end
|
90
89
|
|
91
90
|
# The number of the first track on this disc.
|
92
91
|
#
|
93
92
|
# @return [Integer] The number of the first track or `nil` if no ID was yet read.
|
94
|
-
def
|
95
|
-
return
|
96
|
-
return Lib.get_first_track_num @handle
|
93
|
+
def first_track_number
|
94
|
+
return Lib.get_first_track_num @handle if @read
|
97
95
|
end
|
98
96
|
|
99
97
|
# The number of the last track on this disc.
|
100
98
|
#
|
101
99
|
# @return [Integer] The number of the last track or `nil` if no ID was yet read.
|
102
|
-
def
|
103
|
-
return
|
104
|
-
return Lib.get_last_track_num @handle
|
100
|
+
def last_track_number
|
101
|
+
return Lib.get_last_track_num @handle if @read
|
105
102
|
end
|
106
103
|
|
107
104
|
# The length of the disc in sectors.
|
108
105
|
#
|
109
106
|
# @return [Integer] Sectors or `nil` if no ID was yet read.
|
110
107
|
def sectors
|
111
|
-
return
|
112
|
-
return Lib.get_sectors @handle
|
108
|
+
return Lib.get_sectors @handle if @read
|
113
109
|
end
|
114
110
|
|
115
111
|
# The length of the disc in seconds.
|
@@ -130,8 +126,7 @@ module DiscId
|
|
130
126
|
#
|
131
127
|
# @return [String] MCN or `nil` if no ID was yet read.
|
132
128
|
def mcn
|
133
|
-
return
|
134
|
-
return Lib.get_mcn @handle
|
129
|
+
return Lib.get_mcn @handle if @read
|
135
130
|
end
|
136
131
|
|
137
132
|
# An URL for submitting the DiscID to MusicBrainz.
|
@@ -142,8 +137,7 @@ module DiscId
|
|
142
137
|
#
|
143
138
|
# @return [String] Submission URL
|
144
139
|
def submission_url
|
145
|
-
return
|
146
|
-
return Lib.get_submission_url @handle
|
140
|
+
return Lib.get_submission_url @handle if @read
|
147
141
|
end
|
148
142
|
|
149
143
|
# DiscID to String conversion. Same as calling the method {#id} but guaranteed
|
@@ -167,26 +161,37 @@ module DiscId
|
|
167
161
|
# @return [Array<TrackInfo>] Array of {TrackInfo} objects.
|
168
162
|
def tracks
|
169
163
|
if @read
|
170
|
-
|
171
|
-
tracks = []
|
164
|
+
read_tracks if @tracks.nil?
|
172
165
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
track_info = TrackInfo.new(track_number, offset, length, isrc)
|
179
|
-
|
180
|
-
if block_given?
|
181
|
-
yield track_info
|
182
|
-
else
|
183
|
-
tracks << track_info
|
184
|
-
end
|
166
|
+
if block_given?
|
167
|
+
@tracks.each(&Proc.new)
|
168
|
+
return nil
|
169
|
+
else
|
170
|
+
return @tracks
|
185
171
|
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
private
|
176
|
+
|
177
|
+
def read_tracks
|
178
|
+
track_number = self.first_track_number - 1
|
179
|
+
@tracks = []
|
180
|
+
|
181
|
+
while track_number < self.last_track_number do
|
182
|
+
track_number += 1
|
183
|
+
isrc = Lib.get_track_isrc(@handle, track_number)
|
184
|
+
offset = Lib.get_track_offset(@handle, track_number)
|
185
|
+
length = Lib.get_track_length(@handle, track_number)
|
186
|
+
track_info = TrackInfo.new(track_number, offset, length, isrc)
|
186
187
|
|
187
|
-
|
188
|
+
@tracks << track_info
|
188
189
|
end
|
189
190
|
end
|
190
191
|
|
191
192
|
end
|
193
|
+
|
194
|
+
# This exception is thrown on errors reading the disc or setting the TOC.
|
195
|
+
class DiscError < StandardError
|
196
|
+
end
|
192
197
|
end
|
data/lib/discid/lib.rb
CHANGED
data/lib/discid/track_info.rb
CHANGED
@@ -109,7 +109,7 @@ module DiscId
|
|
109
109
|
# puts track[:sectors] # 16007
|
110
110
|
def [](key)
|
111
111
|
if [:number, :sectors, :start_sector, :end_sector,
|
112
|
-
:seconds, :start_time, :end_time].include?(key.to_sym)
|
112
|
+
:seconds, :start_time, :end_time, :isrc].include?(key.to_sym)
|
113
113
|
method(key).call
|
114
114
|
end
|
115
115
|
end
|
@@ -119,6 +119,7 @@ module DiscId
|
|
119
119
|
# @return [Hash]
|
120
120
|
def to_hash
|
121
121
|
{
|
122
|
+
:number => number,
|
122
123
|
:sectors => sectors,
|
123
124
|
:start_sector => start_sector,
|
124
125
|
:end_sector => end_sector,
|
data/lib/discid/version.rb
CHANGED
data/test/test_disc.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# Copyright (C) 2013 Philipp Wolfer
|
2
|
+
#
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require 'test/unit'
|
17
|
+
require 'discid'
|
18
|
+
|
19
|
+
# Unit test for the DiscId::Disc class.
|
20
|
+
class TestDisc < Test::Unit::TestCase
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@fiction_disc_id = 'Wn8eRBtfLDfM0qjYPdxrz.Zjs_U-'
|
24
|
+
@fiction_first_track = 1
|
25
|
+
@fiction_last_track = 10
|
26
|
+
@fiction_sectors = 206535
|
27
|
+
@fiction_seconds = 2754
|
28
|
+
@fiction_offsets = [150, 18901, 39738, 59557, 79152, 100126,
|
29
|
+
124833, 147278, 166336, 182560]
|
30
|
+
@fiction_lengths = [18751, 20837, 19819, 19595, 20974,
|
31
|
+
24707, 22445, 19058, 16224, 23975]
|
32
|
+
end
|
33
|
+
|
34
|
+
def teardown
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_empty_disc
|
38
|
+
disc = DiscId::Disc.new
|
39
|
+
assert_equal nil, disc.id
|
40
|
+
assert_equal nil, disc.freedb_id
|
41
|
+
assert_equal '', disc.to_s
|
42
|
+
assert_equal nil, disc.first_track_number
|
43
|
+
assert_equal nil, disc.last_track_number
|
44
|
+
assert_equal nil, disc.sectors
|
45
|
+
assert_equal nil, disc.seconds
|
46
|
+
assert_equal nil, disc.tracks
|
47
|
+
assert_equal nil, disc.device
|
48
|
+
assert_equal nil, disc.submission_url
|
49
|
+
assert_equal nil, disc.mcn
|
50
|
+
assert_equal nil, disc.device
|
51
|
+
end
|
52
|
+
|
53
|
+
# Test calculation of the disc id if the TOC information
|
54
|
+
# gets set by the put method.
|
55
|
+
# All attributes should be nil after a failure, even if there was a
|
56
|
+
# successfull put before.
|
57
|
+
def test_put
|
58
|
+
disc = DiscId::Disc.new
|
59
|
+
|
60
|
+
# Erroneous put
|
61
|
+
assert_raise(DiscId::DiscError) do
|
62
|
+
disc = DiscId.put(-1, @fiction_sectors, @fiction_offsets)
|
63
|
+
end
|
64
|
+
assert_equal nil, disc.id
|
65
|
+
assert_equal '', disc.to_s
|
66
|
+
assert_equal nil, disc.first_track_number
|
67
|
+
assert_equal nil, disc.last_track_number
|
68
|
+
assert_equal nil, disc.sectors
|
69
|
+
assert_equal nil, disc.seconds
|
70
|
+
assert_equal nil, disc.tracks
|
71
|
+
|
72
|
+
# Second successfull put
|
73
|
+
assert_nothing_raised do
|
74
|
+
disc = DiscId.put(@fiction_first_track, @fiction_sectors,
|
75
|
+
@fiction_offsets)
|
76
|
+
end
|
77
|
+
assert_equal @fiction_disc_id, disc.id
|
78
|
+
assert_equal @fiction_disc_id, disc.to_s
|
79
|
+
assert_equal @fiction_first_track, disc.first_track_number
|
80
|
+
assert_equal @fiction_last_track, disc.last_track_number
|
81
|
+
assert_equal @fiction_sectors, disc.sectors
|
82
|
+
assert_equal @fiction_seconds, disc.seconds
|
83
|
+
assert_equal @fiction_offsets, disc.tracks.map{|t| t.start_sector}
|
84
|
+
assert_equal @fiction_lengths, disc.tracks.map{|t| t.sectors}
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
data/test/test_discid.rb
CHANGED
@@ -1,7 +1,17 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
1
|
+
# Copyright (C) 2013 Philipp Wolfer
|
2
|
+
#
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
5
15
|
|
6
16
|
require 'test/unit'
|
7
17
|
require 'discid'
|
@@ -16,8 +26,8 @@ class NotAString
|
|
16
26
|
|
17
27
|
end
|
18
28
|
|
19
|
-
# Unit test for the
|
20
|
-
class
|
29
|
+
# Unit test for the DiscId module.
|
30
|
+
class TestDiscId < Test::Unit::TestCase
|
21
31
|
|
22
32
|
def setup
|
23
33
|
@fiction_disc_id = 'Wn8eRBtfLDfM0qjYPdxrz.Zjs_U-'
|
@@ -44,60 +54,27 @@ class TestDiscID < Test::Unit::TestCase
|
|
44
54
|
# Those reads should all fail, but they must never cause a segmentation fault.
|
45
55
|
def test_read_invalid_arguments
|
46
56
|
assert_raise(TypeError) {DiscId.read(NotAString.new)}
|
47
|
-
assert_raise(
|
48
|
-
assert_raise(
|
49
|
-
assert_raise(
|
50
|
-
# assert_raise(ArgumentError) {disc.read(DiscId::DiscId.default_device,
|
51
|
-
# 'second argument')}
|
57
|
+
assert_raise(DiscId::DiscError) {DiscId.read(1)}
|
58
|
+
assert_raise(DiscId::DiscError) {DiscId.read('invalid_device')}
|
59
|
+
assert_raise(DiscId::DiscError) {DiscId.read(:invalid_device)}
|
52
60
|
end
|
53
61
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
assert_equal nil, disc.id
|
61
|
-
assert_equal '', disc.to_s
|
62
|
-
assert_equal nil, disc.first_track_num
|
63
|
-
assert_equal nil, disc.last_track_num
|
64
|
-
assert_equal nil, disc.sectors
|
65
|
-
assert_equal nil, disc.seconds
|
66
|
-
assert_equal nil, disc.tracks
|
67
|
-
assert_equal nil, disc.device
|
68
|
-
|
69
|
-
# Erroneous put
|
70
|
-
assert_raise(Exception) {disc = DiscId.put(-1, @fiction_sectors, @fiction_offsets)}
|
71
|
-
assert_equal nil, disc.id
|
72
|
-
assert_equal '', disc.to_s
|
73
|
-
assert_equal nil, disc.first_track_num
|
74
|
-
assert_equal nil, disc.last_track_num
|
75
|
-
assert_equal nil, disc.sectors
|
76
|
-
assert_equal nil, disc.seconds
|
77
|
-
assert_equal nil, disc.tracks
|
78
|
-
assert_equal nil, disc.device
|
79
|
-
|
80
|
-
# Second successfull put
|
81
|
-
assert_nothing_raised {disc = DiscId.put(@fiction_first_track, @fiction_sectors,
|
82
|
-
@fiction_offsets)}
|
83
|
-
assert_equal @fiction_disc_id, disc.id
|
84
|
-
assert_equal @fiction_disc_id, disc.to_s
|
85
|
-
assert_equal @fiction_first_track, disc.first_track_num
|
86
|
-
assert_equal @fiction_last_track, disc.last_track_num
|
87
|
-
assert_equal @fiction_sectors, disc.sectors
|
88
|
-
assert_equal @fiction_seconds, disc.seconds
|
89
|
-
assert_equal @fiction_offsets, disc.tracks.map{|t| t.start_sector}
|
90
|
-
assert_equal @fiction_lengths, disc.tracks.map{|t| t.sectors}
|
91
|
-
assert_equal nil, disc.device
|
62
|
+
def test_put_first_track_not_one
|
63
|
+
disc = DiscId.put(3, @fiction_sectors,
|
64
|
+
@fiction_offsets)
|
65
|
+
assert_equal 3, disc.first_track_number
|
66
|
+
assert_equal 12, disc.last_track_number
|
67
|
+
assert_equal 10, disc.tracks.size
|
92
68
|
end
|
93
69
|
|
94
70
|
# Test the tracks method and TrackInfo objects
|
95
|
-
def
|
71
|
+
def test_put_and_tracks
|
96
72
|
disc = nil
|
97
73
|
|
98
|
-
assert_nothing_raised
|
99
|
-
|
100
|
-
|
74
|
+
assert_nothing_raised do
|
75
|
+
disc = DiscId.put(@fiction_first_track, @fiction_sectors,
|
76
|
+
@fiction_offsets)
|
77
|
+
end
|
101
78
|
|
102
79
|
# Save a block for testing each track
|
103
80
|
number = 0
|
@@ -109,21 +86,13 @@ class TestDiscID < Test::Unit::TestCase
|
|
109
86
|
assert_equal @fiction_offsets[number]+ @fiction_lengths[number],
|
110
87
|
track.end_sector
|
111
88
|
|
112
|
-
assert_equal
|
113
|
-
|
114
|
-
assert_equal
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
assert_equal track.sectors, track[:sectors]
|
120
|
-
assert_equal track.start_sector, track[:start_sector]
|
121
|
-
assert_equal track.end_sector, track[:end_sector]
|
122
|
-
assert_equal track.seconds, track[:seconds]
|
123
|
-
assert_equal track.start_time, track[:start_time]
|
124
|
-
assert_equal track.end_time, track[:end_time]
|
125
|
-
|
126
|
-
assert_equal nil, track[:invalid_value]
|
89
|
+
assert_equal(DiscId.sectors_to_seconds(@fiction_offsets[number]),
|
90
|
+
track.start_time)
|
91
|
+
assert_equal(DiscId.sectors_to_seconds(@fiction_lengths[number]),
|
92
|
+
track.seconds)
|
93
|
+
assert_equal(DiscId.sectors_to_seconds(
|
94
|
+
@fiction_offsets[number]+ @fiction_lengths[number]),
|
95
|
+
track.end_time)
|
127
96
|
|
128
97
|
number += 1
|
129
98
|
end
|
@@ -133,12 +102,13 @@ class TestDiscID < Test::Unit::TestCase
|
|
133
102
|
assert_nothing_raised {track_info = disc.tracks}
|
134
103
|
assert track_info.is_a?(Array)
|
135
104
|
track_info.each(&proc_test_track)
|
136
|
-
assert_equal disc.
|
105
|
+
assert_equal disc.last_track_number, number
|
137
106
|
|
138
107
|
# Calling track_info directly with a given block
|
139
|
-
|
108
|
+
# Reset the number of tracks (the above block is a closure, so this works)
|
109
|
+
number = 0
|
140
110
|
assert_equal nil, disc.tracks(&proc_test_track)
|
141
|
-
assert_equal disc.
|
111
|
+
assert_equal disc.last_track_number, number
|
142
112
|
end
|
143
113
|
|
144
114
|
# Test the conversion from sectors to seconds
|
@@ -164,4 +134,15 @@ class TestDiscID < Test::Unit::TestCase
|
|
164
134
|
"Feature :read should be supported")
|
165
135
|
end
|
166
136
|
|
137
|
+
def test_libdiscid_version_should_start_with_libdiscid
|
138
|
+
version = DiscId::LIBDISCID_VERSION
|
139
|
+
assert version.kind_of?(String)
|
140
|
+
assert version.start_with?("libdiscid")
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_default_device_is_a_string
|
144
|
+
device = DiscId.default_device
|
145
|
+
assert device.kind_of?(String)
|
146
|
+
end
|
147
|
+
|
167
148
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# Copyright (C) 2013 Philipp Wolfer
|
2
|
+
#
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require 'test/unit'
|
17
|
+
require 'discid/track_info'
|
18
|
+
|
19
|
+
# Unit test for the DiscId::TrackInfo class.
|
20
|
+
class TestTrackInfo < Test::Unit::TestCase
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@number = 3
|
24
|
+
@offset = 1035
|
25
|
+
@length = 23643
|
26
|
+
@isrc = "US4E40731510"
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_init_track_info
|
30
|
+
track = DiscId::TrackInfo.new @number, @offset, @length, @isrc
|
31
|
+
|
32
|
+
assert_equal @number, track.number
|
33
|
+
assert_equal @offset, track.start_sector
|
34
|
+
assert_equal @length, track.sectors
|
35
|
+
assert_equal @isrc, track.isrc
|
36
|
+
|
37
|
+
assert_equal @offset + @length, track.end_sector
|
38
|
+
assert_equal 315, track.seconds
|
39
|
+
assert_equal 14, track.start_time
|
40
|
+
assert_equal 329, track.end_time
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_to_hash
|
44
|
+
track = DiscId::TrackInfo.new @number, @offset, @length, @isrc
|
45
|
+
hash = track.to_hash
|
46
|
+
|
47
|
+
assert_equal track.number, hash[:number]
|
48
|
+
assert_equal track.start_sector, hash[:start_sector]
|
49
|
+
assert_equal track.sectors, hash[:sectors]
|
50
|
+
assert_equal track.isrc, hash[:isrc]
|
51
|
+
|
52
|
+
assert_equal track.end_sector, hash[:end_sector]
|
53
|
+
assert_equal track.seconds, hash[:seconds]
|
54
|
+
assert_equal track.start_time, hash[:start_time]
|
55
|
+
assert_equal track.end_time, hash[:end_time]
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_selector_access
|
59
|
+
track = DiscId::TrackInfo.new @number, @offset, @length, @isrc
|
60
|
+
|
61
|
+
assert_equal track.number, track[:number]
|
62
|
+
assert_equal track.start_sector, track[:start_sector]
|
63
|
+
assert_equal track.sectors, track[:sectors]
|
64
|
+
assert_equal track.isrc, track[:isrc]
|
65
|
+
|
66
|
+
assert_equal track.end_sector, track[:end_sector]
|
67
|
+
assert_equal track.seconds, track[:seconds]
|
68
|
+
assert_equal track.start_time, track[:start_time]
|
69
|
+
assert_equal track.end_time, track[:end_time]
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_invalid_selector_value
|
73
|
+
track = DiscId::TrackInfo.new @number, @offset, @length, @isrc
|
74
|
+
assert_equal nil, track[:invalid_value]
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0rc2
|
5
|
+
prerelease: 5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Philipp Wolfer
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
@@ -105,18 +105,19 @@ files:
|
|
105
105
|
- .yardopts
|
106
106
|
- CHANGES
|
107
107
|
- Gemfile
|
108
|
-
- LICENSE
|
108
|
+
- LICENSE
|
109
109
|
- README.md
|
110
110
|
- Rakefile
|
111
|
-
- changelog
|
112
111
|
- discid.gemspec
|
113
|
-
- examples/
|
112
|
+
- examples/readdiscid.rb
|
114
113
|
- lib/discid.rb
|
115
114
|
- lib/discid/disc.rb
|
116
115
|
- lib/discid/lib.rb
|
117
116
|
- lib/discid/track_info.rb
|
118
117
|
- lib/discid/version.rb
|
118
|
+
- test/test_disc.rb
|
119
119
|
- test/test_discid.rb
|
120
|
+
- test/test_track_info.rb
|
120
121
|
homepage: https://github.com/phw/ruby-discid
|
121
122
|
licenses:
|
122
123
|
- LGPL-3
|
@@ -137,12 +138,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
138
|
- - ! '>'
|
138
139
|
- !ruby/object:Gem::Version
|
139
140
|
version: 1.3.1
|
140
|
-
requirements:
|
141
|
+
requirements:
|
142
|
+
- libdiscid >= 0.1.0
|
141
143
|
rubyforge_project:
|
142
144
|
rubygems_version: 1.8.23
|
143
145
|
signing_key:
|
144
146
|
specification_version: 3
|
145
147
|
summary: Ruby bindings for libdiscid
|
146
148
|
test_files:
|
149
|
+
- test/test_disc.rb
|
147
150
|
- test/test_discid.rb
|
151
|
+
- test/test_track_info.rb
|
148
152
|
has_rdoc:
|
data/changelog
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
mb-discid (0.2.0-1) quantal; urgency=low
|
2
|
-
|
3
|
-
* Fixed build dependencies
|
4
|
-
|
5
|
-
-- Philipp Wolfer <ph.wolfer@gmail.com> Mon, 18 Feb 2013 08:59:35 +0100
|
6
|
-
|
7
|
-
mb-discid (0.2.0-0) quantal; urgency=low
|
8
|
-
|
9
|
-
* New upstream release
|
10
|
-
|
11
|
-
-- Philipp Wolfer <ph.wolfer@gmail.com> Sun, 17 Feb 2013 15:56:01 +0100
|
12
|
-
|
13
|
-
mb-discid (0.1.5-0) lucid; urgency=low
|
14
|
-
|
15
|
-
* New upstream release
|
16
|
-
|
17
|
-
-- Philipp Wolfer <ph.wolfer@googlemail.com> Sat, 02 Jul 2011 16:14:51 +0200
|
18
|
-
|
19
|
-
mb-discid (0.1.4-2) lucid; urgency=low
|
20
|
-
|
21
|
-
* Fixed building on Maverick and Natty
|
22
|
-
|
23
|
-
-- Philipp Wolfer <ph.wolfer@googlemail.com> Mon, 16 May 2011 00:05:40 +0200
|
24
|
-
|
25
|
-
mb-discid (0.1.4-1) karmic; urgency=low
|
26
|
-
|
27
|
-
* New upstream release
|
28
|
-
|
29
|
-
-- Philipp Wolfer <ph.wolfer@googlemail.com> Mon, 14 Jun 2010 23:10:51 +0200
|
30
|
-
|
31
|
-
mb-discid (0.1.2-1) gutsy; urgency=low
|
32
|
-
|
33
|
-
* Initial packaging
|
34
|
-
|
35
|
-
-- Philipp Wolfer <phw@rubyforge.org> Mon, 17 Dec 2007 22:56:57 +0100
|