drogon/unittest/DrObjectUnittest.cpp

49 lines
1.1 KiB
C++
Raw Normal View History

#include <drogon/DrObject.h>
#include <gtest/gtest.h>
#include <string>
#include <iostream>
using namespace drogon;
class TestA : public DrObject<TestA>
{
};
namespace test
{
class TestB : public DrObject<TestB>
{
};
} // namespace test
TEST(DrObjectTest, creationTest)
{
2021-02-17 01:58:33 +00:00
using PtrType = std::shared_ptr<DrObjectBase>;
auto obj = PtrType(DrClassMap::newObject("TestA"));
EXPECT_NE(obj, nullptr);
auto objPtr = DrClassMap::getSingleInstance("TestA");
EXPECT_NE(objPtr.get(), nullptr);
auto objPtr2 = DrClassMap::getSingleInstance<TestA>();
EXPECT_NE(objPtr2.get(), nullptr);
EXPECT_EQ(objPtr, objPtr2);
}
TEST(DrObjectTest, namespaceTest)
{
2021-02-17 01:58:33 +00:00
using PtrType = std::shared_ptr<DrObjectBase>;
auto obj = PtrType(DrClassMap::newObject("test::TestB"));
EXPECT_NE(obj, nullptr);
auto objPtr = DrClassMap::getSingleInstance("test::TestB");
EXPECT_NE(objPtr.get(), nullptr);
auto objPtr2 = DrClassMap::getSingleInstance<test::TestB>();
EXPECT_NE(objPtr2.get(), nullptr);
EXPECT_EQ(objPtr, objPtr2);
}
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
2021-02-17 01:58:33 +00:00
}