drogon/lib/tests/unittests/DrObjectTest.cc

42 lines
1019 B
C++
Raw Normal View History

#include <drogon/DrObject.h>
2021-05-27 20:09:57 +08:00
#include <drogon/drogon_test.h>
using namespace drogon;
2021-05-27 20:09:57 +08:00
class TestA : public DrObject<TestA>
{
};
namespace test
{
class TestB : public DrObject<TestB>
{
};
} // namespace test
2021-05-27 20:09:57 +08:00
DROGON_TEST(DrObjectCreationTest)
{
2021-02-17 09:58:33 +08:00
using PtrType = std::shared_ptr<DrObjectBase>;
auto obj = PtrType(DrClassMap::newObject("TestA"));
2021-05-27 20:09:57 +08:00
CHECK(obj != nullptr);
auto objPtr = DrClassMap::getSingleInstance("TestA");
2021-05-27 20:09:57 +08:00
CHECK(objPtr.get() != nullptr);
auto objPtr2 = DrClassMap::getSingleInstance<TestA>();
2021-05-27 20:09:57 +08:00
CHECK(objPtr2.get() != nullptr);
CHECK(objPtr == objPtr2);
}
2021-05-27 20:09:57 +08:00
DROGON_TEST(DrObjectNamespaceTest)
{
2021-02-17 09:58:33 +08:00
using PtrType = std::shared_ptr<DrObjectBase>;
auto obj = PtrType(DrClassMap::newObject("test::TestB"));
2021-05-27 20:09:57 +08:00
CHECK(obj != nullptr);
auto objPtr = DrClassMap::getSingleInstance("test::TestB");
2021-05-27 20:09:57 +08:00
CHECK(objPtr.get() != nullptr);
2021-05-27 20:09:57 +08:00
auto objPtr2 = DrClassMap::getSingleInstance<::test::TestB>();
CHECK(objPtr2.get() != nullptr);
CHECK(objPtr == objPtr2);
}