Skip to content

Commit c0cc6e4

Browse files
committed
BUG: Safely return INVALID in GetAsString
Address warning related to unused value of the map::find operations. Add more tests related to INVALID DICOMOrientation value.
1 parent c8c4243 commit c0cc6e4

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/itkDICOMOrientation.cxx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ DICOMOrientation::DICOMOrientation(std::string str)
5454
const std::string &
5555
DICOMOrientation::GetAsString() const
5656
{
57-
auto iter = GetCodeToString().find(m_Value);
58-
if (iter != GetCodeToString().end())
59-
{
60-
GetCodeToString().find(OrientationEnum::INVALID);
61-
}
62-
return iter->second;
57+
const auto & codeToString = GetCodeToString();
58+
auto iter = codeToString.find(m_Value);
59+
if (iter != codeToString.end())
60+
{
61+
return iter->second;
62+
}
63+
assert( codeToString.find(OrientationEnum::INVALID) != codeToString.end());
64+
return codeToString.find(OrientationEnum::INVALID)->second;
6365
}
6466

6567

test/itkDICOMOrientImageFilterGTest.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,13 @@ TEST(DICOMOrientation, ConstructionAndValues)
385385
EXPECT_EQ(OE::PIR, do2.GetAsOrientation());
386386

387387
EXPECT_EQ(d, do2.GetAsDirection());
388+
389+
DICOMOrientation do3("something invalid");
390+
EXPECT_EQ("INVALID", do3.GetAsString());
391+
EXPECT_EQ(CE::UNKNOWN, do3.GetPrimaryTerm());
392+
EXPECT_EQ(CE::UNKNOWN, do3.GetSecondaryTerm());
393+
EXPECT_EQ(CE::UNKNOWN, do3.GetTertiaryTerm());
394+
EXPECT_EQ(OE::INVALID, do3.GetAsOrientation());
388395
}
389396

390397

0 commit comments

Comments
 (0)