Navigation Menu

Skip to content

Commit

Permalink
Tests: Add NodeResolver unittests
Browse files Browse the repository at this point in the history
Minor misc. NodeResolver cleanups
Prefix faux content type constants for testing with t_ to avoid
confusion or name collisions
  • Loading branch information
kwolekr committed May 5, 2015
1 parent 1be2d32 commit b45df9d
Show file tree
Hide file tree
Showing 8 changed files with 349 additions and 25 deletions.
1 change: 1 addition & 0 deletions build/android/jni/Android.mk
Expand Up @@ -219,6 +219,7 @@ LOCAL_SRC_FILES := \
jni/src/unittest/test_inventory.cpp \
jni/src/unittest/test_mapnode.cpp \
jni/src/unittest/test_nodedef.cpp \
jni/src/unittest/test_noderesolver.cpp \
jni/src/unittest/test_noise.cpp \
jni/src/unittest/test_objdef.cpp \
jni/src/unittest/test_profiler.cpp \
Expand Down
19 changes: 10 additions & 9 deletions src/nodedef.cpp
Expand Up @@ -1346,7 +1346,8 @@ void CNodeDefManager::runNodeResolveCallbacks()
//// NodeResolver
////

NodeResolver::NodeResolver() {
NodeResolver::NodeResolver()
{
m_ndef = NULL;
m_nodenames_idx = 0;
m_nnlistsizes_idx = 0;
Expand Down Expand Up @@ -1379,14 +1380,14 @@ void NodeResolver::nodeResolveInternal()

const std::string &NodeResolver::getNodeName(content_t c) const
{
if (m_nodenames.size() == 0) {
if (c < m_nodenames.size())
return m_nodenames[c];

if (m_ndef)
return m_ndef->get(c).name;
} else {
if (c < m_nodenames.size())
return m_nodenames[c];
else
return m_ndef->get(CONTENT_UNKNOWN).name;
}

static const std::string unknown_str("unknown");
return unknown_str;
}


Expand All @@ -1395,7 +1396,7 @@ bool NodeResolver::getIdFromNrBacklog(content_t *result_out,
{
if (m_nodenames_idx == m_nodenames.size()) {
*result_out = c_fallback;
errorstream << "Resolver: no more nodes in list" << std::endl;
errorstream << "NodeResolver: no more nodes in list" << std::endl;
return false;
}

Expand Down
1 change: 1 addition & 0 deletions src/unittest/CMakeLists.txt
Expand Up @@ -7,6 +7,7 @@ set (UNITTEST_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/test_inventory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_mapnode.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_nodedef.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_noderesolver.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_noise.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_objdef.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_profiler.cpp
Expand Down
77 changes: 71 additions & 6 deletions src/unittest/test.cpp
Expand Up @@ -25,9 +25,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#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;

////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -111,7 +114,7 @@ void TestGameDef::defineSomeNodes()
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();
Expand All @@ -131,7 +134,7 @@ void TestGameDef::defineSomeNodes()
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();
Expand All @@ -144,7 +147,69 @@ void TestGameDef::defineSomeNodes()
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);
}

////
Expand Down
9 changes: 6 additions & 3 deletions src/unittest/test.h
Expand Up @@ -124,9 +124,12 @@ class TestManager {
};

// A few item and node definitions for those tests that need them
extern content_t CONTENT_STONE;
extern content_t CONTENT_GRASS;
extern content_t CONTENT_TORCH;
extern content_t t_CONTENT_STONE;
extern content_t t_CONTENT_GRASS;
extern content_t t_CONTENT_TORCH;
extern content_t t_CONTENT_WATER;
extern content_t t_CONTENT_LAVA;
extern content_t t_CONTENT_BRICK;

void run_tests();

Expand Down

0 comments on commit b45df9d

Please sign in to comment.