mini_exiftool 2.11.0 → 2.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog +4 -0
- data/lib/mini_exiftool.rb +1 -1
- metadata +42 -46
- data/.aspell.pws +0 -123
- data/Rakefile +0 -40
- data/mini_exiftool.gemspec +0 -31
- data/regtest/read_all.rb +0 -12
- data/regtest/read_all.yml +0 -575
- data/test/data/Bad_PreviewIFD.jpg +0 -0
- data/test/data/Canon.jpg +0 -0
- data/test/data/INFORMATION +0 -3
- data/test/data/invalid_byte_sequence_in_utf8.json +0 -4
- data/test/data/invalid_rational.json +0 -3
- data/test/data/test.jpg +0 -0
- data/test/data/test.jpg.json +0 -106
- data/test/data/test_coordinates.jpg +0 -0
- data/test/data/test_encodings.jpg +0 -0
- data/test/data/test_special_dates.jpg +0 -0
- data/test/helpers_for_test.rb +0 -25
- data/test/test_bad_preview_ifd.rb +0 -29
- data/test/test_class_methods.rb +0 -80
- data/test/test_composite.rb +0 -19
- data/test/test_copy_tags_from.rb +0 -55
- data/test/test_dumping.rb +0 -80
- data/test/test_encodings.rb +0 -30
- data/test/test_filename_access.rb +0 -60
- data/test/test_from_hash.rb +0 -22
- data/test/test_instance_methods.rb +0 -24
- data/test/test_invalid_byte_sequence_in_utf8.rb +0 -29
- data/test/test_invalid_rational.rb +0 -13
- data/test/test_io.rb +0 -67
- data/test/test_pstore.rb +0 -37
- data/test/test_read.rb +0 -49
- data/test/test_read_coordinates.rb +0 -18
- data/test/test_read_numerical.rb +0 -40
- data/test/test_save.rb +0 -73
- data/test/test_special.rb +0 -42
- data/test/test_special_dates.rb +0 -52
- data/test/test_write.rb +0 -161
Binary file
|
Binary file
|
Binary file
|
data/test/helpers_for_test.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# -- encoding: utf-8 --
|
2
|
-
require 'mini_exiftool'
|
3
|
-
require 'test/unit'
|
4
|
-
require 'fileutils'
|
5
|
-
require 'tempfile'
|
6
|
-
require 'yaml'
|
7
|
-
|
8
|
-
include Test::Unit
|
9
|
-
|
10
|
-
module TempfileTest
|
11
|
-
def setup
|
12
|
-
@temp_file = Tempfile.new('test')
|
13
|
-
@temp_filename = @temp_file.path
|
14
|
-
@data_dir = File.dirname(__FILE__) + '/data'
|
15
|
-
end
|
16
|
-
|
17
|
-
def teardown
|
18
|
-
@temp_file.close
|
19
|
-
end
|
20
|
-
|
21
|
-
def assert_md5 md5, filename
|
22
|
-
assert_equal md5, Digest::MD5.hexdigest(File.read(filename))
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# -- encoding: utf-8 --
|
2
|
-
require 'helpers_for_test'
|
3
|
-
|
4
|
-
class TestBadPreviewIFD < TestCase
|
5
|
-
|
6
|
-
include TempfileTest
|
7
|
-
|
8
|
-
def setup
|
9
|
-
super
|
10
|
-
@org_filename = @data_dir + '/Bad_PreviewIFD.jpg'
|
11
|
-
FileUtils.cp @org_filename, @temp_filename
|
12
|
-
@bad_preview_ifd = MiniExiftool.new @temp_filename
|
13
|
-
end
|
14
|
-
|
15
|
-
# Feature request rubyforge [#29587]
|
16
|
-
# Thanks to Michael Grove for reporting
|
17
|
-
def test_m_option
|
18
|
-
title = 'anything'
|
19
|
-
@bad_preview_ifd.title = title
|
20
|
-
assert_equal false, @bad_preview_ifd.save, '-m option seems to be not neccessary'
|
21
|
-
@bad_preview_ifd.reload
|
22
|
-
@bad_preview_ifd.title = title
|
23
|
-
@bad_preview_ifd.ignore_minor_errors = true
|
24
|
-
assert_equal true, @bad_preview_ifd.save, 'Error while saving'
|
25
|
-
@bad_preview_ifd.reload
|
26
|
-
assert_equal title, @bad_preview_ifd.title
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
data/test/test_class_methods.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
# -- encoding: utf-8 --
|
2
|
-
require 'helpers_for_test'
|
3
|
-
|
4
|
-
class TestClassMethods < TestCase
|
5
|
-
|
6
|
-
def test_new
|
7
|
-
assert_nothing_raised do
|
8
|
-
@mini_exiftool = MiniExiftool.new
|
9
|
-
end
|
10
|
-
assert_equal nil, @mini_exiftool.filename
|
11
|
-
assert_nothing_raised do
|
12
|
-
MiniExiftool.new nil
|
13
|
-
end
|
14
|
-
assert_raises MiniExiftool::Error do
|
15
|
-
MiniExiftool.new false
|
16
|
-
end
|
17
|
-
assert_raises MiniExiftool::Error do
|
18
|
-
MiniExiftool.new ''
|
19
|
-
end
|
20
|
-
assert_raises MiniExiftool::Error do
|
21
|
-
MiniExiftool.new 'not_existing_file'
|
22
|
-
end
|
23
|
-
assert_raises MiniExiftool::Error do
|
24
|
-
MiniExiftool.new '.' # directory
|
25
|
-
end
|
26
|
-
begin
|
27
|
-
MiniExiftool.new 'not_existing_file'
|
28
|
-
rescue MiniExiftool::Error => e
|
29
|
-
assert_match /File 'not_existing_file' does not exist/, e.message
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_command
|
34
|
-
cmd = MiniExiftool.command
|
35
|
-
assert_equal 'exiftool', cmd
|
36
|
-
MiniExiftool.command = 'non_existend'
|
37
|
-
assert_equal 'non_existend', MiniExiftool.command
|
38
|
-
assert_raises MiniExiftool::Error do
|
39
|
-
met = MiniExiftool.new(File.join(File.dirname(__FILE__),
|
40
|
-
'data/test.jpg'))
|
41
|
-
end
|
42
|
-
MiniExiftool.command = cmd
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_opts
|
46
|
-
opts = MiniExiftool.opts
|
47
|
-
assert_kind_of Hash, opts
|
48
|
-
begin
|
49
|
-
org = MiniExiftool.opts[:composite]
|
50
|
-
met1 = MiniExiftool.new
|
51
|
-
MiniExiftool.opts[:composite] = !org
|
52
|
-
met2 = MiniExiftool.new
|
53
|
-
MiniExiftool.opts[:composite] = org
|
54
|
-
met3 = MiniExiftool.new
|
55
|
-
assert_equal org, met1.composite
|
56
|
-
assert_equal !org, met2.composite
|
57
|
-
assert_equal org, met1.composite
|
58
|
-
ensure
|
59
|
-
MiniExiftool.opts[:composite] = org
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_all_tags
|
64
|
-
all_tags = MiniExiftool.all_tags
|
65
|
-
assert all_tags.include?('ISO')
|
66
|
-
assert all_tags.include?('ExifToolVersion')
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_writable_tags
|
70
|
-
w_tags = MiniExiftool.writable_tags
|
71
|
-
assert w_tags.include?('ISO')
|
72
|
-
assert ! w_tags.include?('ExifToolVersion')
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_exiftool_version
|
76
|
-
v = MiniExiftool.exiftool_version
|
77
|
-
assert_match /\A\d+\.\d+\z/, v
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
data/test/test_composite.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# -- encoding: utf-8 --
|
2
|
-
require 'helpers_for_test'
|
3
|
-
|
4
|
-
class TestComposite < TestCase
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@data_dir = File.dirname(__FILE__) + '/data'
|
8
|
-
@filename_test = @data_dir + '/test.jpg'
|
9
|
-
@mini_exiftool = MiniExiftool.new @filename_test, :composite => false
|
10
|
-
@mini_exiftool_c = MiniExiftool.new @filename_test
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_composite_tags
|
14
|
-
assert_equal false, @mini_exiftool.tags.include?('Aperture')
|
15
|
-
assert_equal true, @mini_exiftool_c.tags.include?('Aperture')
|
16
|
-
assert_equal 9.5, @mini_exiftool_c['Aperture']
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
data/test/test_copy_tags_from.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
# -- encoding: utf-8 --
|
2
|
-
require 'helpers_for_test'
|
3
|
-
|
4
|
-
class TestCopyTagsFrom < TestCase
|
5
|
-
|
6
|
-
include TempfileTest
|
7
|
-
|
8
|
-
def setup
|
9
|
-
super
|
10
|
-
@canon_filename = @data_dir + '/Canon.jpg'
|
11
|
-
FileUtils.cp(@canon_filename, @temp_filename)
|
12
|
-
@mini_exiftool = MiniExiftool.new(@temp_filename)
|
13
|
-
@source_filename = @data_dir + '/test.jpg'
|
14
|
-
@canon_md5 = Digest::MD5.hexdigest(File.read(@canon_filename))
|
15
|
-
@source_md5 = Digest::MD5.hexdigest(File.read(@source_filename))
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_single_tag
|
19
|
-
assert_nil @mini_exiftool.title
|
20
|
-
res = @mini_exiftool.copy_tags_from(@source_filename, :title)
|
21
|
-
assert res
|
22
|
-
assert_equal 'Abenddämmerung', @mini_exiftool.title
|
23
|
-
assert_md5 @source_md5, @source_filename
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_more_than_one_tag
|
27
|
-
assert_nil @mini_exiftool.title
|
28
|
-
assert_nil @mini_exiftool.keywords
|
29
|
-
res = @mini_exiftool.copy_tags_from(@source_filename, %w[title keywords])
|
30
|
-
assert res
|
31
|
-
assert_equal 'Abenddämmerung', @mini_exiftool.title
|
32
|
-
assert_equal %w[Orange Rot], @mini_exiftool.keywords
|
33
|
-
assert_md5 @source_md5, @source_filename
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_non_existing_sourcefile
|
37
|
-
assert_raises MiniExiftool::Error do
|
38
|
-
@mini_exiftool.copy_tags_from('non_existend_file', :title)
|
39
|
-
end
|
40
|
-
assert_md5 @source_md5, @source_filename
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_non_existend_tag
|
44
|
-
@mini_exiftool.copy_tags_from(@source_filename, :non_existend_tag)
|
45
|
-
assert_md5 @canon_md5, @canon_filename
|
46
|
-
assert_md5 @source_md5, @source_filename
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_non_writable_tag
|
50
|
-
@mini_exiftool.copy_tags_from(@source_filename, 'JFIF')
|
51
|
-
assert_md5 @canon_md5, @canon_filename
|
52
|
-
assert_md5 @source_md5, @source_filename
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
data/test/test_dumping.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
# -- encoding: utf-8 --
|
2
|
-
require 'helpers_for_test'
|
3
|
-
|
4
|
-
class TestDumping < TestCase
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@data_dir = File.dirname(__FILE__) + '/data'
|
8
|
-
@filename_test = @data_dir + '/test.jpg'
|
9
|
-
@mini_exiftool = MiniExiftool.new @filename_test
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_to_hash
|
13
|
-
hash = @mini_exiftool.to_hash
|
14
|
-
assert_equal Hash, hash.class
|
15
|
-
assert_equal @mini_exiftool.tags.size, hash.size, 'Size of Hash is not correct.'
|
16
|
-
assert_not_nil hash['ExifToolVersion'], 'Original name of exiftool tag is not preserved.'
|
17
|
-
all_ok = true
|
18
|
-
different_tag = ''
|
19
|
-
v = ''
|
20
|
-
hash.each do |k,v|
|
21
|
-
unless @mini_exiftool[k] == v
|
22
|
-
all_ok = false
|
23
|
-
different_tag = k
|
24
|
-
break
|
25
|
-
end
|
26
|
-
end
|
27
|
-
assert all_ok, "Tag #{different_tag.inspect}: expected: #{@mini_exiftool[different_tag].inspect}, actual: #{v.inspect}"
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_from_hash
|
31
|
-
hash = @mini_exiftool.to_hash
|
32
|
-
mini_exiftool_new = MiniExiftool.from_hash hash
|
33
|
-
assert_equal MiniExiftool, mini_exiftool_new.class
|
34
|
-
assert_equal @mini_exiftool.tags.size, mini_exiftool_new.tags.size
|
35
|
-
all_ok = true
|
36
|
-
different_tag = ''
|
37
|
-
@mini_exiftool.tags.each do |tag|
|
38
|
-
unless @mini_exiftool[tag] == mini_exiftool_new[tag]
|
39
|
-
all_ok = false
|
40
|
-
different_tag = tag
|
41
|
-
break
|
42
|
-
end
|
43
|
-
end
|
44
|
-
assert all_ok, "Tag #{different_tag.inspect}: expected: #{@mini_exiftool[different_tag].inspect}, actual: #{mini_exiftool_new[different_tag].inspect}"
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_to_yaml
|
49
|
-
hash = @mini_exiftool.to_hash
|
50
|
-
yaml = @mini_exiftool.to_yaml
|
51
|
-
assert_equal hash, YAML.unsafe_load(yaml)
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_from_yaml
|
55
|
-
hash = @mini_exiftool.to_hash
|
56
|
-
yaml = hash.to_yaml
|
57
|
-
mini_exiftool_new = MiniExiftool.from_yaml(yaml)
|
58
|
-
assert_equal MiniExiftool, mini_exiftool_new.class
|
59
|
-
assert_equal hash, mini_exiftool_new.to_hash
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_heuristics_for_restoring_composite
|
63
|
-
standard = @mini_exiftool.to_hash
|
64
|
-
no_composite = MiniExiftool.new(@filename_test, :composite => false).to_hash
|
65
|
-
assert_equal true, MiniExiftool.from_hash(standard).composite
|
66
|
-
assert_equal false, MiniExiftool.from_hash(no_composite).composite
|
67
|
-
assert_equal true, MiniExiftool.from_yaml(standard.to_yaml).composite
|
68
|
-
assert_equal false, MiniExiftool.from_yaml(no_composite.to_yaml).composite
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_heuristics_for_restoring_numerical
|
72
|
-
standard = @mini_exiftool.to_hash
|
73
|
-
numerical = MiniExiftool.new(@filename_test, :numerical => true).to_hash
|
74
|
-
assert_equal false, MiniExiftool.from_hash(standard).numerical
|
75
|
-
assert_equal true, MiniExiftool.from_hash(numerical).numerical
|
76
|
-
assert_equal false, MiniExiftool.from_yaml(standard.to_yaml).numerical
|
77
|
-
assert_equal true, MiniExiftool.from_yaml(numerical.to_yaml).numerical
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
data/test/test_encodings.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# -- encoding: utf-8 --
|
2
|
-
require 'helpers_for_test'
|
3
|
-
|
4
|
-
class TestEncodings < TestCase
|
5
|
-
|
6
|
-
include TempfileTest
|
7
|
-
|
8
|
-
def setup
|
9
|
-
super
|
10
|
-
@data_dir = File.dirname(__FILE__) + '/data'
|
11
|
-
@filename_test = @data_dir + '/test_encodings.jpg'
|
12
|
-
@mini_exiftool = MiniExiftool.new @filename_test
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_iptc_encoding
|
16
|
-
object_name = "Möhre"
|
17
|
-
assert_not_equal object_name, @mini_exiftool.object_name
|
18
|
-
correct_iptc = MiniExiftool.new(@filename_test, iptc_encoding: 'MacRoman')
|
19
|
-
assert_equal object_name, correct_iptc.object_name
|
20
|
-
FileUtils.cp(@filename_test, @temp_filename)
|
21
|
-
correct_iptc_write = MiniExiftool.new(@temp_filename, iptc_encoding: 'MacRoman')
|
22
|
-
caption = 'Das ist eine Möhre'
|
23
|
-
correct_iptc_write.caption_abstract = caption
|
24
|
-
correct_iptc_write.save!
|
25
|
-
correct_iptc_write.reload
|
26
|
-
assert_equal object_name, correct_iptc_write.object_name
|
27
|
-
assert_equal caption, correct_iptc_write.caption_abstract
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# -- encoding: utf-8 --
|
2
|
-
require 'helpers_for_test'
|
3
|
-
require 'rbconfig'
|
4
|
-
require 'tmpdir'
|
5
|
-
|
6
|
-
# Thanks to uwe58 and others for hints
|
7
|
-
|
8
|
-
class TestFilenameAccess < TestCase
|
9
|
-
|
10
|
-
@@running_on_windows = /mswin|mingw|cygwin/ === RbConfig::CONFIG['host_os']
|
11
|
-
|
12
|
-
@@fs_enc = Encoding.find('filesystem')
|
13
|
-
|
14
|
-
def create_testfile(basename_new)
|
15
|
-
tmpdir = Dir.tmpdir
|
16
|
-
filename_org = File.join(File.dirname(__FILE__), 'data/test.jpg')
|
17
|
-
filename_new = File.join(tmpdir, basename_new)
|
18
|
-
FileUtils.cp filename_org, filename_new.encode(@@fs_enc)
|
19
|
-
filename_new
|
20
|
-
end
|
21
|
-
|
22
|
-
def do_testing_with(basename)
|
23
|
-
filename_test = create_testfile(basename)
|
24
|
-
# read
|
25
|
-
m = MiniExiftool.new filename_test
|
26
|
-
assert_equal 400, m.iso
|
27
|
-
# save
|
28
|
-
m.iso = 200
|
29
|
-
m.save
|
30
|
-
assert_equal 200, m.iso
|
31
|
-
# Check original filename maybe with other encoding than filesystem
|
32
|
-
assert_equal basename, File.basename(m.filename)
|
33
|
-
rescue Exception => e
|
34
|
-
assert false, "File #{filename_test.inspect} not found!"
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_access_filename_with_spaces
|
38
|
-
do_testing_with 'filename with spaces.jpg'
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_access_filename_with_special_chars
|
42
|
-
do_testing_with 'filename_with_Ümläüts.jpg'
|
43
|
-
end
|
44
|
-
|
45
|
-
unless @@running_on_windows
|
46
|
-
def test_access_filename_with_doublequotes
|
47
|
-
do_testing_with 'filename_with_"doublequotes"_inside.jpg'
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_access_filename_with_dollar_sign
|
52
|
-
# Thanks to Michael Dungan for the hint
|
53
|
-
do_testing_with 'filename_with_$_sign.jpg'
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_access_filename_with_ampersand
|
57
|
-
do_testing_with 'filename_with_&_sign.jpg'
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
data/test/test_from_hash.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'helpers_for_test'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
class TestFromHash < TestCase
|
5
|
-
def setup
|
6
|
-
@data_dir = File.dirname(__FILE__) + '/data'
|
7
|
-
hash_data = JSON.parse(File.read( @data_dir + '/test.jpg.json')).first
|
8
|
-
@mini_exiftool = MiniExiftool.from_hash hash_data
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_conversion
|
12
|
-
assert_kind_of String, @mini_exiftool.model
|
13
|
-
assert_kind_of Time, @mini_exiftool['DateTimeOriginal']
|
14
|
-
assert_kind_of Float, @mini_exiftool['MaxApertureValue']
|
15
|
-
assert_kind_of String, @mini_exiftool.flash
|
16
|
-
assert_kind_of Integer, @mini_exiftool['ExposureCompensation']
|
17
|
-
assert_kind_of String, (@mini_exiftool['SubjectLocation'] || @mini_exiftool['SubjectArea'])
|
18
|
-
assert_kind_of Array, @mini_exiftool['Keywords']
|
19
|
-
assert_kind_of String, @mini_exiftool['SupplementalCategories']
|
20
|
-
assert_kind_of Rational, @mini_exiftool.shutterspeed
|
21
|
-
end
|
22
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# -- encoding: utf-8 --
|
2
|
-
require 'helpers_for_test'
|
3
|
-
|
4
|
-
class TestRead < TestCase
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@data_dir = File.dirname(__FILE__) + '/data'
|
8
|
-
@filename_test = @data_dir + '/test.jpg'
|
9
|
-
@mini_exiftool = MiniExiftool.new @filename_test
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_respond_to_missing
|
13
|
-
assert_true @mini_exiftool.respond_to?(:iso), 'instance should respond to iso because it has a value for ISO'
|
14
|
-
assert_true @mini_exiftool.respond_to?('iso'), 'instance should respond to iso because it has a value for ISO'
|
15
|
-
assert_true @mini_exiftool.respond_to?('ISO'), 'instance should respond to ISO because it has a value for ISO'
|
16
|
-
assert_true @mini_exiftool.respond_to?(:iso=), 'instance should respond to iso= because all setters are allowed'
|
17
|
-
assert_true @mini_exiftool.respond_to?('iso='), 'instance should respond to iso= because all setters are allowed'
|
18
|
-
assert_true @mini_exiftool.respond_to?('ISO='), 'instance should respond to ISO= because all setters are allowed'
|
19
|
-
assert_false @mini_exiftool.respond_to?(:comment), 'instance should not respond to comment because it has no value for Comment'
|
20
|
-
assert_false @mini_exiftool.respond_to?('comment'), 'instance should not respond to comment because it has no value for Comment'
|
21
|
-
assert_false @mini_exiftool.respond_to?('Comment'), 'instance should not respond to Comment because it has no value for Comment'
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# -- encoding: utf-8 --
|
2
|
-
require 'helpers_for_test'
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
# Thanks to Chris Salzberg (aka shioyama) and
|
6
|
-
# Robert May (aka robotmay) for precious hints
|
7
|
-
|
8
|
-
class TestInvalidByteSequenceInUtf8 < TestCase
|
9
|
-
|
10
|
-
def setup
|
11
|
-
@json = File.read(File.dirname(__FILE__) + '/data/invalid_byte_sequence_in_utf8.json')
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_invalid_byte_sequence_gets_unconverted_value_with_invalid_encoding
|
15
|
-
omit 'Java version of json gem can not handle invalid encoded data' if RUBY_PLATFORM == 'java'
|
16
|
-
assert_nothing_raised do
|
17
|
-
mini_exiftool = MiniExiftool.from_json(@json)
|
18
|
-
assert_equal 1561, mini_exiftool.color_balance_unknown.size
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_replace_invalid_chars
|
23
|
-
assert_nothing_raised do
|
24
|
-
mini_exiftool = MiniExiftool.from_json(@json, :replace_invalid_chars => '')
|
25
|
-
assert_equal 1036, mini_exiftool.color_balance_unknown.size
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# -- encoding: utf-8 --
|
2
|
-
require 'helpers_for_test'
|
3
|
-
|
4
|
-
class TestInvalidRational < TestCase
|
5
|
-
|
6
|
-
def test_rescue_from_invalid_rational
|
7
|
-
mini_exiftool = MiniExiftool.from_json(File.read('test/data/invalid_rational.json'))
|
8
|
-
assert_equal '1/0', mini_exiftool.user_comment
|
9
|
-
rescue Exception
|
10
|
-
assert false, 'Tag values of the form x/0 should not raise an Exception.'
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
data/test/test_io.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
# -- encoding: utf-8 --
|
2
|
-
require 'helpers_for_test'
|
3
|
-
require 'stringio'
|
4
|
-
|
5
|
-
class TestIo < TestCase
|
6
|
-
|
7
|
-
def test_simple_case
|
8
|
-
io = open_real_io
|
9
|
-
mini_exiftool = MiniExiftool.new(io)
|
10
|
-
assert_equal false, io.closed?, 'IO should not be closed.'
|
11
|
-
assert_equal 400, mini_exiftool.iso
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_non_readable_io
|
15
|
-
assert_raises MiniExiftool::Error do
|
16
|
-
begin
|
17
|
-
MiniExiftool.new($stdout)
|
18
|
-
rescue MiniExiftool::Error => e
|
19
|
-
assert_equal 'IO is not readable.', e.message
|
20
|
-
raise e
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_no_writing_when_using_io
|
26
|
-
io = open_real_io
|
27
|
-
m = MiniExiftool.new(io)
|
28
|
-
m.iso = 100
|
29
|
-
assert_raises MiniExiftool::Error do
|
30
|
-
begin
|
31
|
-
m.save
|
32
|
-
rescue MiniExiftool::Error => e
|
33
|
-
assert_equal 'No writing support when using an IO.', e.message
|
34
|
-
raise e
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_fast_options
|
40
|
-
$DEBUG = true
|
41
|
-
s = StringIO.new
|
42
|
-
$stderr = s
|
43
|
-
MiniExiftool.new open_real_io
|
44
|
-
s.rewind
|
45
|
-
assert_match /^exiftool -j "-"$/, s.read
|
46
|
-
s = StringIO.new
|
47
|
-
$stderr = s
|
48
|
-
MiniExiftool.new open_real_io, :fast => true
|
49
|
-
s.rewind
|
50
|
-
assert_match /^exiftool -j -fast "-"$/, s.read
|
51
|
-
s = StringIO.new
|
52
|
-
$stderr = s
|
53
|
-
MiniExiftool.new open_real_io, :fast2 => true
|
54
|
-
s.rewind
|
55
|
-
assert_match /^exiftool -j -fast2 "-"$/, s.read
|
56
|
-
ensure
|
57
|
-
$DEBUG = false
|
58
|
-
$stderr = STDERR
|
59
|
-
end
|
60
|
-
|
61
|
-
protected
|
62
|
-
|
63
|
-
def open_real_io
|
64
|
-
File.open(File.join(File.dirname(__FILE__), 'data', 'test.jpg'), 'r')
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
data/test/test_pstore.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# -- encoding: utf-8 --
|
2
|
-
require 'helpers_for_test'
|
3
|
-
|
4
|
-
class TestPstore < TestCase
|
5
|
-
|
6
|
-
def test_pstore
|
7
|
-
pstore_dir = Dir.mktmpdir
|
8
|
-
writable_tags = MiniExiftool.writable_tags
|
9
|
-
res = execute(pstore_dir)
|
10
|
-
t1 = res['time']
|
11
|
-
assert_equal writable_tags, res['writable_tags']
|
12
|
-
assert_equal 1, Dir[File.join(pstore_dir, '*')].size
|
13
|
-
res = execute(pstore_dir)
|
14
|
-
t2 = res['time']
|
15
|
-
assert_equal writable_tags, res['writable_tags']
|
16
|
-
assert t2 < 1.0, format('loading cached tag information should be done in under 1 second but needed %.2fs', t2)
|
17
|
-
assert 10 * t2 < t1, format('loading cached tag information (%.2fs) should be 10 times faster than loading uncached information (%.2fs)', t2, t1)
|
18
|
-
ensure
|
19
|
-
FileUtils.rm_rf pstore_dir
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def execute pstore_dir
|
25
|
-
script = <<-END
|
26
|
-
MiniExiftool.pstore_dir = '#{pstore_dir}'
|
27
|
-
res = {}
|
28
|
-
start = Time.now
|
29
|
-
res['writable_tags'] = MiniExiftool.writable_tags
|
30
|
-
res['time'] = Time.now - start
|
31
|
-
puts YAML.dump res
|
32
|
-
END
|
33
|
-
cmd = %Q(#{RUBY_ENGINE} -EUTF-8 -I lib -r mini_exiftool -r yaml -e "#{script}")
|
34
|
-
YAML.unsafe_load(`#{cmd}`)
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
data/test/test_read.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
# -- encoding: utf-8 --
|
2
|
-
require 'helpers_for_test'
|
3
|
-
|
4
|
-
class TestRead < TestCase
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@data_dir = File.dirname(__FILE__) + '/data'
|
8
|
-
@filename_test = @data_dir + '/test.jpg'
|
9
|
-
@mini_exiftool = MiniExiftool.new @filename_test
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_access
|
13
|
-
assert_equal 'DYNAX 7D', @mini_exiftool['Model']
|
14
|
-
assert_equal 'MLT0', @mini_exiftool['maker_note_version']
|
15
|
-
assert_equal 'MLT0', @mini_exiftool[:MakerNoteVersion]
|
16
|
-
assert_equal 'MLT0', @mini_exiftool[:maker_note_version]
|
17
|
-
assert_equal 'MLT0', @mini_exiftool.maker_note_version
|
18
|
-
assert_equal 400, @mini_exiftool.iso
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_tags
|
22
|
-
assert @mini_exiftool.tags.include?('FileSize')
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_conversion
|
26
|
-
assert_kind_of String, @mini_exiftool.model
|
27
|
-
assert_kind_of Time, @mini_exiftool['DateTimeOriginal']
|
28
|
-
assert_kind_of Float, @mini_exiftool['MaxApertureValue']
|
29
|
-
assert_kind_of String, @mini_exiftool.flash
|
30
|
-
assert_kind_of Integer, @mini_exiftool['ExposureCompensation']
|
31
|
-
assert_kind_of String, (@mini_exiftool['SubjectLocation'] || @mini_exiftool['SubjectArea'])
|
32
|
-
assert_kind_of Array, @mini_exiftool['Keywords']
|
33
|
-
assert_kind_of String, @mini_exiftool['SupplementalCategories']
|
34
|
-
assert_kind_of Rational, @mini_exiftool.shutterspeed
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_list_tags
|
38
|
-
assert_equal ['Orange', 'Rot'], @mini_exiftool['Keywords']
|
39
|
-
assert_equal 'Natur', @mini_exiftool['SupplementalCategories']
|
40
|
-
assert_equal ['Natur'], Array(@mini_exiftool['SupplementalCategories'])
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_value_encoding
|
44
|
-
title= 'Abenddämmerung'
|
45
|
-
assert_equal Encoding::UTF_8, @mini_exiftool.title.encoding
|
46
|
-
assert_equal title, @mini_exiftool.title
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# -- encoding: utf-8 --
|
2
|
-
require 'helpers_for_test'
|
3
|
-
|
4
|
-
class TestReadCoordinates < TestCase
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@data_dir = File.dirname(__FILE__) + '/data'
|
8
|
-
@filename_test = @data_dir + '/test_coordinates.jpg'
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_access_coordinates
|
12
|
-
mini_exiftool_coord = MiniExiftool.new @filename_test, :coord_format => "%.6f degrees"
|
13
|
-
assert_match /^43.653167 degrees/, mini_exiftool_coord['GPSLatitude']
|
14
|
-
assert_match /^79.373167 degrees/, mini_exiftool_coord['GPSLongitude']
|
15
|
-
assert_match /^43.653167 degrees.*, 79.373167 degrees/, mini_exiftool_coord['GPSPosition']
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|