Skip to content

Commit

Permalink
Merge pull request #1372 from ivanimanishi/blockNegativeSteps
Browse files Browse the repository at this point in the history
FrameRange : Prevent creation of FrameRanges with negative steps
  • Loading branch information
johnhaddon authored Jul 14, 2023
2 parents 225c6fa + 4c1438b commit 5fb3e51
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
10.4.x.x (relative to 10.4.10.0)
========

Fixes
-----

- FrameRange : Prevented creation of FrameRanges with negative steps

10.4.10.0 (relative to 10.4.9.1)
========

Expand Down
8 changes: 8 additions & 0 deletions src/IECore/FrameRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ FrameRange::FrameRange( Frame start, Frame end, Frame step ) : m_start( start ),
{
throw Exception( "FrameRange step cannot be zero" );
}
if ( step < 0 )
{
throw Exception( "FrameRange step cannot be negative. Consider using the reverse suffix instead." );
}
}

FrameRange::~FrameRange()
Expand Down Expand Up @@ -102,6 +106,10 @@ void FrameRange::setStep( Frame step )
{
throw Exception( "FrameRange step cannot be zero" );
}
if ( step < 0 )
{
throw Exception( "FrameRange step cannot be negative. Consider using the reverse suffix instead." );
}
m_step = step;
}

Expand Down
19 changes: 18 additions & 1 deletion test/IECore/FrameList.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,24 @@ def testReverseConstruction( self ) :
self.assertEqual( f.asList(), [ 5, 4, 3, 2, 1 ] )
self.assertEqual( IECore.frameListFromList( [ 5, 4, 3, 2, 1 ] ), f )

def testFrameRange( self ) :

f = IECore.FrameList.parse( "1-5" )
self.assertTrue( isinstance( f, IECore.FrameRange ) )
self.assertEqual( f.asList(), [ 1, 2, 3, 4, 5 ] )
# test step
f = IECore.FrameList.parse( "10-20x5" )
self.assertTrue( isinstance( f, IECore.FrameRange ) )
self.assertEqual( f.asList(), [ 10, 15, 20 ] )
# start must be smaller or equal to end
self.assertRaises( Exception, IECore.FrameList.parse, "5-1" )
# step must be positive
self.assertRaises( Exception, IECore.FrameList.parse, "1-5x0" )
self.assertRaises( Exception, IECore.FrameList.parse, "1-5x-1" )
self.assertRaises( Exception, IECore.FrameList.parse, "5-1x-1" )


## \todo: there should probably be a lot more tests in here...

if __name__ == "__main__":
unittest.main()
unittest.main()

0 comments on commit 5fb3e51

Please sign in to comment.