QA: Fix ownership of new CPolyline in qa_shape_poly_set_refactor

CPolyLine::Chamfer returns a newly allocated object. The current
test of this doesn't take ownership, leading to memory leaks.

Use a std::unique_ptr to:

* Fix the leak, and
* Document the expected semantics of the interface in the test

Fixes coverity:183869
This commit is contained in:
John Beard 2018-09-28 17:59:42 +01:00 committed by Wayne Stambaugh
parent 0a43584c5c
commit 96d06929ea
1 changed files with 7 additions and 6 deletions

View File

@ -99,23 +99,24 @@ void TestLineChainEqualCPolyLine(SHAPE_LINE_CHAIN& lineChain, CPolyLine& polyLin
BOOST_AUTO_TEST_CASE( Chamfer )
{
SHAPE_POLY_SET::POLYGON actual;
CPolyLine expected;
// Test different distances, up to the half of the minimum segment longitude
for (int distance = 0; distance < 5; distance++) {
for( int distance = 0; distance < 5; distance++ )
{
// Chamfered polygon to be tested.
actual = common.holeyPolySet.ChamferPolygon( distance, 0 );
// Chamfered polygon assumed to be right.
expected = *legacyPolyLine.Chamfer( distance );
// CPolyline::Chamfer returns new CPolyline - take ownership
std::unique_ptr<CPolyLine> expected( legacyPolyLine.Chamfer( distance ) );
// Double check that there are no repeated corners in the legacy shape.
expected.RemoveNullSegments();
expected->RemoveNullSegments();
// Test equality
for (size_t contourIdx = 0; contourIdx < actual.size(); contourIdx++)
for( size_t contourIdx = 0; contourIdx < actual.size(); contourIdx++ )
{
TestLineChainEqualCPolyLine(actual[contourIdx], expected, contourIdx);
TestLineChainEqualCPolyLine(actual[contourIdx], *expected, contourIdx);
}
}
}