From b0efaac80d1d3a5c57eda9f056afa7273846f301 Mon Sep 17 00:00:00 2001 From: Don Boogert Date: Wed, 7 Feb 2018 15:34:27 -0800 Subject: [PATCH] PathMatcher Test : Demonstrate potential issue with find & Iterators. --- test/IECore/IECoreTest.cpp | 2 + test/IECore/PathMatcherTest.cpp | 85 +++++++++++++++++++++++++++++++++ test/IECore/PathMatcherTest.h | 53 ++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 test/IECore/PathMatcherTest.cpp create mode 100644 test/IECore/PathMatcherTest.h diff --git a/test/IECore/IECoreTest.cpp b/test/IECore/IECoreTest.cpp index 65da377621..5539b8a63b 100644 --- a/test/IECore/IECoreTest.cpp +++ b/test/IECore/IECoreTest.cpp @@ -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; @@ -99,6 +100,7 @@ bool init() addCompoundDataTest(test); addCompoundObjectTest(test); addComputationCacheTest(test); + addPathMatcherTest(test); } catch (std::exception &ex) { diff --git a/test/IECore/PathMatcherTest.cpp b/test/IECore/PathMatcherTest.cpp new file mode 100644 index 0000000000..11fa2697c9 --- /dev/null +++ b/test/IECore/PathMatcherTest.cpp @@ -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 +#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 instance( new PathMatcherTest() ); + add( BOOST_CLASS_TEST_CASE( &PathMatcherTest::testPathMatcherIterator, instance ) ); + } +}; + +void addPathMatcherTest(boost::unit_test::test_suite* test) +{ + test->add( new PathMatcherTestSuite() ); +} + +} // IECore \ No newline at end of file diff --git a/test/IECore/PathMatcherTest.h b/test/IECore/PathMatcherTest.h new file mode 100644 index 0000000000..5f5a1e15d4 --- /dev/null +++ b/test/IECore/PathMatcherTest.h @@ -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 +