spec/util_bitcompat_spec.lua
author Kim Alvefur <zash@zash.se>
Fri, 27 May 2022 14:45:35 +0200
branch0.12
changeset 12530 252ed01896dd
parent 12370 c640717e01ca
child 13453 9912baa541c0
permissions -rw-r--r--
mod_smacks: Bounce unhandled stanzas from local origin (fix #1759) Sending stanzas with a remote session as origin when the stanzas have a local JID in the from attribute trips validation in core.stanza_router, leading to warnings: > Received a stanza claiming to be from remote.example, over a stream authed for localhost.example Using module:send() uses the local host as origin, which is fine here.

describe("util.bitcompat", function ()
	-- bitcompat will pass through to an appropriate implementation. Our
	-- goal here is to check that whatever implementation is in use passes
	-- these basic sanity checks.

	local bit = require "util.bitcompat";

	it("bor works", function ()
		assert.equal(0xF0FF, bit.bor(0xF000, 0x00F0, 0x000F));
	end);

	it("band works", function ()
		assert.equal(0x0F, bit.band(0xFF, 0x1F, 0x0F));
	end);

	it("bxor works", function ()
		assert.equal(0x13, bit.bxor(0x10, 0x0F, 0x0C));
	end);

	it("rshift works", function ()
		assert.equal(0x0F, bit.rshift(0xFF, 4));
	end);

	it("lshift works", function ()
		assert.equal(0xFF00, bit.lshift(0xFF, 8));
	end);
end);