From 967654f1750f4171818e8d168ebb14447881687e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Fri, 16 Mar 2018 18:00:56 +0100 Subject: [PATCH] Add unit test for postblit behavior of InterfaceProxy. --- source/vibe/internal/interfaceproxy.d | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/source/vibe/internal/interfaceproxy.d b/source/vibe/internal/interfaceproxy.d index 46e89cb..203443a 100644 --- a/source/vibe/internal/interfaceproxy.d +++ b/source/vibe/internal/interfaceproxy.d @@ -336,3 +336,53 @@ private string parameterNames(alias F)() } private alias ProxyOf(I) = InterfaceProxy!I.Proxy; + + +unittest { + static interface I { + @property int count() const; + } + + static struct S { + int* cnt; + this(bool) { cnt = new int; *cnt = 1; } + this(this) { if (cnt) (*cnt)++; } + ~this() { if (cnt) (*cnt)--; } + @property int count() const { return cnt ? *cnt : 0; } + } + + auto s = S(true); + assert(s.count == 1); + + auto t = interfaceProxy!I(s); + assert(s.count == 2); + + t = interfaceProxy!I(s); + assert(s.count == 2); + + t = s; + assert(s.count == 2); + + s = S.init; + assert(t.count == 1); + + s = t.extract!S; + assert(s.count == 2); + + t = InterfaceProxy!I.init; + assert(s.count == 1); + + t = s; + assert(s.count == 2); + + s = S(true); + assert(s.count == 1); + assert(t.count == 1); + + { + InterfaceProxy!I u; + u = s; + assert(u.count == 2); + } + assert(s.count == 1); +}