2009-11-22 07:26:51 +01:00
|
|
|
|
/*
|
|
|
|
|
|
QueryFocusStack(Test) - verify the stack of focus path frames
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2009, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
**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.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
* *****************************************************************/
|
2009-11-22 07:26:51 +01:00
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
|
/** @file query-focus-stack-test.cpp
|
2017-02-22 03:17:18 +01:00
|
|
|
|
** unit test \ref QueryFocusStack_test
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2009-11-22 07:26:51 +01:00
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
|
#include "lib/test/test-helper.hpp"
|
2018-11-15 23:42:43 +01:00
|
|
|
|
#include "steam/mobject/session/test-scopes.hpp"
|
|
|
|
|
|
#include "steam/mobject/session/query-focus-stack.hpp"
|
|
|
|
|
|
#include "steam/mobject/session/test-scope-invalid.hpp"
|
2009-11-22 07:26:51 +01:00
|
|
|
|
#include "lib/util.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-16 02:04:47 +01:00
|
|
|
|
namespace steam {
|
2009-11-22 07:26:51 +01:00
|
|
|
|
namespace mobject {
|
|
|
|
|
|
namespace session {
|
|
|
|
|
|
namespace test {
|
|
|
|
|
|
|
|
|
|
|
|
using util::isnil;
|
|
|
|
|
|
using util::isSameObject;
|
2024-03-16 02:04:47 +01:00
|
|
|
|
using LERR_(INVALID_SCOPE);
|
2009-11-22 07:26:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
2013-10-24 23:06:36 +02:00
|
|
|
|
/***********************************************************************//**
|
2009-11-22 07:26:51 +01:00
|
|
|
|
* @test behaviour of the stack of focus location paths.
|
|
|
|
|
|
* Basically this is just a stack, but has a somewhat unusual behaviour
|
|
|
|
|
|
* on pop(), as it considers the (intrusive) ref-count maintained within
|
|
|
|
|
|
* the stack frames (ScopePath instances) and cleans up unused frames.
|
|
|
|
|
|
* Similar to the ScopePath_test, we use a pseudo-session to create
|
|
|
|
|
|
* some path frames to play with.
|
2010-10-09 06:18:40 +02:00
|
|
|
|
* @note this test executes a lot of functionality in a manual by-hand way,
|
|
|
|
|
|
* which in the actual application is accessed and utilised through
|
2024-03-16 02:04:47 +01:00
|
|
|
|
* QueryFocus objects as frontend.
|
2009-11-22 07:26:51 +01:00
|
|
|
|
*
|
|
|
|
|
|
* @see mobject::session::QueryFocusStack
|
|
|
|
|
|
* @see mobject::session::ScopePath
|
|
|
|
|
|
*/
|
|
|
|
|
|
class QueryFocusStack_test : public Test
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
virtual void
|
2024-03-16 02:04:47 +01:00
|
|
|
|
run (Arg)
|
2009-11-22 07:26:51 +01:00
|
|
|
|
{
|
2010-10-09 06:18:40 +02:00
|
|
|
|
// Prepare an (test)Index and
|
|
|
|
|
|
// set up dummy session contents
|
2009-11-22 07:26:51 +01:00
|
|
|
|
PPIdx index = build_testScopes();
|
|
|
|
|
|
|
|
|
|
|
|
createStack();
|
|
|
|
|
|
usePushedFrame();
|
|
|
|
|
|
automaticFrameHandling();
|
|
|
|
|
|
verify_errorHandling();
|
|
|
|
|
|
clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
createStack ()
|
|
|
|
|
|
{
|
|
|
|
|
|
QueryFocusStack stack;
|
|
|
|
|
|
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (!isnil (stack));
|
|
|
|
|
|
CHECK (!isnil (stack.top()));
|
|
|
|
|
|
CHECK (stack.top().isRoot());
|
2009-11-22 07:26:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
usePushedFrame ()
|
|
|
|
|
|
{
|
|
|
|
|
|
QueryFocusStack stack;
|
|
|
|
|
|
PMO& startPoint = retrieve_startElm();
|
|
|
|
|
|
|
|
|
|
|
|
ScopePath& firstFrame = stack.top(); // remember for later
|
|
|
|
|
|
intrusive_ptr_add_ref (&firstFrame);
|
|
|
|
|
|
stack.top().navigate(startPoint);
|
|
|
|
|
|
stack.top().moveUp();
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (Scope(startPoint).getParent() == stack.top().getLeaf());
|
|
|
|
|
|
CHECK (1 == stack.size());
|
2009-11-22 07:26:51 +01:00
|
|
|
|
|
|
|
|
|
|
// now open a second path frame, pushing aside the initial one
|
|
|
|
|
|
ScopePath& secondFrame = stack.push(startPoint);
|
|
|
|
|
|
intrusive_ptr_add_ref (&secondFrame);
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (2 == stack.size());
|
|
|
|
|
|
CHECK (secondFrame == stack.top());
|
|
|
|
|
|
CHECK (secondFrame.getLeaf() == startPoint);
|
|
|
|
|
|
CHECK (secondFrame.getLeaf() != firstFrame.getLeaf());
|
2009-11-22 07:26:51 +01:00
|
|
|
|
|
|
|
|
|
|
// can still reach and manipulate the ref-count of the first frame
|
|
|
|
|
|
intrusive_ptr_add_ref (&firstFrame);
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (2 == firstFrame.ref_count());
|
|
|
|
|
|
CHECK (1 == secondFrame.ref_count());
|
2009-11-22 07:26:51 +01:00
|
|
|
|
|
|
|
|
|
|
// can use/navigate the stack top frame
|
|
|
|
|
|
stack.top().goRoot();
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (!stack.top()); // now indeed at root == no path
|
|
|
|
|
|
CHECK (secondFrame.getLeaf().isRoot());
|
|
|
|
|
|
CHECK (secondFrame == stack.top());
|
2009-11-22 07:26:51 +01:00
|
|
|
|
|
|
|
|
|
|
// now drop back to the first frame:
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (1 == secondFrame.ref_count());
|
2009-11-22 07:26:51 +01:00
|
|
|
|
intrusive_ptr_release (&secondFrame);
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (0 == secondFrame.ref_count());
|
2009-11-22 07:26:51 +01:00
|
|
|
|
stack.pop_unused();
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (1 == stack.size());
|
|
|
|
|
|
CHECK (firstFrame == stack.top());
|
2009-11-22 07:26:51 +01:00
|
|
|
|
|
|
|
|
|
|
// ...still pointing at the previous location
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (Scope(startPoint).getParent() == stack.top().getLeaf());
|
|
|
|
|
|
CHECK (2 == firstFrame.ref_count());
|
2009-11-22 07:26:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
automaticFrameHandling ()
|
|
|
|
|
|
{
|
|
|
|
|
|
QueryFocusStack stack;
|
|
|
|
|
|
PMO& startPoint = retrieve_startElm();
|
|
|
|
|
|
|
|
|
|
|
|
ScopePath& firstFrame = stack.top(); // remember for later
|
|
|
|
|
|
stack.top().navigate(startPoint);
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (1 == stack.size());
|
2009-11-22 07:26:51 +01:00
|
|
|
|
intrusive_ptr_add_ref (&firstFrame);
|
|
|
|
|
|
|
|
|
|
|
|
// now open two new frames, but don't add ref-counts on them
|
|
|
|
|
|
ScopePath& secondFrame = stack.push(startPoint);
|
|
|
|
|
|
ScopePath& thirdFrame = stack.push(startPoint);
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (3 == stack.size());
|
|
|
|
|
|
CHECK (1 == firstFrame.ref_count());
|
|
|
|
|
|
CHECK (0 == secondFrame.ref_count());
|
|
|
|
|
|
CHECK (0 == thirdFrame.ref_count());
|
2009-11-22 07:26:51 +01:00
|
|
|
|
|
|
|
|
|
|
// any ref to top detects the non-referred-to state (by ref count==0)
|
|
|
|
|
|
// and will automatically pop and clean up...
|
|
|
|
|
|
ScopePath& newTop = stack.top();
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (1 == stack.size());
|
|
|
|
|
|
CHECK (firstFrame == stack.top());
|
|
|
|
|
|
CHECK (isSameObject(newTop, firstFrame));
|
|
|
|
|
|
CHECK (stack.top().getLeaf() == startPoint);
|
2009-11-22 07:26:51 +01:00
|
|
|
|
|
|
|
|
|
|
// second exercise: a pop_unused may even completely empty the stack
|
|
|
|
|
|
ScopePath& anotherFrame = stack.push(startPoint);
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (0 == anotherFrame.ref_count());
|
|
|
|
|
|
CHECK (1 == firstFrame.ref_count());
|
2010-10-09 06:18:40 +02:00
|
|
|
|
intrusive_ptr_release (&firstFrame);
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (0 == firstFrame.ref_count());
|
|
|
|
|
|
CHECK (firstFrame.getLeaf() == startPoint);
|
2009-11-22 07:26:51 +01:00
|
|
|
|
|
|
|
|
|
|
stack.pop_unused();
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (1 == stack.size());
|
2009-11-22 07:26:51 +01:00
|
|
|
|
// Note: don't use previously taken pointers
|
|
|
|
|
|
// or references anymore, after the stack
|
|
|
|
|
|
// triggered a cleanup!
|
|
|
|
|
|
ScopePath& anotherFrame2 = stack.top();
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (0 == anotherFrame2.ref_count());
|
|
|
|
|
|
CHECK (anotherFrame2.getLeaf().isRoot());
|
2009-11-22 07:26:51 +01:00
|
|
|
|
anotherFrame2.navigate(startPoint);
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (anotherFrame2.getLeaf() == startPoint);
|
2009-11-22 07:26:51 +01:00
|
|
|
|
|
|
|
|
|
|
stack.top();
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (1 == stack.size());
|
|
|
|
|
|
CHECK (stack.top().getLeaf().isRoot());
|
2009-11-22 07:26:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
verify_errorHandling ()
|
|
|
|
|
|
{
|
|
|
|
|
|
QueryFocusStack stack;
|
|
|
|
|
|
PMO& startPoint = retrieve_startElm();
|
|
|
|
|
|
|
|
|
|
|
|
ScopePath& firstFrame = stack.top(); // remember for later
|
|
|
|
|
|
stack.top().navigate(startPoint);
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (1 == stack.size());
|
2009-11-22 07:26:51 +01:00
|
|
|
|
intrusive_ptr_add_ref (&firstFrame);
|
|
|
|
|
|
|
|
|
|
|
|
ScopePath beforeInvalidNavigation = firstFrame;
|
2010-10-09 06:18:40 +02:00
|
|
|
|
Scope const& unrelatedScope = fabricate_invalidScope();
|
2009-11-22 07:26:51 +01:00
|
|
|
|
|
|
|
|
|
|
// try to navigate to an invalid place
|
2010-10-09 06:18:40 +02:00
|
|
|
|
VERIFY_ERROR (INVALID_SCOPE, stack.top().navigate (unrelatedScope) );
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (1 == stack.size());
|
|
|
|
|
|
CHECK (1 == firstFrame.ref_count());
|
|
|
|
|
|
CHECK (stack.top().getLeaf() == startPoint);
|
2009-11-22 07:26:51 +01:00
|
|
|
|
|
|
|
|
|
|
// try to push an invalid place
|
2010-10-09 06:18:40 +02:00
|
|
|
|
VERIFY_ERROR (INVALID_SCOPE, stack.push (unrelatedScope) );
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (1 == stack.size());
|
|
|
|
|
|
CHECK (1 == firstFrame.ref_count());
|
|
|
|
|
|
CHECK (stack.top().getLeaf() == startPoint);
|
2009-11-22 07:26:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
clear ()
|
|
|
|
|
|
{
|
|
|
|
|
|
QueryFocusStack stack;
|
|
|
|
|
|
intrusive_ptr_add_ref (&stack.top());
|
|
|
|
|
|
stack.top().moveUp();
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (stack.top().empty());
|
2009-11-22 07:26:51 +01:00
|
|
|
|
|
|
|
|
|
|
PMO& startPoint = retrieve_startElm();
|
|
|
|
|
|
intrusive_ptr_add_ref ( & stack.push(startPoint) );
|
|
|
|
|
|
intrusive_ptr_add_ref ( & stack.push(startPoint) );
|
|
|
|
|
|
intrusive_ptr_add_ref ( & stack.push(startPoint) );
|
|
|
|
|
|
intrusive_ptr_add_ref ( & stack.push(startPoint) );
|
|
|
|
|
|
intrusive_ptr_add_ref ( & stack.push(startPoint) );
|
|
|
|
|
|
intrusive_ptr_add_ref ( & stack.push(startPoint) );
|
|
|
|
|
|
intrusive_ptr_add_ref ( & stack.push(startPoint) );
|
|
|
|
|
|
intrusive_ptr_add_ref ( & stack.push(startPoint) );
|
|
|
|
|
|
intrusive_ptr_add_ref ( & stack.push(startPoint) );
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (10 == stack.size());
|
2009-11-22 07:26:51 +01:00
|
|
|
|
stack.pop_unused();
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (10 == stack.size());
|
|
|
|
|
|
CHECK (1 == stack.top().ref_count());
|
2009-11-22 07:26:51 +01:00
|
|
|
|
|
|
|
|
|
|
stack.clear();
|
2010-12-10 02:55:40 +01:00
|
|
|
|
CHECK (1 == stack.size());
|
|
|
|
|
|
CHECK (!stack.top().empty());
|
|
|
|
|
|
CHECK (stack.top().getLeaf().isRoot());
|
|
|
|
|
|
CHECK (0 == stack.top().ref_count());
|
2009-11-22 07:26:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
|
LAUNCHER (QueryFocusStack_test, "unit session");
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-16 02:04:47 +01:00
|
|
|
|
}}}}// namespace steam::mobject::session::test
|