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/ChecksumWordSumTest.lvt

namespace Livt.Net.Tests

// Standalone test for the inline RFC 1071 word-sum algorithm.
//
// Verifies that reading logic[8] bytes from a const byte[] into int via
// implicit unsigned conversion and accumulating (hi * 256 + lo) over 32
// big-endian words produces the correct unfolded word sum.
//
// This keeps the payload checksum fixture covered until the
// package has a dedicated payload abstraction.

/**
 * Checks the fixed HTML fixture against an independently calculated unfolded sum.
 */
@Test
component ChecksumWordSumTest
{
	const INDEX_CONTENT : byte[] = "<!doctype html><html><body><h1>Livt FPGA Web</h1></body></html>\n".Encode()

	/**
	 * No mutable fixture state is needed; the content table is fixed for this test.
	 */
	new()
	{
	}

	/**
	 * Compares the supplied network-order inputs with an independent expected checksum or sum.
	 */
	@Test
	fn ComputesWordSumOf64ByteHtmlContent()
	{
		// 64 bytes = 32 big-endian 16-bit words.
		// Expected: sum of all 32 words = 717318.
		var sum: int = 0

		for (var i = 0; i < 32; i++) {
			var hi: int = INDEX_CONTENT[i * 2]
			var lo: int = INDEX_CONTENT[i * 2 + 1]
			sum = sum + hi * 256 + lo
		}

		assert sum == 717318
	}
}