/* ReplaceableItem(Test) - adapter to take snapshot from non-assignable values Copyright (C) Lumiera.org 2017, Hermann Vosseler This program 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * *****************************************************/ #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::rand; using std::swap; namespace { // Test helper: yet another ctor/dtor counting class long cntTracker = 0; struct Tracker { uint i_; Tracker() : i_(rand() % 500) { ++cntTracker; } Tracker(Tracker const& ot) : i_(ot.i_) { ++cntTracker; } Tracker(uint i) : i_(i) { ++cntTracker; } ~Tracker() { --cntTracker; } }; 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) { ulong l1 (rand() % 1000); ulong l2 (rand() % 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