Commit 27714977 authored by Robert Maynard's avatar Robert Maynard Committed by Kitware Robot

Merge topic 'handle_dynamic_cellset_gracefully'

1b62901e Empty DynamicCellSet doesn't segfault on certain queries.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Kenneth Moreland's avatarKenneth Moreland <kmorel@sandia.gov>
Merge-request: !1675
parents 4674af74 1b62901e
......@@ -161,7 +161,10 @@ public:
DynamicCellSetBase<CellSetList> NewInstance() const
{
DynamicCellSetBase<CellSetList> newCellSet;
newCellSet.CellSet = this->CellSet->NewInstance();
if (this->CellSet)
{
newCellSet.CellSet = this->CellSet->NewInstance();
}
return newCellSet;
}
......@@ -172,22 +175,44 @@ public:
const vtkm::cont::CellSet* GetCellSetBase() const { return this->CellSet.get(); }
VTKM_CONT
std::string GetName() const { return this->CellSet->GetName(); }
std::string GetName() const { return this->CellSet ? this->CellSet->GetName() : std::string{}; }
VTKM_CONT
vtkm::Id GetNumberOfCells() const { return this->CellSet->GetNumberOfCells(); }
vtkm::Id GetNumberOfCells() const
{
return this->CellSet ? this->CellSet->GetNumberOfCells() : 0;
}
VTKM_CONT
vtkm::Id GetNumberOfFaces() const { return this->CellSet->GetNumberOfFaces(); }
vtkm::Id GetNumberOfFaces() const
{
return this->CellSet ? this->CellSet->GetNumberOfFaces() : 0;
}
VTKM_CONT
vtkm::Id GetNumberOfEdges() const { return this->CellSet->GetNumberOfEdges(); }
vtkm::Id GetNumberOfEdges() const
{
return this->CellSet ? this->CellSet->GetNumberOfEdges() : 0;
}
VTKM_CONT
vtkm::Id GetNumberOfPoints() const { return this->CellSet->GetNumberOfPoints(); }
vtkm::Id GetNumberOfPoints() const
{
return this->CellSet ? this->CellSet->GetNumberOfPoints() : 0;
}
VTKM_CONT
void PrintSummary(std::ostream& stream) const { return this->CellSet->PrintSummary(stream); }
void PrintSummary(std::ostream& stream) const
{
if (this->CellSet)
{
this->CellSet->PrintSummary(stream);
}
else
{
stream << " DynamicCellSet = nullptr" << std::endl;
}
}
private:
std::shared_ptr<vtkm::cont::CellSet> CellSet;
......
......@@ -41,6 +41,43 @@ class DummyCellSet : public vtkm::cont::CellSet
{
};
void CheckEmptyDynamicCellSet()
{
vtkm::cont::DynamicCellSet empty;
VTKM_TEST_ASSERT(empty.GetName() == std::string{}, "DynamicCellSet should have no name");
VTKM_TEST_ASSERT(empty.GetNumberOfCells() == 0, "DynamicCellSet should have no cells");
VTKM_TEST_ASSERT(empty.GetNumberOfFaces() == 0, "DynamicCellSet should have no faces");
VTKM_TEST_ASSERT(empty.GetNumberOfEdges() == 0, "DynamicCellSet should have no edges");
VTKM_TEST_ASSERT(empty.GetNumberOfPoints() == 0, "DynamicCellSet should have no points");
empty.PrintSummary(std::cout);
using CellSet2D = vtkm::cont::CellSetStructured<2>;
using CellSet3D = vtkm::cont::CellSetStructured<3>;
VTKM_TEST_ASSERT(!empty.template IsType<CellSet2D>(), "DynamicCellSet reports wrong type.");
VTKM_TEST_ASSERT(!empty.template IsType<CellSet3D>(), "DynamicCellSet reports wrong type.");
VTKM_TEST_ASSERT(!empty.template IsType<DummyCellSet>(), "DynamicCellSet reports wrong type.");
CellSet2D instance;
VTKM_TEST_ASSERT(!empty.IsSameType(instance), "DynamicCellSet reports wrong type.");
bool gotException = false;
try
{
instance = empty.Cast<CellSet2D>();
}
catch (vtkm::cont::ErrorBadType&)
{
gotException = true;
}
VTKM_TEST_ASSERT(gotException, "Empty DynamicCellSet should have thrown on casting");
auto empty2 = empty.NewInstance();
VTKM_TEST_ASSERT(empty.GetCellSetBase() == nullptr, "DynamicCellSet should contain a nullptr");
VTKM_TEST_ASSERT(empty2.GetCellSetBase() == nullptr, "DynamicCellSet should contain a nullptr");
}
template <typename CellSetType, typename CellSetList>
void CheckDynamicCellSet(const CellSetType& cellSet,
vtkm::cont::DynamicCellSetBase<CellSetList> dynamicCellSet)
......@@ -119,6 +156,9 @@ void TestDynamicCellSet()
std::cout << "*** Explicit Grid Constant Shape ********" << std::endl;
TryNonDefaultCellSet(
vtkm::cont::CellSetExplicit<vtkm::cont::ArrayHandleConstant<vtkm::UInt8>::StorageTag>());
std::cout << std::endl << "Try empty DynamicCellSet." << std::endl;
CheckEmptyDynamicCellSet();
}
} // anonymous namespace
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment