lumiera_/tests/gui/interact/state-map-grouping-storage-test.cpp
Ichthyostega f80982b52b gen-node: fix insidious data conssitency problem
I assumed that, since GenNode is composed of copyable and
assignable types, the standard implementation will do.
But I overlooked the run time type check on the opaque
payload type within lib::Variant. When a type mismatch
is detected, the default implementation has already
assigned and thus altered the IDs.

So we need to roll our own implementation, and to add
insult to injury, we can't use the copy-and-swap idiom either.
2016-02-13 22:55:59 +01:00

145 lines
4.7 KiB
C++

/*
StateMapGroupingStorage(Test) - verify storage table for capturing UI state
Copyright (C) Lumiera.org
2016, Hermann Vosseler <Ichthyostega@web.de>
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 "gui/ctrl/bus-term.hpp"
//#include "gui/interact/presentation-state-manager.hpp"
#include "gui/interact/state-map-grouping-storage.hpp"
//#include "test/test-nexus.hpp"
//#include "test/mock-elm.hpp"
#include "lib/idi/entry-id.hpp"
#include "lib/diff/gen-node.hpp"
#include "lib/format-cout.hpp"
//#include "lib/time/timevalue.hpp"
//#include "lib/luid.h"
#include "lib/util.hpp"
#include <string>
using std::string;
using lib::idi::EntryID;
//using lib::idi::BareEntryID;
//using gui::interact::PresentationStateManager;
//using gui::ctrl::BusTerm;
//using gui::test::MockElm;
using lib::diff::GenNode;
//using lib::diff::Rec;
//using lib::diff::Ref;
//using lib::time::Time;
//using lib::time::TimeSpan;
//using lib::hash::LuidH;
//using lib::HashVal;
using util::isSameObject;
using util::isnil;
namespace gui {
namespace interact{
namespace test {
// using proc::control::LUMIERA_ERROR_UNBOUND_ARGUMENTS;
using lumiera::error::LUMIERA_ERROR_WRONG_TYPE;
namespace { // test fixture...
}//(End) test fixture
/**************************************************************************//**
* @test verify the storage structure for capturing UI state works as intended.
*
* @see BusTerm_test::captureStateMark()
* @see BusTerm_test::replayStateMark()
*/
class StateMapGroupingStorage_test : public Test
{
virtual void
run (Arg)
{
EntryID<char> woof ("wau");
EntryID<int> wooof ("wau");
EntryID<int> miaow ("miau");
EntryID<int> quack ("quack");
GenNode poodle{"poodle", "Pudel"};
GenNode toyPoodle{"poodle", "Zwergpudel"};
GenNode pseudoPoodle {"poodle", false};
GenNode mastiff{"mastiff", "Dogge"};
GenNode duck{"duck", "Ente"};
StateMapGroupingStorage storage;
CHECK (isnil (storage));
CHECK (0 == storage.size());
storage.record (woof, poodle);
CHECK (not isnil(storage));
CHECK (1 == storage.size());
CHECK (poodle == storage.retrieve(woof, "poodle"));
CHECK (not isSameObject (poodle, storage.retrieve(woof, "poodle")));
CHECK (Ref::NO == storage.retrieve(wooof, "poodle"));
CHECK (Ref::NO == storage.retrieve(woof, "pooodle"));
storage.record (woof, mastiff);
CHECK (2 == storage.size());
CHECK (poodle == storage.retrieve(woof, "poodle"));
CHECK (mastiff == storage.retrieve(woof, "mastiff"));
// upgrade the poodle
storage.record (woof, toyPoodle);
CHECK (2 == storage.size());
CHECK (poodle != storage.retrieve(woof, "poodle"));
CHECK (toyPoodle == storage.retrieve(woof, "poodle"));
// since properties are keyed just by ID-string,
// we might attempt sneak in a fake poodle
// fortunately GenNode disallows cross-type assignments
VERIFY_ERROR (WRONG_TYPE, storage.record (woof, pseudoPoodle) );
CHECK (2 == storage.size());
cout << toyPoodle <<endl;
cout << storage.retrieve(woof, "poodle") <<endl;
cout << size_t(toyPoodle.idi.getHash()) <<endl;
cout << size_t(storage.retrieve(woof, "poodle").idi.getHash()) <<endl;
cout << size_t(pseudoPoodle.idi.getHash()) <<endl;
CHECK (toyPoodle == storage.retrieve(woof, "poodle"));
CHECK (mastiff == storage.retrieve(woof, "mastiff"));
}
};
/** Register this test class... */
LAUNCHER (StateMapGroupingStorage_test, "unit gui");
}}} // namespace gui::model::test