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:
parent
0a43584c5c
commit
96d06929ea
|
@ -99,23 +99,24 @@ void TestLineChainEqualCPolyLine(SHAPE_LINE_CHAIN& lineChain, CPolyLine& polyLin
|
||||||
BOOST_AUTO_TEST_CASE( Chamfer )
|
BOOST_AUTO_TEST_CASE( Chamfer )
|
||||||
{
|
{
|
||||||
SHAPE_POLY_SET::POLYGON actual;
|
SHAPE_POLY_SET::POLYGON actual;
|
||||||
CPolyLine expected;
|
|
||||||
|
|
||||||
// Test different distances, up to the half of the minimum segment longitude
|
// 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.
|
// Chamfered polygon to be tested.
|
||||||
actual = common.holeyPolySet.ChamferPolygon( distance, 0 );
|
actual = common.holeyPolySet.ChamferPolygon( distance, 0 );
|
||||||
|
|
||||||
// Chamfered polygon assumed to be right.
|
// 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.
|
// Double check that there are no repeated corners in the legacy shape.
|
||||||
expected.RemoveNullSegments();
|
expected->RemoveNullSegments();
|
||||||
|
|
||||||
// Test equality
|
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue