Skip to content

Commit 0675697

Browse files
committed
Test largest cursor
1 parent bf18e5f commit 0675697

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Tests/test_file_cur.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
from __future__ import annotations
22

3+
from io import BytesIO
4+
35
import pytest
46

57
from PIL import CurImagePlugin, Image
8+
from PIL._binary import o8
9+
from PIL._binary import o16le as o16
10+
from PIL._binary import o32le as o32
611

712
TEST_FILE = "Tests/images/deerstalker.cur"
813

@@ -17,6 +22,24 @@ def test_sanity() -> None:
1722
assert im.getpixel((16, 16)) == (84, 87, 86, 255)
1823

1924

25+
def test_largest_cursor() -> None:
26+
magic = b"\x00\x00\x02\x00"
27+
sizes = ((1, 1), (8, 8), (4, 4))
28+
data = magic + o16(len(sizes))
29+
for w, h in sizes:
30+
image_offset = 6 + len(sizes) * 16 if (w, h) == max(sizes) else 0
31+
data += o8(w) + o8(h) + o8(0) * 10 + o32(image_offset)
32+
data += (
33+
o32(12) # header size
34+
+ o16(8) # width
35+
+ o16(16) # height
36+
+ o16(0) # planes
37+
+ o16(1) # bits
38+
)
39+
with Image.open(BytesIO(data)) as im:
40+
assert im.size == (8, 8)
41+
42+
2043
def test_invalid_file() -> None:
2144
invalid_file = "Tests/images/flower.jpg"
2245

0 commit comments

Comments
 (0)