5 changes: 2 additions & 3 deletions src/script/lua_api/l_mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1734,11 +1734,10 @@ int ModApiMapgen::l_serialize_schematic(lua_State *L)
std::ostringstream os(std::ios_base::binary);
switch (schem_format) {
case SCHEM_FMT_MTS:
schem->serializeToMts(&os, schem->m_nodenames);
schem->serializeToMts(&os);
break;
case SCHEM_FMT_LUA:
schem->serializeToLua(&os, schem->m_nodenames,
use_comments, indent_spaces);
schem->serializeToLua(&os, use_comments, indent_spaces);
break;
default:
return 0;
Expand Down
2 changes: 2 additions & 0 deletions src/unittest/test_noderesolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ void TestNodeResolver::runTests(IGameDef *gamedef)

class Foobar : public NodeResolver {
public:
friend class TestNodeResolver; // m_ndef

void resolveNodeNames();

content_t test_nr_node1;
Expand Down
40 changes: 23 additions & 17 deletions src/unittest/test_schematic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ void TestSchematic::testMtsSerializeDeserialize(const NodeDefManager *ndef)
std::stringstream ss(std::ios_base::binary |
std::ios_base::in | std::ios_base::out);

std::vector<std::string> names;
names.emplace_back("foo");
names.emplace_back("bar");
names.emplace_back("baz");
names.emplace_back("qux");

Schematic schem, schem2;
Schematic schem;
{
std::vector<std::string> &names = schem.m_nodenames;
names.emplace_back("foo");
names.emplace_back("bar");
names.emplace_back("baz");
names.emplace_back("qux");
}

schem.flags = 0;
schem.size = size;
Expand All @@ -83,18 +84,21 @@ void TestSchematic::testMtsSerializeDeserialize(const NodeDefManager *ndef)
for (s16 y = 0; y != size.Y; y++)
schem.slice_probs[y] = MTSCHEM_PROB_ALWAYS;

UASSERT(schem.serializeToMts(&ss, names));
UASSERT(schem.serializeToMts(&ss));

ss.seekg(0);
names.clear();

UASSERT(schem2.deserializeFromMts(&ss, &names));
Schematic schem2;
UASSERT(schem2.deserializeFromMts(&ss));

UASSERTEQ(size_t, names.size(), 4);
UASSERTEQ(std::string, names[0], "foo");
UASSERTEQ(std::string, names[1], "bar");
UASSERTEQ(std::string, names[2], "baz");
UASSERTEQ(std::string, names[3], "qux");
{
std::vector<std::string> &names = schem2.m_nodenames;
UASSERTEQ(size_t, names.size(), 4);
UASSERTEQ(std::string, names[0], "foo");
UASSERTEQ(std::string, names[1], "bar");
UASSERTEQ(std::string, names[2], "baz");
UASSERTEQ(std::string, names[3], "qux");
}

UASSERT(schem2.size == size);
for (size_t i = 0; i != volume; i++)
Expand All @@ -120,14 +124,14 @@ void TestSchematic::testLuaTableSerialize(const NodeDefManager *ndef)
for (s16 y = 0; y != size.Y; y++)
schem.slice_probs[y] = MTSCHEM_PROB_ALWAYS;

std::vector<std::string> names;
std::vector<std::string> &names = schem.m_nodenames;
names.emplace_back("air");
names.emplace_back("default:lava_source");
names.emplace_back("default:glass");

std::ostringstream ss(std::ios_base::binary);

UASSERT(schem.serializeToLua(&ss, names, false, 0));
UASSERT(schem.serializeToLua(&ss, false, 0));
UASSERTEQ(std::string, ss.str(), expected_lua_output);
}

Expand Down Expand Up @@ -159,6 +163,8 @@ void TestSchematic::testFileSerializeDeserialize(const NodeDefManager *ndef)
schem1.slice_probs[0] = 80;
schem1.slice_probs[1] = 160;
schem1.slice_probs[2] = 240;
// Node resolving happened manually.
schem1.m_resolve_done = true;

for (size_t i = 0; i != volume; i++) {
content_t c = content_map[test_schem2_data[i]];
Expand Down