1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-27 17:28:41 +00:00

Add unittests for item movement code (#11885)

This commit is contained in:
savilli 2022-09-27 22:22:11 +02:00 committed by GitHub
parent 3f801bc096
commit 907dcdcf7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 382 additions and 81 deletions

View file

@ -17,23 +17,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "server/activeobjectmgr.h"
#include "test.h"
#include "mock_serveractiveobject.h"
#include <algorithm>
#include <queue>
#include "test.h"
#include "server/activeobjectmgr.h"
#include "profiler.h"
class TestServerActiveObject : public ServerActiveObject
{
public:
TestServerActiveObject(const v3f &p = v3f()) : ServerActiveObject(nullptr, p) {}
~TestServerActiveObject() = default;
ActiveObjectType getType() const override { return ACTIVEOBJECT_TYPE_TEST; }
bool getCollisionBox(aabb3f *toset) const override { return false; }
bool getSelectionBox(aabb3f *toset) const override { return false; }
bool collideWithObjects() const override { return false; }
};
class TestServerActiveObjectMgr : public TestBase
{
@ -86,9 +78,9 @@ void TestServerActiveObjectMgr::testFreeID()
// Register basic objects, ensure we never found
for (u8 i = 0; i < UINT8_MAX; i++) {
// Register an object
auto tsao = new TestServerActiveObject();
saomgr.registerObject(tsao);
aoids.push_back(tsao->getId());
auto sao = new MockServerActiveObject();
saomgr.registerObject(sao);
aoids.push_back(sao->getId());
// Ensure next id is not in registered list
UASSERT(std::find(aoids.begin(), aoids.end(), saomgr.getFreeId()) ==
@ -101,19 +93,19 @@ void TestServerActiveObjectMgr::testFreeID()
void TestServerActiveObjectMgr::testRegisterObject()
{
server::ActiveObjectMgr saomgr;
auto tsao = new TestServerActiveObject();
UASSERT(saomgr.registerObject(tsao));
auto sao = new MockServerActiveObject();
UASSERT(saomgr.registerObject(sao));
u16 id = tsao->getId();
u16 id = sao->getId();
auto tsaoToCompare = saomgr.getActiveObject(id);
UASSERT(tsaoToCompare->getId() == id);
UASSERT(tsaoToCompare == tsao);
auto saoToCompare = saomgr.getActiveObject(id);
UASSERT(saoToCompare->getId() == id);
UASSERT(saoToCompare == sao);
tsao = new TestServerActiveObject();
UASSERT(saomgr.registerObject(tsao));
UASSERT(saomgr.getActiveObject(tsao->getId()) == tsao);
UASSERT(saomgr.getActiveObject(tsao->getId()) != tsaoToCompare);
sao = new MockServerActiveObject();
UASSERT(saomgr.registerObject(sao));
UASSERT(saomgr.getActiveObject(sao->getId()) == sao);
UASSERT(saomgr.getActiveObject(sao->getId()) != saoToCompare);
clearSAOMgr(&saomgr);
}
@ -121,13 +113,13 @@ void TestServerActiveObjectMgr::testRegisterObject()
void TestServerActiveObjectMgr::testRemoveObject()
{
server::ActiveObjectMgr saomgr;
auto tsao = new TestServerActiveObject();
UASSERT(saomgr.registerObject(tsao));
auto sao = new MockServerActiveObject();
UASSERT(saomgr.registerObject(sao));
u16 id = tsao->getId();
u16 id = sao->getId();
UASSERT(saomgr.getActiveObject(id) != nullptr)
saomgr.removeObject(tsao->getId());
saomgr.removeObject(sao->getId());
UASSERT(saomgr.getActiveObject(id) == nullptr);
clearSAOMgr(&saomgr);
@ -145,7 +137,7 @@ void TestServerActiveObjectMgr::testGetObjectsInsideRadius()
};
for (const auto &p : sao_pos) {
saomgr.registerObject(new TestServerActiveObject(p));
saomgr.registerObject(new MockServerActiveObject(nullptr, p));
}
std::vector<ServerActiveObject *> result;
@ -183,7 +175,7 @@ void TestServerActiveObjectMgr::testGetAddedActiveObjectsAroundPos()
};
for (const auto &p : sao_pos) {
saomgr.registerObject(new TestServerActiveObject(p));
saomgr.registerObject(new MockServerActiveObject(nullptr, p));
}
std::queue<u16> result;