mirror of
https://gitee.com/an-tao/drogon.git
synced 2024-12-05 05:07:58 +08:00
42 lines
1019 B
C++
42 lines
1019 B
C++
#include <drogon/DrObject.h>
|
|
#include <drogon/drogon_test.h>
|
|
|
|
using namespace drogon;
|
|
|
|
class TestA : public DrObject<TestA>
|
|
{
|
|
};
|
|
namespace test
|
|
{
|
|
class TestB : public DrObject<TestB>
|
|
{
|
|
};
|
|
} // namespace test
|
|
|
|
DROGON_TEST(DrObjectCreationTest)
|
|
{
|
|
using PtrType = std::shared_ptr<DrObjectBase>;
|
|
auto obj = PtrType(DrClassMap::newObject("TestA"));
|
|
CHECK(obj != nullptr);
|
|
|
|
auto objPtr = DrClassMap::getSingleInstance("TestA");
|
|
CHECK(objPtr.get() != nullptr);
|
|
|
|
auto objPtr2 = DrClassMap::getSingleInstance<TestA>();
|
|
CHECK(objPtr2.get() != nullptr);
|
|
CHECK(objPtr == objPtr2);
|
|
}
|
|
|
|
DROGON_TEST(DrObjectNamespaceTest)
|
|
{
|
|
using PtrType = std::shared_ptr<DrObjectBase>;
|
|
auto obj = PtrType(DrClassMap::newObject("test::TestB"));
|
|
CHECK(obj != nullptr);
|
|
|
|
auto objPtr = DrClassMap::getSingleInstance("test::TestB");
|
|
CHECK(objPtr.get() != nullptr);
|
|
|
|
auto objPtr2 = DrClassMap::getSingleInstance<::test::TestB>();
|
|
CHECK(objPtr2.get() != nullptr);
|
|
CHECK(objPtr == objPtr2);
|
|
} |