diff --git a/autotest/Create/Create.cpp b/autotest/Create/Create.cpp index a5c6ed5a3..3923de0a6 100644 --- a/autotest/Create/Create.cpp +++ b/autotest/Create/Create.cpp @@ -5,45 +5,88 @@ using namespace Upp; struct Test : Moveable { Test(const Vector& a, int b) : a(clone(a)), b(b) {} Test(Vector&& a, int b) : a(pick(a)), b(b) {} + Test() {} Vector a; int b; }; +template +void TestCreate() +{ + T h; + DLOG("---- Create " << typeid(T).name()); + Vector v; + v.Add(12); + // Copy-constructor + h.Create(v, 22); + DDUMP(v.GetCount()); + ASSERT(v.GetCount() == 1); + // Move-constructor + h.Create(pick(v), 22); + DDUMP(v.GetCount()); + ASSERT(v.GetCount() == 0); + v.Add(21); + h.Create(clone(v), 22); + DDUMP(v.GetCount()); + ASSERT(v.GetCount() == 1); +} + +template +void TestCreateT() +{ + T h; + DLOG("---- Create " << typeid(T).name()); + Vector v; + v.Add(12); + // Copy-constructor + h.Create(v, 22); + DDUMP(v.GetCount()); + ASSERT(v.GetCount() == 1); + // Move-constructor + h.Create(pick(v), 22); + DDUMP(v.GetCount()); + ASSERT(v.GetCount() == 0); + v.Add(21); + h.Create(clone(v), 22); + DDUMP(v.GetCount()); + ASSERT(v.GetCount() == 1); +} + +template +void TestCreateMap() +{ + T h; + DLOG("---- Create " << typeid(T).name()); + Vector v; + v.Add(12); + // Copy-constructor + h.Create("a", v, 22); + DDUMP(v.GetCount()); + ASSERT(v.GetCount() == 1); + // Move-constructor + h.Create("a", pick(v), 22); + DDUMP(v.GetCount()); + ASSERT(v.GetCount() == 0); + v.Add(21); + h.Create("a", clone(v), 22); + DDUMP(v.GetCount()); + ASSERT(v.GetCount() == 1); +} + CONSOLE_APP_MAIN { - { - Array h; - Vector v; - v.Add(12); - // Copy-constructor - h.Create(v, 22); - DDUMP(v.GetCount()); - ASSERT(v.GetCount() == 1); - // Move-constructor - h.Create(pick(v), 22); - DDUMP(v.GetCount()); - ASSERT(v.GetCount() == 0); - v.Add(21); - h.Create(Vector(v, 0), 22); - DDUMP(v.GetCount()); - ASSERT(v.GetCount() == 1); - } - { - Vector h; - Vector v; - v.Add(12); - // Copy-constructor - h.Create(v, 22); - DDUMP(v.GetCount()); - ASSERT(v.GetCount() == 1); - // Move-constructor - h.Create(pick(v), 22); - DDUMP(v.GetCount()); - ASSERT(v.GetCount() == 0); - v.Add(21); - h.Create(Vector(v, 0), 22); - DDUMP(v.GetCount()); - ASSERT(v.GetCount() == 1); - } + StdLogSetup(LOG_COUT|LOG_FILE); + + TestCreate>(); + TestCreateT>(); + TestCreateT(); + TestCreate>(); + TestCreateT>(); + TestCreateT>(); + TestCreateMap>(); + TestCreateMap>(); + TestCreateMap>(); + + LOG("======== OK"); }