void TestMapSettingsManager::testMapMetaSaveLoad() { Settings conf; std::string path = getTestTempDirectory() + DIR_DELIM + "foobar" + DIR_DELIM + "map_meta.txt"; // Create a set of mapgen params and save them to map meta conf.set("seed", "12345"); conf.set("water_level", "5"); MapSettingsManager mgr1(&conf, path); MapgenParams *params1 = mgr1.makeMapgenParams(); UASSERT(params1); UASSERT(mgr1.saveMapMeta()); // Now try loading the map meta to mapgen params conf.set("seed", "67890"); conf.set("water_level", "32"); MapSettingsManager mgr2(&conf, path); UASSERT(mgr2.loadMapMeta()); MapgenParams *params2 = mgr2.makeMapgenParams(); UASSERT(params2); // Check that both results are correct UASSERTEQ(u64, params1->seed, 12345); UASSERTEQ(s16, params1->water_level, 5); UASSERTEQ(u64, params2->seed, 12345); UASSERTEQ(s16, params2->water_level, 5); }
void TestRandom::testPcgRandom() { PcgRandom pr(814538, 998877); for (u32 i = 0; i != 256; i++) UASSERTEQ(u32, pr.next(), expected_pcgrandom_results[i]); }
void TestSchematic::testLuaTableSerialize(INodeDefManager *ndef) { static const v3s16 size(3, 3, 3); static const u32 volume = size.X * size.Y * size.Z; Schematic schem; schem.flags = 0; schem.size = size; schem.schemdata = new MapNode[volume]; schem.slice_probs = new u8[size.Y]; for (size_t i = 0; i != volume; i++) schem.schemdata[i] = MapNode(test_schem2_data[i], test_schem2_prob[i], 0); for (s16 y = 0; y != size.Y; y++) schem.slice_probs[y] = MTSCHEM_PROB_ALWAYS; std::vector<std::string> names; names.push_back("air"); names.push_back("default:lava_source"); names.push_back("default:glass"); std::ostringstream ss(std::ios_base::binary); UASSERT(schem.serializeToLua(&ss, names, false, 0)); UASSERTEQ(std::string, ss.str(), expected_lua_output); }
void TestInventory::testSerializeDeserialize(IItemDefManager *idef) { Inventory inv(idef); std::istringstream is(serialized_inventory, std::ios::binary); inv.deSerialize(is); UASSERT(inv.getList("0")); UASSERT(!inv.getList("main")); inv.getList("0")->setName("main"); UASSERT(!inv.getList("0")); UASSERT(inv.getList("main")); UASSERTEQ(u32, inv.getList("main")->getWidth(), 3); inv.getList("main")->setWidth(5); std::ostringstream inv_os(std::ios::binary); inv.serialize(inv_os); UASSERTEQ(std::string, inv_os.str(), serialized_inventory_2); }
void TestVoxelAlgorithms::testVoxelLineIterator(INodeDefManager *ndef) { // Test some lines // Do not test lines that start or end on the border of // two voxels as rounding errors can make the test fail! std::vector<core::line3d<f32> > lines; for (f32 x = -9.1; x < 9; x += 3.124) { for (f32 y = -9.2; y < 9; y += 3.123) { for (f32 z = -9.3; z < 9; z += 3.122) { lines.push_back(core::line3d<f32>(-x, -y, -z, x, y, z)); } } } lines.push_back(core::line3d<f32>(0, 0, 0, 0, 0, 0)); // Test every line std::vector<core::line3d<f32> >::iterator it = lines.begin(); for (; it < lines.end(); it++) { core::line3d<f32> l = *it; // Initialize test voxalgo::VoxelLineIterator iterator(l.start, l.getVector()); //Test the first voxel v3s16 start_voxel = floatToInt(l.start, 1); UASSERT(iterator.m_current_node_pos == start_voxel); // Values for testing v3s16 end_voxel = floatToInt(l.end, 1); v3s16 voxel_vector = end_voxel - start_voxel; int nodecount = abs(voxel_vector.X) + abs(voxel_vector.Y) + abs(voxel_vector.Z); int actual_nodecount = 0; v3s16 old_voxel = iterator.m_current_node_pos; while (iterator.hasNext()) { iterator.next(); actual_nodecount++; v3s16 new_voxel = iterator.m_current_node_pos; // This must be a neighbor of the old voxel UASSERTEQ(f32, (new_voxel - old_voxel).getLengthSQ(), 1); // The line must intersect with the voxel v3f voxel_center = intToFloat(iterator.m_current_node_pos, 1); aabb3f box(voxel_center - v3f(0.5, 0.5, 0.5), voxel_center + v3f(0.5, 0.5, 0.5)); UASSERT(box.intersectsWithLine(l)); // Update old voxel old_voxel = new_voxel; } // Test last node UASSERT(iterator.m_current_node_pos == end_voxel); // Test node count UASSERTEQ(int, actual_nodecount, nodecount); } }
void TestAreaStore::testSerialization() { VectorAreaStore store; Area a(v3s16(-1, 0, 1), v3s16(0, 1, 2)); a.data = "Area A"; store.insertArea(&a); Area b(v3s16(123, 456, 789), v3s16(32000, 100, 10)); b.data = "Area B"; store.insertArea(&b); std::ostringstream os; store.serialize(os); std::string str = os.str(); std::string str_wanted("\x00" // Version "\x00\x02" // Count "\xFF\xFF\x00\x00\x00\x01" // Area A min edge "\x00\x00\x00\x01\x00\x02" // Area A max edge "\x00\x06" // Area A data length "Area A" // Area A data "\x00\x7B\x00\x64\x00\x0A" // Area B min edge (last two swapped with max edge for sorting) "\x7D\x00\x01\xC8\x03\x15" // Area B max edge (^) "\x00\x06" // Area B data length "Area B", // Area B data 1 + 2 + 6 + 6 + 2 + 6 + 6 + 6 + 2 + 6); UASSERTEQ(std::string, str, str_wanted); std::istringstream is(str); store.deserialize(is); UASSERTEQ(size_t, store.size(), 4); // deserialize() doesn't clear the store }
void TestSchematic::testMtsSerializeDeserialize(INodeDefManager *ndef) { static const v3s16 size(7, 6, 4); static const u32 volume = size.X * size.Y * size.Z; std::stringstream ss(std::ios_base::binary | std::ios_base::in | std::ios_base::out); std::vector<std::string> names; names.push_back("foo"); names.push_back("bar"); names.push_back("baz"); names.push_back("qux"); Schematic schem, schem2; schem.flags = 0; schem.size = size; schem.schemdata = new MapNode[volume]; schem.slice_probs = new u8[size.Y]; for (size_t i = 0; i != volume; i++) schem.schemdata[i] = MapNode(test_schem1_data[i], MTSCHEM_PROB_ALWAYS, 0); for (s16 y = 0; y != size.Y; y++) schem.slice_probs[y] = MTSCHEM_PROB_ALWAYS; UASSERT(schem.serializeToMts(&ss, names)); ss.seekg(0); names.clear(); UASSERT(schem2.deserializeFromMts(&ss, &names)); 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++) UASSERT(schem2.schemdata[i] == schem.schemdata[i]); for (s16 y = 0; y != size.Y; y++) UASSERTEQ(u8, schem2.slice_probs[y], schem.slice_probs[y]); }
void TestAreaStore::genericStoreTest(AreaStore *store) { Area a(v3s16(-10, -3, 5), v3s16(0, 29, 7)); a.id = 1; Area b(v3s16(-5, -2, 5), v3s16(0, 28, 6)); b.id = 2; Area c(v3s16(-7, -3, 6), v3s16(-1, 27, 7)); c.id = 3; std::vector<Area *> res; UASSERTEQ(size_t, store->size(), 0); store->reserve(2); // sic store->insertArea(a); store->insertArea(b); store->insertArea(c); UASSERTEQ(size_t, store->size(), 3); store->getAreasForPos(&res, v3s16(-1, 0, 6)); UASSERTEQ(size_t, res.size(), 3); res.clear(); store->getAreasForPos(&res, v3s16(0, 0, 7)); UASSERTEQ(size_t, res.size(), 1); UASSERTEQ(u32, res[0]->id, 1); res.clear(); store->removeArea(1); store->getAreasForPos(&res, v3s16(0, 0, 7)); UASSERTEQ(size_t, res.size(), 0); res.clear(); store->insertArea(a); store->getAreasForPos(&res, v3s16(0, 0, 7)); UASSERTEQ(size_t, res.size(), 1); UASSERTEQ(u32, res[0]->id, 1); res.clear(); store->getAreasInArea(&res, v3s16(-10, -3, 5), v3s16(0, 29, 7), false); UASSERTEQ(size_t, res.size(), 3); res.clear(); store->getAreasInArea(&res, v3s16(-100, 0, 6), v3s16(200, 0, 6), false); UASSERTEQ(size_t, res.size(), 0); res.clear(); store->getAreasInArea(&res, v3s16(-100, 0, 6), v3s16(200, 0, 6), true); UASSERTEQ(size_t, res.size(), 3); res.clear(); store->removeArea(1); store->removeArea(2); store->removeArea(3); Area d(v3s16(-100, -300, -200), v3s16(-50, -200, -100)); d.id = 4; d.data = "Hi!"; store->insertArea(d); store->getAreasForPos(&res, v3s16(-75, -250, -150)); UASSERTEQ(size_t, res.size(), 1); UASSERTEQ(u32, res[0]->id, 4); UASSERTEQ(u16, res[0]->data.size(), 3); UASSERT(strncmp(res[0]->data.c_str(), "Hi!", 3) == 0); res.clear(); store->removeArea(4); }