From baa3d2bff0baeb1f2f66b6e7dfe7cce66fce577b Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 16 Aug 2018 03:31:22 +0200 Subject: [PATCH] WLink: define expected copy behaviour --- tests/gui/model/w-link-test.cpp | 57 +++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/tests/gui/model/w-link-test.cpp b/tests/gui/model/w-link-test.cpp index 2c9177904..fa157337c 100644 --- a/tests/gui/model/w-link-test.cpp +++ b/tests/gui/model/w-link-test.cpp @@ -34,7 +34,7 @@ //#include "lib/diff/gen-node.hpp" #include "lib/util.hpp" -//#include +#include #include @@ -43,8 +43,9 @@ //using lib::diff::Rec; //using lib::idi::EntryID; //using lib::diff::GenNode; -using std::make_unique; using util::isSameObject; +using std::make_unique; +using std::move; //using util::isnil; @@ -158,7 +159,57 @@ namespace test { void verify_copy() { - UNIMPLEMENTED ("copy with magic"); + using Wint = DummyWidget; + auto w1 = make_unique(); + auto w2 = make_unique(); + + WLink l1; + WLink l2{l1}; + CHECK (not l2); + l2.connect(*w1); + + WLink l3{l2}; + CHECK (l3); + CHECK (w1->val == l3->val); + + CHECK (not l1); // they are statefull and independent + l1 = move(l2); + CHECK (not l2); + CHECK (l1); + CHECK (isSameObject (*l1, *l3)); + + l2 = WLink{WLink{*w2}}; + CHECK (w2->val == l2->val); + + l1 = l3; + CHECK (w1->val == l1->val); + WLink& ref{l1}; + l1 = move(ref); + CHECK (w1->val == l1->val); + CHECK (w1->val == l3->val); + + std::swap (l2, l3); + CHECK (w1->val == l1->val); + CHECK (w1->val == l2->val); + CHECK (w2->val == l3->val); + + w1.reset(); + CHECK (not l1); + CHECK (not l2); + CHECK (w2->val == l3->val); + + using Wuint = DummyWidget; + auto uu = make_unique(); + WLink lu{*uu}; + +///////////////does not compile... +// l1 = uu; +// l1.connect(*uu); + + // but it is a compile time check... + l1 = reinterpret_cast&&> (uu); + CHECK ((int)uu->val == l1->val); + CHECK (not lu); } };