#
# PWG 5101.1-2023: Media Standardized Names v2.1 (MSN)
#
# https://ftp.pwg.org/pub/pwg/candidates/cs-pwgmsn21-20230915-5101.1.pdf
#
# Copyright © 2022-2025 by OpenPrinting.
# Copyright © 2007-2017 by Apple Inc.
# Copyright © 2001-2006 by Easy Software Products. All rights reserved.
#
# Licensed under Apache License v2.0.  See the file "LICENSE" for more
# information.
#
# Usage:
#
#   ./ipptool [OPTIONS] -t PRINTER-URI pwg5101.1.test
#
# Options:
#
#   -d REQUIRE_MSN=1          Require support for the MSN v2.1 specification.
#

# Regular expression for PWG self-describing media size names (eek!)
DEFINE MEDIA_REGEX "/^(((custom|na|asme|roc|oe|roll)_([A-Za-z0-9][-A-Z.a-z0-9]*)_([1-9][0-9]*(\.[0-9]*[1-9])?|0\.[0-9]*[1-9])x(([1-9][0-9]*(\.[0-9]*[1-9])?|0\.[0-9]*[1-9])|0)in|(custom|iso|jis|jpn|prc|om|roll)_([A-Za-z0-9][-A-Z.a-z0-9]*)_([1-9][0-9]*(\.[0-9]*[1-9])?|0\.[0-9]*[1-9])x(([1-9][0-9]*(\.[0-9]*[1-9])?|0\.[0-9]*[1-9])|0)mm|disc_([A-Za-z0-9][-A-Z.a-z0-9]*)_([1-9][0-9]*(\.[0-9]*[1-9])?|0\.[0-9]*[1-9])x([1-9][0-9]*(\.[0-9]*[1-9])?|0\.[0-9]*[1-9])mm)|choice(_((custom|na|asme|roc|oe|roll)_([A-Za-z0-9][-A-Z.a-z0-9]*)_([1-9][0-9]*(\.[0-9]*[1-9])?|0\.[0-9]*[1-9])x(([1-9][0-9]*(\.[0-9]*[1-9])?|0\.[0-9]*[1-9])|0)in|(custom|iso|jis|jpn|prc|om|roll)_([A-Za-z0-9][-A-Z.a-z0-9]*)_([1-9][0-9]*(\.[0-9]*[1-9])?|0\.[0-9]*[1-9])x(([1-9][0-9]*(\.[0-9]*[1-9])?|0\.[0-9]*[1-9])|0)mm|disc_([A-Za-z0-9][-A-Z.a-z0-9]*)_([1-9][0-9]*(\.[0-9]*[1-9])?|0\.[0-9]*[1-9])x([1-9][0-9]*(\.[0-9]*[1-9])?|0\.[0-9]*[1-9])mm)){2,})$$/"


# Simple test of media-xxx values...
{
    SKIP-IF-NOT-DEFINED REQUIRE_MSN

    NAME "PWG 5101.1-2023: Self-Describing Media Size Names"
    OPERATION Get-Printer-Attributes
    GROUP operation-attributes-tag
    ATTR charset attributes-charset utf-8
    ATTR naturalLanguage attributes-natural-language en
    ATTR uri printer-uri $uri
    ATTR name requesting-user-name $user
    ATTR mimeMediaType document-format application/octet-stream

    STATUS successful-ok

    EXPECT media-default OF-TYPE keyword|name COUNT 1 IN-GROUP printer-attributes-tag WITH-VALUE "$MEDIA_REGEX"
    EXPECT ?media-ready OF-TYPE keyword|name IN-GROUP printer-attributes-tag WITH-ALL-VALUES "$MEDIA_REGEX"
    EXPECT media-supported OF-TYPE keyword|name IN-GROUP printer-attributes-tag WITH-ALL-VALUES "$MEDIA_REGEX"
}
