2010-10-17 05:08:47 +02:00
|
|
|
/*
|
2010-10-17 05:54:21 +02:00
|
|
|
SessionElementQuery(Test) - querying and retrieving elements from the session
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2010-10-17 05:08:47 +02:00
|
|
|
Copyright (C) Lumiera.org
|
2010-10-17 05:54:21 +02:00
|
|
|
2010, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2010-10-17 05:08:47 +02:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
2010-12-17 23:28:49 +01:00
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
2010-10-17 05:08:47 +02:00
|
|
|
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.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2010-10-17 05:08:47 +02:00
|
|
|
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.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2010-10-17 05:08:47 +02:00
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
#include "proc/mobject/session/test-scopes.hpp"
|
2010-10-17 05:54:21 +02:00
|
|
|
#include "proc/mobject/session/element-query.hpp"
|
|
|
|
|
#include "proc/mobject/session/scope-path.hpp"
|
|
|
|
|
#include "proc/mobject/session/scope.hpp"
|
|
|
|
|
#include "proc/mobject/mobject-ref.hpp"
|
2010-10-17 05:08:47 +02:00
|
|
|
#include "lib/util.hpp"
|
|
|
|
|
|
2014-04-03 22:42:48 +02:00
|
|
|
#include <functional>
|
2010-10-17 05:08:47 +02:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-02 17:50:44 +01:00
|
|
|
namespace proc {
|
2010-10-17 05:08:47 +02:00
|
|
|
namespace mobject {
|
|
|
|
|
namespace session {
|
|
|
|
|
namespace test {
|
|
|
|
|
|
2014-04-03 22:42:48 +02:00
|
|
|
using std::placeholders::_1;
|
|
|
|
|
using std::function;
|
|
|
|
|
using std::bind;
|
2010-10-17 05:08:47 +02:00
|
|
|
using std::string;
|
|
|
|
|
|
2010-10-17 05:54:21 +02:00
|
|
|
using util::cStr;
|
2010-10-17 05:08:47 +02:00
|
|
|
using util::contains;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace { // helpers and shortcuts....
|
|
|
|
|
|
2010-10-17 05:54:21 +02:00
|
|
|
typedef Placement<DummyMO> const& PDummy; // note const& required by ElementQuery filter definition
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** a filter predicate to pick some objects from a resultset,
|
|
|
|
|
* based on string match with the element's self-display string.
|
2014-05-11 02:08:53 +02:00
|
|
|
* @note the query system allows us to use the specific API of DummyMO,
|
|
|
|
|
* without the need for any cast. It is sufficient to declare
|
|
|
|
|
* a suitable signature on the query predicate! */
|
2010-10-17 05:54:21 +02:00
|
|
|
inline function<bool(PDummy)>
|
|
|
|
|
elementID_contains (string expectedText)
|
2010-10-17 05:08:47 +02:00
|
|
|
{
|
2014-05-11 02:08:53 +02:00
|
|
|
return [=] (PDummy candidate)
|
|
|
|
|
{
|
|
|
|
|
REQUIRE (candidate.isValid());
|
|
|
|
|
string desc(candidate->operator string());
|
|
|
|
|
return contains(desc, expectedText);
|
|
|
|
|
};
|
2010-10-17 05:08:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-24 23:06:36 +02:00
|
|
|
/******************************************************************************************//**
|
2010-10-17 05:54:21 +02:00
|
|
|
* @test cover the part of the session API allowing to retrieve specific elements by query.
|
|
|
|
|
* - This test first picks an object from the test session, where the filter predicate
|
|
|
|
|
* utilises the specific MObject subclass (here DummyMO).
|
|
|
|
|
* - Then re-fetches the same object using a different filter
|
|
|
|
|
* (based on the specific random int-ID).
|
|
|
|
|
* - Next the element is removed from the test session to verify the "not found" result
|
|
|
|
|
* - finally we re-attach another placement of the same underlying MObject instance
|
|
|
|
|
* at a different location in the test session and verify we can again pick this
|
|
|
|
|
* element with the specific query.
|
2010-10-17 05:08:47 +02:00
|
|
|
*
|
2010-10-17 05:54:21 +02:00
|
|
|
* @see mobject::session::ElementQuery
|
2010-10-17 05:08:47 +02:00
|
|
|
* @see mobject::session::ContentsQuery
|
2010-10-17 05:54:21 +02:00
|
|
|
* @see scope-query-test.cpp
|
2010-10-17 05:08:47 +02:00
|
|
|
*/
|
2010-10-17 05:54:21 +02:00
|
|
|
class SessionElementQuery_test : public Test
|
2010-10-17 05:08:47 +02:00
|
|
|
{
|
|
|
|
|
virtual void
|
|
|
|
|
run (Arg)
|
|
|
|
|
{
|
|
|
|
|
// Prepare an (test)Index (dummy "session")
|
|
|
|
|
PPIdx testSession (build_testScopes());
|
|
|
|
|
|
2010-10-17 05:54:21 +02:00
|
|
|
ElementQuery queryAPI;
|
2010-10-17 05:08:47 +02:00
|
|
|
|
2010-10-17 05:54:21 +02:00
|
|
|
MORef<DummyMO> dummy1 = queryAPI.pick (elementID_contains("MO2"));
|
|
|
|
|
CHECK (dummy1);
|
|
|
|
|
CHECK (dummy1->isValid());
|
2010-10-17 06:30:56 +02:00
|
|
|
INFO (test, "Location in Tree: %s", cStr(ScopePath(dummy1.getPlacement())));
|
|
|
|
|
|
2010-10-17 05:54:21 +02:00
|
|
|
string elementID = dummy1->operator string();
|
|
|
|
|
CHECK (contains (elementID, "MO2"));
|
2010-10-17 05:08:47 +02:00
|
|
|
|
2010-10-17 05:54:21 +02:00
|
|
|
string specificID = elementID.substr(10); // should contain the random int-ID
|
|
|
|
|
MORef<DummyMO> dummy2;
|
|
|
|
|
CHECK (!dummy2);
|
|
|
|
|
dummy2 = queryAPI.pick (elementID_contains(specificID));
|
|
|
|
|
CHECK (dummy2); // found the same object again
|
|
|
|
|
CHECK (dummy2->isValid());
|
|
|
|
|
CHECK (dummy2 == dummy1);
|
2010-10-17 05:08:47 +02:00
|
|
|
|
2010-10-17 05:54:21 +02:00
|
|
|
|
|
|
|
|
// put aside a new handle holding onto the MObject
|
|
|
|
|
PDum newPlacement(dummy1.getPlacement());
|
2010-10-17 06:30:56 +02:00
|
|
|
CHECK (testSession->contains(dummy1));
|
2010-10-17 05:54:21 +02:00
|
|
|
CHECK (!testSession->contains(newPlacement));
|
|
|
|
|
|
|
|
|
|
// and now remove the placement and all contained elements
|
2010-10-17 06:30:56 +02:00
|
|
|
testSession->clear (dummy1);
|
|
|
|
|
CHECK (!testSession->contains(dummy1));
|
2010-10-17 05:54:21 +02:00
|
|
|
|
|
|
|
|
MORef<DummyMO> findAgain = queryAPI.pick (elementID_contains(specificID));
|
|
|
|
|
CHECK (!findAgain); // empty result because searched element was removed from session...
|
|
|
|
|
|
2014-05-11 02:08:53 +02:00
|
|
|
MORef<DummyMO> otherElm = queryAPI.pick (elementID_contains("MO21"));
|
2010-10-17 05:54:21 +02:00
|
|
|
CHECK (otherElm); // now pick just some other arbitrary element
|
|
|
|
|
|
2010-10-17 06:30:56 +02:00
|
|
|
testSession->insert(newPlacement, otherElm);
|
2010-10-17 05:54:21 +02:00
|
|
|
dummy2 = queryAPI.pick (elementID_contains(specificID));
|
|
|
|
|
CHECK (dummy2);
|
|
|
|
|
CHECK (dummy2 != dummy1);
|
|
|
|
|
CHECK (dummy2 != newPlacement);
|
|
|
|
|
CHECK (isSharedPointee(newPlacement, dummy2.getPlacement()));
|
2010-10-17 06:30:56 +02:00
|
|
|
CHECK (Scope::containing (dummy2.getRef()) == Scope (otherElm));
|
|
|
|
|
INFO (test, "New treelocation: %s", cStr(ScopePath(dummy2.getPlacement())));
|
2010-10-17 05:08:47 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2010-10-17 05:54:21 +02:00
|
|
|
|
2010-10-17 05:08:47 +02:00
|
|
|
/** Register this test class... */
|
2010-10-17 05:54:21 +02:00
|
|
|
LAUNCHER (SessionElementQuery_test, "function session");
|
2010-10-17 05:08:47 +02:00
|
|
|
|
|
|
|
|
|
2011-12-02 17:50:44 +01:00
|
|
|
}}}} // namespace proc::mobject::session::test
|