2014-02-10 19:53:03 +00:00
|
|
|
//============================================================================
|
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
|
2014-06-23 23:33:04 +00:00
|
|
|
#define VTKM_STORAGE VTKM_STORAGE_ERROR
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
#include <vtkm/Types.h>
|
2014-10-07 23:27:31 +00:00
|
|
|
#include <vtkm/VecTraits.h>
|
2014-06-23 23:33:04 +00:00
|
|
|
|
2014-02-10 19:53:03 +00:00
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
2014-06-23 23:33:04 +00:00
|
|
|
#include <vtkm/cont/StorageImplicit.h>
|
|
|
|
|
2014-02-10 19:53:03 +00:00
|
|
|
#include <vtkm/cont/internal/IteratorFromArrayPortal.h>
|
|
|
|
|
2014-06-23 23:33:04 +00:00
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
2014-02-10 19:53:03 +00:00
|
|
|
|
2014-02-11 21:20:30 +00:00
|
|
|
namespace {
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2014-06-23 23:33:04 +00:00
|
|
|
struct TestImplicitStorage
|
2014-02-10 19:53:03 +00:00
|
|
|
{
|
|
|
|
typedef T ValueType;
|
|
|
|
ValueType Temp;
|
|
|
|
|
|
|
|
|
|
|
|
VTKM_EXEC_CONT_EXPORT
|
2014-06-23 23:33:04 +00:00
|
|
|
TestImplicitStorage(): Temp(1) { }
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
VTKM_EXEC_CONT_EXPORT
|
|
|
|
vtkm::Id GetNumberOfValues() const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_EXEC_CONT_EXPORT
|
|
|
|
ValueType Get(vtkm::Id vtkmNotUsed(index)) const
|
|
|
|
{
|
2014-02-11 21:20:30 +00:00
|
|
|
return Temp;
|
2014-02-10 19:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
const vtkm::Id ARRAY_SIZE = 1;
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct TemplatedTests
|
|
|
|
{
|
2014-06-23 23:33:04 +00:00
|
|
|
typedef vtkm::cont::StorageTagImplicit< TestImplicitStorage<T> >
|
|
|
|
StorageTagType;
|
|
|
|
typedef vtkm::cont::internal::Storage< T, StorageTagType > StorageType;
|
2014-02-10 19:53:03 +00:00
|
|
|
|
2014-06-23 23:33:04 +00:00
|
|
|
typedef typename StorageType::ValueType ValueType;
|
|
|
|
typedef typename StorageType::PortalType PortalType;
|
2014-02-10 19:53:03 +00:00
|
|
|
typedef typename PortalType::IteratorType IteratorType;
|
|
|
|
|
|
|
|
void BasicAllocation()
|
|
|
|
{
|
2014-06-23 23:33:04 +00:00
|
|
|
StorageType arrayStorage;
|
2014-02-10 19:53:03 +00:00
|
|
|
|
2014-02-11 21:20:30 +00:00
|
|
|
try
|
|
|
|
{
|
2014-06-23 23:33:04 +00:00
|
|
|
arrayStorage.GetNumberOfValues();
|
2014-02-10 19:53:03 +00:00
|
|
|
VTKM_TEST_ASSERT(false == true,
|
2014-06-23 23:33:04 +00:00
|
|
|
"Implicit Storage GetNumberOfValues method didn't throw error.");
|
2014-02-11 21:20:30 +00:00
|
|
|
}
|
|
|
|
catch(vtkm::cont::ErrorControlBadValue e) {}
|
2014-02-10 19:53:03 +00:00
|
|
|
|
2014-02-11 21:20:30 +00:00
|
|
|
try
|
|
|
|
{
|
2014-06-23 23:33:04 +00:00
|
|
|
arrayStorage.Allocate(ARRAY_SIZE);
|
2014-02-10 19:53:03 +00:00
|
|
|
VTKM_TEST_ASSERT(false == true,
|
2014-06-23 23:33:04 +00:00
|
|
|
"Implicit Storage Allocate method didn't throw error.");
|
2014-02-11 21:20:30 +00:00
|
|
|
}
|
|
|
|
catch(vtkm::cont::ErrorControlBadValue e) {}
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
try
|
2014-02-11 21:20:30 +00:00
|
|
|
{
|
2014-06-23 23:33:04 +00:00
|
|
|
arrayStorage.Shrink(ARRAY_SIZE);
|
2014-02-10 19:53:03 +00:00
|
|
|
VTKM_TEST_ASSERT(true==false,
|
2014-02-11 21:20:30 +00:00
|
|
|
"Array shrink do a larger size was possible. This can't be allowed.");
|
|
|
|
}
|
|
|
|
catch(vtkm::cont::ErrorControlBadValue) {}
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
try
|
2014-02-11 21:20:30 +00:00
|
|
|
{
|
2014-06-23 23:33:04 +00:00
|
|
|
arrayStorage.ReleaseResources();
|
2014-02-10 19:53:03 +00:00
|
|
|
VTKM_TEST_ASSERT(true==false,
|
2014-02-11 21:20:30 +00:00
|
|
|
"Can't Release an implicit array");
|
|
|
|
}
|
|
|
|
catch(vtkm::cont::ErrorControlBadValue) {}
|
2014-02-10 19:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BasicAccess()
|
2014-02-11 21:20:30 +00:00
|
|
|
{
|
2014-06-23 23:33:04 +00:00
|
|
|
TestImplicitStorage<T> portal;
|
|
|
|
vtkm::cont::ArrayHandle<T,StorageTagType> implictHandle(portal);
|
2014-02-10 19:53:03 +00:00
|
|
|
VTKM_TEST_ASSERT(implictHandle.GetNumberOfValues() == 1,
|
2014-02-11 21:20:30 +00:00
|
|
|
"handle should have size 1");
|
2014-02-10 19:53:03 +00:00
|
|
|
VTKM_TEST_ASSERT(implictHandle.GetPortalConstControl().Get(0) == T(1),
|
2014-02-11 21:20:30 +00:00
|
|
|
"portals first values should be 1");
|
2014-02-10 19:53:03 +00:00
|
|
|
;
|
2014-02-11 21:20:30 +00:00
|
|
|
}
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
void operator()()
|
|
|
|
{
|
|
|
|
BasicAllocation();
|
|
|
|
BasicAccess();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TestFunctor
|
|
|
|
{
|
|
|
|
template <typename T>
|
2014-10-08 22:56:33 +00:00
|
|
|
void operator()(T) const
|
2014-02-10 19:53:03 +00:00
|
|
|
{
|
|
|
|
TemplatedTests<T> tests;
|
|
|
|
tests();
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-23 23:33:04 +00:00
|
|
|
void TestStorageBasic()
|
2014-02-10 19:53:03 +00:00
|
|
|
{
|
|
|
|
vtkm::testing::Testing::TryAllTypes(TestFunctor());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // Anonymous namespace
|
|
|
|
|
2014-06-23 23:33:04 +00:00
|
|
|
int UnitTestStorageImplicit(int, char *[])
|
2014-02-10 19:53:03 +00:00
|
|
|
{
|
2014-06-23 23:33:04 +00:00
|
|
|
return vtkm::cont::testing::Testing::Run(TestStorageBasic);
|
2014-02-10 19:53:03 +00:00
|
|
|
}
|