-
Notifications
You must be signed in to change notification settings - Fork 50
/
test_write.rb
111 lines (99 loc) · 3.94 KB
/
test_write.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
require 'digest/md5'
require 'fileutils'
require 'tempfile'
require 'helpers_for_test'
class TestWrite < TestCase
def setup
@temp_file = Tempfile.new('test')
@temp_file.close
@temp_filename = @temp_file.path
@org_filename = File.dirname(__FILE__) + '/data/test.jpg'
FileUtils.cp(@org_filename, @temp_filename)
@mini_exiftool = MiniExiftool.new @temp_filename
@mini_exiftool_num = MiniExiftool.new @temp_filename, :numerical => true
end
def teardown
@temp_file.delete
end
def test_access_existing_tags
assert_equal 'Horizontal (normal)', @mini_exiftool['Orientation']
@mini_exiftool['Orientation'] = 'some string'
assert_equal 'some string', @mini_exiftool['Orientation']
assert_equal false, @mini_exiftool.changed?('Orientation')
@mini_exiftool['Orientation'] = 2
assert_equal 2, @mini_exiftool['Orientation']
assert @mini_exiftool.changed_tags.include?('Orientation')
@mini_exiftool.save
assert_equal 'Mirror horizontal', @mini_exiftool['Orientation']
@mini_exiftool_num.reload
assert_equal 2, @mini_exiftool_num['Orientation']
end
def test_access_existing_tags_numerical
assert_equal 1, @mini_exiftool_num['Orientation']
@mini_exiftool_num['Orientation'] = 2
assert_equal 2, @mini_exiftool_num['Orientation']
assert_equal 2, @mini_exiftool_num.orientation
@mini_exiftool_num.orientation = 3
assert_equal 3, @mini_exiftool_num.orientation
assert @mini_exiftool_num.changed_tags.include?('Orientation')
@mini_exiftool_num.save
assert_equal 3, @mini_exiftool_num['Orientation']
@mini_exiftool.reload
assert_equal 'Rotate 180', @mini_exiftool['Orientation']
end
def test_access_non_writable_tags
@mini_exiftool_num['FileSize'] = 1
assert_equal true, @mini_exiftool_num.changed?
@mini_exiftool_num['SomeNonWritableName'] = 'test'
assert_equal true, @mini_exiftool_num.changed?
end
def test_time_conversion
t = Time.now
@mini_exiftool_num['DateTimeOriginal'] = t
assert_kind_of Time, @mini_exiftool_num['DateTimeOriginal']
assert true, @mini_exiftool_num.changed_tags.include?('DateTimeOriginal')
@mini_exiftool_num.save
assert_equal false, @mini_exiftool_num.changed?
assert_kind_of Time, @mini_exiftool_num['DateTimeOriginal']
assert_equal t.to_s, @mini_exiftool_num['DateTimeOriginal'].to_s
end
def test_float_conversion
assert_kind_of Float, @mini_exiftool_num['BrightnessValue']
new_time = @mini_exiftool_num['BrightnessValue'] + 1
@mini_exiftool_num['BrightnessValue'] = new_time
assert_equal new_time, @mini_exiftool_num['BrightnessValue']
assert true, @mini_exiftool_num.changed_tags.include?('BrightnessValue')
@mini_exiftool_num.save
assert_kind_of Float, @mini_exiftool_num['BrightnessValue']
assert_equal new_time, @mini_exiftool_num['BrightnessValue']
end
def test_integer_conversion
assert_kind_of Integer, @mini_exiftool_num['MeteringMode']
new_mode = @mini_exiftool_num['MeteringMode'] - 1
@mini_exiftool_num['MeteringMode'] = new_mode
assert_equal new_mode, @mini_exiftool_num['MeteringMode']
assert @mini_exiftool_num.changed_tags.include?('MeteringMode')
@mini_exiftool_num.save
assert_equal new_mode, @mini_exiftool_num['MeteringMode']
end
def test_revert_one
@mini_exiftool_num['Orientation'] = 2
@mini_exiftool_num['ISO'] = 200
res = @mini_exiftool_num.revert 'Orientation'
assert_equal 1, @mini_exiftool_num['Orientation']
assert_equal 200, @mini_exiftool_num['ISO']
assert_equal true, res
res = @mini_exiftool_num.revert 'Orientation'
assert_equal false, res
end
def test_revert_all
@mini_exiftool_num['Orientation'] = 2
@mini_exiftool_num['ISO'] = 200
res = @mini_exiftool_num.revert
assert_equal 1, @mini_exiftool_num['Orientation']
assert_equal 400, @mini_exiftool_num['ISO']
assert_equal true, res
res = @mini_exiftool_num.revert
assert_equal false, res
end
end