#include "itemdef.h"
#include "gamedef.h"
-content_t CONTENT_STONE;
-content_t CONTENT_GRASS;
-content_t CONTENT_TORCH;
+content_t t_CONTENT_STONE;
+content_t t_CONTENT_GRASS;
+content_t t_CONTENT_TORCH;
+content_t t_CONTENT_WATER;
+content_t t_CONTENT_LAVA;
+content_t t_CONTENT_BRICK;
////////////////////////////////////////////////////////////////////////////////
f.tiledef[i].name = "default_stone.png";
f.is_ground_content = true;
idef->registerItem(itemdef);
- CONTENT_STONE = ndef->set(f.name, f);
+ t_CONTENT_STONE = ndef->set(f.name, f);
//// Grass
itemdef = ItemDefinition();
f.tiledef[i].name = "default_dirt.png^default_grass_side.png";
f.is_ground_content = true;
idef->registerItem(itemdef);
- CONTENT_GRASS = ndef->set(f.name, f);
+ t_CONTENT_GRASS = ndef->set(f.name, f);
//// Torch (minimal definition for lighting tests)
itemdef = ItemDefinition();
f.sunlight_propagates = true;
f.light_source = LIGHT_MAX-1;
idef->registerItem(itemdef);
- CONTENT_TORCH = ndef->set(f.name, f);
+ t_CONTENT_TORCH = ndef->set(f.name, f);
+
+ //// Water
+ itemdef = ItemDefinition();
+ itemdef.type = ITEM_NODE;
+ itemdef.name = "default:water";
+ itemdef.description = "Water";
+ itemdef.inventory_image = "[inventorycube"
+ "{default_water.png"
+ "{default_water.png"
+ "{default_water.png";
+ f = ContentFeatures();
+ f.name = itemdef.name;
+ f.alpha = 128;
+ f.liquid_type = LIQUID_SOURCE;
+ f.liquid_viscosity = 4;
+ f.is_ground_content = true;
+ f.groups["liquids"] = 3;
+ for(int i = 0; i < 6; i++)
+ f.tiledef[i].name = "default_water.png";
+ idef->registerItem(itemdef);
+ t_CONTENT_WATER = ndef->set(f.name, f);
+
+ //// Lava
+ itemdef = ItemDefinition();
+ itemdef.type = ITEM_NODE;
+ itemdef.name = "default:lava";
+ itemdef.description = "Lava";
+ itemdef.inventory_image = "[inventorycube"
+ "{default_lava.png"
+ "{default_lava.png"
+ "{default_lava.png";
+ f = ContentFeatures();
+ f.name = itemdef.name;
+ f.alpha = 128;
+ f.liquid_type = LIQUID_SOURCE;
+ f.liquid_viscosity = 7;
+ f.light_source = LIGHT_MAX-1;
+ f.is_ground_content = true;
+ f.groups["liquids"] = 3;
+ for(int i = 0; i < 6; i++)
+ f.tiledef[i].name = "default_lava.png";
+ idef->registerItem(itemdef);
+ t_CONTENT_LAVA = ndef->set(f.name, f);
+
+
+ //// Brick
+ itemdef = ItemDefinition();
+ itemdef.type = ITEM_NODE;
+ itemdef.name = "default:brick";
+ itemdef.description = "Brick";
+ itemdef.groups["cracky"] = 3;
+ itemdef.inventory_image = "[inventorycube"
+ "{default_brick.png"
+ "{default_brick.png"
+ "{default_brick.png";
+ f = ContentFeatures();
+ f.name = itemdef.name;
+ for(int i = 0; i < 6; i++)
+ f.tiledef[i].name = "default_brick.png";
+ f.is_ground_content = true;
+ idef->registerItem(itemdef);
+ t_CONTENT_BRICK = ndef->set(f.name, f);
}
////
--- /dev/null
+/*
+Minetest
+Copyright (C) 2010-2014 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "test.h"
+
+#include "exceptions.h"
+#include "gamedef.h"
+#include "nodedef.h"
+
+
+class TestNodeResolver : public TestBase {
+public:
+ TestNodeResolver() { TestManager::registerTestModule(this); }
+ const char *getName() { return "TestNodeResolver"; }
+
+ void runTests(IGameDef *gamedef);
+
+ void testNodeResolving(INodeDefManager *ndef);
+ void testPendingResolveCancellation(INodeDefManager *ndef);
+ void testDirectResolveMethod(INodeDefManager *ndef);
+ void testNoneResolveMethod(INodeDefManager *ndef);
+};
+
+static TestNodeResolver g_test_instance;
+
+void TestNodeResolver::runTests(IGameDef *gamedef)
+{
+ IWritableNodeDefManager *parent_ndef;
+ INodeDefManager *ndef;
+
+ parent_ndef = (IWritableNodeDefManager *)gamedef->getNodeDefManager();
+
+ ndef = parent_ndef->clone();
+ TEST(testNodeResolving, ndef);
+ delete ndef;
+
+ ndef = parent_ndef->clone();
+ TEST(testPendingResolveCancellation, ndef);
+ delete ndef;
+
+ ndef = parent_ndef->clone();
+ TEST(testDirectResolveMethod, ndef);
+ delete ndef;
+
+ ndef = parent_ndef->clone();
+ TEST(testNoneResolveMethod, ndef);
+ delete ndef;
+}
+
+class Foobar : public NodeResolver {
+public:
+ void resolveNodeNames();
+
+ content_t test_nr_node1;
+ content_t test_nr_node2;
+ content_t test_nr_node3;
+ content_t test_nr_node4;
+ content_t test_nr_node5;
+ std::vector<content_t> test_nr_list;
+ std::vector<content_t> test_nr_list_group;
+ std::vector<content_t> test_nr_list_required;
+ std::vector<content_t> test_nr_list_empty;
+};
+
+class Foobaz : public NodeResolver {
+public:
+ void resolveNodeNames();
+
+ content_t test_content1;
+ content_t test_content2;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
+void Foobar::resolveNodeNames()
+{
+ UASSERT(getIdFromNrBacklog(&test_nr_node1, "", CONTENT_IGNORE) == true);
+ UASSERT(getIdsFromNrBacklog(&test_nr_list) == true);
+ UASSERT(getIdsFromNrBacklog(&test_nr_list_group) == true);
+ UASSERT(getIdsFromNrBacklog(&test_nr_list_required,
+ true, CONTENT_AIR) == false);
+ UASSERT(getIdsFromNrBacklog(&test_nr_list_empty) == true);
+
+ UASSERT(getIdFromNrBacklog(&test_nr_node2, "", CONTENT_IGNORE) == true);
+ UASSERT(getIdFromNrBacklog(&test_nr_node3,
+ "default:brick", CONTENT_IGNORE) == true);
+ UASSERT(getIdFromNrBacklog(&test_nr_node4,
+ "default:gobbledygook", CONTENT_AIR) == false);
+ UASSERT(getIdFromNrBacklog(&test_nr_node5, "", CONTENT_IGNORE) == false);
+}
+
+
+void Foobaz::resolveNodeNames()
+{
+ UASSERT(getIdFromNrBacklog(&test_content1, "", CONTENT_IGNORE) == true);
+ UASSERT(getIdFromNrBacklog(&test_content2, "", CONTENT_IGNORE) == false);
+}
+
+
+void TestNodeResolver::testNodeResolving(INodeDefManager *ndef)
+{
+ Foobar foobar;
+ size_t i;
+
+ foobar.m_nodenames.push_back("default:torch");
+
+ foobar.m_nodenames.push_back("default:dirt_with_grass");
+ foobar.m_nodenames.push_back("default:water");
+ foobar.m_nodenames.push_back("default:abloobloobloo");
+ foobar.m_nodenames.push_back("default:stone");
+ foobar.m_nodenames.push_back("default:shmegoldorf");
+ foobar.m_nnlistsizes.push_back(5);
+
+ foobar.m_nodenames.push_back("group:liquids");
+ foobar.m_nnlistsizes.push_back(1);
+
+ foobar.m_nodenames.push_back("default:warf");
+ foobar.m_nodenames.push_back("default:stone");
+ foobar.m_nodenames.push_back("default:bloop");
+ foobar.m_nnlistsizes.push_back(3);
+
+ foobar.m_nnlistsizes.push_back(0);
+
+ foobar.m_nodenames.push_back("default:brick");
+ foobar.m_nodenames.push_back("default:desert_stone");
+ foobar.m_nodenames.push_back("default:shnitzle");
+
+ ndef->pendNodeResolve(&foobar, NODE_RESOLVE_DEFERRED);
+ UASSERT(foobar.m_ndef == ndef);
+
+ ndef->setNodeRegistrationStatus(true);
+ ndef->runNodeResolveCallbacks();
+
+ // Check that we read single nodes successfully
+ UASSERTEQ(content_t, foobar.test_nr_node1, t_CONTENT_TORCH);
+ UASSERTEQ(content_t, foobar.test_nr_node2, t_CONTENT_BRICK);
+ UASSERTEQ(content_t, foobar.test_nr_node3, t_CONTENT_BRICK);
+ UASSERTEQ(content_t, foobar.test_nr_node4, CONTENT_AIR);
+ UASSERTEQ(content_t, foobar.test_nr_node5, CONTENT_IGNORE);
+
+ // Check that we read all the regular list items
+ static const content_t expected_test_nr_list[] = {
+ t_CONTENT_GRASS,
+ t_CONTENT_WATER,
+ t_CONTENT_STONE,
+ };
+ UASSERTEQ(size_t, foobar.test_nr_list.size(), 3);
+ for (i = 0; i != foobar.test_nr_list.size(); i++)
+ UASSERTEQ(content_t, foobar.test_nr_list[i], expected_test_nr_list[i]);
+
+ // Check that we read all the list items that were from a group entry
+ static const content_t expected_test_nr_list_group[] = {
+ t_CONTENT_WATER,
+ t_CONTENT_LAVA,
+ };
+ UASSERTEQ(size_t, foobar.test_nr_list_group.size(), 2);
+ for (i = 0; i != foobar.test_nr_list_group.size(); i++) {
+ UASSERT(CONTAINS(foobar.test_nr_list_group,
+ expected_test_nr_list_group[i]));
+ }
+
+ // Check that we read all the items we're able to in a required list
+ static const content_t expected_test_nr_list_required[] = {
+ CONTENT_AIR,
+ t_CONTENT_STONE,
+ CONTENT_AIR,
+ };
+ UASSERTEQ(size_t, foobar.test_nr_list_required.size(), 3);
+ for (i = 0; i != foobar.test_nr_list_required.size(); i++)
+ UASSERTEQ(content_t, foobar.test_nr_list_required[i],
+ expected_test_nr_list_required[i]);
+
+ // Check that the edge case of 0 is successful
+ UASSERTEQ(size_t, foobar.test_nr_list_empty.size(), 0);
+}
+
+
+void TestNodeResolver::testPendingResolveCancellation(INodeDefManager *ndef)
+{
+ Foobaz foobaz1;
+ foobaz1.test_content1 = 1234;
+ foobaz1.test_content2 = 5678;
+ foobaz1.m_nodenames.push_back("default:dirt_with_grass");
+ foobaz1.m_nodenames.push_back("default:abloobloobloo");
+ ndef->pendNodeResolve(&foobaz1, NODE_RESOLVE_DEFERRED);
+
+ Foobaz foobaz2;
+ foobaz2.test_content1 = 1234;
+ foobaz2.test_content2 = 5678;
+ foobaz2.m_nodenames.push_back("default:dirt_with_grass");
+ foobaz2.m_nodenames.push_back("default:abloobloobloo");
+ ndef->pendNodeResolve(&foobaz2, NODE_RESOLVE_DEFERRED);
+
+ ndef->cancelNodeResolveCallback(&foobaz1);
+
+ ndef->setNodeRegistrationStatus(true);
+ ndef->runNodeResolveCallbacks();
+
+ UASSERT(foobaz1.test_content1 == 1234);
+ UASSERT(foobaz1.test_content2 == 5678);
+ UASSERT(foobaz2.test_content1 == t_CONTENT_GRASS);
+ UASSERT(foobaz2.test_content2 == CONTENT_IGNORE);
+}
+
+
+void TestNodeResolver::testDirectResolveMethod(INodeDefManager *ndef)
+{
+ Foobaz foobaz;
+
+ foobaz.m_nodenames.push_back("default:dirt_with_grass");
+ foobaz.m_nodenames.push_back("default:abloobloobloo");
+
+ UASSERTEQ(std::string, foobaz.getNodeName(1), "default:abloobloobloo");
+
+ ndef->pendNodeResolve(&foobaz, NODE_RESOLVE_DIRECT);
+
+ UASSERTEQ(content_t, foobaz.test_content1, t_CONTENT_GRASS);
+ UASSERTEQ(content_t, foobaz.test_content2, CONTENT_IGNORE);
+
+ // We expect this to be *different* because the resolution of this node had
+ // failed. The internal nodename buffer is cleared and lookups should now
+ // use the nodedef manager.
+ UASSERT(foobaz.getNodeName(1) != "default:abloobloobloo");
+}
+
+
+void TestNodeResolver::testNoneResolveMethod(INodeDefManager *ndef)
+{
+ Foobaz foobaz;
+
+ foobaz.m_nodenames.push_back("default:dirt_with_grass");
+ foobaz.m_nodenames.push_back("default:abloobloobloo");
+
+ ndef->pendNodeResolve(&foobaz, NODE_RESOLVE_NONE);
+
+ UASSERTEQ(std::string, foobaz.getNodeName(1), "default:abloobloobloo");
+}