"options from Brother backends"

from pathlib import Path
import pytest
from scanner.options import Options, Option
from frontend import enums


@pytest.mark.skipif(
    not Path("scantpaper/tests/scanners/Brother_DCP-7025").exists(),
    reason="source tree not found",
)
def test_dcp_7025():
    "options from Brother_DCP-7025 backend"
    output = Path("scantpaper/tests/scanners/Brother_DCP-7025").read_text(
        encoding="utf-8"
    )
    options = Options(output)
    that = [
        Option(
            index=0,
            name="",
            title="Number of options",
            desc="Read-only option that specifies how many options a specific device supports.",
            type=1,
            unit=0,
            size=4,
            cap=4,
            constraint=None,
        ),
        Option(
            title="Mode",
            type=enums.TYPE_GROUP,
            cap=0,
            size=0,
            name="",
            unit=enums.UNIT_NONE,
            index=1,
            desc="",
            constraint=None,
        ),
        Option(
            name="mode",
            title="Mode",
            index=2,
            desc="Select the scan mode",
            constraint=[
                "Black & White",
                "Gray[Error Diffusion]",
                "True Gray",
                "24bit Color",
                "24bit Color[Fast]",
            ],
            unit=enums.UNIT_NONE,
            type=enums.TYPE_STRING,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
        Option(
            name="resolution",
            title="Resolution",
            index=3,
            desc="Sets the resolution of the scanned image.",
            constraint=[100, 150, 200, 300, 400, 600, 1200, 2400, 4800, 9600],
            unit=enums.UNIT_DPI,
            type=enums.TYPE_INT,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
        Option(
            name="source",
            title="Source",
            index=4,
            desc="Selects the scan source (such as a document-feeder).",
            constraint=["FlatBed", "Automatic Document Feeder"],
            unit=enums.UNIT_NONE,
            type=enums.TYPE_STRING,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
        Option(
            name="brightness",
            title="Brightness",
            index=5,
            desc="Controls the brightness of the acquired image.",
            constraint=(-50, 50, 1),
            unit=enums.UNIT_PERCENT,
            type=enums.TYPE_INT,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
        Option(
            name="contrast",
            title="Contrast",
            index=6,
            desc="Controls the contrast of the acquired image.",
            constraint=(-50, 50, 1),
            unit=enums.UNIT_PERCENT,
            type=enums.TYPE_INT,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT + enums.CAP_INACTIVE,
            size=1,
        ),
        Option(
            index=7,
            title="Geometry",
            type=enums.TYPE_GROUP,
            cap=0,
            size=0,
            name="",
            unit=enums.UNIT_NONE,
            desc="",
            constraint=None,
        ),
        Option(
            name="tl-x",
            title="Top-left x",
            index=8,
            desc="Top-left x position of scan area.",
            constraint=(0.0, 210.0, 0.0999908),
            unit=enums.UNIT_MM,
            type=enums.TYPE_FIXED,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
        Option(
            name="tl-y",
            title="Top-left y",
            index=9,
            desc="Top-left y position of scan area.",
            constraint=(0.0, 297.0, 0.0999908),
            unit=enums.UNIT_MM,
            type=enums.TYPE_FIXED,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
        Option(
            name="br-x",
            title="Bottom-right x",
            desc="Bottom-right x position of scan area.",
            index=10,
            constraint=(0.0, 210.0, 0.0999908),
            unit=enums.UNIT_MM,
            type=enums.TYPE_FIXED,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
        Option(
            name="br-y",
            title="Bottom-right y",
            desc="Bottom-right y position of scan area.",
            index=11,
            constraint=(0.0, 297.0, 0.0999908),
            unit=enums.UNIT_MM,
            type=enums.TYPE_FIXED,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
    ]
    assert options.array == that, "Brother_DCP-7025"
    assert options.device == "brother2:bus5;dev1", "device name"


@pytest.mark.skipif(
    not Path("scantpaper/tests/scanners/Brother_MFC_5100c").exists(),
    reason="source tree not found",
)
def test_mfc_5100c():
    "options from Brother_MFC_5100c backend"
    output = Path("scantpaper/tests/scanners/Brother_MFC_5100c").read_text(
        encoding="utf-8"
    )
    options = Options(output)
    that = [
        Option(
            index=0,
            name="",
            title="Number of options",
            desc="Read-only option that specifies how many options a specific device supports.",
            type=1,
            unit=0,
            size=4,
            cap=4,
            constraint=None,
        ),
        Option(
            title="Mode",
            index=1,
            type=enums.TYPE_GROUP,
            cap=0,
            size=0,
            name="",
            unit=enums.UNIT_NONE,
            desc="",
            constraint=None,
        ),
        Option(
            name="mode",
            title="Mode",
            index=2,
            desc="Select the scan mode",
            constraint=[
                "Black & White",
                "Gray[Error Diffusion]",
                "True Gray",
                "24bit Color",
            ],
            unit=enums.UNIT_NONE,
            type=enums.TYPE_STRING,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
        Option(
            name="resolution",
            title="Resolution",
            index=3,
            desc="Sets the resolution of the scanned image.",
            constraint=[
                100,
                150,
                200,
                300,
                400,
                600,
                1200,
                2400,
                4800,
                9600,
            ],
            unit=enums.UNIT_DPI,
            type=enums.TYPE_INT,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
        Option(
            name="source",
            title="Source",
            index=4,
            desc="Selects the scan source (such as a document-feeder).",
            constraint=["FlatBed", "Automatic Document Feeder"],
            unit=enums.UNIT_NONE,
            type=enums.TYPE_STRING,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
        Option(
            name="brightness",
            title="Brightness",
            index=5,
            desc="Controls the brightness of the acquired image.",
            constraint=(-50, 50, 1),
            unit=enums.UNIT_PERCENT,
            type=enums.TYPE_INT,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT + enums.CAP_INACTIVE,
            size=1,
        ),
        Option(
            name="contrast",
            title="Contrast",
            index=6,
            desc="Controls the contrast of the acquired image.",
            constraint=(-50, 50, 1),
            unit=enums.UNIT_PERCENT,
            type=enums.TYPE_INT,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT + enums.CAP_INACTIVE,
            size=1,
        ),
        Option(
            index=7,
            title="Geometry",
            cap=0,
            size=0,
            name="",
            unit=enums.UNIT_NONE,
            desc="",
            type=enums.TYPE_GROUP,
            constraint=None,
        ),
        Option(
            name="tl-x",
            title="Top-left x",
            index=8,
            desc="Top-left x position of scan area.",
            constraint=(0.0, 208.0, 0.0999908),
            unit=enums.UNIT_MM,
            type=enums.TYPE_FIXED,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
        Option(
            name="tl-y",
            title="Top-left y",
            index=9,
            desc="Top-left y position of scan area.",
            constraint=(0.0, 355.6, 0.0999908),
            unit=enums.UNIT_MM,
            type=enums.TYPE_FIXED,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
        Option(
            name="br-x",
            title="Bottom-right x",
            desc="Bottom-right x position of scan area.",
            index=10,
            constraint=(0.0, 208.0, 0.0999908),
            unit=enums.UNIT_MM,
            type=enums.TYPE_FIXED,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
        Option(
            name="br-y",
            title="Bottom-right y",
            desc="Bottom-right y position of scan area.",
            index=11,
            constraint=(0.0, 355.6, 0.0999908),
            unit=enums.UNIT_MM,
            type=enums.TYPE_FIXED,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
    ]
    assert options.array == that, "Brother_MFC_5100c"
    assert options.device == "brother:bus1;dev2", "device name"
    assert options.can_duplex() is False, "can duplex"


@pytest.mark.skipif(
    not Path("scantpaper/tests/scanners/Brother_MFC-8860DN").exists(),
    reason="source tree not found",
)
def test_mfc_8860dn():
    "options from Brother_MFC-8860DN backend"
    output = Path("scantpaper/tests/scanners/Brother_MFC-8860DN").read_text(
        encoding="utf-8"
    )
    options = Options(output)
    that = [
        Option(
            index=0,
            name="",
            title="Number of options",
            desc="Read-only option that specifies how many options a specific device supports.",
            type=1,
            unit=0,
            size=4,
            cap=4,
            constraint=None,
        ),
        Option(
            title="Mode",
            index=1,
            type=enums.TYPE_GROUP,
            cap=0,
            size=0,
            name="",
            unit=enums.UNIT_NONE,
            desc="",
            constraint=None,
        ),
        Option(
            name="mode",
            title="Mode",
            index=2,
            desc="Select the scan mode",
            constraint=[
                "Black & White",
                "Gray[Error Diffusion]",
                "True Gray",
                "24bit Color",
                "24bit Color[Fast]",
            ],
            unit=enums.UNIT_NONE,
            type=enums.TYPE_STRING,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
        Option(
            name="resolution",
            title="Resolution",
            index=3,
            desc="Sets the resolution of the scanned image.",
            constraint=[
                100,
                150,
                200,
                300,
                400,
                600,
                1200,
                2400,
                4800,
                9600,
            ],
            unit=enums.UNIT_DPI,
            type=enums.TYPE_INT,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
        Option(
            name="source",
            title="Source",
            index=4,
            desc="Selects the scan source (such as a document-feeder).",
            constraint=[
                "FlatBed",
                "Automatic Document Feeder",
                "Automatic Document Feeder(Duplex)",
            ],
            unit=enums.UNIT_NONE,
            type=enums.TYPE_STRING,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
        Option(
            name="brightness",
            title="Brightness",
            index=5,
            desc="Controls the brightness of the acquired image.",
            constraint=(-50, 50, 1),
            unit=enums.UNIT_PERCENT,
            type=enums.TYPE_INT,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT + enums.CAP_INACTIVE,
            size=1,
        ),
        Option(
            name="contrast",
            title="Contrast",
            index=6,
            desc="Controls the contrast of the acquired image.",
            constraint=(-50, 50, 1),
            unit=enums.UNIT_PERCENT,
            type=enums.TYPE_INT,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT + enums.CAP_INACTIVE,
            size=1,
        ),
        Option(
            index=7,
            title="Geometry",
            cap=0,
            size=0,
            name="",
            unit=enums.UNIT_NONE,
            desc="",
            type=enums.TYPE_GROUP,
            constraint=None,
        ),
        Option(
            name="tl-x",
            title="Top-left x",
            index=8,
            desc="Top-left x position of scan area.",
            constraint=(0.0, 215.9, 0.0999908),
            unit=enums.UNIT_MM,
            type=enums.TYPE_FIXED,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
        Option(
            name="tl-y",
            title="Top-left y",
            index=9,
            desc="Top-left y position of scan area.",
            constraint=(0.0, 355.6, 0.0999908),
            unit=enums.UNIT_MM,
            type=enums.TYPE_FIXED,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
        Option(
            name="br-x",
            title="Bottom-right x",
            desc="Bottom-right x position of scan area.",
            index=10,
            constraint=(0.0, 215.9, 0.0999908),
            unit=enums.UNIT_MM,
            type=enums.TYPE_FIXED,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
        Option(
            name="br-y",
            title="Bottom-right y",
            desc="Bottom-right y position of scan area.",
            index=11,
            constraint=(0.0, 355.6, 0.0999908),
            unit=enums.UNIT_MM,
            type=enums.TYPE_FIXED,
            cap=enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            size=1,
        ),
    ]
    assert options.array == that, "Brother_MFC-8860DN"
    assert options.device == "brother2:net1;dev0", "device name"
    assert options.can_duplex(), "can duplex"


@pytest.mark.skipif(
    not Path("scantpaper/tests/scanners/brother").exists(),
    reason="source tree not found",
)
def test_generic():
    "options from brother backend"
    output = Path("scantpaper/tests/scanners/brother").read_text(encoding="utf-8")
    options = Options(output)
    that = [
        # (index, name, title, desc, type, unit, size, cap, constraint)
        Option(
            0,
            "",
            "Number of options",
            "Read-only option that specifies how many options a specific device supports.",
            1,
            0,
            4,
            4,
            None,
        ),
        Option(1, "", "Mode", "", enums.TYPE_GROUP, enums.UNIT_NONE, 0, 0, None),
        Option(
            2,
            "mode",
            "Mode",
            "Select the scan mode",
            enums.TYPE_STRING,
            enums.UNIT_NONE,
            1,
            enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            [
                "Black & White",
                "Gray[Error Diffusion]",
                "True Gray",
                "24bit Color",
                "24bit Color[Fast]",
            ],
        ),
        Option(
            3,
            "resolution",
            "Resolution",
            "Sets the resolution of the scanned image.",
            enums.TYPE_INT,
            enums.UNIT_DPI,
            1,
            enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            [100, 150, 200, 300, 400, 600, 1200, 2400, 4800, 9600],
        ),
        Option(
            4,
            "source",
            "Source",
            "Selects the scan source (such as a document-feeder).",
            enums.TYPE_STRING,
            enums.UNIT_NONE,
            1,
            enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            ["FlatBed", "Automatic Document Feeder"],
        ),
        Option(
            5,
            "brightness",
            "Brightness",
            "Controls the brightness of the acquired image.",
            enums.TYPE_INT,
            enums.UNIT_PERCENT,
            1,
            enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT + enums.CAP_INACTIVE,
            (-50, 50, 1),
        ),
        Option(
            6,
            "contrast",
            "Contrast",
            "Controls the contrast of the acquired image.",
            enums.TYPE_INT,
            enums.UNIT_PERCENT,
            1,
            enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT + enums.CAP_INACTIVE,
            (-50, 50, 1),
        ),
        Option(
            7,
            "",
            "Geometry",
            "",
            enums.TYPE_GROUP,
            enums.UNIT_NONE,
            0,
            0,
            None,
        ),
        Option(
            8,
            "tl-x",
            "Top-left x",
            "Top-left x position of scan area.",
            enums.TYPE_FIXED,
            enums.UNIT_MM,
            1,
            enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            (0.0, 210.0, 0.0999908),
        ),
        Option(
            9,
            "tl-y",
            "Top-left y",
            "Top-left y position of scan area.",
            enums.TYPE_FIXED,
            enums.UNIT_MM,
            1,
            enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            (0.0, 297.0, 0.0999908),
        ),
        Option(
            10,
            "br-x",
            "Bottom-right x",
            "Bottom-right x position of scan area.",
            enums.TYPE_FIXED,
            enums.UNIT_MM,
            1,
            enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            (0.0, 210.0, 0.0999908),
        ),
        Option(
            11,
            "br-y",
            "Bottom-right y",
            "Bottom-right y position of scan area.",
            enums.TYPE_FIXED,
            enums.UNIT_MM,
            1,
            enums.CAP_SOFT_DETECT + enums.CAP_SOFT_SELECT,
            (0.0, 297.0, 0.0999908),
        ),
    ]
    assert options.array == that, "brother"
    assert options.device == "brother2:net1;dev0", "device name"
