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

WFBonjourRxTest.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.

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

local WFPlatformInfo = require 'WFPlatformInfo'

-- FIXME [jclauson 2020-03-22]: Disabling this test suite on windows, as we've
-- removed bonjour support on that platform.

if WFPlatformInfo.isWindows then
	return {}
end

	-- WF.core.logging
local WFLogger = require 'WFLogger'

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

	-- WF.web.bonjour
local WFBonjour = require 'WFBonjour'


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

local WFBonjourRxTest = {}

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

local logger = WFLogger( 'WFBonjourRxTest' )

local publishServiceName = "" -- Empty name lets the system choose (machine name mostly)
local publishServicePort = 7890
local publishServiceType = WFBonjour.kServiceTypeLightroomP2P
local publishServiceTxtData = { ["attrib1"] = "value1", ["attrib2"] = "value2" }
-- local publishServiceTxtData2 = { ["attrib1"] = "value1", ["attrib2"] = "value2", ["surprise"] = "Hello World!" }

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

function WFBonjourRxTest.rxTest_00_Start( rxTest )

	logger:enable( 'print' )
	
	rxTest:setTimeLimit( 30 ) -- All duration values are in seconds.

	local publishHandle = nil

	--
	-- Acquire an observable for the WFBonjour event stream:
	--
	
	local sub1 = WFBonjour.observable()
		:subscribe( function( data ) 
			logger:infof( '%s', data )
		end )

	--
	-- Start Bonjour service
	--
	
	rxTest:expectOnlyCompleted( WFBonjour.start() )
		
	--
	-- Publish a service
	--

	local sub2 = WFBonjour.publishService( publishServiceName, publishServiceType, publishServicePort, publishServiceTxtData )
		:filter( function( result ) 
			return( result.success )
		end )
		:subscribe( function( result ) 
			publishHandle = result.data
		end )

	--
	-- Wait a while
	--

	rxTest:expectOnlyCompleted( WFBonjour.sleep( 5 ) )

	--
	-- Stop Bonjour service
	--

	rxTest:expectOnlyCompleted( WFBonjour.stop() )
	
	sub1:dispose()
	sub2:dispose()
	
end


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

return WFRxTestCase.wrapSuite( 'WFBonjourRxTest', WFBonjourRxTest )
