forked from Mirrorlandia_minetest/minetest
Add unit test on client::ActiveObjectMgr::getActiveSelectableObjects
This commit is contained in:
parent
d7291e0600
commit
21035bf5d4
@ -32,6 +32,24 @@ public:
|
|||||||
virtual void addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) {}
|
virtual void addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TestSelectableClientActiveObject : public ClientActiveObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TestSelectableClientActiveObject(aabb3f _selection_box)
|
||||||
|
: ClientActiveObject(0, nullptr, nullptr)
|
||||||
|
, selection_box(_selection_box)
|
||||||
|
{}
|
||||||
|
|
||||||
|
~TestSelectableClientActiveObject() = default;
|
||||||
|
ActiveObjectType getType() const override { return ACTIVEOBJECT_TYPE_TEST; }
|
||||||
|
void addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) override {}
|
||||||
|
bool getSelectionBox(aabb3f *toset) const override { *toset = selection_box; return true; }
|
||||||
|
const v3f getPosition() const override { return position; }
|
||||||
|
|
||||||
|
v3f position;
|
||||||
|
aabb3f selection_box;
|
||||||
|
};
|
||||||
|
|
||||||
class TestClientActiveObjectMgr : public TestBase
|
class TestClientActiveObjectMgr : public TestBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -43,6 +61,7 @@ public:
|
|||||||
void testFreeID();
|
void testFreeID();
|
||||||
void testRegisterObject();
|
void testRegisterObject();
|
||||||
void testRemoveObject();
|
void testRemoveObject();
|
||||||
|
void testGetActiveSelectableObjects();
|
||||||
};
|
};
|
||||||
|
|
||||||
static TestClientActiveObjectMgr g_test_instance;
|
static TestClientActiveObjectMgr g_test_instance;
|
||||||
@ -52,6 +71,7 @@ void TestClientActiveObjectMgr::runTests(IGameDef *gamedef)
|
|||||||
TEST(testFreeID);
|
TEST(testFreeID);
|
||||||
TEST(testRegisterObject)
|
TEST(testRegisterObject)
|
||||||
TEST(testRemoveObject)
|
TEST(testRemoveObject)
|
||||||
|
TEST(testGetActiveSelectableObjects)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -116,3 +136,48 @@ void TestClientActiveObjectMgr::testRemoveObject()
|
|||||||
|
|
||||||
caomgr.clear();
|
caomgr.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestClientActiveObjectMgr::testGetActiveSelectableObjects()
|
||||||
|
{
|
||||||
|
client::ActiveObjectMgr caomgr;
|
||||||
|
auto obj = new TestSelectableClientActiveObject({v3f{-1, -1, -1}, v3f{1, 1, 1}});
|
||||||
|
UASSERT(caomgr.registerObject(obj));
|
||||||
|
|
||||||
|
auto assert_obj_selected = [&] (v3f a, v3f b) {
|
||||||
|
auto actual = caomgr.getActiveSelectableObjects({a, b});
|
||||||
|
UASSERTEQ(auto, actual.size(), 1u);
|
||||||
|
UASSERTEQ(auto, actual.at(0).obj, obj);
|
||||||
|
};
|
||||||
|
|
||||||
|
auto assert_obj_missed = [&] (v3f a, v3f b) {
|
||||||
|
auto actual = caomgr.getActiveSelectableObjects({a, b});
|
||||||
|
UASSERTEQ(auto, actual.size(), 0u);
|
||||||
|
};
|
||||||
|
|
||||||
|
float x = 12, y = 3, z = 6;
|
||||||
|
obj->position = {x, y, z};
|
||||||
|
|
||||||
|
assert_obj_selected({0, 0, 0}, {x-1, y-1, z-1});
|
||||||
|
assert_obj_selected({0, 0, 0}, {2*(x-1), 2*(y-1), 2*(z-1)});
|
||||||
|
assert_obj_selected({0, 0, 0}, {2*(x+1), 2*(y-1), 2*(z+1)});
|
||||||
|
assert_obj_selected({0, 0, 0}, {20, 5, 10});
|
||||||
|
|
||||||
|
assert_obj_selected({30, -12, 17}, {x+1, y+1, z-1});
|
||||||
|
assert_obj_selected({30, -12, 17}, {x, y+1, z});
|
||||||
|
assert_obj_selected({30, -12, 17}, {-6, 20, -5});
|
||||||
|
assert_obj_selected({30, -12, 17}, {-8, 20, -7});
|
||||||
|
|
||||||
|
assert_obj_selected({-21, 6, -13}, {x+1.4f, y, z});
|
||||||
|
assert_obj_selected({-21, 6, -13}, {x-1.4f, y, z});
|
||||||
|
assert_obj_missed({-21, 6, -13}, {x-3.f, y, z});
|
||||||
|
|
||||||
|
assert_obj_selected({-21, 6, -13}, {x, y-1.4f, z});
|
||||||
|
assert_obj_selected({-21, 6, -13}, {x, y+1.4f, z});
|
||||||
|
assert_obj_missed({-21, 6, -13}, {x, y+3.f, z});
|
||||||
|
|
||||||
|
assert_obj_selected({-21, 6, -13}, {x, y, z+1.4f});
|
||||||
|
assert_obj_selected({-21, 6, -13}, {x, y, z-1.4f});
|
||||||
|
assert_obj_missed({-21, 6, -13}, {x, y, z-3.f});
|
||||||
|
|
||||||
|
caomgr.clear();
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user