//============================================================================ // Copyright (c) Kitware, Inc. // All rights reserved. // See LICENSE.txt for details. // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. // // Copyright 2015 Sandia Corporation. // Copyright 2015 UT-Battelle, LLC. // Copyright 2015 Los Alamos National Security. // // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, // the U.S. Government retains certain rights in this software. // // Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National // Laboratory (LANL), the U.S. Government retains certain rights in // this software. //============================================================================ #include #include #include namespace { struct NonDefaultCellSetList : vtkm::ListTagBase< vtkm::cont::CellSetStructured<1>, vtkm::cont::CellSetExplicit::StorageTag > > { }; bool CheckCalled; template struct CheckFunctor { void operator()(const ExpectedCellType &) const { CheckCalled = true; } template void operator()(const UnexpectedType &) const { VTKM_TEST_FAIL("CastAndCall functor called with wrong type."); } }; template void CheckDynamicCellSet( const CellSetType &cellSet, vtkm::cont::DynamicCellSetBase dynamicCellSet) { VTKM_TEST_ASSERT(dynamicCellSet.IsType(cellSet), "DynamicCellSet reports wrong type."); VTKM_TEST_ASSERT(!dynamicCellSet.IsType(vtkm::Id()), "DynamicCellSet reports wrong type."); dynamicCellSet.CastTo(cellSet); CheckCalled = false; dynamicCellSet.CastAndCall(CheckFunctor()); VTKM_TEST_ASSERT(CheckCalled, "The functor was never called (and apparently a bad value exception not thrown)."); } template void TryNewInstance( CellSetType, vtkm::cont::DynamicCellSetBase &originalCellSet) { vtkm::cont::DynamicCellSetBase newCellSet = originalCellSet.NewInstance(); VTKM_TEST_ASSERT(newCellSet.IsType(CellSetType()), "New cell set wrong type."); VTKM_TEST_ASSERT(&originalCellSet.CastTo(CellSetType()) != &newCellSet.CastTo(CellSetType()), "NewInstance did not make a copy."); } template void TryCellSet(CellSetType cellSet, vtkm::cont::DynamicCellSetBase &dynamicCellSet) { CheckDynamicCellSet(cellSet, dynamicCellSet); CheckDynamicCellSet( cellSet, dynamicCellSet.ResetCellSetList(vtkm::ListTagBase())); TryNewInstance(cellSet, dynamicCellSet); } template void TryDefaultCellSet(CellSetType cellSet) { vtkm::cont::DynamicCellSet dynamicCellSet(cellSet); TryCellSet(cellSet, dynamicCellSet); } template void TryNonDefaultCellSet(CellSetType cellSet) { vtkm::cont::DynamicCellSetBase dynamicCellSet(cellSet); TryCellSet(cellSet, dynamicCellSet); } void TestDynamicCellSet() { std::cout << "Try default types with default type lists." << std::endl; std::cout << "*** 2D Structured Grid ******************" << std::endl; TryDefaultCellSet(vtkm::cont::CellSetStructured<2>()); std::cout << "*** 3D Structured Grid ******************" << std::endl; TryDefaultCellSet(vtkm::cont::CellSetStructured<3>()); std::cout << "*** Explicit Grid ***********************" << std::endl; TryDefaultCellSet(vtkm::cont::CellSetExplicit<>()); std::cout << std::endl << "Try non-default types." << std::endl; std::cout << "*** 1D Structured Grid ******************" << std::endl; TryNonDefaultCellSet(vtkm::cont::CellSetStructured<1>()); std::cout << "*** Explicit Grid Constant Shape ********" << std::endl; TryNonDefaultCellSet(vtkm::cont::CellSetExplicit< vtkm::cont::ArrayHandleConstant::StorageTag>()); } } // anonymous namespace int UnitTestDynamicCellSet(int, char *[]) { return vtkm::cont::testing::Testing::Run(TestDynamicCellSet); }