2014-04-10 19:35:06 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2014-04-10 19:35:06 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
#include <vtkm/internal/FunctionInterface.h>
|
2019-04-17 17:59:49 +00:00
|
|
|
#include <vtkm/testing/Testing.h>
|
2014-04-10 19:35:06 +00:00
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace
|
|
|
|
{
|
2014-04-10 19:35:06 +00:00
|
|
|
|
2018-02-22 13:29:13 +00:00
|
|
|
using Type1 = vtkm::Id;
|
2014-04-10 19:35:06 +00:00
|
|
|
const Type1 Arg1 = 1234;
|
|
|
|
|
2018-02-22 13:29:13 +00:00
|
|
|
using Type2 = vtkm::Float64;
|
2014-04-10 19:35:06 +00:00
|
|
|
const Type2 Arg2 = 5678.125;
|
|
|
|
|
2018-02-22 13:29:13 +00:00
|
|
|
using Type3 = std::string;
|
2014-04-10 19:35:06 +00:00
|
|
|
const Type3 Arg3("Third argument");
|
|
|
|
|
2019-07-31 16:20:38 +00:00
|
|
|
using Type4 = vtkm::Vec3f_32;
|
2014-06-10 21:51:24 +00:00
|
|
|
const Type4 Arg4(1.2f, 3.4f, 5.6f);
|
2014-04-10 19:35:06 +00:00
|
|
|
|
2018-02-22 13:29:13 +00:00
|
|
|
using Type5 = vtkm::Id3;
|
2014-04-10 19:35:06 +00:00
|
|
|
const Type5 Arg5(4, 5, 6);
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
struct PointerTransform
|
|
|
|
{
|
|
|
|
template <typename T, vtkm::IdComponent Index>
|
|
|
|
struct ReturnType
|
|
|
|
{
|
2018-02-22 13:29:13 +00:00
|
|
|
using type = const T*;
|
2014-05-06 19:28:08 +00:00
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T, typename IndexTag>
|
|
|
|
const T* operator()(const T& x, IndexTag) const
|
|
|
|
{
|
2014-05-06 19:28:08 +00:00
|
|
|
return &x;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-10 19:35:06 +00:00
|
|
|
void TestBasicFunctionInterface()
|
|
|
|
{
|
2019-12-03 18:30:43 +00:00
|
|
|
using vtkm::internal::ParameterGet;
|
2014-04-10 19:35:06 +00:00
|
|
|
std::cout << "Creating basic function interface." << std::endl;
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::internal::FunctionInterface<void(Type1, Type2, Type3)> funcInterface =
|
|
|
|
vtkm::internal::make_FunctionInterface<void>(Arg1, Arg2, Arg3);
|
2014-04-10 19:35:06 +00:00
|
|
|
|
|
|
|
std::cout << "Checking parameters." << std::endl;
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(funcInterface.GetArity() == 3, "Got wrong number of parameters.");
|
2019-12-03 18:30:43 +00:00
|
|
|
VTKM_TEST_ASSERT(ParameterGet<1>(funcInterface) == Arg1, "Arg 1 incorrect.");
|
|
|
|
VTKM_TEST_ASSERT(ParameterGet<2>(funcInterface) == Arg2, "Arg 2 incorrect.");
|
|
|
|
VTKM_TEST_ASSERT(ParameterGet<3>(funcInterface) == Arg3, "Arg 3 incorrect.");
|
2014-04-10 19:35:06 +00:00
|
|
|
|
2019-12-03 18:30:43 +00:00
|
|
|
vtkm::internal::FunctionInterface<void(Type1, Type2, Type3)> funcInterfaceEmpty;
|
|
|
|
VTKM_TEST_ASSERT(funcInterfaceEmpty.GetArity() == 3, "Got wrong number of parameters.");
|
|
|
|
VTKM_TEST_ASSERT(ParameterGet<1>(funcInterfaceEmpty) != Arg1, "Arg 1 incorrect.");
|
|
|
|
VTKM_TEST_ASSERT(ParameterGet<2>(funcInterfaceEmpty) != Arg2, "Arg 2 incorrect.");
|
|
|
|
VTKM_TEST_ASSERT(ParameterGet<3>(funcInterfaceEmpty) != Arg3, "Arg 3 incorrect.");
|
|
|
|
|
|
|
|
auto funcInterface5 = vtkm::internal::make_FunctionInterface<void>(Arg1, Arg2, Arg3, Arg4, Arg5);
|
|
|
|
std::cout << "Checking 5 parameter function interface." << std::endl;
|
|
|
|
VTKM_TEST_ASSERT(funcInterface5.GetArity() == 5, "Got wrong number of parameters.");
|
|
|
|
VTKM_TEST_ASSERT(ParameterGet<1>(funcInterface5) == Arg1, "Arg 1 incorrect.");
|
|
|
|
VTKM_TEST_ASSERT(ParameterGet<2>(funcInterface5) == Arg2, "Arg 2 incorrect.");
|
|
|
|
VTKM_TEST_ASSERT(ParameterGet<3>(funcInterface5) == Arg3, "Arg 3 incorrect.");
|
|
|
|
VTKM_TEST_ASSERT(ParameterGet<4>(funcInterface5) == Arg4, "Arg 4 incorrect.");
|
|
|
|
VTKM_TEST_ASSERT(ParameterGet<5>(funcInterface5) == Arg5, "Arg 5 incorrect.");
|
2014-04-10 19:35:06 +00:00
|
|
|
}
|
|
|
|
|
2014-05-06 19:28:08 +00:00
|
|
|
void TestStaticTransform()
|
|
|
|
{
|
2019-12-03 18:30:43 +00:00
|
|
|
using vtkm::internal::ParameterGet;
|
2014-05-06 19:28:08 +00:00
|
|
|
std::cout << "Trying static transform." << std::endl;
|
2018-05-25 21:18:41 +00:00
|
|
|
using OriginalType = vtkm::internal::FunctionInterface<void(Type1, Type2, Type3)>;
|
2017-05-18 14:29:41 +00:00
|
|
|
OriginalType funcInterface = vtkm::internal::make_FunctionInterface<void>(Arg1, Arg2, Arg3);
|
2014-05-06 19:28:08 +00:00
|
|
|
|
2019-11-26 19:26:32 +00:00
|
|
|
std::cout << "Transform to pointer type." << std::endl;
|
|
|
|
auto funcInterfaceTransform1 = funcInterface.StaticTransformCont(PointerTransform());
|
2014-05-13 19:18:21 +00:00
|
|
|
|
2019-12-03 18:30:43 +00:00
|
|
|
using P1 = typename std::decay<decltype(ParameterGet<1>(funcInterfaceTransform1))>::type;
|
|
|
|
using P2 = typename std::decay<decltype(ParameterGet<2>(funcInterfaceTransform1))>::type;
|
|
|
|
using P3 = typename std::decay<decltype(ParameterGet<3>(funcInterfaceTransform1))>::type;
|
2014-04-10 19:35:06 +00:00
|
|
|
|
2019-11-26 19:26:32 +00:00
|
|
|
VTKM_STATIC_ASSERT((std::is_same<const Type1*, P1>::value));
|
|
|
|
VTKM_STATIC_ASSERT((std::is_same<const Type2*, P2>::value));
|
|
|
|
VTKM_STATIC_ASSERT((std::is_same<const Type3*, P3>::value));
|
2014-04-10 19:35:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestFunctionInterface()
|
|
|
|
{
|
|
|
|
TestBasicFunctionInterface();
|
2014-05-06 19:28:08 +00:00
|
|
|
TestStaticTransform();
|
2014-04-10 19:35:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2019-01-01 22:19:02 +00:00
|
|
|
int UnitTestFunctionInterface(int argc, char* argv[])
|
2014-04-10 19:35:06 +00:00
|
|
|
{
|
2019-04-17 17:59:49 +00:00
|
|
|
return vtkm::testing::Testing::Run(TestFunctionInterface, argc, argv);
|
2014-04-10 19:35:06 +00:00
|
|
|
}
|