summaryrefslogtreecommitdiff
path: root/src/unittest
diff options
context:
space:
mode:
Diffstat (limited to 'src/unittest')
-rw-r--r--src/unittest/test.cpp20
-rw-r--r--src/unittest/test.h4
-rw-r--r--src/unittest/test_connection.cpp2
-rw-r--r--src/unittest/test_mapnode.cpp3
-rw-r--r--src/unittest/test_nodedef.cpp5
-rw-r--r--src/unittest/test_noderesolver.cpp2
-rw-r--r--src/unittest/test_objdef.cpp4
-rw-r--r--src/unittest/test_player.cpp52
-rw-r--r--src/unittest/test_profiler.cpp3
-rw-r--r--src/unittest/test_threading.cpp2
-rw-r--r--src/unittest/test_voxelalgorithms.cpp59
11 files changed, 90 insertions, 66 deletions
diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp
index 41ccf0d2d..570807ba7 100644
--- a/src/unittest/test.cpp
+++ b/src/unittest/test.cpp
@@ -19,10 +19,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "test.h"
-#include "log.h"
#include "nodedef.h"
#include "itemdef.h"
#include "gamedef.h"
+#include "mods.h"
content_t t_CONTENT_STONE;
content_t t_CONTENT_GRASS;
@@ -59,6 +59,16 @@ public:
void defineSomeNodes();
+ virtual const std::vector<ModSpec> &getMods() const
+ {
+ static std::vector<ModSpec> testmodspec;
+ return testmodspec;
+ }
+ 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) {}
+
private:
IItemDefManager *m_itemdef;
INodeDefManager *m_nodedef;
@@ -219,7 +229,7 @@ bool run_tests()
{
DSTACK(FUNCTION_NAME);
- u32 t1 = porting::getTime(PRECISION_MILLI);
+ u64 t1 = porting::getTimeMs();
TestGameDef gamedef;
g_logger.setLevelSilenced(LL_ERROR, true);
@@ -236,7 +246,7 @@ bool run_tests()
num_total_tests_run += testmods[i]->num_tests_run;
}
- u32 tdiff = porting::getTime(PRECISION_MILLI) - t1;
+ u64 tdiff = porting::getTimeMs() - t1;
g_logger.setLevelSilenced(LL_ERROR, false);
@@ -263,12 +273,12 @@ bool run_tests()
bool TestBase::testModule(IGameDef *gamedef)
{
rawstream << "======== Testing module " << getName() << std::endl;
- u32 t1 = porting::getTime(PRECISION_MILLI);
+ u64 t1 = porting::getTimeMs();
runTests(gamedef);
- u32 tdiff = porting::getTime(PRECISION_MILLI) - t1;
+ u64 tdiff = porting::getTimeMs() - t1;
rawstream << "======== Module " << getName() << " "
<< (num_tests_failed ? "failed" : "passed") << " (" << num_tests_failed
<< " failures / " << num_tests_run << " tests) - " << tdiff
diff --git a/src/unittest/test.h b/src/unittest/test.h
index e60e657cc..bf76e8bb2 100644
--- a/src/unittest/test.h
+++ b/src/unittest/test.h
@@ -33,7 +33,7 @@ class TestFailedException : public std::exception {
// Runs a unit test and reports results
#define TEST(fxn, ...) do { \
- u32 t1 = porting::getTime(PRECISION_MILLI); \
+ u64 t1 = porting::getTimeMs(); \
try { \
fxn(__VA_ARGS__); \
rawstream << "[PASS] "; \
@@ -46,7 +46,7 @@ class TestFailedException : public std::exception {
num_tests_failed++; \
} \
num_tests_run++; \
- u32 tdiff = porting::getTime(PRECISION_MILLI) - t1; \
+ u64 tdiff = porting::getTimeMs() - t1; \
rawstream << #fxn << " - " << tdiff << "ms" << std::endl; \
} while (0)
diff --git a/src/unittest/test_connection.cpp b/src/unittest/test_connection.cpp
index 49e412fc8..d63322d69 100644
--- a/src/unittest/test_connection.cpp
+++ b/src/unittest/test_connection.cpp
@@ -305,7 +305,7 @@ void TestConnection::testConnectSendReceive()
u16 peer_id = 132;
u16 size = 0;
bool received = false;
- u32 timems0 = porting::getTimeMs();
+ u64 timems0 = porting::getTimeMs();
for (;;) {
if (porting::getTimeMs() - timems0 > 5000 || received)
break;
diff --git a/src/unittest/test_mapnode.cpp b/src/unittest/test_mapnode.cpp
index 9ecc2f82d..70e7d42cf 100644
--- a/src/unittest/test_mapnode.cpp
+++ b/src/unittest/test_mapnode.cpp
@@ -23,7 +23,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "nodedef.h"
#include "content_mapnode.h"
-class TestMapNode : public TestBase {
+class TestMapNode : public TestBase
+{
public:
TestMapNode() { TestManager::registerTestModule(this); }
const char *getName() { return "TestMapNode"; }
diff --git a/src/unittest/test_nodedef.cpp b/src/unittest/test_nodedef.cpp
index 85093f52f..cb99ae854 100644
--- a/src/unittest/test_nodedef.cpp
+++ b/src/unittest/test_nodedef.cpp
@@ -25,7 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "nodedef.h"
#include "network/networkprotocol.h"
-class TestNodeDef : public TestBase {
+class TestNodeDef : public TestBase
+{
public:
TestNodeDef() { TestManager::registerTestModule(this); }
const char *getName() { return "TestNodeDef"; }
@@ -55,7 +56,7 @@ void TestNodeDef::testContentFeaturesSerialization()
std::ostringstream os(std::ios::binary);
f.serialize(os, LATEST_PROTOCOL_VERSION);
- //verbosestream<<"Test ContentFeatures size: "<<os.str().size()<<std::endl;
+ // verbosestream<<"Test ContentFeatures size: "<<os.str().size()<<std::endl;
std::istringstream is(os.str(), std::ios::binary);
ContentFeatures f2;
diff --git a/src/unittest/test_noderesolver.cpp b/src/unittest/test_noderesolver.cpp
index 55acece6a..b009f5d2e 100644
--- a/src/unittest/test_noderesolver.cpp
+++ b/src/unittest/test_noderesolver.cpp
@@ -24,6 +24,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "gamedef.h"
#include "nodedef.h"
+#include <algorithm>
+
class TestNodeResolver : public TestBase {
public:
diff --git a/src/unittest/test_objdef.cpp b/src/unittest/test_objdef.cpp
index df2633b38..c2acdcfe7 100644
--- a/src/unittest/test_objdef.cpp
+++ b/src/unittest/test_objdef.cpp
@@ -22,7 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "exceptions.h"
#include "objdef.h"
-class TestObjDef : public TestBase {
+class TestObjDef : public TestBase
+{
public:
TestObjDef() { TestManager::registerTestModule(this); }
const char *getName() { return "TestObjDef"; }
@@ -60,7 +61,6 @@ void TestObjDef::testHandles()
UASSERTEQ(ObjDefHandle, OBJDEF_ORE, type);
}
-
void TestObjDef::testAddGetSetClear()
{
ObjDefManager testmgr(NULL, OBJDEF_GENERIC);
diff --git a/src/unittest/test_player.cpp b/src/unittest/test_player.cpp
index 85fbc8b2d..e2b1cd855 100644
--- a/src/unittest/test_player.cpp
+++ b/src/unittest/test_player.cpp
@@ -24,65 +24,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "content_sao.h"
#include "server.h"
-class TestPlayer : public TestBase {
+class TestPlayer : public TestBase
+{
public:
TestPlayer() { TestManager::registerTestModule(this); }
const char *getName() { return "TestPlayer"; }
void runTests(IGameDef *gamedef);
-
- void testSave(IGameDef *gamedef);
- void testLoad(IGameDef *gamedef);
};
static TestPlayer g_test_instance;
void TestPlayer::runTests(IGameDef *gamedef)
{
- TEST(testSave, gamedef);
- TEST(testLoad, gamedef);
-}
-
-void TestPlayer::testSave(IGameDef *gamedef)
-{
- RemotePlayer rplayer("testplayer_save", gamedef->idef());
- PlayerSAO sao(NULL, 1, false);
- sao.initialize(&rplayer, std::set<std::string>());
- rplayer.setPlayerSAO(&sao);
- sao.setBreath(10);
- sao.setHPRaw(8);
- sao.setYaw(0.1f);
- sao.setPitch(0.6f);
- sao.setBasePosition(v3f(450.2f, -15.7f, 68.1f));
- rplayer.save(".", gamedef);
- UASSERT(fs::PathExists("testplayer_save"));
-}
-
-void TestPlayer::testLoad(IGameDef *gamedef)
-{
- RemotePlayer rplayer("testplayer_load", gamedef->idef());
- PlayerSAO sao(NULL, 1, false);
- sao.initialize(&rplayer, std::set<std::string>());
- rplayer.setPlayerSAO(&sao);
- sao.setBreath(10);
- sao.setHPRaw(8);
- sao.setYaw(0.1f);
- sao.setPitch(0.6f);
- sao.setBasePosition(v3f(450.2f, -15.7f, 68.1f));
- rplayer.save(".", gamedef);
- UASSERT(fs::PathExists("testplayer_load"));
-
- RemotePlayer rplayer_load("testplayer_load", gamedef->idef());
- PlayerSAO sao_load(NULL, 2, false);
- std::ifstream is("testplayer_load", std::ios_base::binary);
- UASSERT(is.good());
- rplayer_load.deSerialize(is, "testplayer_load", &sao_load);
- is.close();
-
- UASSERT(strcmp(rplayer_load.getName(), "testplayer_load") == 0);
- UASSERT(sao_load.getBreath() == 10);
- UASSERT(sao_load.getHP() == 8);
- UASSERT(sao_load.getYaw() == 0.1f);
- UASSERT(sao_load.getPitch() == 0.6f);
- UASSERT(sao_load.getBasePosition() == v3f(450.2f, -15.7f, 68.1f));
}
diff --git a/src/unittest/test_profiler.cpp b/src/unittest/test_profiler.cpp
index fbc03f232..92d336a72 100644
--- a/src/unittest/test_profiler.cpp
+++ b/src/unittest/test_profiler.cpp
@@ -21,7 +21,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "profiler.h"
-class TestProfiler : public TestBase {
+class TestProfiler : public TestBase
+{
public:
TestProfiler() { TestManager::registerTestModule(this); }
const char *getName() { return "TestProfiler"; }
diff --git a/src/unittest/test_threading.cpp b/src/unittest/test_threading.cpp
index cdbf9674e..e1e1d3660 100644
--- a/src/unittest/test_threading.cpp
+++ b/src/unittest/test_threading.cpp
@@ -39,9 +39,7 @@ static TestThreading g_test_instance;
void TestThreading::runTests(IGameDef *gamedef)
{
-#if !(defined(__MACH__) && defined(__APPLE__))
TEST(testStartStopWait);
-#endif
TEST(testThreadKill);
TEST(testAtomicSemaphoreThread);
}
diff --git a/src/unittest/test_voxelalgorithms.cpp b/src/unittest/test_voxelalgorithms.cpp
index 31b9cadd5..fd83844af 100644
--- a/src/unittest/test_voxelalgorithms.cpp
+++ b/src/unittest/test_voxelalgorithms.cpp
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "gamedef.h"
#include "voxelalgorithms.h"
+#include "util/numeric.h"
class TestVoxelAlgorithms : public TestBase {
public:
@@ -31,6 +32,7 @@ public:
void testPropogateSunlight(INodeDefManager *ndef);
void testClearLightAndCollectSources(INodeDefManager *ndef);
+ void testVoxelLineIterator(INodeDefManager *ndef);
};
static TestVoxelAlgorithms g_test_instance;
@@ -41,6 +43,7 @@ void TestVoxelAlgorithms::runTests(IGameDef *gamedef)
TEST(testPropogateSunlight, ndef);
TEST(testClearLightAndCollectSources, ndef);
+ TEST(testVoxelLineIterator, ndef);
}
////////////////////////////////////////////////////////////////////////////////
@@ -202,3 +205,59 @@ void TestVoxelAlgorithms::testClearLightAndCollectSources(INodeDefManager *ndef)
UASSERT(unlight_from.size() == 1);
}
}
+
+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);
+ }
+}