/** * @author Edouard DUPIN * * @copyright 2011, Edouard DUPIN, all right reserved * * @license MPL v2.0 (see license file) */ #include #include #include TEST(TestEmemoryUniquePtr, Creation_1) { ememory::UniquePtr testData; EXPECT_EQ(testData.get(), nullptr); } TEST(TestEmemoryUniquePtr, Creation_2) { ememory::UniquePtr testData(new uint32_t(55)); EXPECT_NE(testData.get(), nullptr); EXPECT_EQ(*testData.get(), 55); } TEST(TestEmemoryUniquePtr, Creation_3) { ememory::UniquePtr testData = ememory::makeUniquePtr(456789); EXPECT_NE(testData.get(), nullptr); EXPECT_EQ(*testData.get(), 456789); } uint32_t vals[] = {0,0,0,0,0,0,0,0,0,0,0,0,0}; class testCreateAndDestroy { public: uint32_t m_val; public: testCreateAndDestroy(uint32_t _val): m_val(_val) { vals[m_val] = 1; } ~testCreateAndDestroy() { vals[m_val] = -1; } }; TEST(TestEmemoryUniquePtr, reset) { memset(vals, 0, sizeof(vals)); EXPECT_EQ(vals[1], 0); ememory::UniquePtr testData = ememory::makeUniquePtr(1); EXPECT_NE(testData.get(), nullptr); EXPECT_EQ(vals[1], 1); testData.reset(); EXPECT_EQ(testData.get(), nullptr); EXPECT_EQ(vals[1], -1); } TEST(TestEmemoryUniquePtr, reset_2) { memset(vals, 0, sizeof(vals)); EXPECT_EQ(vals[1], 0); ememory::UniquePtr testData = ememory::makeUniquePtr(1); EXPECT_NE(testData.get(), nullptr); EXPECT_EQ(vals[1], 1); testData = nullptr; EXPECT_EQ(testData.get(), nullptr); EXPECT_EQ(vals[1], -1); } TEST(TestEmemoryUniquePtr, overwrite) { memset(vals, 0, sizeof(vals)); ememory::UniquePtr testData = ememory::makeUniquePtr(1); EXPECT_NE(testData.get(), nullptr); EXPECT_EQ(vals[1], 1); EXPECT_EQ(vals[2], 0); testData = ememory::makeUniquePtr(2); EXPECT_EQ(vals[1], -1); EXPECT_EQ(vals[2], 1); testData.reset(); EXPECT_EQ(vals[1], -1); EXPECT_EQ(vals[2], -1); }