Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PathMatcher Test : Demonstrate potential issue with find & Iterators. #728

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/IECore/IECoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ IECORE_POP_DEFAULT_VISIBILITY
#include "CompoundDataTest.h"
#include "CompoundObjectTest.h"
#include "ComputationCacheTest.h"
#include "PathMatcherTest.h"

using namespace boost::unit_test;

Expand Down Expand Up @@ -99,6 +100,7 @@ bool init()
addCompoundDataTest(test);
addCompoundObjectTest(test);
addComputationCacheTest(test);
addPathMatcherTest(test);
}
catch (std::exception &ex)
{
Expand Down
85 changes: 85 additions & 0 deletions test/IECore/PathMatcherTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2018, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of Image Engine Design nor the names of any
// other contributors to this software may be used to endorse or
// promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////


#include <IECoreScene/SceneInterface.h>
#include "PathMatcherTest.h"

#include "IECoreScene/SceneInterface.h"

#include "IECore/PathMatcher.h"

namespace IECore
{

struct PathMatcherTest
{
void testPathMatcherIterator()
{
IECore::PathMatcher pathMatcher;

pathMatcher.addPath("/a/b/c");
pathMatcher.addPath("/a/b/c/d/e/f");
pathMatcher.addPath("/a/b/c/d/g/h");

BOOST_CHECK( pathMatcher.find({ IECore::InternedString( "a" ) } ) != pathMatcher.end() );
BOOST_CHECK( pathMatcher.find({ IECore::InternedString( "a" ), IECore::InternedString( "b" ) } ) != pathMatcher.end() );
BOOST_CHECK( pathMatcher.find({ IECore::InternedString( "a" ), IECore::InternedString( "b" ), IECore::InternedString( "c" ) } ) != pathMatcher.end() );

IECore::PathMatcher::RawIterator x = pathMatcher.find( { IECore::InternedString( "a" ), IECore::InternedString( "b" ), IECore::InternedString( "c" ), IECore::InternedString( "d" ) } );

// Finds the next terminal node
IECore::PathMatcher::Iterator y = IECore::PathMatcher::Iterator( x );

// This check to see if the path we're querying has been explicitly added.
BOOST_CHECK( y != x);
}
};

struct PathMatcherTestSuite : public boost::unit_test::test_suite
{

PathMatcherTestSuite() : boost::unit_test::test_suite( "PathMatcherTestSuite" )
{
boost::shared_ptr<PathMatcherTest> instance( new PathMatcherTest() );
add( BOOST_CLASS_TEST_CASE( &PathMatcherTest::testPathMatcherIterator, instance ) );
}
};

void addPathMatcherTest(boost::unit_test::test_suite* test)
{
test->add( new PathMatcherTestSuite() );
}

} // IECore
53 changes: 53 additions & 0 deletions test/IECore/PathMatcherTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2018, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of Image Engine Design nor the names of any
// other contributors to this software may be used to endorse or
// promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

#ifndef IECORE_PATHMATCHERTEST_H
#define IECORE_PATHMATCHERTEST_H

#include "IECore/Export.h"

IECORE_PUSH_DEFAULT_VISIBILITY
#include "boost/test/unit_test.hpp"
IECORE_POP_DEFAULT_VISIBILITY

namespace IECore
{

void addPathMatcherTest( boost::unit_test::test_suite *test );

}


#endif // IECORE_PATHMATCHERTEST_H