Files
pymol-open-source/layerCTest/Test_copyable_ptr.cpp
2019-10-29 16:02:11 +01:00

94 lines
1.7 KiB
C++

#include "Test.h"
#include "pymol/memory.h"
using namespace pymol::test;
TEST_CASE("copyable_ptr move construct", "[copyable_ptr]")
{
pymol::copyable_ptr<int> p1;
{
pymol::copyable_ptr<int> p2(std::move(p1));
REQUIRE(p1.get() == nullptr);
REQUIRE(p2.get() == nullptr);
}
auto ptr = new int(123);
p1.reset(ptr);
{
pymol::copyable_ptr<int> p2(std::move(p1));
REQUIRE(p1.get() == nullptr);
REQUIRE(p2.get() == ptr);
}
}
TEST_CASE("copyable_ptr copy construct", "[copyable_ptr]")
{
pymol::copyable_ptr<int> p1;
{
pymol::copyable_ptr<int> p2(p1);
REQUIRE(p1.get() == nullptr);
REQUIRE(p2.get() == nullptr);
}
auto ptr = new int(123);
p1.reset(ptr);
{
pymol::copyable_ptr<int> p2(p1);
REQUIRE(p1.get() == ptr);
REQUIRE(p2.get() != ptr);
REQUIRE(p2.get() != nullptr);
REQUIRE(*p2 == 123);
}
}
TEST_CASE("copyable_ptr move assign", "[copyable_ptr]")
{
pymol::copyable_ptr<int> p1;
{
pymol::copyable_ptr<int> p2;
p2 = std::move(p1);
REQUIRE(p1.get() == nullptr);
REQUIRE(p2.get() == nullptr);
}
auto ptr = new int(123);
p1.reset(ptr);
{
pymol::copyable_ptr<int> p2;
p2 = std::move(p1);
REQUIRE(p1.get() == nullptr);
REQUIRE(p2.get() == ptr);
}
}
TEST_CASE("copyable_ptr copy assign", "[copyable_ptr]")
{
pymol::copyable_ptr<int> p1;
{
pymol::copyable_ptr<int> p2;
p2 = p1;
REQUIRE(p1.get() == nullptr);
REQUIRE(p2.get() == nullptr);
}
auto ptr = new int(123);
p1.reset(ptr);
{
pymol::copyable_ptr<int> p2;
p2 = p1;
REQUIRE(p1.get() == ptr);
REQUIRE(p2.get() != ptr);
REQUIRE(p2.get() != nullptr);
REQUIRE(*p2 == 123);
}
}