--[[----------------------------------------------------------------------------

WFCatImportReadMetadataTaskTest.lua

--------------------------------------------------------------------------------

ADOBE CONFIDENTIAL
------------------
Copyright 2015 Adobe Systems Incorporated
All Rights Reserved.

NOTICE: All information contained herein is, and remain the property of
Adobe Systems Incorporated and its suppliers, if any. The intellectual and
technical concepts contained herein are proprietary to Adobe Systems
Incorporated and its suppliers and may be covered by U.S. and Foreign
Patents, patents in process, and are protected by trade secret or copyright
law.  Dissemination of this information or reproduction of this material is
strictly forbidden unless prior written permission is obtained from
Adobe Systems Incorporated.

------------------------------------------------------------------------------]]

if not require 'WFPlatformInfo'.hasACR then return {} end

--------------------------------------------------------------------------------

	-- WF.core.os
local KSPathUtils = require 'KSPathUtils'

	-- WF.core.self_test
local WFRxTestCase = require 'WFRxTestCase'

	-- WF.imaging
local WFXmp = require 'WFXmp'

	-- WF.oz_client.managed_catalog
local WFCatImportReadMetadataTask = require 'WFCatImportReadMetadataTask'


--------------------------------------------------------------------------------

local testDataPath = KSPathUtils.child( KSPathUtils.getStandardFilePath( 'testdata' ),
										"import-samples" )

local testDataFolder1 = KSPathUtils.child( testDataPath, "folder-1" )

local filePath = KSPathUtils.child( testDataFolder1, "IMG_7763.jpg" )


--============================================================================--

local WFCatImportReadMetadataTaskTest = {}

--------------------------------------------------------------------------------

local kNamespace_xap = "http://ns.adobe.com/xap/1.0/"
local kNamespace_exif = "http://ns.adobe.com/exif/1.0/"
local kNamespace_dc = "http://purl.org/dc/elements/1.1/"
	-- TODO [scouten 2015-06-22]: Maybe these namespace declarations should
	-- be coalesced somewhere?

--------------------------------------------------------------------------------

function WFCatImportReadMetadataTaskTest.rxTestReadMetadataFromFile( rxTest )

	rxTest:setTimeLimit( 5 )

	local result

	rxTest:expectSingleValue(
		WFCatImportReadMetadataTask.readMetadataForFileAtPath( filePath )
			:tap( function( value )
				result = value
			end ),
		':ignore:' )

	rxTest:expectEqual( 'table', type( result ) )

	-- TODO [scouten 2015-06-19]: Parsing the XMP here is hopefully temporary.
	-- Eventually the API should return a WFXmp object directly.

	local xmp = WFXmp.WFXmp()
	xmp:parse( result.metadata )

	rxTest:expectEqual( '2015-06-08T08:19:58', xmp:get( kNamespace_xap, 'ModifyDate' ) )

	rxTest:expectEqual( '1153/64', xmp:get( kNamespace_exif, 'GPSAltitude' ) )
	rxTest:expectEqual( '0', xmp:get( kNamespace_exif, 'GPSAltitudeRef' ) )
	rxTest:expectEqual( '47,36.7028333N', xmp:get( kNamespace_exif, 'GPSLatitude' ) )
	rxTest:expectEqual( '122,24.1805W', xmp:get( kNamespace_exif, 'GPSLongitude' ) )
	rxTest:expectEqual( 'image/jpeg', xmp:get( kNamespace_dc, 'format' ) )
		-- TODO [scouten 2015-06-19]: Construct an example that has keywords.

	-- Hard to sample this comprehensively, but we'll take a few important samples.

	rxTest:expectEqual( false, result.isRawFile )

	local additionalInfo = result.additionalInfo

	rxTest:expectEqual( 'table', type( additionalInfo ) )

	rxTest:expectEqual( true, additionalInfo.embeddedXmp )
	rxTest:expectEqual( 2448, additionalInfo.fileHeight )
	rxTest:expectEqual( 3264, additionalInfo.fileWidth )

	rxTest:expectEqual(

		{
			day = 8,
			hour = 8,
			minute = 19,
			month = 6,
			second = 58,
			year = 2015,
		},

		additionalInfo.ExifDateTimeValue )

end

--------------------------------------------------------------------------------

return WFRxTestCase.wrapSuite( WFCatImportReadMetadataTaskTest )
