aboutsummaryrefslogtreecommitdiff
path: root/src/unittest
diff options
context:
space:
mode:
Diffstat (limited to 'src/unittest')
-rw-r--r--src/unittest/CMakeLists.txt2
-rw-r--r--src/unittest/test_ban.cpp3
-rw-r--r--src/unittest/test_collision.cpp64
-rw-r--r--src/unittest/test_objdef.cpp76
-rw-r--r--src/unittest/test_player.cpp1
-rw-r--r--src/unittest/test_serveractiveobjectmgr.cpp18
-rw-r--r--src/unittest/test_servermodmanager.cpp10
7 files changed, 128 insertions, 46 deletions
diff --git a/src/unittest/CMakeLists.txt b/src/unittest/CMakeLists.txt
index 82f9a4a13..5703b8906 100644
--- a/src/unittest/CMakeLists.txt
+++ b/src/unittest/CMakeLists.txt
@@ -43,7 +43,7 @@ set (UNITTEST_CLIENT_SRCS
PARENT_SCOPE)
set (TEST_WORLDDIR ${CMAKE_CURRENT_SOURCE_DIR}/test_world)
-set (TEST_SUBGAME_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../games/minimal)
+set (TEST_SUBGAME_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../games/devtest)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/test_config.h.in"
diff --git a/src/unittest/test_ban.cpp b/src/unittest/test_ban.cpp
index 2a95b945f..bab2b9ee8 100644
--- a/src/unittest/test_ban.cpp
+++ b/src/unittest/test_ban.cpp
@@ -61,6 +61,9 @@ void TestBan::runTests(IGameDef *gamedef)
reinitTestEnv();
TEST(testGetBanDescription);
+
+ // Delete leftover files
+ reinitTestEnv();
}
// This module is stateful due to disk writes, add helper to remove files
diff --git a/src/unittest/test_collision.cpp b/src/unittest/test_collision.cpp
index 332d3fa13..2f39c2489 100644
--- a/src/unittest/test_collision.cpp
+++ b/src/unittest/test_collision.cpp
@@ -50,38 +50,38 @@ void TestCollision::testAxisAlignedCollision()
aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
aabb3f m(bx-2, by, bz, bx-1, by+1, bz+1);
v3f v(1, 0, 0);
- f32 dtime = 0;
- UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 0);
+ f32 dtime = 1.0f;
+ UASSERT(axisAlignedCollision(s, m, v, &dtime) == 0);
UASSERT(fabs(dtime - 1.000) < 0.001);
}
{
aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
aabb3f m(bx-2, by, bz, bx-1, by+1, bz+1);
v3f v(-1, 0, 0);
- f32 dtime = 0;
- UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == -1);
+ f32 dtime = 1.0f;
+ UASSERT(axisAlignedCollision(s, m, v, &dtime) == -1);
}
{
aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
aabb3f m(bx-2, by+1.5, bz, bx-1, by+2.5, bz-1);
v3f v(1, 0, 0);
- f32 dtime;
- UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == -1);
+ f32 dtime = 1.0f;
+ UASSERT(axisAlignedCollision(s, m, v, &dtime) == -1);
}
{
aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
aabb3f m(bx-2, by-1.5, bz, bx-1.5, by+0.5, bz+1);
v3f v(0.5, 0.1, 0);
- f32 dtime;
- UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 0);
+ f32 dtime = 3.0f;
+ UASSERT(axisAlignedCollision(s, m, v, &dtime) == 0);
UASSERT(fabs(dtime - 3.000) < 0.001);
}
{
aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
aabb3f m(bx-2, by-1.5, bz, bx-1.5, by+0.5, bz+1);
v3f v(0.5, 0.1, 0);
- f32 dtime;
- UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 0);
+ f32 dtime = 3.0f;
+ UASSERT(axisAlignedCollision(s, m, v, &dtime) == 0);
UASSERT(fabs(dtime - 3.000) < 0.001);
}
@@ -90,38 +90,38 @@ void TestCollision::testAxisAlignedCollision()
aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
aabb3f m(bx+2, by, bz, bx+3, by+1, bz+1);
v3f v(-1, 0, 0);
- f32 dtime;
- UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 0);
+ f32 dtime = 1.0f;
+ UASSERT(axisAlignedCollision(s, m, v, &dtime) == 0);
UASSERT(fabs(dtime - 1.000) < 0.001);
}
{
aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
aabb3f m(bx+2, by, bz, bx+3, by+1, bz+1);
v3f v(1, 0, 0);
- f32 dtime;
- UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == -1);
+ f32 dtime = 1.0f;
+ UASSERT(axisAlignedCollision(s, m, v, &dtime) == -1);
}
{
aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
aabb3f m(bx+2, by, bz+1.5, bx+3, by+1, bz+3.5);
v3f v(-1, 0, 0);
- f32 dtime;
- UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == -1);
+ f32 dtime = 1.0f;
+ UASSERT(axisAlignedCollision(s, m, v, &dtime) == -1);
}
{
aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
aabb3f m(bx+2, by-1.5, bz, bx+2.5, by-0.5, bz+1);
v3f v(-0.5, 0.2, 0);
- f32 dtime;
- UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 1); // Y, not X!
+ f32 dtime = 2.5f;
+ UASSERT(axisAlignedCollision(s, m, v, &dtime) == 1); // Y, not X!
UASSERT(fabs(dtime - 2.500) < 0.001);
}
{
aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
aabb3f m(bx+2, by-1.5, bz, bx+2.5, by-0.5, bz+1);
v3f v(-0.5, 0.3, 0);
- f32 dtime;
- UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 0);
+ f32 dtime = 2.0f;
+ UASSERT(axisAlignedCollision(s, m, v, &dtime) == 0);
UASSERT(fabs(dtime - 2.000) < 0.001);
}
@@ -132,48 +132,48 @@ void TestCollision::testAxisAlignedCollision()
aabb3f s(bx, by, bz, bx+2, by+2, bz+2);
aabb3f m(bx+2.3, by+2.29, bz+2.29, bx+4.2, by+4.2, bz+4.2);
v3f v(-1./3, -1./3, -1./3);
- f32 dtime;
- UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 0);
+ f32 dtime = 1.0f;
+ UASSERT(axisAlignedCollision(s, m, v, &dtime) == 0);
UASSERT(fabs(dtime - 0.9) < 0.001);
}
{
aabb3f s(bx, by, bz, bx+2, by+2, bz+2);
aabb3f m(bx+2.29, by+2.3, bz+2.29, bx+4.2, by+4.2, bz+4.2);
v3f v(-1./3, -1./3, -1./3);
- f32 dtime;
- UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 1);
+ f32 dtime = 1.0f;
+ UASSERT(axisAlignedCollision(s, m, v, &dtime) == 1);
UASSERT(fabs(dtime - 0.9) < 0.001);
}
{
aabb3f s(bx, by, bz, bx+2, by+2, bz+2);
aabb3f m(bx+2.29, by+2.29, bz+2.3, bx+4.2, by+4.2, bz+4.2);
v3f v(-1./3, -1./3, -1./3);
- f32 dtime;
- UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 2);
+ f32 dtime = 1.0f;
+ UASSERT(axisAlignedCollision(s, m, v, &dtime) == 2);
UASSERT(fabs(dtime - 0.9) < 0.001);
}
{
aabb3f s(bx, by, bz, bx+2, by+2, bz+2);
aabb3f m(bx-4.2, by-4.2, bz-4.2, bx-2.3, by-2.29, bz-2.29);
v3f v(1./7, 1./7, 1./7);
- f32 dtime;
- UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 0);
+ f32 dtime = 17.0f;
+ UASSERT(axisAlignedCollision(s, m, v, &dtime) == 0);
UASSERT(fabs(dtime - 16.1) < 0.001);
}
{
aabb3f s(bx, by, bz, bx+2, by+2, bz+2);
aabb3f m(bx-4.2, by-4.2, bz-4.2, bx-2.29, by-2.3, bz-2.29);
v3f v(1./7, 1./7, 1./7);
- f32 dtime;
- UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 1);
+ f32 dtime = 17.0f;
+ UASSERT(axisAlignedCollision(s, m, v, &dtime) == 1);
UASSERT(fabs(dtime - 16.1) < 0.001);
}
{
aabb3f s(bx, by, bz, bx+2, by+2, bz+2);
aabb3f m(bx-4.2, by-4.2, bz-4.2, bx-2.29, by-2.29, bz-2.3);
v3f v(1./7, 1./7, 1./7);
- f32 dtime;
- UASSERT(axisAlignedCollision(s, m, v, 0, &dtime) == 2);
+ f32 dtime = 17.0f;
+ UASSERT(axisAlignedCollision(s, m, v, &dtime) == 2);
UASSERT(fabs(dtime - 16.1) < 0.001);
}
}
diff --git a/src/unittest/test_objdef.cpp b/src/unittest/test_objdef.cpp
index c2acdcfe7..40f7faa9d 100644
--- a/src/unittest/test_objdef.cpp
+++ b/src/unittest/test_objdef.cpp
@@ -32,6 +32,7 @@ public:
void testHandles();
void testAddGetSetClear();
+ void testClone();
};
static TestObjDef g_test_instance;
@@ -40,10 +41,42 @@ void TestObjDef::runTests(IGameDef *gamedef)
{
TEST(testHandles);
TEST(testAddGetSetClear);
+ TEST(testClone);
}
////////////////////////////////////////////////////////////////////////////////
+/* Minimal implementation of ObjDef and ObjDefManager subclass */
+
+class MyObjDef : public ObjDef
+{
+public:
+ ObjDef *clone() const
+ {
+ auto def = new MyObjDef();
+ ObjDef::cloneTo(def);
+ def->testvalue = testvalue;
+ return def;
+ };
+
+ u32 testvalue;
+};
+
+class MyObjDefManager : public ObjDefManager
+{
+public:
+ MyObjDefManager(ObjDefType type) : ObjDefManager(NULL, type){};
+ MyObjDefManager *clone() const
+ {
+ auto mgr = new MyObjDefManager();
+ ObjDefManager::cloneTo(mgr);
+ return mgr;
+ };
+
+protected:
+ MyObjDefManager(){};
+};
+
void TestObjDef::testHandles()
{
u32 uid = 0;
@@ -69,25 +102,25 @@ void TestObjDef::testAddGetSetClear()
UASSERTEQ(ObjDefType, testmgr.getType(), OBJDEF_GENERIC);
- obj0 = new ObjDef;
+ obj0 = new MyObjDef;
obj0->name = "foobar";
hObj0 = testmgr.add(obj0);
UASSERT(hObj0 != OBJDEF_INVALID_HANDLE);
UASSERTEQ(u32, obj0->index, 0);
- obj1 = new ObjDef;
+ obj1 = new MyObjDef;
obj1->name = "FooBaz";
hObj1 = testmgr.add(obj1);
UASSERT(hObj1 != OBJDEF_INVALID_HANDLE);
UASSERTEQ(u32, obj1->index, 1);
- obj2 = new ObjDef;
+ obj2 = new MyObjDef;
obj2->name = "asdf";
hObj2 = testmgr.add(obj2);
UASSERT(hObj2 != OBJDEF_INVALID_HANDLE);
UASSERTEQ(u32, obj2->index, 2);
- obj3 = new ObjDef;
+ obj3 = new MyObjDef;
obj3->name = "foobaz";
hObj3 = testmgr.add(obj3);
UASSERT(hObj3 == OBJDEF_INVALID_HANDLE);
@@ -104,3 +137,38 @@ void TestObjDef::testAddGetSetClear()
testmgr.clear();
UASSERTEQ(size_t, testmgr.getNumObjects(), 0);
}
+
+void TestObjDef::testClone()
+{
+ MyObjDefManager testmgr(OBJDEF_GENERIC);
+ ObjDefManager *mgrcopy;
+ MyObjDef *obj, *temp2;
+ ObjDef *temp1;
+ ObjDefHandle hObj;
+
+ obj = new MyObjDef;
+ obj->testvalue = 0xee00ff11;
+ hObj = testmgr.add(obj);
+ UASSERT(hObj != OBJDEF_INVALID_HANDLE);
+
+ mgrcopy = testmgr.clone();
+ UASSERT(mgrcopy);
+ UASSERTEQ(ObjDefType, mgrcopy->getType(), testmgr.getType());
+ UASSERTEQ(size_t, mgrcopy->getNumObjects(), testmgr.getNumObjects());
+
+ // 1) check that the same handle is still valid on the copy
+ temp1 = mgrcopy->get(hObj);
+ UASSERT(temp1);
+ UASSERT(temp1 == mgrcopy->getRaw(0));
+ // 2) check that the copy has the correct C++ class
+ temp2 = dynamic_cast<MyObjDef *>(temp1);
+ UASSERT(temp2);
+ // 3) check that it was correctly copied
+ UASSERTEQ(u32, obj->testvalue, temp2->testvalue);
+ // 4) check that it was copied AT ALL (not the same)
+ UASSERT(obj != temp2);
+
+ testmgr.clear();
+ mgrcopy->clear();
+ delete mgrcopy;
+}
diff --git a/src/unittest/test_player.cpp b/src/unittest/test_player.cpp
index e2b1cd855..6990b4016 100644
--- a/src/unittest/test_player.cpp
+++ b/src/unittest/test_player.cpp
@@ -21,7 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "exceptions.h"
#include "remoteplayer.h"
-#include "content_sao.h"
#include "server.h"
class TestPlayer : public TestBase
diff --git a/src/unittest/test_serveractiveobjectmgr.cpp b/src/unittest/test_serveractiveobjectmgr.cpp
index 0806972ab..aa0047400 100644
--- a/src/unittest/test_serveractiveobjectmgr.cpp
+++ b/src/unittest/test_serveractiveobjectmgr.cpp
@@ -148,14 +148,26 @@ void TestServerActiveObjectMgr::testGetObjectsInsideRadius()
saomgr.registerObject(new TestServerActiveObject(p));
}
- std::vector<u16> result;
- saomgr.getObjectsInsideRadius(v3f(), 50, result);
+ std::vector<ServerActiveObject *> result;
+ saomgr.getObjectsInsideRadius(v3f(), 50, result, nullptr);
UASSERTCMP(int, ==, result.size(), 1);
result.clear();
- saomgr.getObjectsInsideRadius(v3f(), 750, result);
+ saomgr.getObjectsInsideRadius(v3f(), 750, result, nullptr);
UASSERTCMP(int, ==, result.size(), 2);
+ result.clear();
+ saomgr.getObjectsInsideRadius(v3f(), 750000, result, nullptr);
+ UASSERTCMP(int, ==, result.size(), 5);
+
+ result.clear();
+ auto include_obj_cb = [](ServerActiveObject *obj) {
+ return (obj->getBasePosition().X != 10);
+ };
+
+ saomgr.getObjectsInsideRadius(v3f(), 750000, result, include_obj_cb);
+ UASSERTCMP(int, ==, result.size(), 4);
+
clearSAOMgr(&saomgr);
}
diff --git a/src/unittest/test_servermodmanager.cpp b/src/unittest/test_servermodmanager.cpp
index 0757323f4..799936757 100644
--- a/src/unittest/test_servermodmanager.cpp
+++ b/src/unittest/test_servermodmanager.cpp
@@ -88,7 +88,7 @@ void TestServerModManager::testCreation()
{
std::string path = std::string(TEST_WORLDDIR) + DIR_DELIM + "world.mt";
Settings world_config;
- world_config.set("gameid", "minimal");
+ world_config.set("gameid", "devtest");
UASSERTEQ(bool, world_config.updateConfigFile(path.c_str()), true);
ServerModManager sm(TEST_WORLDDIR);
}
@@ -118,10 +118,10 @@ void TestServerModManager::testGetMods()
const auto &mods = sm.getMods();
UASSERTEQ(bool, mods.empty(), false);
- // Ensure we found default mod inside the test folder
+ // Ensure we found basenodes mod (part of devtest)
bool default_found = false;
for (const auto &m : mods) {
- if (m.name == "default")
+ if (m.name == "basenodes")
default_found = true;
// Verify if paths are not empty
@@ -135,7 +135,7 @@ void TestServerModManager::testGetModspec()
{
ServerModManager sm(std::string(TEST_WORLDDIR));
UASSERTEQ(const ModSpec *, sm.getModSpec("wrongmod"), NULL);
- UASSERT(sm.getModSpec("default") != NULL);
+ UASSERT(sm.getModSpec("basenodes") != NULL);
}
void TestServerModManager::testGetModNamesWrongDir()
@@ -152,7 +152,7 @@ void TestServerModManager::testGetModNames()
std::vector<std::string> result;
sm.getModNames(result);
UASSERTEQ(bool, result.empty(), false);
- UASSERT(std::find(result.begin(), result.end(), "default") != result.end());
+ UASSERT(std::find(result.begin(), result.end(), "basenodes") != result.end());
}
void TestServerModManager::testGetModMediaPathsWrongDir()