]> git.lizzy.rs Git - dragonfireclient.git/blob - games/devtest/mods/unittests/misc.lua
Get rid of node metadata when it becomes empty
[dragonfireclient.git] / games / devtest / mods / unittests / misc.lua
1 local function test_random()
2         -- Try out PseudoRandom
3         local pseudo = PseudoRandom(13)
4         assert(pseudo:next() == 22290)
5         assert(pseudo:next() == 13854)
6 end
7 unittests.register("test_random", test_random)
8
9 local function test_dynamic_media(cb, player)
10         if core.get_player_information(player:get_player_name()).protocol_version < 40 then
11                 core.log("warning", "test_dynamic_media: Client too old, skipping test.")
12                 return cb()
13         end
14
15         -- Check that the client acknowledges media transfers
16         local path = core.get_worldpath() .. "/test_media.obj"
17         local f = io.open(path, "w")
18         f:write("# contents don't matter\n")
19         f:close()
20
21         local call_ok = false
22         local ok = core.dynamic_add_media({
23                 filepath = path,
24                 to_player = player:get_player_name(),
25         }, function(name)
26                 if not call_ok then
27                         cb("impossible condition")
28                 end
29                 cb()
30         end)
31         if not ok then
32                 return cb("dynamic_add_media() returned error")
33         end
34         call_ok = true
35
36         -- if the callback isn't called this test will just hang :shrug:
37 end
38 unittests.register("test_dynamic_media", test_dynamic_media, {async=true, player=true})
39
40 local function test_v3f_metatable(player)
41         assert(vector.check(player:get_pos()))
42 end
43 unittests.register("test_v3f_metatable", test_v3f_metatable, {player=true})
44
45 local function test_v3s16_metatable(player, pos)
46         local node = minetest.get_node(pos)
47         local found_pos = minetest.find_node_near(pos, 0, node.name, true)
48         assert(vector.check(found_pos))
49 end
50 unittests.register("test_v3s16_metatable", test_v3s16_metatable, {map=true})
51
52 local function test_clear_meta(_, pos)
53         local ref = core.get_meta(pos)
54
55         for way = 1, 3 do
56                 ref:set_string("foo", "bar")
57                 assert(ref:contains("foo"))
58
59                 if way == 1 then
60                         ref:from_table({})
61                 elseif way == 2 then
62                         ref:from_table(nil)
63                 else
64                         ref:set_string("foo", "")
65                 end
66
67                 assert(#core.find_nodes_with_meta(pos, pos) == 0, "clearing failed " .. way)
68         end
69 end
70 unittests.register("test_clear_meta", test_clear_meta, {map=true})