#
# PWG 5100.6-2003: IPP Page Overrides
#
# https://ftp.pwg.org/pub/pwg/candidates/cs-ipppageoverride10-20031031-5100.6.pdf
#
# Copyright © 2024 by OpenPrinting.
# Copyright © 2014-2022 by the Printer Working Group.
#
# Licensed under Apache License v2.0.  See the file "LICENSE" for more
# information.
#
# Usage:
#
#   ./ipptool [OPTIONS] -f FILENAME -t PRINTER-URI pwg5100.5.test
#
# Options:
#
#   -d NOPRINT=1              Disable the print tests.
#   -d REQUIRE_PAGEOVERRIDE=1 Require support for page overrides.
#

{
    NAME "PWG 5100.6-2003: Attributes and Values"
    OPERATION Get-Printer-Attributes
    GROUP operation-attributes-tag
    ATTR charset attributes-charset utf-8
    ATTR language attributes-natural-language en
    ATTR uri printer-uri $uri

    STATUS successful-ok

    EXPECT operations-supported OF-TYPE enum IN-GROUP printer-attributes-tag
    EXPECT operations-supported WITH-VALUE 0x0005 DEFINE-MATCH PRINTER_HAS_CREATE_JOB		# Create-Job
    EXPECT operations-supported WITH-VALUE 0x0003 DEFINE-MATCH PRINTER_HAS_PRINT_URI		# Print-URI
    EXPECT operations-supported WITH-VALUE 0x0007 DEFINE-MATCH PRINTER_HAS_SEND_URI		# Send-URI

    EXPECT multiple-document-jobs-supported OF-TYPE boolean IN-GROUP printer-attributes-tag COUNT 1 WITH-VALUE true DEFINE-MATCH PRINTER_HAS_MULTIPLE_DOCUMENT_JOBS

    EXPECT ?overrides-supported OF-TYPE keyword IN-GROUP printer-attributes-tag
    EXPECT overrides-supported DEFINE-MATCH PRINTER_HAS_OVERRIDES
    EXPECT overrides-supported WITH-VALUE pages IF-DEFINED REQUIRE_PAGEOVERRIDE
    EXPECT overrides-supported WITH-VALUE document-numbers IF-DEFINED REQUIRE_PAGEOVERRIDE IF-DEFINE PRINTER_HAS_MULTIPLE_DOCUMENT_JOBS
    EXPECT overrides-supported WITH-VALUE document-copies DEFINE-MATCH PRINTER_HAS_OVERRIDES_DOCUMENT_COPIES
    EXPECT overrides-supported WITH-VALUE finishings DEFINE-MATCH PRINTER_HAS_OVERRIDES_FINISHINGS
    EXPECT overrides-supported WITH-VALUE media-col DEFINE-MATCH PRINTER_HAS_OVERRIDES_MEDIA_COL
    EXPECT overrides-supported WITH-VALUE orientation-requested DEFINE-MATCH PRINTER_HAS_OVERRIDES_ORIENTATION_REQUESTED
    EXPECT overrides-supported WITH-VALUE sides DEFINE-MATCH PRINTER_HAS_OVERRIDES_SIDES

    EXPECT finishings-supported OF-TYPE enum IN-GROUP printer-attributes-tag WITH-VALUE 4 DEFINE-MATCH PRINTER_HAS_FINISHINGS_STAPLE
}

{
    SKIP-IF-DEFINED NOPRINT
    SKIP-IF-NOT-DEFINED PRINTER_HAS_OVERRIDES
    SKIP-IF-NOT-DEFINED PRINTER_HAS_OVERRIDES_MEDIA_COL

    NAME "Print-Job w/Mixed Media Sizes"
    OPERATION Print-Job
    GROUP operation-attributes-tag
    ATTR charset attributes-charset utf-8
    ATTR language attributes-natural-language en
    ATTR uri printer-uri $uri
    ATTR name requesting-user-name $user
    ATTR name job-name "Mixed Media Sizes"
    ATTR mimeMediaType document-format $filetype
    ATTR boolean ipp-attribute-fidelity false

    GROUP job-attributes-tag
    ATTR collection media-col {
        MEMBER collection media-size {
            # A4
            MEMBER integer x-dimension 21000
            MEMBER integer y-dimension 29700
        }
    }
    ATTR collection overrides {
	MEMBER rangeOfInteger pages 1-2
	MEMBER collection media-col {
	    MEMBER collection media-size {
	        # Letter
		MEMBER integer x-dimension 21590
		MEMBER integer y-dimension 27940
	    }
	}
    }

    FILE $filename

    STATUS successful-ok

    EXPECT job-id OF-TYPE integer IN-GROUP job-attributes-tag WITH-VALUE >0 COUNT 1
    EXPECT job-uri OF-TYPE uri IN-GROUP job-attributes-tag COUNT 1
}

{
    SKIP-IF-DEFINED NOPRINT
    SKIP-IF-NOT-DEFINED PRINTER_HAS_OVERRIDES
    SKIP-IF-NOT-DEFINED PRINTER_HAS_OVERRIDES_MEDIA_COL

    NAME "Verify Mixed Media Size Job"
    OPERATION Get-Job-Attributes
    GROUP operation-attributes-tag
    ATTR charset attributes-charset utf-8
    ATTR language attributes-natural-language en
    ATTR uri printer-uri $uri
    ATTR integer job-id $job-id
    ATTR name requesting-user-name $user

    STATUS successful-ok

    # Keep monitoring until completed/canceled/aborted
    EXPECT job-state WITH-VALUE <6 REPEAT-MATCH

    EXPECT media-col OF-TYPE collection IN-GROUP job-attributes-tag COUNT 1
    EXPECT overrides OF-TYPE collection IN-GROUP job-attributes-tag COUNT 1
    EXPECT overrides/pages OF-TYPE rangeOfInteger WITH-VALUE 1-2 COUNT 1
    EXPECT overrides/media-col OF-TYPE collection COUNT 1
}

{
    SKIP-IF-DEFINED NOPRINT
    SKIP-IF-NOT-DEFINED PRINTER_HAS_OVERRIDES
    SKIP-IF-NOT-DEFINED PRINTER_HAS_OVERRIDES_ORIENTATION_REQUESTED

    NAME "Print-Job w/Mixed Orientations"
    OPERATION Print-Job
    GROUP operation-attributes-tag
    ATTR charset attributes-charset utf-8
    ATTR language attributes-natural-language en
    ATTR uri printer-uri $uri
    ATTR name requesting-user-name $user
    ATTR name job-name "Mixed Orientations"
    ATTR mimeMediaType document-format $filetype
    ATTR boolean ipp-attribute-fidelity false

    GROUP job-attributes-tag
    ATTR enum orientation-requested 3
    ATTR collection overrides {
	MEMBER rangeOfInteger pages 1-2
	MEMBER enum orientation-requested 4
    }

    FILE $filename

    STATUS successful-ok

    EXPECT job-id OF-TYPE integer IN-GROUP job-attributes-tag WITH-VALUE >0 COUNT 1
    EXPECT job-uri OF-TYPE uri IN-GROUP job-attributes-tag COUNT 1
}

{
    SKIP-IF-DEFINED NOPRINT
    SKIP-IF-NOT-DEFINED PRINTER_HAS_OVERRIDES
    SKIP-IF-NOT-DEFINED PRINTER_HAS_OVERRIDES_ORIENTATION_REQUESTED

    NAME "Verify Mixed Orientation Job"
    OPERATION Get-Job-Attributes
    GROUP operation-attributes-tag
    ATTR charset attributes-charset utf-8
    ATTR language attributes-natural-language en
    ATTR uri printer-uri $uri
    ATTR integer job-id $job-id
    ATTR name requesting-user-name $user

    STATUS successful-ok

    # Keep monitoring until completed/canceled/aborted
    EXPECT job-state WITH-VALUE <6 REPEAT-MATCH

    EXPECT orientation-requested OF-TYPE enum IN-GROUP job-attributes-tag COUNT 1
    EXPECT overrides OF-TYPE collection IN-GROUP job-attributes-tag COUNT 1
    EXPECT overrides/pages OF-TYPE rangeOfInteger WITH-VALUE 1-2 COUNT 1
    EXPECT overrides/finishings OF-TYPE enum COUNT 1
}

{
    SKIP-IF-DEFINED NOPRINT
    SKIP-IF-NOT-DEFINED PRINTER_HAS_OVERRIDES
    SKIP-IF-NOT-DEFINED PRINTER_HAS_OVERRIDES_SIDES

    NAME "Print-Job w/Mixed Duplex"
    OPERATION Print-Job
    GROUP operation-attributes-tag
    ATTR charset attributes-charset utf-8
    ATTR language attributes-natural-language en
    ATTR uri printer-uri $uri
    ATTR name requesting-user-name $user
    ATTR name job-name "Mixed Duplex"
    ATTR mimeMediaType document-format $filetype
    ATTR boolean ipp-attribute-fidelity false

    GROUP job-attributes-tag
    ATTR keyword sides two-sided-long-edge
    ATTR collection overrides {
	MEMBER rangeOfInteger pages 1-2
	MEMBER keyword sides one-sided
    }

    FILE $filename

    STATUS successful-ok

    EXPECT job-id OF-TYPE integer IN-GROUP job-attributes-tag WITH-VALUE >0 COUNT 1
    EXPECT job-uri OF-TYPE uri IN-GROUP job-attributes-tag COUNT 1
}

{
    SKIP-IF-DEFINED NOPRINT
    SKIP-IF-NOT-DEFINED PRINTER_HAS_OVERRIDES
    SKIP-IF-NOT-DEFINED PRINTER_HAS_OVERRIDES_SIDES

    NAME "Verify Mixed Duplex Job"
    OPERATION Get-Job-Attributes
    GROUP operation-attributes-tag
    ATTR charset attributes-charset utf-8
    ATTR language attributes-natural-language en
    ATTR uri printer-uri $uri
    ATTR integer job-id $job-id
    ATTR name requesting-user-name $user

    STATUS successful-ok

    # Keep monitoring until completed/canceled/aborted
    EXPECT job-state WITH-VALUE <6 REPEAT-MATCH

    EXPECT sides OF-TYPE keyword IN-GROUP job-attributes-tag COUNT 1
    EXPECT overrides OF-TYPE collection IN-GROUP job-attributes-tag COUNT 1
    EXPECT overrides/pages OF-TYPE rangeOfInteger WITH-VALUE 1-2 COUNT 1
    EXPECT overrides/sides OF-TYPE keyword COUNT 1
}

{
    SKIP-IF-DEFINED NOPRINT
    SKIP-IF-NOT-DEFINED PRINTER_HAS_OVERRIDES
    SKIP-IF-NOT-DEFINED PRINTER_HAS_OVERRIDES_FINISHINGS
    SKIP-IF-NOT-DEFINED PRINTER_HAS_FINISHINGS_STAPLE

    NAME "Print-Job w/Mixed Finishings"
    OPERATION Print-Job
    GROUP operation-attributes-tag
    ATTR charset attributes-charset utf-8
    ATTR language attributes-natural-language en
    ATTR uri printer-uri $uri
    ATTR name requesting-user-name $user
    ATTR name job-name "Mixed Finishings"
    ATTR mimeMediaType document-format $filetype
    ATTR boolean ipp-attribute-fidelity false

    GROUP job-attributes-tag
    ATTR enum finishings 4
    ATTR collection overrides {
	MEMBER rangeOfInteger pages 1-2
	MEMBER enum finishings 3
    }

    FILE $filename

    STATUS successful-ok

    EXPECT job-id OF-TYPE integer IN-GROUP job-attributes-tag WITH-VALUE >0 COUNT 1
    EXPECT job-uri OF-TYPE uri IN-GROUP job-attributes-tag COUNT 1
}

{
    SKIP-IF-DEFINED NOPRINT
    SKIP-IF-NOT-DEFINED PRINTER_HAS_OVERRIDES
    SKIP-IF-NOT-DEFINED PRINTER_HAS_OVERRIDES_FINISHINGS
    SKIP-IF-NOT-DEFINED PRINTER_HAS_FINISHINGS_STAPLE

    NAME "Verify Mixed Finishings Job"
    OPERATION Get-Job-Attributes
    GROUP operation-attributes-tag
    ATTR charset attributes-charset utf-8
    ATTR language attributes-natural-language en
    ATTR uri printer-uri $uri
    ATTR integer job-id $job-id
    ATTR name requesting-user-name $user

    STATUS successful-ok

    # Keep monitoring until completed/canceled/aborted
    EXPECT job-state WITH-VALUE <6 REPEAT-MATCH

    EXPECT finishings OF-TYPE enum IN-GROUP job-attributes-tag COUNT 1
    EXPECT overrides OF-TYPE collection IN-GROUP job-attributes-tag COUNT 1
    EXPECT overrides/pages OF-TYPE rangeOfInteger WITH-VALUE 1-2 COUNT 1
    EXPECT overrides/finishings OF-TYPE enum COUNT 1
}
