vtk-m2/vtkm/cont/testing/UnitTestArrayContainerControlImplicit.cxx

158 lines
4.1 KiB
C++
Raw Normal View History

//============================================================================
// 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 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014. 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.
//============================================================================
#define VTKM_ARRAY_CONTAINER_CONTROL VTKM_ARRAY_CONTAINER_CONTROL_ERROR
#include <vtkm/Types.h>
#include <vtkm/cont/ArrayContainerControlImplicit.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/internal/IteratorFromArrayPortal.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/VectorTraits.h>
namespace
{
template <typename T>
struct TestImplicitContainer
{
typedef T ValueType;
ValueType Temp;
typedef vtkm::cont::internal::IteratorFromArrayPortal<
TestImplicitContainer<T> > IteratorType;
VTKM_EXEC_CONT_EXPORT
TestImplicitContainer(): Temp(1) { }
VTKM_EXEC_CONT_EXPORT
vtkm::Id GetNumberOfValues() const
{
return 1;
}
VTKM_EXEC_CONT_EXPORT
ValueType Get(vtkm::Id vtkmNotUsed(index)) const
{
return Temp;
}
VTKM_CONT_EXPORT
IteratorType GetIteratorBegin() const {
return IteratorType(*this);
}
VTKM_CONT_EXPORT
IteratorType GetIteratorEnd() const {
return IteratorType(*this, this->GetNumberOfValues());
}
};
const vtkm::Id ARRAY_SIZE = 1;
template <typename T>
struct TemplatedTests
{
typedef vtkm::cont::ArrayContainerControlTagImplicit<
TestImplicitContainer<T> > ContainerTagType;
typedef vtkm::cont::internal::ArrayContainerControl<
T, ContainerTagType > ArrayContainerType;
typedef typename ArrayContainerType::ValueType ValueType;
typedef typename ArrayContainerType::PortalType PortalType;
typedef typename PortalType::IteratorType IteratorType;
void BasicAllocation()
{
ArrayContainerType arrayContainer;
try{ arrayContainer.GetNumberOfValues();
VTKM_TEST_ASSERT(false == true,
"Implicit Container GetNumberOfValues method didn't throw error.");
}
catch(vtkm::cont::ErrorControlBadValue e){}
try{ arrayContainer.Allocate(ARRAY_SIZE);
VTKM_TEST_ASSERT(false == true,
"Implicit Container Allocate method didn't throw error.");
}
catch(vtkm::cont::ErrorControlBadValue e){}
try
{
arrayContainer.Shrink(ARRAY_SIZE);
VTKM_TEST_ASSERT(true==false,
"Array shrink do a larger size was possible. This can't be allowed.");
}
catch(vtkm::cont::ErrorControlBadValue){}
try
{
arrayContainer.ReleaseResources();
VTKM_TEST_ASSERT(true==false,
"Can't Release an implicit array");
}
catch(vtkm::cont::ErrorControlBadValue){}
}
void BasicAccess()
{
TestImplicitContainer<T> portal;
vtkm::cont::ArrayHandle<T,ContainerTagType> implictHandle(portal);
VTKM_TEST_ASSERT(implictHandle.GetNumberOfValues() == 1,
"handle should have size 1");
VTKM_TEST_ASSERT(implictHandle.GetPortalConstControl().Get(0) == T(1),
"portals first values should be 1");
;
}
void operator()()
{
BasicAllocation();
BasicAccess();
}
};
struct TestFunctor
{
template <typename T>
void operator()(T)
{
TemplatedTests<T> tests;
tests();
}
};
void TestArrayContainerControlBasic()
{
vtkm::testing::Testing::TryAllTypes(TestFunctor());
}
} // Anonymous namespace
int UnitTestArrayContainerControlImplicit(int, char *[])
{
return vtkm::cont::testing::Testing::Run(TestArrayContainerControlBasic);
}