From d3a5d1e31450506249af9a4d42eee828bf934c5a Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Fri, 20 Aug 2021 18:35:00 +0100 Subject: [PATCH] Add tests for transmitting via wired modems It crashes on 1.17 right now, so worth checking! --- .../dan200/computercraft/ingame/ModemTest.kt | 6 + .../modem_test.transmits_messages.receive.lua | 10 + .../modem_test.transmits_messages.send.lua | 5 + .../modem_test.transmits_messages.snbt | 588 ++++++++++++++++++ 4 files changed, 609 insertions(+) create mode 100644 src/testMod/server-files/computers/computer/0/tests/modem_test.transmits_messages.receive.lua create mode 100644 src/testMod/server-files/computers/computer/0/tests/modem_test.transmits_messages.send.lua create mode 100644 src/testMod/server-files/structures/modem_test.transmits_messages.snbt diff --git a/src/testMod/java/dan200/computercraft/ingame/ModemTest.kt b/src/testMod/java/dan200/computercraft/ingame/ModemTest.kt index 5a3e417b2..552151a09 100644 --- a/src/testMod/java/dan200/computercraft/ingame/ModemTest.kt +++ b/src/testMod/java/dan200/computercraft/ingame/ModemTest.kt @@ -22,4 +22,10 @@ class Modem_Test { } .thenComputerOk() } + + /** + * Sends a modem message to another computer on the same network + */ + @GameTest + fun Transmits_messages(context: GameTestHelper) = context.sequence { thenComputerOk("receive") } } diff --git a/src/testMod/server-files/computers/computer/0/tests/modem_test.transmits_messages.receive.lua b/src/testMod/server-files/computers/computer/0/tests/modem_test.transmits_messages.receive.lua new file mode 100644 index 000000000..7a2daa82b --- /dev/null +++ b/src/testMod/server-files/computers/computer/0/tests/modem_test.transmits_messages.receive.lua @@ -0,0 +1,10 @@ +local modem = peripheral.find("modem") +modem.open(12) + + +local _, name, chan, reply, payload, distance = os.pullEvent("modem_message") +test.eq("left", name, "Modem name") +test.eq(12, chan, "Channel") +test.eq(34, reply, "Reply channel") +test.eq("Hello!", payload, "Payload") +test.eq(4, distance, "Distance") -- Why 4?! diff --git a/src/testMod/server-files/computers/computer/0/tests/modem_test.transmits_messages.send.lua b/src/testMod/server-files/computers/computer/0/tests/modem_test.transmits_messages.send.lua new file mode 100644 index 000000000..0d36bb1a0 --- /dev/null +++ b/src/testMod/server-files/computers/computer/0/tests/modem_test.transmits_messages.send.lua @@ -0,0 +1,5 @@ +local modem = peripheral.find("modem") +while true do + modem.transmit(12, 34, "Hello!") + sleep(1) +end diff --git a/src/testMod/server-files/structures/modem_test.transmits_messages.snbt b/src/testMod/server-files/structures/modem_test.transmits_messages.snbt new file mode 100644 index 000000000..cb6945577 --- /dev/null +++ b/src/testMod/server-files/structures/modem_test.transmits_messages.snbt @@ -0,0 +1,588 @@ +{ + size: [5, 5, 5], + entities: [], + blocks: [ + { + pos: [0, 0, 0], + state: 0 + }, + { + pos: [0, 0, 1], + state: 0 + }, + { + pos: [0, 0, 2], + state: 0 + }, + { + pos: [0, 0, 3], + state: 0 + }, + { + pos: [0, 0, 4], + state: 0 + }, + { + pos: [1, 0, 0], + state: 0 + }, + { + pos: [1, 0, 1], + state: 0 + }, + { + pos: [1, 0, 2], + state: 0 + }, + { + pos: [1, 0, 3], + state: 0 + }, + { + pos: [1, 0, 4], + state: 0 + }, + { + pos: [2, 0, 0], + state: 0 + }, + { + pos: [2, 0, 1], + state: 0 + }, + { + pos: [2, 0, 2], + state: 0 + }, + { + pos: [2, 0, 3], + state: 0 + }, + { + pos: [2, 0, 4], + state: 0 + }, + { + pos: [3, 0, 0], + state: 0 + }, + { + pos: [3, 0, 1], + state: 0 + }, + { + pos: [3, 0, 2], + state: 0 + }, + { + pos: [3, 0, 3], + state: 0 + }, + { + pos: [3, 0, 4], + state: 0 + }, + { + pos: [4, 0, 0], + state: 0 + }, + { + pos: [4, 0, 1], + state: 0 + }, + { + pos: [4, 0, 2], + state: 0 + }, + { + pos: [4, 0, 3], + state: 0 + }, + { + pos: [4, 0, 4], + state: 0 + }, + { + pos: [0, 1, 0], + state: 1 + }, + { + pos: [0, 1, 1], + state: 1 + }, + { + pos: [0, 1, 2], + state: 1 + }, + { + pos: [0, 1, 3], + state: 1 + }, + { + pos: [0, 1, 4], + state: 1 + }, + { + pos: [1, 1, 0], + state: 1 + }, + { + pos: [1, 1, 1], + state: 1 + }, + { + pos: [1, 1, 2], + state: 1 + }, + { + pos: [1, 1, 4], + state: 1 + }, + { + pos: [2, 1, 0], + state: 1 + }, + { + pos: [2, 1, 4], + state: 1 + }, + { + pos: [3, 1, 0], + state: 1 + }, + { + pos: [3, 1, 2], + state: 1 + }, + { + pos: [3, 1, 3], + state: 1 + }, + { + pos: [3, 1, 4], + state: 1 + }, + { + pos: [4, 1, 0], + state: 1 + }, + { + pos: [4, 1, 1], + state: 1 + }, + { + pos: [4, 1, 2], + state: 1 + }, + { + pos: [4, 1, 3], + state: 1 + }, + { + pos: [4, 1, 4], + state: 1 + }, + { + pos: [0, 2, 0], + state: 1 + }, + { + pos: [0, 2, 1], + state: 1 + }, + { + pos: [0, 2, 2], + state: 1 + }, + { + pos: [0, 2, 3], + state: 1 + }, + { + pos: [0, 2, 4], + state: 1 + }, + { + pos: [1, 2, 0], + state: 1 + }, + { + pos: [1, 2, 1], + state: 1 + }, + { + pos: [1, 2, 2], + state: 1 + }, + { + pos: [1, 2, 3], + state: 1 + }, + { + pos: [1, 2, 4], + state: 1 + }, + { + pos: [2, 2, 0], + state: 1 + }, + { + pos: [2, 2, 1], + state: 1 + }, + { + pos: [2, 2, 2], + state: 1 + }, + { + pos: [2, 2, 3], + state: 1 + }, + { + pos: [2, 2, 4], + state: 1 + }, + { + pos: [3, 2, 0], + state: 1 + }, + { + pos: [3, 2, 1], + state: 1 + }, + { + pos: [3, 2, 2], + state: 1 + }, + { + pos: [3, 2, 3], + state: 1 + }, + { + pos: [3, 2, 4], + state: 1 + }, + { + pos: [4, 2, 0], + state: 1 + }, + { + pos: [4, 2, 1], + state: 1 + }, + { + pos: [4, 2, 2], + state: 1 + }, + { + pos: [4, 2, 3], + state: 1 + }, + { + pos: [4, 2, 4], + state: 1 + }, + { + pos: [0, 3, 0], + state: 1 + }, + { + pos: [0, 3, 1], + state: 1 + }, + { + pos: [0, 3, 2], + state: 1 + }, + { + pos: [0, 3, 3], + state: 1 + }, + { + pos: [0, 3, 4], + state: 1 + }, + { + pos: [1, 3, 0], + state: 1 + }, + { + pos: [1, 3, 1], + state: 1 + }, + { + pos: [1, 3, 2], + state: 1 + }, + { + pos: [1, 3, 3], + state: 1 + }, + { + pos: [1, 3, 4], + state: 1 + }, + { + pos: [2, 3, 0], + state: 1 + }, + { + pos: [2, 3, 1], + state: 1 + }, + { + pos: [2, 3, 2], + state: 1 + }, + { + pos: [2, 3, 3], + state: 1 + }, + { + pos: [2, 3, 4], + state: 1 + }, + { + pos: [3, 3, 0], + state: 1 + }, + { + pos: [3, 3, 1], + state: 1 + }, + { + pos: [3, 3, 2], + state: 1 + }, + { + pos: [3, 3, 3], + state: 1 + }, + { + pos: [3, 3, 4], + state: 1 + }, + { + pos: [4, 3, 0], + state: 1 + }, + { + pos: [4, 3, 1], + state: 1 + }, + { + pos: [4, 3, 2], + state: 1 + }, + { + pos: [4, 3, 3], + state: 1 + }, + { + pos: [4, 3, 4], + state: 1 + }, + { + pos: [0, 4, 0], + state: 1 + }, + { + pos: [0, 4, 1], + state: 1 + }, + { + pos: [0, 4, 2], + state: 1 + }, + { + pos: [0, 4, 3], + state: 1 + }, + { + pos: [0, 4, 4], + state: 1 + }, + { + pos: [1, 4, 0], + state: 1 + }, + { + pos: [1, 4, 1], + state: 1 + }, + { + pos: [1, 4, 2], + state: 1 + }, + { + pos: [1, 4, 3], + state: 1 + }, + { + pos: [1, 4, 4], + state: 1 + }, + { + pos: [2, 4, 0], + state: 1 + }, + { + pos: [2, 4, 1], + state: 1 + }, + { + pos: [2, 4, 2], + state: 1 + }, + { + pos: [2, 4, 3], + state: 1 + }, + { + pos: [2, 4, 4], + state: 1 + }, + { + pos: [3, 4, 0], + state: 1 + }, + { + pos: [3, 4, 1], + state: 1 + }, + { + pos: [3, 4, 2], + state: 1 + }, + { + pos: [3, 4, 3], + state: 1 + }, + { + pos: [3, 4, 4], + state: 1 + }, + { + pos: [4, 4, 0], + state: 1 + }, + { + pos: [4, 4, 1], + state: 1 + }, + { + pos: [4, 4, 2], + state: 1 + }, + { + pos: [4, 4, 3], + state: 1 + }, + { + pos: [4, 4, 4], + state: 1 + }, + { + nbt: { + Label: "modem_test.transmits_messages.receive", + id: "computercraft:computer_advanced", + ComputerId: 0, + On: 1b + }, + pos: [1, 1, 3], + state: 2 + }, + { + nbt: { + PeirpheralAccess: 0b, + id: "computercraft:cable" + }, + pos: [2, 1, 1], + state: 3 + }, + { + nbt: { + PeirpheralAccess: 0b, + id: "computercraft:cable" + }, + pos: [2, 1, 2], + state: 4 + }, + { + nbt: { + PeirpheralAccess: 0b, + id: "computercraft:cable" + }, + pos: [2, 1, 3], + state: 5 + }, + { + nbt: { + Label: "modem_test.transmits_messages.send", + id: "computercraft:computer_advanced", + ComputerId: 0, + On: 1b + }, + pos: [3, 1, 1], + state: 2 + } + ], + palette: [ + { + Name: "minecraft:polished_andesite" + }, + { + Name: "minecraft:air" + }, + { + Properties: { + facing: "north", + state: "blinking" + }, + Name: "computercraft:computer_advanced" + }, + { + Properties: { + east: "true", + waterlogged: "false", + south: "true", + north: "false", + west: "false", + modem: "east_off", + up: "false", + cable: "true", + down: "false" + }, + Name: "computercraft:cable" + }, + { + Properties: { + east: "false", + waterlogged: "false", + south: "true", + north: "true", + west: "false", + modem: "none", + up: "false", + cable: "true", + down: "false" + }, + Name: "computercraft:cable" + }, + { + Properties: { + east: "false", + waterlogged: "false", + south: "false", + north: "true", + west: "true", + modem: "west_off", + up: "false", + cable: "true", + down: "false" + }, + Name: "computercraft:cable" + } + ], + DataVersion: 2586 +}