Skip to content

Commit

Permalink
DDLNode: add missing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
kimkulling committed Nov 16, 2016
1 parent f6ddd5a commit 26aa8b8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
11 changes: 5 additions & 6 deletions code/DDLNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ DDLNode::~DDLNode() {
if( s_allocatedNodes[ m_idx ] == this ) {
s_allocatedNodes[ m_idx ] = ddl_nullptr;
}
for(size_t i = 0 ; i<m_children.size();i++){
delete m_children[i];
for ( size_t i = 0; i<m_children.size(); i++ ){
delete m_children[ i ];
}
}

Expand All @@ -94,9 +94,8 @@ void DDLNode::attachParent( DDLNode *parent ) {
}

void DDLNode::detachParent() {
if( m_parent ) {
std::vector<DDLNode*>::iterator it;
it = std::find( m_parent->m_children.begin(), m_parent->m_children.end(), this );
if( ddl_nullptr != m_parent ) {
DDLNodeIt it = std::find( m_parent->m_children.begin(), m_parent->m_children.end(), this );
if( m_parent->m_children.end() != it ) {
m_parent->m_children.erase( it );
}
Expand Down Expand Up @@ -202,7 +201,7 @@ DDLNode *DDLNode::create( const std::string &type, const std::string &name, DDLN

void DDLNode::releaseNodes() {
if( s_allocatedNodes.size() > 0 ) {
for( DllNodeList::iterator it = s_allocatedNodes.begin(); it != s_allocatedNodes.end(); it++ ) {
for( DDLNodeIt it = s_allocatedNodes.begin(); it != s_allocatedNodes.end(); it++ ) {
if( *it ) {
delete *it;
}
Expand Down
3 changes: 3 additions & 0 deletions include/openddlparser/DDLNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class DLL_ODDLPARSER_EXPORT DDLNode {
/// @brief The child-node-list type.
typedef std::vector<DDLNode*> DllNodeList;

/// @brief The child-node-list iterator.
typedef std::vector<DDLNode*>::iterator DDLNodeIt;

public:
/// @brief The class destructor.
~DDLNode();
Expand Down
16 changes: 16 additions & 0 deletions test/DDLNodeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ TEST_F( DDLNodeTest, createDDLNodeTest ) {
delete myNode;
}

TEST_F( DDLNodeTest, attach_detach_parent_Test ) {
DDLNode *myParent = DDLNode::create( "parent", "" );
DDLNode *myChild = DDLNode::create( "child", "" );
EXPECT_EQ( nullptr, myParent->getParent() );
myChild->attachParent( myParent );
EXPECT_EQ( myParent, myChild->getParent() );

myChild->detachParent();
EXPECT_EQ( nullptr, myChild->getParent() );

// must not fail
myChild->detachParent();
myParent->detachParent();
myParent->attachParent( nullptr );
}

TEST_F( DDLNodeTest, accessTypeTest ) {
static const std::string type1 = "type";
static const std::string name1 = "test";
Expand Down

0 comments on commit 26aa8b8

Please sign in to comment.