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

WFDeviceInfoTest.lua

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

ADOBE CONFIDENTIAL
------------------
Copyright 2014 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.

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

	-- WF.core.crypto
local WFCrypto = require 'WFCrypto'

	-- WF.core.os
local WFDeviceInfo = require 'WFDeviceInfo'
local WFPlatformInfo = require 'WFPlatformInfo'


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

local WFDeviceInfoTest = {}

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

local function testIsNonEmptyString( test, funcName )

	local value = WFDeviceInfo[ funcName ]()
	test:log( funcName .. " = " .. tostring( value ) )
	
	assert( type( value ) == 'string' )
	assert( #value > 0 )
	
	return value

end

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

function WFDeviceInfoTest.testDeviceName( test )

	testIsNonEmptyString( test, 'deviceName' )

end

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

function WFDeviceInfoTest.testDeviceModel( test )

	testIsNonEmptyString( test, 'deviceModel' )

end

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

if not WFPlatformInfo.isAndroid then

function WFDeviceInfoTest.testCpuType( test )

	testIsNonEmptyString( test, 'cpuType' )

end

end

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

function WFDeviceInfoTest.testUserName( test )

	testIsNonEmptyString( test, 'userName' )

end

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

if not WFPlatformInfo.isMobile() then

function WFDeviceInfoTest.testMacAddress( test )

	testIsNonEmptyString( test, 'macAddress' )

end

end

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

if not WFPlatformInfo.isAndroid then

-- SPAM [immisch 2023-03-16]: this uses the MAC address on Android and is not available any more

function WFDeviceInfoTest.testUniqueVendorIdentifier( test )

	testIsNonEmptyString( test, 'uniqueVendorIdentifier' )

end

end

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

function WFDeviceInfoTest.testUniqueDeviceId( test )

	testIsNonEmptyString( test, 'uniqueDeviceId' )
	
end


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

function WFDeviceInfoTest.testDeviceDescription( test )

	local deviceName = "Test Device"
	local deviceId = "asdfqwer"

	local function dummyDeviceName()
		return deviceName
	end

	local function dummyDeviceId()
		return deviceId
	end

	local realImpl = WFDeviceInfo.DEBUG_overrideImpl {
		deviceName = dummyDeviceName,
		uniqueDeviceId = dummyDeviceId,
	}

	-- formats correctly when device and id are avaiable

	local expectedValue = string.format( "Test Device {%s}", WFCrypto.SHA256.digest( deviceId ) )
	assert( WFDeviceInfo.deviceDescription() == expectedValue )

	-- formats correctly when device and id are not avaiable

	deviceName = nil
	deviceId = nil

	local tryIt = WFDeviceInfo.deviceDescription()
	assert( WFDeviceInfo.deviceDescription() == "Unknown Device {}" )

	WFDeviceInfo.DEBUG_overrideImpl( realImpl )

end

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

return WFDeviceInfoTest
