QueryFocusStack_test pass

This commit is contained in:
Fischlurch 2010-10-09 06:18:40 +02:00
parent 46597009f9
commit 64f017da43
6 changed files with 91 additions and 32 deletions

View file

@ -112,6 +112,7 @@ namespace session {
QueryFocusStack::clear ()
{
paths_.clear();
openDefaultFrame();
}

View file

@ -159,6 +159,7 @@ namespace session {
/* == state diagnostics == */
bool isValid() const;
bool empty() const;
bool isRoot() const;
size_t size() const;
size_t length() const;
size_t ref_count()const;
@ -267,6 +268,17 @@ namespace session {
return path_.empty();
}
inline bool
ScopePath::isRoot() const
{
return (1 == size())
#if NOBUG_MODE_ALPHA
&& path_[0].isRoot()
#endif
;
}
/** @note actually this is an Lumiera Forward Iterator,
* yielding the path up to root as a sequence of

View file

@ -193,7 +193,8 @@ PLANNED "Query focus management" QueryFocus_test <<END
END
PLANNED "Query focus stack" QueryFocusStack_test <<END
TEST "Query focus stack" QueryFocusStack_test <<END
return: 0
END

View file

@ -25,6 +25,7 @@
#include "lib/test/test-helper.hpp"
#include "proc/mobject/session/test-scopes.hpp"
#include "proc/mobject/session/query-focus-stack.hpp"
#include "proc/mobject/session/test-scope-invalid.hpp"
#include "lib/util.hpp"
@ -46,6 +47,9 @@ namespace test {
* 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.
* @note this test executes a lot of functionality in a manual by-hand way,
* which in the actual application is accessed and utilised through
* QueryFocus objects as frontend.
*
* @see mobject::session::QueryFocusStack
* @see mobject::session::ScopePath
@ -56,7 +60,8 @@ namespace test {
virtual void
run (Arg)
{
// Prepare an (test)Index backing the PlacementRefs
// Prepare an (test)Index and
// set up dummy session contents
PPIdx index = build_testScopes();
createStack();
@ -74,7 +79,7 @@ namespace test {
ASSERT (!isnil (stack));
ASSERT (!isnil (stack.top()));
ASSERT (stack.top().getLeaf().isRoot());
ASSERT (stack.top().isRoot());
}
@ -106,7 +111,7 @@ namespace test {
// can use/navigate the stack top frame
stack.top().goRoot();
ASSERT (isnil (stack.top())); // now indeed at root == empty path
ASSERT (!stack.top()); // now indeed at root == no path
ASSERT (secondFrame.getLeaf().isRoot());
ASSERT (secondFrame == stack.top());
@ -155,7 +160,7 @@ namespace test {
ScopePath& anotherFrame = stack.push(startPoint);
ASSERT (0 == anotherFrame.ref_count());
ASSERT (1 == firstFrame.ref_count());
intrusive_ptr_release (&anotherFrame);
intrusive_ptr_release (&firstFrame);
ASSERT (0 == firstFrame.ref_count());
ASSERT (firstFrame.getLeaf() == startPoint);
@ -188,16 +193,16 @@ namespace test {
intrusive_ptr_add_ref (&firstFrame);
ScopePath beforeInvalidNavigation = firstFrame;
Scope unrelatedScope (TestPlacement<> (*new DummyMO));
Scope const& unrelatedScope = fabricate_invalidScope();
// try to navigate to an invalid place
VERIFY_ERROR (INVALID, stack.top().navigate (unrelatedScope) );
VERIFY_ERROR (INVALID_SCOPE, stack.top().navigate (unrelatedScope) );
ASSERT (1 == stack.size());
ASSERT (1 == firstFrame.ref_count());
ASSERT (stack.top().getLeaf() == startPoint);
// try to push an invalid place
VERIFY_ERROR (INVALID, stack.push (unrelatedScope) );
VERIFY_ERROR (INVALID_SCOPE, stack.push (unrelatedScope) );
ASSERT (1 == stack.size());
ASSERT (1 == firstFrame.ref_count());
ASSERT (stack.top().getLeaf() == startPoint);

View file

@ -26,6 +26,7 @@
#include "proc/mobject/session/test-scopes.hpp"
#include "proc/mobject/session/placement-index.hpp"
#include "proc/mobject/session/scope-path.hpp"
#include "proc/mobject/session/test-scope-invalid.hpp"
#include "lib/util.hpp"
@ -41,30 +42,6 @@ namespace test {
using lumiera::error::LUMIERA_ERROR_INVALID;
namespace { // subversive test helper...
Scope const&
fabricate_invalidScope()
{ /**
* assumed to have identical memory layout
* to a Scope object, as the latter is implemented
* by a PlacementRef, which in turn is just an
* encapsulated Placement-ID
*/
struct Ambush
{
/** random ID assumed to be
* nowhere in the model */
PlacementMO::ID derailed_;
};
static Ambush _kinky_;
return *reinterpret_cast<Scope*> (&_kinky_);
}
}
/***************************************************************************

View file

@ -0,0 +1,63 @@
/*
TEST-SCOPE-INVALID.hpp - helper for placement scope and scope stack tests
Copyright (C) Lumiera.org
2010, 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.
*/
#ifndef MOBJECT_SESSION_TEST_SCOPE_INVALID_H
#define MOBJECT_SESSION_TEST_SCOPE_INVALID_H
#include "proc/mobject/placement.hpp"
#include "proc/mobject/session/scope.hpp"
namespace mobject {
namespace session {
namespace test {
namespace { // nifty subversive test helper...
Scope const&
fabricate_invalidScope()
{ /**
* assumed to have identical memory layout
* to a Scope object, as the latter is implemented
* by a PlacementRef, which in turn is just an
* encapsulated Placement-ID
*/
struct Ambush
{
/** random ID assumed to be
* nowhere in the model */
PlacementMO::ID derailed_;
};
static Ambush _kinky_;
return *reinterpret_cast<Scope*> (&_kinky_);
}
}
}}} // namespace mobject::session::test
#endif