Skip to content

Commit 0f22dd4

Browse files
committed
wiki: Add unit test for image ext and size
Change-Id: Ic6896cade9756b266f3bcc9fbf174cd01c87ab21
1 parent 38dde35 commit 0f22dd4

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

test/validate.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,20 @@ def validate_json(schema, device_json, device_path)
2626
end
2727
end
2828

29-
def validate_image(path, device_path)
30-
unless File.file?(path)
29+
def validate_image(path, device_path, size)
30+
if !File.file?(path)
3131
puts "Missing image #{to_relative_path(path)} specified in #{to_relative_path(device_path)}"
3232
at_exit { exit false }
33+
elsif File.extname(path) != ".png"
34+
puts "Invalid image #{to_relative_path(path)} extension specified in #{to_relative_path(device_path)}"
35+
at_exit { exit false }
36+
else
37+
resolution = File.binread(path, 24)[0x10..0x18].unpack('NN')
38+
39+
if resolution[0] > size || resolution[1] > size
40+
puts "Image #{to_relative_path(path)} resolution #{resolution[0]}x#{resolution[1]} exceeds #{size}x#{size}"
41+
at_exit { exit false }
42+
end
3343
end
3444
end
3545

@@ -165,7 +175,7 @@ def validate_yaml_lint(path)
165175
end
166176

167177
image = device_json["image"]
168-
validate_image(device_image_dir + image, device_path)
169-
validate_image(device_image_small_dir + image, device_path)
178+
validate_image(device_image_dir + image, device_path, 500)
179+
validate_image(device_image_small_dir + image, device_path, 150)
170180
end
171181
end

0 commit comments

Comments
 (0)