#
#Check a printer for conformance with pwg5100.5: IPP Document Object
#
#
#Usage:
#
#	./ipptool -f FILENAME -d "document-uri=URI" printer-uri pwg5100.5.test

{
	NAME "Check for 5100.5 required and optional operations support"
	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
	ATTR keyword requested-attributes operations-supported,document-creation-attributes-supported
	STATUS successful-ok

	EXPECT ?operations-supported OF-TYPE enum IN-GROUP printer-attributes-tag WITH-VALUE 0x0037
	EXPECT operations-supported OF-TYPE enum IN-GROUP printer-attributes-tag WITH-VALUE 0x0037 DEFINE-MATCH HAVE_SET_DOCUMENT_ATTRIBUTES	# Set-Document-Attributes
    EXPECT operations-supported OF-TYPE enum IN-GROUP printer-attributes-tag WITH-VALUE 0x0003 
	EXPECT operations-supported OF-TYPE enum IN-GROUP printer-attributes-tag WITH-VALUE 0x0003 DEFINE-MATCH HAVE_PRINT_URI                  # Print-URI
	EXPECT operations-supported OF-TYPE enum IN-GROUP printer-attributes-tag WITH-VALUE 0x0007 
	EXPECT operations-supported OF-TYPE enum IN-GROUP printer-attributes-tag WITH-VALUE 0x0007 DEFINE-MATCH HAVE_SEND_URI		            # Send-URI
	EXPECT operations-supported OF-TYPE enum IN-GROUP printer-attributes-tag WITH-VALUE 0x0033 
	EXPECT operations-supported OF-TYPE enum IN-GROUP printer-attributes-tag WITH-VALUE 0x0033 DEFINE-MATCH HAVE_CANCEL_DOCUMENT			# Cancel-Document
	EXPECT operations-supported OF-TYPE enum IN-GROUP printer-attributes-tag WITH-VALUE 0x0034
	EXPECT operations-supported OF-TYPE enum IN-GROUP printer-attributes-tag WITH-VALUE 0x0034 DEFINE-MATCH HAVE_GET_DOCUMENT_ATTRIBUTES	# Get-Document-Attributes

	#REQUIRED Job operations
	EXPECT operations-supported OF-TYPE enum IN-GROUP printer-attributes-tag WITH-VALUE 0x0035
	EXPECT operations-supported OF-TYPE enum IN-GROUP printer-attributes-tag WITH-VALUE 0x0035 DEFINE-MATCH HAVE_GET_DOCUMENTS				# Get-Documents
	
	# Checking REQUIRED attributes.

	EXPECT document-creation-attributes-supported OF-TYPE keyword IN-GROUP printer-attributes-tag 
	



}

# testing document operations

{
	NAME "print-job to create document object"
	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 mimeMediaType document-format $filetype

	GROUP job-attributes-tag
	ATTR integer copies 1

	ATTR name document-name "test-document-1"

	FILE $filename

	STATUS successful-ok
	STATUS successful-ok-ignored-or-substituted-attributes

	EXPECT job-id OF-TYPE integer IN-GROUP job-attributes-tag WITH-VALUE >0 COUNT 1
	EXPECT ?document-number OF-TYPE integer IN-GROUP document-attributes-tag WITH-VALUE 1 COUNT 1
	EXPECT ?document-state OF-TYPE enum IN-GROUP document-attributes-tag
	EXPECT ?document-state-reasons OF-TYPE keyword IN-GROUP document-attributes-tag
}

{
	SKIP-IF-NOT-DEFINED HAVE_GET_DOCUMENT_ATTRIBUTE
	NAME "Get document attributes"
	OPERATION Get-Document-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 integer document-number 1
	ATTR name requesting-user-name $user
	GROUP document-attributes-tag
	ATTR integer printer-up-time 1
	STATUS successful-ok

	#Document description
	EXPECT document-name OF-TYPE name IN-GROUP document-attributes-tag WITH-VALUE "test-document-1" COUNT 1

	#Document STATUS
	EXPECT document-number OF-TYPE integer IN-GROUP document-attributes-tag WITH-VALUE 1 COUNT 1
	EXPECT last-document OF-TYPE boolean IN-GROUP document-attributes-tag



	EXPECT document-job-id OF-TYPE integer IN-GROUP document-attributes-tag WITH-VALUE >0 COUNT 1
	EXPECT document-job-uri OF-TYPE uri IN-GROUP document-attributes-tag COUNT 1
	
	
	EXPECT document-printer-uri OF-TYPE uri IN-GROUP document-attributes-tag WITH-VALUE $uri COUNT 1
	EXPECT document-state OF-TYPE enum IN-GROUP document-attributes-tag
	EXPECT document-state-reasons OF-TYPE keyword IN-GROUP document-attributes-tag

	EXPECT printer-up-time OF-TYPE integer IN-GROUP document-attributes-tag WITH-VALUE >0 COUNT 1
	EXPECT time-at-completed OF-TYPE integer|no-value IN-GROUP document-attributes-tag WITH-VALUE >0 COUNT 1
	EXPECT time-at-created OF-TYPE integer|no-value IN-GROUP document-attributes-tag WITH-VALUE >0 COUNT 1
	EXPECT time-at-processing OF-TYPE integer|no-value IN-GROUP document-attributes-tag WITH-VALUE >0 COUNT 1



}

{
	SKIP-IF-NOT-DEFINED HAVE_SET_DOCUMENT_ATTRIBUTES

	NAME "Set Document Attributes"
	OPERATION Set-Document-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 integer document-number 1
	ATTR name requesting-user-name $user

	GROUP document-attributes-tag
	ATTR name document-name "test-document-2" 

	STATUS successful-ok
	STATUS client-error-not-possible


}

{
	SKIP-IF-NOT-DEFINED HAVE_SET_DOCUMENT_ATTRIBUTES

	NAME "To Set New Document Description Values"
	OPERATION Get-Document-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 integer document-number 1
	ATTR name requesting-user-name $user

	STATUS successful-ok

	EXPECT document-job-id OF-TYPE integer IN-GROUP document-attributes-tag WITH-VALUE >0 COUNT 1
	EXPECT document-job-uri OF-TYPE uri IN-GROUP document-attributes-tag COUNT 1
	EXPECT document-name OF-TYPE name IN-GROUP document-attributes-tag COUNT 1
	EXPECT document-number OF-TYPE integer IN-GROUP document-attributes-tag WITH-VALUE 1 COUNT 1
	EXPECT document-printer-uri OF-TYPE uri IN-GROUP document-attributes-tag WITH-VALUE $uri COUNT 1
	EXPECT document-state OF-TYPE enum IN-GROUP document-attributes-tag
	EXPECT document-state-reasons OF-TYPE keyword IN-GROUP document-attributes-tag
}

{
	NAME "Create job"

	OPERATION create-job

	GROUP operation
	ATTR charset attributes-charset utf-8
	ATTR language attributes-natural-language en
	ATTR uri printer-uri $uri
	ATTR name requesting-user-name $user

	GROUP job
	ATTR integer copies 1

	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
}

{
	NAME "testing document-attributes in send-document operation"
	OPERATION send-document

	GROUP operation
	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
	ATTR boolean last-document true

	GROUP job
	ATTR integer copies 1

	FILE $filename

	STATUS successful-ok

    EXPECT ?document-number OF-TYPE integer IN-GROUP document-attributes-tag WITH-VALUE >0 COUNT 1
    EXPECT ?document-state OF-TYPE enum IN-GROUP document-attributes-tag
    EXPECT ?document-state-reasons OF-TYPE keyword IN-GROUP document-attributes-tag
	EXPECT ?document-state-message
#ISSUE: document-number, document-state, and document-state-reasons NOT PRESENT.

}

{
	SKIP-IF-NOT-DEFINED HAVE_SEND_URI

	NAME "testing document-attributes in send-uri operation"
	OPERATION Send-URI

	GROUP operation-attributes-tag
	ATTR charset attributes-charset utf-8
	ATTR naturalLanguage attributes-natural-language en
	ATTR uri printer-uri $uri
	ATTR integer job-id $job-id
	ATTR name requesting-user-name $user	
	ATTR boolean last-document true
	ATTR uri document-uri $document-uri

	GROUP job-attributes-tag
	ATTR integer copies 1
	FILE $filename
	STATUS successful-ok
	EXPECT ?document-number OF-TYPE integer IN-GROUP document-attributes-tag WITH-VALUE >0 COUNT 1
    EXPECT ?document-state OF-TYPE enum IN-GROUP document-attributes-tag
    EXPECT ?document-state-reasons OF-TYPE keyword IN-GROUP document-attributes-tag

#ISSUE: Multiple document jobs are not supported

}

{
	SKIP-IF-NOT-DEFINED HAVE_CANCEL_DOCUMENT
	NAME "testing cancel-document operation"
	OPERATION Cancel-Document

	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 integer document-number 1
	ATTR name requesting-user-name $user

	STATUS successful-ok



}
# To test Get-Documents operation
{
	SKIP-IF-NOT-DEFINED HAVE_GET_DOCUMENTS
	NAME "Get Documents"
	OPERATION Get-Documents

	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

	


	#Document STATUS
	EXPECT document-number OF-TYPE integer IN-GROUP document-attributes-tag WITH-VALUE 1 COUNT 1
	EXPECT last-document OF-TYPE boolean IN-GROUP document-attributes-tag
	EXPECT ?document-charset OF-TYPE charset IN-GROUP document-attributes-tag
	EXPECT ?document-format-detected OF-TYPE mimeMediaType IN-GROUP document-attributes-tag
	EXPECT ?document-message OF-TYPE text IN-GROUP document-attributes-tag


}
{
	NAME "Get document attributes"
	OPERATION Get-Document-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 integer document-number 1
	ATTR name requesting-user-name $user

	STATUS successful-ok

	EXPECT document-job-id OF-TYPE integer IN-GROUP document-attributes-tag WITH-VALUE >0 COUNT 1
	EXPECT document-job-uri OF-TYPE uri IN-GROUP document-attributes-tag COUNT 1
	EXPECT document-number OF-TYPE integer IN-GROUP document-attributes-tag WITH-VALUE 1 COUNT 1
	EXPECT document-printer-uri OF-TYPE uri IN-GROUP document-attributes-tag WITH-VALUE $uri COUNT 1
	EXPECT ?document-state OF-TYPE enum IN-GROUP document-attributes-tag WITH-VALUE 5 COUNT 1 DEFINE-MATCH DOCUMENT_PROCESSING			# processing
	EXPECT document-state OF-TYPE enum IN-GROUP document-attributes-tag WITH-VALUE 7 COUNT 1 IF-NOT-DEFINED DOCUMENT_PROCESSING 		# cancelled
	EXPECT document-state-reasons OF-TYPE keyword IN-GROUP document-attributes-tag WITH-VALUE "processing-to-stop-print" IF-DEFINED DOCUMENT_PROCESSING
}

