Skip to content

Commit

Permalink
FrameSet::isValid() should also return false for 0-length ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfx committed Oct 11, 2016
1 parent f8c167e commit 1ea6b6c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cpp-port/frameset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,15 @@ void FrameSet::handleMatch(const internal::RangePatternMatch* match, Status* ok)
}

bool FrameSet::isValid() const {
return m_frameData != NULL;
if ( m_frameData == NULL ) {
return false;
}

if ( m_frameData->ranges.length() == 0 ) {
return false;
}

return true;
}

std::string FrameSet::string() const {
Expand Down
32 changes: 32 additions & 0 deletions cpp-port/test/TestFrameSet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ TEST_F( TestFrameSetRanges, NewFrameSet ) {
ASSERT_TRUE(stat)
<< "#" << i << ": Failed to parse " << t.range << " : " << stat;

ASSERT_TRUE(s.isValid())
<< "#" << i << ": Expected valid FrameSet for '" << t.range << "'";

EXPECT_NE("", s.frameRange())
<< "#" << i << ": Got an empty frange field on FrameSet";

Expand All @@ -97,6 +100,35 @@ TEST_F( TestFrameSetRanges, NewFrameSet ) {
}
};

TEST( TestFrameSet, Invalid ) {
std::vector<TestFrameSetRanges::Case> cases;
fileseq::Frames empty;

{
TestFrameSetRanges::Case t = {"", empty};
cases.push_back(t);
}
{
TestFrameSetRanges::Case t = {"abc", empty};
cases.push_back(t);
}
{
TestFrameSetRanges::Case t = {"1-abc", empty};
cases.push_back(t);
}
{
TestFrameSetRanges::Case t = {" ", empty};
cases.push_back(t);
}

for (size_t i=0; i < cases.size(); ++i) {
TestFrameSetRanges::Case t = cases[i];

fileseq::FrameSet s(t.range);
EXPECT_FALSE(s.isValid())
<< "#" << i << ": Expected invalid FrameSet for '" << t.range << "'";
}
}

TEST_F( TestFrameSetRanges, Lookup ) {
fileseq::Status stat;
Expand Down

0 comments on commit 1ea6b6c

Please sign in to comment.