aboutsummaryrefslogtreecommitdiff
path: root/games/devtest/mods/unittests/misc.lua
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2022-05-17 22:12:00 +0200
committerElias Fleckenstein <eliasfleckenstein@web.de>2022-05-17 22:12:00 +0200
commit21df26984da91143c15587f5a03c98d68c3adc4e (patch)
treeaaa707a628ad331f67890023dffe1b4f60dd01d3 /games/devtest/mods/unittests/misc.lua
parentb09fc5de5cdb021f43ad32b7e3f50dc75c0bc622 (diff)
parenteabf05758e3ba5f6f4bb1b8d1d1f02179b84e410 (diff)
downloaddragonfireclient-21df26984da91143c15587f5a03c98d68c3adc4e.tar.xz
Merge branch 'master' of https://github.com/minetest/minetest
Diffstat (limited to 'games/devtest/mods/unittests/misc.lua')
-rw-r--r--games/devtest/mods/unittests/misc.lua50
1 files changed, 50 insertions, 0 deletions
diff --git a/games/devtest/mods/unittests/misc.lua b/games/devtest/mods/unittests/misc.lua
new file mode 100644
index 000000000..ba980866a
--- /dev/null
+++ b/games/devtest/mods/unittests/misc.lua
@@ -0,0 +1,50 @@
+local function test_random()
+ -- Try out PseudoRandom
+ local pseudo = PseudoRandom(13)
+ assert(pseudo:next() == 22290)
+ assert(pseudo:next() == 13854)
+end
+unittests.register("test_random", test_random)
+
+local function test_dynamic_media(cb, player)
+ if core.get_player_information(player:get_player_name()).protocol_version < 40 then
+ core.log("warning", "test_dynamic_media: Client too old, skipping test.")
+ return cb()
+ end
+
+ -- Check that the client acknowledges media transfers
+ local path = core.get_worldpath() .. "/test_media.obj"
+ local f = io.open(path, "w")
+ f:write("# contents don't matter\n")
+ f:close()
+
+ local call_ok = false
+ local ok = core.dynamic_add_media({
+ filepath = path,
+ to_player = player:get_player_name(),
+ }, function(name)
+ if not call_ok then
+ cb("impossible condition")
+ end
+ cb()
+ end)
+ if not ok then
+ return cb("dynamic_add_media() returned error")
+ end
+ call_ok = true
+
+ -- if the callback isn't called this test will just hang :shrug:
+end
+unittests.register("test_dynamic_media", test_dynamic_media, {async=true, player=true})
+
+local function test_v3f_metatable(player)
+ assert(vector.check(player:get_pos()))
+end
+unittests.register("test_v3f_metatable", test_v3f_metatable, {player=true})
+
+local function test_v3s16_metatable(player, pos)
+ local node = minetest.get_node(pos)
+ local found_pos = minetest.find_node_near(pos, 0, node.name, true)
+ assert(vector.check(found_pos))
+end
+unittests.register("test_v3s16_metatable", test_v3s16_metatable, {map=true})