Livt packages

Livt.Net

Version 1.4.1

Ethernet, IPv4, TCP, UDP, ARP, TFTP, and Telnet networking components for Livt hardware.

Published files (163)

tests/services/ServiceChainTest.lvt

namespace Livt.Net.Tests

using Livt.Net

/**
 * Proves that overlapping custom handlers have deterministic priority.
 */
@Test
component ServiceChainTest
{
	first: FixedService<17>
	second: FixedService<34>
	chain: ServiceChain<FixedService<17>, FixedService<34>>

	/**
	 * Creates two eligible handlers in an explicit priority order.
	 */
	new()
	{
		this.first = new FixedService<17>()
		this.second = new FixedService<34>()
		this.chain = new ServiceChain<FixedService<17>, FixedService<34>>(this.first, this.second)
	}

	/**
	 * Holds the first choice and falls through only after an ignored request.
	 */
	@Test
	fn PreservesPriorityAndSelectedResponse()
	{
		assert this.chain.TryHandle() == ServiceResult.Prepared
		assert this.chain.GetSelection() == ServiceSelection.First
		assert this.first.GetCalls() == 1
		assert this.second.GetCalls() == 0
		assert this.chain.TryHandle() == ServiceResult.Busy
		var value: byte = 0x00
		assert this.chain.TryRead(0, value) == PacketDataResult.Success
		assert value == 0x11
		assert this.chain.TryReleaseResponse() == PacketDataResult.Success
		this.first.Disable()
		assert this.chain.TryHandle() == ServiceResult.Prepared
		assert this.chain.GetSelection() == ServiceSelection.Second
		assert this.first.GetCalls() == 2
		assert this.second.GetCalls() == 1
		assert this.chain.TryRead(0, value) == PacketDataResult.Success
		assert value == 0x22
		assert this.chain.TryReleaseResponse() == PacketDataResult.Success
		assert !this.chain.IsReady()
		assert this.chain.TryRead(0, value) == PacketDataResult.NotReady
		assert value == 0x00
	}
}