forked from boostorg/compute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_type_traits.cpp
131 lines (112 loc) · 6.1 KB
/
test_type_traits.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <[email protected]>
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#define BOOST_TEST_MODULE TestTypeTraits
#include <boost/test/unit_test.hpp>
#include <set>
#include <list>
#include <vector>
#include <boost/type_traits.hpp>
#include <boost/static_assert.hpp>
#include <boost/compute/types.hpp>
#include <boost/compute/type_traits.hpp>
#include <boost/compute/iterator/buffer_iterator.hpp>
#include <boost/compute/iterator/constant_iterator.hpp>
#include <boost/compute/detail/is_buffer_iterator.hpp>
#include <boost/compute/detail/is_contiguous_iterator.hpp>
namespace bc = boost::compute;
BOOST_AUTO_TEST_CASE(scalar_type)
{
BOOST_STATIC_ASSERT((boost::is_same<bc::scalar_type<bc::int_>::type, int>::value));
BOOST_STATIC_ASSERT((boost::is_same<bc::scalar_type<bc::int2_>::type, int>::value));
BOOST_STATIC_ASSERT((boost::is_same<bc::scalar_type<bc::float_>::type, float>::value));
BOOST_STATIC_ASSERT((boost::is_same<bc::scalar_type<bc::float4_>::type, float>::value));
}
BOOST_AUTO_TEST_CASE(vector_size)
{
BOOST_STATIC_ASSERT(bc::vector_size<bc::int_>::value == 1);
BOOST_STATIC_ASSERT(bc::vector_size<bc::int2_>::value == 2);
BOOST_STATIC_ASSERT(bc::vector_size<bc::float_>::value == 1);
BOOST_STATIC_ASSERT(bc::vector_size<bc::float4_>::value == 4);
}
BOOST_AUTO_TEST_CASE(is_vector_type)
{
BOOST_STATIC_ASSERT(bc::is_vector_type<bc::int_>::value == false);
BOOST_STATIC_ASSERT(bc::is_vector_type<bc::int2_>::value == true);
BOOST_STATIC_ASSERT(bc::is_vector_type<bc::float_>::value == false);
BOOST_STATIC_ASSERT(bc::is_vector_type<bc::float4_>::value == true);
}
BOOST_AUTO_TEST_CASE(make_vector_type)
{
BOOST_STATIC_ASSERT((boost::is_same<bc::make_vector_type<cl_uint, 2>::type, bc::uint2_>::value));
BOOST_STATIC_ASSERT((boost::is_same<bc::make_vector_type<int, 4>::type, bc::int4_>::value));
BOOST_STATIC_ASSERT((boost::is_same<bc::make_vector_type<float, 8>::type, bc::float8_>::value));
BOOST_STATIC_ASSERT((boost::is_same<bc::make_vector_type<bc::char_, 16>::type, bc::char16_>::value));
}
BOOST_AUTO_TEST_CASE(is_fundamental_type)
{
BOOST_STATIC_ASSERT((bc::is_fundamental<int>::value == true));
BOOST_STATIC_ASSERT((bc::is_fundamental<bc::int_>::value == true));
BOOST_STATIC_ASSERT((bc::is_fundamental<bc::int2_>::value == true));
BOOST_STATIC_ASSERT((bc::is_fundamental<float>::value == true));
BOOST_STATIC_ASSERT((bc::is_fundamental<bc::float_>::value == true));
BOOST_STATIC_ASSERT((bc::is_fundamental<bc::float4_>::value == true));
BOOST_STATIC_ASSERT((bc::is_fundamental<std::pair<int, float> >::value == false));
BOOST_STATIC_ASSERT((bc::is_fundamental<std::complex<float> >::value == false));
}
BOOST_AUTO_TEST_CASE(type_name)
{
// scalar types
BOOST_CHECK(std::strcmp(bc::type_name<bc::char_>(), "char") == 0);
BOOST_CHECK(std::strcmp(bc::type_name<bc::uchar_>(), "uchar") == 0);
BOOST_CHECK(std::strcmp(bc::type_name<bc::short_>(), "short") == 0);
BOOST_CHECK(std::strcmp(bc::type_name<bc::ushort_>(), "ushort") == 0);
BOOST_CHECK(std::strcmp(bc::type_name<bc::int_>(), "int") == 0);
BOOST_CHECK(std::strcmp(bc::type_name<bc::uint_>(), "uint") == 0);
BOOST_CHECK(std::strcmp(bc::type_name<bc::long_>(), "long") == 0);
BOOST_CHECK(std::strcmp(bc::type_name<bc::ulong_>(), "ulong") == 0);
BOOST_CHECK(std::strcmp(bc::type_name<bc::float_>(), "float") == 0);
BOOST_CHECK(std::strcmp(bc::type_name<bc::double_>(), "double") == 0);
BOOST_CHECK(std::strcmp(bc::type_name<bool>(), "bool") == 0);
// vector types
BOOST_CHECK(std::strcmp(bc::type_name<bc::char16_>(), "char16") == 0);
BOOST_CHECK(std::strcmp(bc::type_name<bc::uint4_>(), "uint4") == 0);
BOOST_CHECK(std::strcmp(bc::type_name<bc::ulong8_>(), "ulong8") == 0);
BOOST_CHECK(std::strcmp(bc::type_name<bc::float2_>(), "float2") == 0);
BOOST_CHECK(std::strcmp(bc::type_name<bc::double4_>(), "double4") == 0);
}
BOOST_AUTO_TEST_CASE(is_contiguous_iterator)
{
using boost::compute::detail::is_contiguous_iterator;
BOOST_STATIC_ASSERT(is_contiguous_iterator<int *>::value == true);
BOOST_STATIC_ASSERT(is_contiguous_iterator<std::vector<int>::iterator>::value == true);
BOOST_STATIC_ASSERT(is_contiguous_iterator<std::vector<int>::const_iterator>::value == true);
BOOST_STATIC_ASSERT(is_contiguous_iterator<std::list<int>::iterator>::value == false);
BOOST_STATIC_ASSERT(is_contiguous_iterator<std::set<int>::iterator>::value == false);
BOOST_STATIC_ASSERT(is_contiguous_iterator<std::insert_iterator<std::set<int> > >::value == false);
BOOST_STATIC_ASSERT(is_contiguous_iterator<std::back_insert_iterator<std::vector<int> > >::value == false);
}
BOOST_AUTO_TEST_CASE(is_buffer_iterator)
{
using boost::compute::detail::is_buffer_iterator;
BOOST_STATIC_ASSERT(is_buffer_iterator<boost::compute::buffer_iterator<int> >::value == true);
BOOST_STATIC_ASSERT(is_buffer_iterator<boost::compute::constant_iterator<int> >::value == false);
}
BOOST_AUTO_TEST_CASE(is_device_iterator)
{
using boost::compute::is_device_iterator;
BOOST_STATIC_ASSERT(is_device_iterator<boost::compute::buffer_iterator<int> >::value == true);
BOOST_STATIC_ASSERT(is_device_iterator<const boost::compute::buffer_iterator<int> >::value == true);
BOOST_STATIC_ASSERT(is_device_iterator<boost::compute::constant_iterator<int> >::value == true);
BOOST_STATIC_ASSERT(is_device_iterator<const boost::compute::constant_iterator<int> >::value == true);
BOOST_STATIC_ASSERT(is_device_iterator<float *>::value == false);
BOOST_STATIC_ASSERT(is_device_iterator<const float *>::value == false);
BOOST_STATIC_ASSERT(is_device_iterator<std::vector<int>::iterator>::value == false);
BOOST_STATIC_ASSERT(is_device_iterator<const std::vector<int>::iterator>::value == false);
}