2019-12-07 01:26:12 +08:00
|
|
|
#include <drogon/DrObject.h>
|
2021-05-27 20:09:57 +08:00
|
|
|
#include <drogon/drogon_test.h>
|
2019-12-07 01:26:12 +08:00
|
|
|
|
|
|
|
using namespace drogon;
|
2021-05-27 20:09:57 +08:00
|
|
|
|
2019-12-07 01:26:12 +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)
|
2019-12-07 01:26:12 +08:00
|
|
|
{
|
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);
|
2019-12-07 01:26:12 +08:00
|
|
|
|
|
|
|
auto objPtr = DrClassMap::getSingleInstance("TestA");
|
2021-05-27 20:09:57 +08:00
|
|
|
CHECK(objPtr.get() != nullptr);
|
2019-12-07 01:26:12 +08:00
|
|
|
|
|
|
|
auto objPtr2 = DrClassMap::getSingleInstance<TestA>();
|
2021-05-27 20:09:57 +08:00
|
|
|
CHECK(objPtr2.get() != nullptr);
|
|
|
|
CHECK(objPtr == objPtr2);
|
2019-12-07 01:26:12 +08:00
|
|
|
}
|
|
|
|
|
2021-05-27 20:09:57 +08:00
|
|
|
DROGON_TEST(DrObjectNamespaceTest)
|
2019-12-07 01:26:12 +08:00
|
|
|
{
|
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);
|
2019-12-07 01:26:12 +08:00
|
|
|
|
|
|
|
auto objPtr = DrClassMap::getSingleInstance("test::TestB");
|
2021-05-27 20:09:57 +08:00
|
|
|
CHECK(objPtr.get() != nullptr);
|
2019-12-07 01:26:12 +08:00
|
|
|
|
2021-05-27 20:09:57 +08:00
|
|
|
auto objPtr2 = DrClassMap::getSingleInstance<::test::TestB>();
|
|
|
|
CHECK(objPtr2.get() != nullptr);
|
|
|
|
CHECK(objPtr == objPtr2);
|
|
|
|
}
|