aboutsummaryrefslogtreecommitdiff
path: root/tests/Jellyfin.Controller.Tests/Drawing/ImageHelperTests.cs
blob: 571cb7f0d4bf1465685cfb0c491ec5d132ee7321 (plain)
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
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Model.Drawing;
using Xunit;

namespace Jellyfin.Controller.Tests.Drawing;

public static class ImageHelperTests
{
    [Fact]
    public static void GetNewImageSize_ExplicitSizeLargerThanSource_ClampsToSource()
    {
        // Regression test for https://github.com/jellyfin/jellyfin/issues/17056: the caller-supplied
        // width/height were used verbatim, so a single request could ask for a 23100x23100 encode.
        var options = new ImageProcessingOptions { Width = 23100, Height = 23100 };

        var newSize = ImageHelper.GetNewImageSize(options, new ImageDimensions(600, 336));

        Assert.Equal(336, newSize.Width);
        Assert.Equal(336, newSize.Height);
    }

    [Fact]
    public static void GetNewImageSize_WidthLargerThanSource_ClampsToSource()
    {
        var options = new ImageProcessingOptions { Width = 10000 };

        var newSize = ImageHelper.GetNewImageSize(options, new ImageDimensions(600, 336));

        Assert.Equal(600, newSize.Width);
        Assert.Equal(336, newSize.Height);
    }

    [Fact]
    public static void GetNewImageSize_FillLargerThanSource_ClampsToSource()
    {
        // ResizeFill already refused to upscale; this pins that behaviour.
        var options = new ImageProcessingOptions { FillWidth = 23100, FillHeight = 23100 };

        var newSize = ImageHelper.GetNewImageSize(options, new ImageDimensions(600, 336));

        Assert.Equal(600, newSize.Width);
        Assert.Equal(336, newSize.Height);
    }

    [Fact]
    public static void GetNewImageSize_SmallerThanSource_StillDownscales()
    {
        var options = new ImageProcessingOptions { MaxWidth = 300 };

        var newSize = ImageHelper.GetNewImageSize(options, new ImageDimensions(600, 336));

        Assert.Equal(300, newSize.Width);
        Assert.Equal(168, newSize.Height);
    }

    [Fact]
    public static void GetNewImageSize_NoSizeRequested_ReturnsSource()
    {
        var newSize = ImageHelper.GetNewImageSize(new ImageProcessingOptions(), new ImageDimensions(600, 336));

        Assert.Equal(600, newSize.Width);
        Assert.Equal(336, newSize.Height);
    }
}