/* ReplaceableItem(Test) - adapter to take snapshot from non-assignable values Copyright (C) 2017, Hermann Vosseler   **Lumiera** is free software; you can redistribute it and/or modify it   under the terms of the GNU General Public License as published by the   Free Software Foundation; either version 2 of the License, or (at your   option) any later version. See the file COPYING for further details. * *****************************************************************/ #include "lib/test/run.hpp" #include "lib/test/test-helper.hpp" #include "lib/util.hpp" #include "lib/time/timevalue.hpp" #include "lib/replaceable-item.hpp" namespace lib { namespace wrapper { namespace test{ using ::Test; using lib::test::randStr; using lib::test::randTime; using util::isSameObject; using time::Time; using time::Duration; using std::string; using std::swap; namespace { // Test helper: yet another ctor/dtor counting class long cntTracker = 0; struct Tracker { uint i_; Tracker() : i_(rani(500)) { ++cntTracker; } Tracker(Tracker const& ot) : i_(ot.i_) { ++cntTracker; } Tracker(uint i) : i_(i) { ++cntTracker; } ~Tracker() { --cntTracker; } Tracker& operator= (Tracker const&) = default; }; struct NonAssign : Tracker { using Tracker::Tracker; NonAssign& operator= (NonAssign const&) =delete; }; bool operator== (Tracker const& t1, Tracker const& t2) { return t1.i_ == t2.i_; } bool operator!= (Tracker const& t1, Tracker const& t2) { return t1.i_ != t2.i_; } } // (END) Test helpers /***************************************************************************//** * @test scrutinise an adapter to snapshot non-assignable values. * - create instantiations for various types * - both assignable and non-assignable types * - empty-construct and copy construct the adapter * - perform assignments and even content swapping * - use counting to verify proper instance management * - compare by delegating to element comparison * * @see replaceable-item.hpp * @see steam::control::MementoTie */ class ReplaceableItem_test : public Test { virtual void run (Arg) { seedRand(); ulong l1 (1 + rani(1000)); ulong l2 (1 + rani(1000)); string s1 (randStr(50)); string s2 (randStr(50)); const char* cp (s1.c_str()); Time t1{randTime()}, t2{randTime()}; Duration d1{randTime()}, d2{randTime()}; verifyUsage (l1, l2); verifyUsage (&l1, &l2); verifyUsage (s1, s2); verifyUsage (&s1, &s2); verifyUsage (s2, cp); verifyUsage (cp, "Lumiera"); verifyUsage (cp, "Lumiera"); // non-assignable types... verifyUsage