aboutsummaryrefslogtreecommitdiff
path: root/src/unittest/test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/unittest/test.cpp')
-rw-r--r--src/unittest/test.cpp89
1 files changed, 46 insertions, 43 deletions
diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp
index 55471746a..0f6b36649 100644
--- a/src/unittest/test.cpp
+++ b/src/unittest/test.cpp
@@ -41,8 +41,7 @@ content_t t_CONTENT_BRICK;
//// TestGameDef
////
-class TestGameDef : public IGameDef
-{
+class TestGameDef : public IGameDef {
public:
TestGameDef();
~TestGameDef();
@@ -70,17 +69,13 @@ public:
static std::vector<ModSpec> testmodspec;
return testmodspec;
}
- virtual const ModSpec *getModSpec(const std::string &modname) const
- {
- return NULL;
- }
+ virtual const ModSpec* getModSpec(const std::string &modname) const { return NULL; }
virtual std::string getModStoragePath() const { return "."; }
virtual bool registerModStorage(ModMetadata *meta) { return true; }
virtual void unregisterModStorage(const std::string &name) {}
bool joinModChannel(const std::string &channel);
bool leaveModChannel(const std::string &channel);
- bool sendModChannelMessage(
- const std::string &channel, const std::string &message);
+ bool sendModChannelMessage(const std::string &channel, const std::string &message);
ModChannel *getModChannel(const std::string &channel)
{
return m_modchannel_mgr->getModChannel(channel);
@@ -99,7 +94,9 @@ private:
std::unique_ptr<ModChannelMgr> m_modchannel_mgr;
};
-TestGameDef::TestGameDef() : m_modchannel_mgr(new ModChannelMgr())
+
+TestGameDef::TestGameDef() :
+ m_modchannel_mgr(new ModChannelMgr())
{
m_itemdef = createItemDefManager();
m_nodedef = createNodeDefManager();
@@ -107,12 +104,14 @@ TestGameDef::TestGameDef() : m_modchannel_mgr(new ModChannelMgr())
defineSomeNodes();
}
+
TestGameDef::~TestGameDef()
{
delete m_itemdef;
delete m_nodedef;
}
+
void TestGameDef::defineSomeNodes()
{
IWritableItemDefManager *idef = (IWritableItemDefManager *)m_itemdef;
@@ -128,9 +127,9 @@ void TestGameDef::defineSomeNodes()
itemdef.description = "Stone";
itemdef.groups["cracky"] = 3;
itemdef.inventory_image = "[inventorycube"
- "{default_stone.png"
- "{default_stone.png"
- "{default_stone.png";
+ "{default_stone.png"
+ "{default_stone.png"
+ "{default_stone.png";
f = ContentFeatures();
f.name = itemdef.name;
for (TileDef &tiledef : f.tiledef)
@@ -146,14 +145,14 @@ void TestGameDef::defineSomeNodes()
itemdef.description = "Dirt with grass";
itemdef.groups["crumbly"] = 3;
itemdef.inventory_image = "[inventorycube"
- "{default_grass.png"
- "{default_dirt.png&default_grass_side.png"
- "{default_dirt.png&default_grass_side.png";
+ "{default_grass.png"
+ "{default_dirt.png&default_grass_side.png"
+ "{default_dirt.png&default_grass_side.png";
f = ContentFeatures();
f.name = itemdef.name;
f.tiledef[0].name = "default_grass.png";
f.tiledef[1].name = "default_dirt.png";
- for (int i = 2; i < 6; i++)
+ for(int i = 2; i < 6; i++)
f.tiledef[i].name = "default_dirt.png^default_grass_side.png";
f.is_ground_content = true;
idef->registerItem(itemdef);
@@ -168,7 +167,7 @@ void TestGameDef::defineSomeNodes()
f.param_type = CPT_LIGHT;
f.light_propagates = true;
f.sunlight_propagates = true;
- f.light_source = LIGHT_MAX - 1;
+ f.light_source = LIGHT_MAX-1;
idef->registerItem(itemdef);
t_CONTENT_TORCH = ndef->set(f.name, f);
@@ -178,9 +177,9 @@ void TestGameDef::defineSomeNodes()
itemdef.name = "default:water";
itemdef.description = "Water";
itemdef.inventory_image = "[inventorycube"
- "{default_water.png"
- "{default_water.png"
- "{default_water.png";
+ "{default_water.png"
+ "{default_water.png"
+ "{default_water.png";
f = ContentFeatures();
f.name = itemdef.name;
f.alpha = 128;
@@ -199,15 +198,15 @@ void TestGameDef::defineSomeNodes()
itemdef.name = "default:lava";
itemdef.description = "Lava";
itemdef.inventory_image = "[inventorycube"
- "{default_lava.png"
- "{default_lava.png"
- "{default_lava.png";
+ "{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.light_source = LIGHT_MAX-1;
f.is_ground_content = true;
f.groups["liquids"] = 3;
for (TileDef &tiledef : f.tiledef)
@@ -215,6 +214,7 @@ void TestGameDef::defineSomeNodes()
idef->registerItem(itemdef);
t_CONTENT_LAVA = ndef->set(f.name, f);
+
//// Brick
itemdef = ItemDefinition();
itemdef.type = ITEM_NODE;
@@ -222,9 +222,9 @@ void TestGameDef::defineSomeNodes()
itemdef.description = "Brick";
itemdef.groups["cracky"] = 3;
itemdef.inventory_image = "[inventorycube"
- "{default_brick.png"
- "{default_brick.png"
- "{default_brick.png";
+ "{default_brick.png"
+ "{default_brick.png"
+ "{default_brick.png";
f = ContentFeatures();
f.name = itemdef.name;
for (TileDef &tiledef : f.tiledef)
@@ -244,8 +244,8 @@ bool TestGameDef::leaveModChannel(const std::string &channel)
return m_modchannel_mgr->leaveChannel(channel, PEER_ID_SERVER);
}
-bool TestGameDef::sendModChannelMessage(
- const std::string &channel, const std::string &message)
+bool TestGameDef::sendModChannelMessage(const std::string &channel,
+ const std::string &message)
{
if (!m_modchannel_mgr->channelRegistered(channel))
return false;
@@ -264,9 +264,9 @@ bool run_tests()
g_logger.setLevelSilenced(LL_ERROR, true);
- u32 num_modules_failed = 0;
+ u32 num_modules_failed = 0;
u32 num_total_tests_failed = 0;
- u32 num_total_tests_run = 0;
+ u32 num_total_tests_run = 0;
std::vector<TestBase *> &testmods = TestManager::getTestModules();
for (size_t i = 0; i != testmods.size(); i++) {
if (!testmods[i]->testModule(&gamedef))
@@ -282,15 +282,16 @@ bool run_tests()
const char *overall_status = (num_modules_failed == 0) ? "PASSED" : "FAILED";
- rawstream << "++++++++++++++++++++++++++++++++++++++++"
- << "++++++++++++++++++++++++++++++++++++++++" << std::endl
- << "Unit Test Results: " << overall_status << std::endl
- << " " << num_modules_failed << " / " << testmods.size()
- << " failed modules (" << num_total_tests_failed << " / "
- << num_total_tests_run << " failed individual tests)." << std::endl
- << " Testing took " << tdiff << "ms total." << std::endl
- << "++++++++++++++++++++++++++++++++++++++++"
- << "++++++++++++++++++++++++++++++++++++++++" << std::endl;
+ rawstream
+ << "++++++++++++++++++++++++++++++++++++++++"
+ << "++++++++++++++++++++++++++++++++++++++++" << std::endl
+ << "Unit Test Results: " << overall_status << std::endl
+ << " " << num_modules_failed << " / " << testmods.size()
+ << " failed modules (" << num_total_tests_failed << " / "
+ << num_total_tests_run << " failed individual tests)." << std::endl
+ << " Testing took " << tdiff << "ms total." << std::endl
+ << "++++++++++++++++++++++++++++++++++++++++"
+ << "++++++++++++++++++++++++++++++++++++++++" << std::endl;
return num_modules_failed;
}
@@ -304,13 +305,14 @@ bool TestBase::testModule(IGameDef *gamedef)
rawstream << "======== Testing module " << getName() << std::endl;
u64 t1 = porting::getTimeMs();
+
runTests(gamedef);
u64 tdiff = porting::getTimeMs() - t1;
rawstream << "======== Module " << getName() << " "
- << (num_tests_failed ? "failed" : "passed") << " (" << num_tests_failed
- << " failures / " << num_tests_run << " tests) - " << tdiff << "ms"
- << std::endl;
+ << (num_tests_failed ? "failed" : "passed") << " (" << num_tests_failed
+ << " failures / " << num_tests_run << " tests) - " << tdiff
+ << "ms" << std::endl;
if (!m_test_dir.empty())
fs::RecursiveDelete(m_test_dir);
@@ -341,6 +343,7 @@ std::string TestBase::getTestTempFile()
return getTestTempDirectory() + DIR_DELIM + buf + ".tmp";
}
+
/*
NOTE: These tests became non-working then NodeContainer was removed.
These should be redone, utilizing some kind of a virtual