add diagnostic self display to ScopePath

This commit is contained in:
Fischlurch 2010-10-15 04:33:10 +02:00
parent e48a9fb811
commit c772359440
4 changed files with 43 additions and 8 deletions

View file

@ -39,6 +39,7 @@ namespace session {
using std::reverse;
using lib::append_all;
using util::isSameObject;
using util::isnil;
using namespace lumiera;
@ -141,6 +142,26 @@ namespace session {
const ScopePath ScopePath::INVALID = ScopePath(Scope());
/** ScopePath diagnostic self display.
* Implemented similar to a filesystem path, where the
* path elements are based on the self-display of the MObject
* attached through the respective scope top placement. */
ScopePath::operator string() const
{
if (isnil (path_)) return "!";
if (1 == length()) return "/";
string res;
vector<Scope>::const_iterator node (path_.begin());
while (++node != path_.end())
{
res += "/";
res += string (*node);
}
return res;
}
/** a \em valid path consists of more than just the root element.
* @note contrary to this, an \em empty path doesn't even contain a root element
*/

View file

@ -93,6 +93,7 @@
#include "lib/error.hpp"
#include <vector>
#include <string>
namespace lib {
@ -163,7 +164,7 @@ namespace session {
size_t size() const;
size_t length() const;
size_t ref_count()const;
////////////////////////////////////////TICKET #429 : diagnostic output to be added later
operator string() const;
/// Iteration is always ascending from leaf to root
typedef _IterType iterator;

View file

@ -190,6 +190,12 @@ END
TEST "Path of nested scopes" ScopePath_test <<END
out: Step\(1\): /\[DummyMO\.[0-9]{3}\]/\[DummyMO\.[0-9]{3}\]
out: Step\(2\): /\[DummyMO\.[0-9]{3}\]
out: Step\(3\): /
out: Step\(4\): /\[DummyMO\.[0-9]{3}\]
out: Step\(5\): /\[DummyMO\.[0-9]{3}\]/\[DummyMO\.[0-9]{3}\]
out: Step\(6\): /\[DummyMO\.[0-9]{3}\]
return: 0
END

View file

@ -29,12 +29,17 @@
#include "proc/mobject/session/test-scope-invalid.hpp"
#include "lib/util.hpp"
#include <iostream>
#include <string>
namespace mobject {
namespace session {
namespace test {
using std::cout;
using std::endl;
using std::string;
using util::isnil;
using util::isSameObject;
@ -75,7 +80,6 @@ namespace test {
check_RefcountProtection (startPlacement);
navigate (testPath, index);
clear (testPath, index);
////////////////////////////////////////TICKET #429 : verify diagnostic output (to be added later)
}
@ -183,6 +187,7 @@ namespace test {
ASSERT (refPath);
ASSERT (!ScopePath::INVALID);
ASSERT (isnil (ScopePath::INVALID));
ASSERT ("!" == string(ScopePath::INVALID));
ScopePath invalidP (ScopePath::INVALID);
ASSERT (isnil (invalidP));
@ -304,11 +309,13 @@ namespace test {
void
navigate (const ScopePath refPath, PPIdx index)
{
ScopePath path (refPath);
#define __SHOWPATH(N) cout << "Step("<<N<<"): "<< string(path) << endl;
ScopePath path (refPath); __SHOWPATH(1)
ASSERT (path == refPath);
Scope leaf = path.getLeaf();
Scope parent = path.moveUp();
Scope parent = path.moveUp(); __SHOWPATH(2)
ASSERT (path != refPath);
ASSERT (refPath.contains (path));
ASSERT (refPath.endsAt (leaf));
@ -316,14 +323,14 @@ namespace test {
ASSERT (parent == leaf.getParent());
ASSERT (parent == path.getLeaf());
Scope root = path.goRoot();
Scope root = path.goRoot(); __SHOWPATH(3)
ASSERT (path != refPath);
ASSERT (path.endsAt (root));
ASSERT (refPath.contains (path));
ASSERT (!path.endsAt (parent));
ASSERT (!path.endsAt (leaf));
path.navigate (parent);
path.navigate (parent); __SHOWPATH(4)
ASSERT (path.endsAt (parent));
ASSERT (!path.endsAt (root));
ASSERT (!path.endsAt (leaf));
@ -333,7 +340,7 @@ namespace test {
Scope newLocation =
index->find( // place newNode as sibling of "leaf"
index->insert (newNode, parentRefPoint));
path.navigate (newLocation);
path.navigate (newLocation); __SHOWPATH(5)
Scope sibling = path.getLeaf();
ASSERT (sibling == newLocation);
ASSERT (parent == sibling.getParent());
@ -350,7 +357,7 @@ namespace test {
ASSERT (prefix.endsAt (parent));
ASSERT (!prefix.contains (leaf));
ASSERT (!prefix.contains (sibling));
path.navigate (prefix.getLeaf());
path.navigate (prefix.getLeaf()); __SHOWPATH(6)
ASSERT (path == prefix);
// try to navigate to an unconnected location...