| 1 | /* |
| 2 | * util_test.hpp |
| 3 | * |
| 4 | * Created on: May 31, 2015 |
| 5 | * Author: Pietro Incardona |
| 6 | */ |
| 7 | |
| 8 | #ifndef UTIL_TEST_HPP_ |
| 9 | #define UTIL_TEST_HPP_ |
| 10 | |
| 11 | #include "config.h" |
| 12 | #include "util/object_util.hpp" |
| 13 | #include "Point_test.hpp" |
| 14 | #include "util/ct_array.hpp" |
| 15 | #include "Vector/map_vector.hpp" |
| 16 | #include "util/common.hpp" |
| 17 | #include "util/check_no_pointers.hpp" |
| 18 | #include "Grid/util.hpp" |
| 19 | |
| 20 | #include "util/convert.hpp" |
| 21 | #include <iostream> |
| 22 | #include "util/mul_array_extents.hpp" |
| 23 | #include "Packer_Unpacker/has_max_prop.hpp" |
| 24 | #include "SparseGrid/SparseGrid.hpp" |
| 25 | |
| 26 | //! test type for has_max_prop |
| 27 | struct test_has_max_prop |
| 28 | { |
| 29 | //! define that the type has 6 properties |
| 30 | static const unsigned int max_prop = 6; |
| 31 | }; |
| 32 | |
| 33 | //! test type for has_max_prop |
| 34 | struct test_has_no_max_prop |
| 35 | { |
| 36 | }; |
| 37 | |
| 38 | typedef openfpm::vector<openfpm::vector<aggregate<float,int,double>>> max_prop_vector_test; |
| 39 | |
| 40 | //! [Check has_posMask struct definition] |
| 41 | |
| 42 | //! test type for has_posMask |
| 43 | struct test_has_posMask |
| 44 | { |
| 45 | //! unused |
| 46 | float data; |
| 47 | |
| 48 | //! staggered mask |
| 49 | static constexpr bool stag_mask[] = {true,false,true}; |
| 50 | }; |
| 51 | |
| 52 | //! test type for has_posMask |
| 53 | struct test_no_has_posMask |
| 54 | { |
| 55 | //! unused |
| 56 | float data; |
| 57 | }; |
| 58 | |
| 59 | //! [Check has_posMask struct definition] |
| 60 | |
| 61 | //! [Declaration of struct with attributes and without] |
| 62 | |
| 63 | //! test type for has_attributes |
| 64 | struct test_has_attributes |
| 65 | { |
| 66 | //! Define attribute names |
| 67 | struct attributes |
| 68 | { |
| 69 | //! This test structure has 2 attribute names |
| 70 | static const std::string name[2]; |
| 71 | }; |
| 72 | }; |
| 73 | |
| 74 | // attribute names |
| 75 | const std::string test_has_attributes::attributes::name[]={"attributes1" ,"attributes2" }; |
| 76 | |
| 77 | struct test_no_attributes |
| 78 | { |
| 79 | }; |
| 80 | |
| 81 | //! [Declaration of struct with attributes and without] |
| 82 | |
| 83 | BOOST_AUTO_TEST_SUITE( util_test ) |
| 84 | |
| 85 | BOOST_AUTO_TEST_CASE( object_s_di_test ) |
| 86 | { |
| 87 | // Object write test |
| 88 | |
| 89 | //! [object write example] |
| 90 | typedef Point_test<float> p; |
| 91 | typedef Point_test<float>::type vboost; |
| 92 | typedef object_creator<Point_test<float>::type,0,1,4>::type vboost_red; |
| 93 | |
| 94 | object<vboost> dst; |
| 95 | object<vboost_red> src; |
| 96 | |
| 97 | // fill the source properties 0,1,2 with data |
| 98 | |
| 99 | boost::fusion::at_c<0>(src.data) = 1.0; |
| 100 | boost::fusion::at_c<1>(src.data) = 2.0; |
| 101 | |
| 102 | for (size_t i = 0 ; i < 3 ; i++) |
| 103 | boost::fusion::at_c<2>(src.data)[i] = i + 5.0; |
| 104 | |
| 105 | // copy from src to dst |
| 106 | object_s_di<object<vboost_red>,object<vboost>,OBJ_NORMAL,0,1,4>(src,dst); |
| 107 | |
| 108 | // Check the result |
| 109 | BOOST_REQUIRE_EQUAL(boost::fusion::at_c<p::x>(dst.data),1.0); |
| 110 | BOOST_REQUIRE_EQUAL(boost::fusion::at_c<p::y>(dst.data),2.0); |
| 111 | |
| 112 | for (size_t i = 0 ; i < 3 ; i++) |
| 113 | BOOST_REQUIRE_EQUAL(boost::fusion::at_c<p::v>(dst.data)[i],i + 5.0); |
| 114 | |
| 115 | //! [object write example] |
| 116 | |
| 117 | //! [object write encap example] |
| 118 | |
| 119 | typedef encapc<1,Point_test<float>,openfpm::vector<Point_test<float>>::layout_type> encap_dst; |
| 120 | typedef encapc<1,object<vboost_red>,openfpm::vector<object<vboost_red>>::layout_type> encap_src; |
| 121 | |
| 122 | openfpm::vector<p> v_point; |
| 123 | openfpm::vector<object<vboost_red>> v_point_red; |
| 124 | |
| 125 | v_point.resize(2); |
| 126 | v_point_red.resize(2); |
| 127 | |
| 128 | v_point_red.template get<0>(0) = 11.0; |
| 129 | v_point_red.template get<1>(0) = 12.0; |
| 130 | |
| 131 | for (size_t i = 0 ; i < 3 ; i++) |
| 132 | v_point_red.template get<2>(0)[i] = i + 15.0; |
| 133 | |
| 134 | auto dst_e = v_point.get(0); |
| 135 | auto src_e = v_point_red.get(0); |
| 136 | |
| 137 | object_s_di<encap_src,encap_dst,OBJ_ENCAP,0,1,4>(src_e,dst_e); |
| 138 | |
| 139 | BOOST_REQUIRE_EQUAL(v_point.get(0).template get<p::x>(),11.0); |
| 140 | BOOST_REQUIRE_EQUAL(v_point.get(0).template get<p::y>(),12.0); |
| 141 | |
| 142 | for (size_t i = 0 ; i < 3 ; i++) |
| 143 | BOOST_REQUIRE_EQUAL(v_point.get(0).template get<p::v>()[i],i + 15.0); |
| 144 | |
| 145 | //! [object write encap example] |
| 146 | } |
| 147 | |
| 148 | BOOST_AUTO_TEST_CASE( object_s_di_op_test ) |
| 149 | { |
| 150 | // Object write test |
| 151 | |
| 152 | //! [object write example with op] |
| 153 | typedef Point_test<float> p; |
| 154 | typedef Point_test<float>::type vboost; |
| 155 | typedef object_creator<Point_test<float>::type,0,1,4>::type vboost_red; |
| 156 | |
| 157 | object<vboost> dst; |
| 158 | object<vboost_red> src; |
| 159 | |
| 160 | // fill the source properties 0,1,2 with data |
| 161 | |
| 162 | boost::fusion::at_c<0>(src.data) = 1.0; |
| 163 | boost::fusion::at_c<1>(src.data) = 2.0; |
| 164 | |
| 165 | for (size_t i = 0 ; i < 3 ; i++) |
| 166 | boost::fusion::at_c<2>(src.data)[i] = i + 5.0; |
| 167 | |
| 168 | boost::fusion::at_c<0>(dst.data) = 2.0; |
| 169 | boost::fusion::at_c<1>(dst.data) = 3.0; |
| 170 | |
| 171 | for (size_t i = 0 ; i < 3 ; i++) |
| 172 | boost::fusion::at_c<4>(dst.data)[i] = i + 7.0; |
| 173 | |
| 174 | // copy from src to dst |
| 175 | object_s_di_op<add_,object<vboost_red>,object<vboost>,OBJ_NORMAL,0,1,4>(src,dst); |
| 176 | |
| 177 | // Check the result |
| 178 | BOOST_REQUIRE_EQUAL(boost::fusion::at_c<p::x>(dst.data),3.0); |
| 179 | BOOST_REQUIRE_EQUAL(boost::fusion::at_c<p::y>(dst.data),5.0); |
| 180 | |
| 181 | for (size_t i = 0 ; i < 3 ; i++) |
| 182 | BOOST_REQUIRE_EQUAL(boost::fusion::at_c<p::v>(dst.data)[i],2*i + 12.0); |
| 183 | |
| 184 | //! [object write example with op] |
| 185 | |
| 186 | //! [object write encap example with op] |
| 187 | |
| 188 | typedef encapc<1,Point_test<float>,openfpm::vector<Point_test<float>>::layout_type> encap_dst; |
| 189 | typedef encapc<1,object<vboost_red>,openfpm::vector<object<vboost_red>>::layout_type> encap_src; |
| 190 | |
| 191 | openfpm::vector<p> v_point; |
| 192 | openfpm::vector<object<vboost_red>> v_point_red; |
| 193 | |
| 194 | v_point.resize(2); |
| 195 | v_point_red.resize(2); |
| 196 | |
| 197 | v_point_red.template get<0>(0) = 11.0; |
| 198 | v_point_red.template get<1>(0) = 12.0; |
| 199 | |
| 200 | v_point.template get<0>(0) = 10.0; |
| 201 | v_point.template get<1>(0) = 9.0; |
| 202 | |
| 203 | for (size_t i = 0 ; i < 3 ; i++) |
| 204 | v_point_red.template get<2>(0)[i] = i + 8.0; |
| 205 | |
| 206 | for (size_t i = 0 ; i < 3 ; i++) |
| 207 | v_point.template get<4>(0)[i] = i + 3.0; |
| 208 | |
| 209 | auto dst_e = v_point.get(0); |
| 210 | auto src_e = v_point_red.get(0); |
| 211 | |
| 212 | object_s_di_op<add_,encap_src,encap_dst,OBJ_ENCAP,0,1,4>(src_e,dst_e); |
| 213 | |
| 214 | BOOST_REQUIRE_EQUAL(v_point.get(0).template get<p::x>(),21.0); |
| 215 | BOOST_REQUIRE_EQUAL(v_point.get(0).template get<p::y>(),21.0); |
| 216 | |
| 217 | for (size_t i = 0 ; i < 3 ; i++) |
| 218 | BOOST_REQUIRE_EQUAL(v_point.get(0).template get<p::v>()[i],2*i + 11.0); |
| 219 | |
| 220 | //! [object write encap example with op] |
| 221 | } |
| 222 | |
| 223 | BOOST_AUTO_TEST_CASE( object_prop_copy ) |
| 224 | { |
| 225 | { |
| 226 | //! [object copy example] |
| 227 | typedef Point_test<float> p; |
| 228 | typedef Point_test<float>::type vboost; |
| 229 | typedef object_creator<Point_test<float>::type,0,1,4>::type vboost_red; |
| 230 | |
| 231 | object<vboost> src; |
| 232 | object<vboost_red> dst; |
| 233 | |
| 234 | // fill the source properties x,y,v = 0,1,4 with data |
| 235 | |
| 236 | boost::fusion::at_c<p::x>(src.data) = 1.0; |
| 237 | boost::fusion::at_c<p::y>(src.data) = 2.0; |
| 238 | |
| 239 | for (size_t i = 0 ; i < 3 ; i++) |
| 240 | boost::fusion::at_c<p::v>(src.data)[i] = i + 5.0; |
| 241 | |
| 242 | // copy from src to dst |
| 243 | object_si_d<object<vboost>,object<vboost_red>,OBJ_NORMAL,0,1,4>(src,dst); |
| 244 | |
| 245 | // Check the result |
| 246 | BOOST_REQUIRE_EQUAL(boost::fusion::at_c<0>(dst.data),1.0); |
| 247 | BOOST_REQUIRE_EQUAL(boost::fusion::at_c<1>(dst.data),2.0); |
| 248 | |
| 249 | for (size_t i = 0 ; i < 3 ; i++) |
| 250 | BOOST_REQUIRE_EQUAL(boost::fusion::at_c<2>(dst.data)[i],i + 5.0); |
| 251 | |
| 252 | //! [object copy example] |
| 253 | |
| 254 | //! [object copy encap example] |
| 255 | |
| 256 | typedef encapc<1,Point_test<float>,openfpm::vector<Point_test<float>>::layout_type> encap_src; |
| 257 | typedef encapc<1,object<vboost_red>,openfpm::vector<object<vboost_red>>::layout_type> encap_dst; |
| 258 | |
| 259 | openfpm::vector<p> v_point; |
| 260 | openfpm::vector<object<vboost_red>> v_point_red; |
| 261 | |
| 262 | v_point.resize(2); |
| 263 | v_point_red.resize(2); |
| 264 | |
| 265 | v_point.template get<p::x>(0) = 1.0; |
| 266 | v_point.template get<p::y>(0) = 2.0; |
| 267 | |
| 268 | for (size_t i = 0 ; i < 3 ; i++) |
| 269 | v_point.template get<p::v>(0)[i] = i + 5.0; |
| 270 | |
| 271 | auto src_e = v_point.get(0); |
| 272 | auto dst_e = v_point_red.get(0); |
| 273 | |
| 274 | object_si_d<encap_src,encap_dst,OBJ_ENCAP,0,1,4>(src_e,dst_e); |
| 275 | |
| 276 | BOOST_REQUIRE_EQUAL(v_point_red.get(0).template get<0>(),1.0); |
| 277 | BOOST_REQUIRE_EQUAL(v_point_red.get(0).template get<1>(),2.0); |
| 278 | |
| 279 | for (size_t i = 0 ; i < 3 ; i++) |
| 280 | BOOST_REQUIRE_EQUAL(v_point_red.get(0).template get<2>()[i],i + 5.0); |
| 281 | |
| 282 | //! [object copy encap example] |
| 283 | } |
| 284 | |
| 285 | |
| 286 | { |
| 287 | //! [object creator check for no pointers] |
| 288 | struct no_method_pointer |
| 289 | { |
| 290 | float a; |
| 291 | int b; |
| 292 | }; |
| 293 | |
| 294 | struct no_pointer |
| 295 | { |
| 296 | double c; |
| 297 | int d; |
| 298 | |
| 299 | static bool noPointers() {return true;} |
| 300 | }; |
| 301 | |
| 302 | struct with_pointer |
| 303 | { |
| 304 | double * c; |
| 305 | int d; |
| 306 | |
| 307 | static bool noPointers() {return false;} |
| 308 | }; |
| 309 | |
| 310 | typedef boost::fusion::vector<int,float,double,no_method_pointer,no_pointer,with_pointer,no_method_pointer> v; |
| 311 | |
| 312 | int val = boost::mpl::size< noPointers_sequence<v,0,2>::type >::value; |
| 313 | BOOST_REQUIRE_EQUAL(val,0); |
| 314 | |
| 315 | val = boost::mpl::size< noPointers_sequence<v,0,2,4,5>::type >::value; |
| 316 | BOOST_REQUIRE_EQUAL(val,0); |
| 317 | |
| 318 | val = boost::mpl::size< noPointers_sequence<v,0,1,2,3,4,5,6>::type >::value; |
| 319 | BOOST_REQUIRE_EQUAL(val,2); |
| 320 | |
| 321 | typedef boost::fusion::vector<int *,float &,double *,no_method_pointer *,no_pointer &,with_pointer *,no_method_pointer &> vp; |
| 322 | |
| 323 | val = boost::mpl::size< noPointers_sequence<vp,0,1,2,3,4,5,6>::type >::value; |
| 324 | BOOST_REQUIRE_EQUAL(val,2); |
| 325 | |
| 326 | //! [object creator check for no pointers] |
| 327 | } |
| 328 | |
| 329 | // Check the the object respect the noPointers construction |
| 330 | { |
| 331 | |
| 332 | struct no_method_pointer |
| 333 | { |
| 334 | float a; |
| 335 | int b; |
| 336 | }; |
| 337 | |
| 338 | struct no_pointer |
| 339 | { |
| 340 | double c; |
| 341 | int d; |
| 342 | |
| 343 | static bool noPointers() {return true;} |
| 344 | }; |
| 345 | |
| 346 | struct with_pointer |
| 347 | { |
| 348 | double * c; |
| 349 | int d; |
| 350 | |
| 351 | static bool noPointers() {return false;} |
| 352 | }; |
| 353 | |
| 354 | typedef boost::fusion::vector<int,float,double> v; |
| 355 | int val = object<v>::noPointers(); |
| 356 | BOOST_REQUIRE_EQUAL(val,PNP::NO_POINTERS); |
| 357 | |
| 358 | typedef boost::fusion::vector<int,float,double,no_pointer> va; |
| 359 | val = object<va>::noPointers(); |
| 360 | BOOST_REQUIRE_EQUAL(val,PNP::NO_POINTERS); |
| 361 | |
| 362 | typedef boost::fusion::vector<int,float,double,no_pointer,with_pointer> vb; |
| 363 | val = object<vb>::noPointers(); |
| 364 | BOOST_REQUIRE_EQUAL(val,PNP::POINTERS); |
| 365 | |
| 366 | typedef boost::fusion::vector<int,float,double,no_pointer,double *> vc; |
| 367 | val = object<vc>::noPointers(); |
| 368 | BOOST_REQUIRE_EQUAL(val,PNP::POINTERS); |
| 369 | |
| 370 | typedef boost::fusion::vector<int,float,double,no_pointer,double &> vd; |
| 371 | val = object<vd>::noPointers(); |
| 372 | BOOST_REQUIRE_EQUAL(val,PNP::POINTERS); |
| 373 | |
| 374 | typedef boost::fusion::vector<int,float,double,no_pointer,double[3]> ve; |
| 375 | val = object<ve>::noPointers(); |
| 376 | BOOST_REQUIRE_EQUAL(val,PNP::NO_POINTERS); |
| 377 | |
| 378 | typedef boost::fusion::vector<int,float,double,no_pointer,no_pointer *> vf; |
| 379 | val = object<vf>::noPointers(); |
| 380 | BOOST_REQUIRE_EQUAL(val,PNP::POINTERS); |
| 381 | |
| 382 | typedef boost::fusion::vector<int,float,double,no_pointer,no_pointer &> vg; |
| 383 | val = object<vg>::noPointers(); |
| 384 | BOOST_REQUIRE_EQUAL(val,PNP::POINTERS); |
| 385 | |
| 386 | typedef boost::fusion::vector<int,float,double,no_pointer,no_pointer[3]> vh; |
| 387 | val = object<vh>::noPointers(); |
| 388 | BOOST_REQUIRE_EQUAL(val,PNP::NO_POINTERS); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | |
| 393 | BOOST_AUTO_TEST_CASE( generate_array ) |
| 394 | { |
| 395 | { |
| 396 | //! [compile time array] |
| 397 | const size_t count = 5; |
| 398 | typedef typename ::generate_array<size_t,count, MetaFunc>::result ct_test; |
| 399 | |
| 400 | // ct_test::data is equivalent to const size_t [5] = {5,6,7,8,9} |
| 401 | |
| 402 | for (size_t i = 0 ; i < count; ++i) |
| 403 | { |
| 404 | const size_t ct_val = ct_test::data[i]; |
| 405 | BOOST_REQUIRE_EQUAL(ct_val,count+i); |
| 406 | } |
| 407 | //! [compile time array] |
| 408 | } |
| 409 | |
| 410 | // check constexpr compile time array as template parameters |
| 411 | |
| 412 | #ifndef COVERTY_SCAN |
| 413 | #if __CUDACC_VER_MAJOR__ >= 9 |
| 414 | { |
| 415 | //! [constexpr array] |
| 416 | const size_t count = 5; |
| 417 | typedef typename ::generate_array_constexpr<size_t,count, MetaFunc>::result ct_test_ce; |
| 418 | |
| 419 | // ct_test_ce::data is equivalent to constexpr size_t [5] = {5,6,7,8,9} |
| 420 | |
| 421 | const size_t ct_calc = MetaFunc<ct_test_ce::data[0],ct_test_ce::data[1]>::value; |
| 422 | BOOST_REQUIRE_EQUAL(ct_calc,11ul); |
| 423 | //! [constexpr array] |
| 424 | } |
| 425 | |
| 426 | #endif |
| 427 | #endif |
| 428 | |
| 429 | |
| 430 | { |
| 431 | //! [indexes array] |
| 432 | const size_t count = 5; |
| 433 | typedef typename ::generate_indexes<size_t,count, MetaFuncOrd>::result ct_test_ce; |
| 434 | |
| 435 | bool check = std::is_same<ct_test_ce,index_tuple<0,1,2,3,4>>::value; |
| 436 | BOOST_REQUIRE_EQUAL(check,true); |
| 437 | //! [indexes array] |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | BOOST_AUTO_TEST_CASE( check_templates_util_function ) |
| 442 | { |
| 443 | { |
| 444 | { |
| 445 | |
| 446 | //! [Check has pack] |
| 447 | |
| 448 | struct test_pack |
| 449 | { |
| 450 | static bool pack() {return true;} |
| 451 | }; |
| 452 | |
| 453 | struct test_unknown_pack |
| 454 | { |
| 455 | }; |
| 456 | |
| 457 | BOOST_REQUIRE_EQUAL(has_pack<test_pack>::type::value,true); |
| 458 | BOOST_REQUIRE_EQUAL(has_pack<test_unknown_pack>::type::value,false); |
| 459 | |
| 460 | //! [Check has packRequest] |
| 461 | |
| 462 | struct test_packRequest |
| 463 | { |
| 464 | static bool packRequest() {return false;} |
| 465 | }; |
| 466 | |
| 467 | struct test_unknown_packRequest |
| 468 | { |
| 469 | }; |
| 470 | |
| 471 | BOOST_REQUIRE_EQUAL(has_packRequest<test_packRequest>::type::value,true); |
| 472 | BOOST_REQUIRE_EQUAL(has_packRequest<test_unknown_packRequest>::type::value,false); |
| 473 | |
| 474 | //! [Check has packMem] |
| 475 | |
| 476 | struct test_packMem |
| 477 | { |
| 478 | static bool packMem() {return true;} |
| 479 | }; |
| 480 | |
| 481 | struct test_unknown_packMem |
| 482 | { |
| 483 | }; |
| 484 | |
| 485 | BOOST_REQUIRE_EQUAL(has_packMem<test_packMem>::type::value,true); |
| 486 | BOOST_REQUIRE_EQUAL(has_packMem<test_unknown_packMem>::type::value,false); |
| 487 | |
| 488 | |
| 489 | //! [Check no pointers] |
| 490 | |
| 491 | struct test_no_ptr |
| 492 | { |
| 493 | static bool noPointers() {return true;} |
| 494 | }; |
| 495 | |
| 496 | struct test_ptr |
| 497 | { |
| 498 | static bool noPointers() {return false;} |
| 499 | }; |
| 500 | |
| 501 | struct test_unknown |
| 502 | { |
| 503 | }; |
| 504 | |
| 505 | BOOST_REQUIRE_EQUAL(has_noPointers<test_no_ptr>::type::value,true); |
| 506 | BOOST_REQUIRE_EQUAL(has_noPointers<test_ptr>::type::value,true); |
| 507 | BOOST_REQUIRE_EQUAL(has_noPointers<test_unknown>::type::value,false); |
| 508 | |
| 509 | //! [Check no pointers] |
| 510 | |
| 511 | } |
| 512 | |
| 513 | { |
| 514 | //! [Declaration of an openfpm native structure] |
| 515 | |
| 516 | int val = is_openfpm_native<Point_test<float>>::value; |
| 517 | BOOST_REQUIRE_EQUAL(val, true); |
| 518 | val = is_openfpm_native<float>::value; |
| 519 | BOOST_REQUIRE_EQUAL(val, false); |
| 520 | |
| 521 | //! [Declaration of an openfpm native structure] |
| 522 | } |
| 523 | |
| 524 | { |
| 525 | //! [Check is_typedef_and_data_same] |
| 526 | |
| 527 | struct test_typedef_same_data |
| 528 | { |
| 529 | typedef boost::fusion::vector<float,double,float[3]> type; |
| 530 | |
| 531 | type data; |
| 532 | }; |
| 533 | |
| 534 | struct test_typedef_not_same_data |
| 535 | { |
| 536 | typedef boost::fusion::vector<float,double,float[3]> type; |
| 537 | |
| 538 | boost::fusion::vector<float,double> data; |
| 539 | }; |
| 540 | |
| 541 | int val = is_typedef_and_data_same<true,test_typedef_same_data>::value; |
| 542 | BOOST_REQUIRE_EQUAL(val, true); |
| 543 | val = is_typedef_and_data_same<true,test_typedef_not_same_data>::value; |
| 544 | BOOST_REQUIRE_EQUAL(val, false); |
| 545 | |
| 546 | //! [Check is_typedef_and_data_same] |
| 547 | } |
| 548 | |
| 549 | { |
| 550 | //! [Check has_data] |
| 551 | |
| 552 | struct test_has_data |
| 553 | { |
| 554 | float data; |
| 555 | }; |
| 556 | |
| 557 | struct test_no_has_data |
| 558 | { |
| 559 | }; |
| 560 | |
| 561 | int val = has_data<test_has_data>::value; |
| 562 | BOOST_REQUIRE_EQUAL(val, true); |
| 563 | val = has_data<test_no_has_data>::value; |
| 564 | BOOST_REQUIRE_EQUAL(val, false); |
| 565 | |
| 566 | //! [Check has_data] |
| 567 | } |
| 568 | |
| 569 | { |
| 570 | //! [Check has_max_prop] |
| 571 | |
| 572 | int val = has_max_prop_nn<test_has_max_prop>::value; |
| 573 | BOOST_REQUIRE_EQUAL(val, true); |
| 574 | val = has_max_prop_nn<test_has_no_max_prop>::value; |
| 575 | BOOST_REQUIRE_EQUAL(val, false); |
| 576 | |
| 577 | |
| 578 | val = has_max_prop<max_prop_vector_test, has_value_type_ofp<max_prop_vector_test>::value>::value; |
| 579 | BOOST_REQUIRE_EQUAL(val, true); |
| 580 | val = has_max_prop<max_prop_vector_test, has_value_type_ofp<max_prop_vector_test>::value>::number; |
| 581 | #ifndef SE_CLASS3 |
| 582 | BOOST_REQUIRE_EQUAL(val, 3); |
| 583 | #endif |
| 584 | |
| 585 | //! [Check has_max_prop] |
| 586 | } |
| 587 | |
| 588 | { |
| 589 | //! [Check has_value_type] |
| 590 | |
| 591 | struct test_has_value_type |
| 592 | { |
| 593 | typedef int value_type; |
| 594 | }; |
| 595 | |
| 596 | struct test_has_no_value_type |
| 597 | { |
| 598 | |
| 599 | }; |
| 600 | |
| 601 | int val = has_value_type_ofp<test_has_value_type>::value; |
| 602 | BOOST_REQUIRE_EQUAL(val, true); |
| 603 | val = has_value_type_ofp<test_has_no_value_type>::value; |
| 604 | BOOST_REQUIRE_EQUAL(val, false); |
| 605 | |
| 606 | //! [Check has_value_type] |
| 607 | } |
| 608 | |
| 609 | |
| 610 | { |
| 611 | //! [Check has_posMask] |
| 612 | |
| 613 | int val = has_posMask<test_has_posMask>::value; |
| 614 | BOOST_REQUIRE_EQUAL(val, true); |
| 615 | val = has_posMask<test_no_has_posMask>::value; |
| 616 | BOOST_REQUIRE_EQUAL(val, false); |
| 617 | |
| 618 | //! [Check has_posMask] |
| 619 | } |
| 620 | |
| 621 | { |
| 622 | //! [Check has_typedef_type] |
| 623 | |
| 624 | struct test_has_typedef |
| 625 | { |
| 626 | typedef float type; |
| 627 | }; |
| 628 | |
| 629 | struct test_no_has_data |
| 630 | { |
| 631 | }; |
| 632 | |
| 633 | int val = has_typedef_type<test_has_typedef>::value; |
| 634 | BOOST_REQUIRE_EQUAL(val, true); |
| 635 | val = has_typedef_type<test_no_has_data>::value; |
| 636 | BOOST_REQUIRE_EQUAL(val, false); |
| 637 | |
| 638 | //! [Check has_typedef_type] |
| 639 | } |
| 640 | |
| 641 | { |
| 642 | //! [Check has_attributes] |
| 643 | |
| 644 | int val = has_attributes<test_has_attributes>::value; |
| 645 | BOOST_REQUIRE_EQUAL(val, true); |
| 646 | val = has_attributes<test_no_attributes>::value; |
| 647 | BOOST_REQUIRE_EQUAL(val, false); |
| 648 | |
| 649 | //! [Check has_attributes] |
| 650 | } |
| 651 | |
| 652 | //! [Check no pointers in structure] |
| 653 | struct test_no_ptr |
| 654 | { |
| 655 | static bool noPointers() {return PNP::NO_POINTERS;} |
| 656 | }; |
| 657 | |
| 658 | struct test_ptr |
| 659 | { |
| 660 | static bool noPointers() {return PNP::POINTERS;} |
| 661 | }; |
| 662 | |
| 663 | struct test_unknown |
| 664 | { |
| 665 | }; |
| 666 | |
| 667 | int val = check_no_pointers<test_no_ptr>::value(); |
| 668 | BOOST_REQUIRE_EQUAL(val,PNP::NO_POINTERS); |
| 669 | val = check_no_pointers<test_ptr>::value(); |
| 670 | BOOST_REQUIRE_EQUAL(val,PNP::POINTERS); |
| 671 | val = check_no_pointers_impl<test_unknown,false>::value(); |
| 672 | BOOST_REQUIRE_EQUAL(val,PNP::UNKNOWN); |
| 673 | |
| 674 | //! [Check no pointers in structure] |
| 675 | |
| 676 | { |
| 677 | //! [Check is_grid] |
| 678 | |
| 679 | struct stub_object |
| 680 | { |
| 681 | float a; |
| 682 | double b; |
| 683 | }; |
| 684 | |
| 685 | bool val = is_grid< grid_cpu<2,aggregate<float> > >::value; |
| 686 | BOOST_REQUIRE_EQUAL( val ,true); |
| 687 | val = is_grid< grid_cpu<3,object< boost::fusion::vector<float,double> > > >::value; |
| 688 | BOOST_REQUIRE_EQUAL( val , true); |
| 689 | val = is_grid< grid_cpu<4,Point_test<float>> >::value; |
| 690 | BOOST_REQUIRE_EQUAL( val ,true); |
| 691 | |
| 692 | val = is_grid< grid_gpu<2,aggregate<float> > >::value; |
| 693 | BOOST_REQUIRE_EQUAL(val ,true); |
| 694 | val = is_grid< grid_gpu<3,object< boost::fusion::vector<float,double>>> >::value; |
| 695 | BOOST_REQUIRE_EQUAL(val, true); |
| 696 | val = is_grid< grid_gpu<4,Point_test<float>> >::value; |
| 697 | BOOST_REQUIRE_EQUAL(val,true); |
| 698 | |
| 699 | val = is_grid< float >::value; |
| 700 | BOOST_REQUIRE_EQUAL( val, false); |
| 701 | val = is_grid< stub_object > ::value; |
| 702 | BOOST_REQUIRE_EQUAL( val, false); |
| 703 | |
| 704 | //! [Check is_grid] |
| 705 | } |
| 706 | |
| 707 | { |
| 708 | //! [Check is_vector] |
| 709 | |
| 710 | struct stub_object |
| 711 | { |
| 712 | float a; |
| 713 | double b; |
| 714 | }; |
| 715 | |
| 716 | bool val = is_vector< openfpm::vector<aggregate<float> > >::value; |
| 717 | BOOST_REQUIRE_EQUAL( val ,true); |
| 718 | val = is_vector< openfpm::vector<object< boost::fusion::vector<float,double> > > >::value; |
| 719 | BOOST_REQUIRE_EQUAL( val , true); |
| 720 | val = is_vector< openfpm::vector<Point_test<float>> >::value; |
| 721 | BOOST_REQUIRE_EQUAL( val ,true); |
| 722 | |
| 723 | val = is_vector< openfpm::vector<aggregate<float> > >::value; |
| 724 | BOOST_REQUIRE_EQUAL(val ,true); |
| 725 | val = is_vector< openfpm::vector<object< boost::fusion::vector<float,double>>> >::value; |
| 726 | BOOST_REQUIRE_EQUAL(val, true); |
| 727 | val = is_vector< openfpm::vector<Point_test<float>> >::value; |
| 728 | BOOST_REQUIRE_EQUAL(val,true); |
| 729 | |
| 730 | val = is_vector< float >::value; |
| 731 | BOOST_REQUIRE_EQUAL( val, false); |
| 732 | val = is_vector< stub_object > ::value; |
| 733 | BOOST_REQUIRE_EQUAL( val, false); |
| 734 | |
| 735 | //! [Check is_vector] |
| 736 | } |
| 737 | |
| 738 | { |
| 739 | //! [Check is_encap] |
| 740 | |
| 741 | struct stub_object |
| 742 | { |
| 743 | float a; |
| 744 | double b; |
| 745 | }; |
| 746 | |
| 747 | bool val = is_encap< encapc<2,aggregate<float>,memory_traits_lin<aggregate<float>>::type > >::value; |
| 748 | BOOST_REQUIRE_EQUAL( val ,true); |
| 749 | val = is_encap< encapc<3,object<boost::fusion::vector<float,double> >,memory_traits_lin<object< boost::fusion::vector<float,double>>>::type > >::value; |
| 750 | BOOST_REQUIRE_EQUAL( val , true); |
| 751 | val = is_encap< encapc<4,Point_test<float>,memory_traits_lin<Point_test<float>>::type > >::value; |
| 752 | BOOST_REQUIRE_EQUAL( val ,true); |
| 753 | |
| 754 | val = is_encap< encapc<2,aggregate<float>,memory_traits_inte<aggregate<float>>::type > >::value; |
| 755 | BOOST_REQUIRE_EQUAL( val ,true); |
| 756 | val = is_encap< encapc<3,object<boost::fusion::vector<float,double> >,memory_traits_inte<object< boost::fusion::vector<float,double>>>::type > >::value; |
| 757 | BOOST_REQUIRE_EQUAL( val , true); |
| 758 | val = is_encap< encapc<4,Point_test<float>,memory_traits_inte<Point_test<float>>::type > >::value; |
| 759 | BOOST_REQUIRE_EQUAL( val ,true); |
| 760 | |
| 761 | val = is_encap< float >::value; |
| 762 | BOOST_REQUIRE_EQUAL( val, false); |
| 763 | val = is_encap< stub_object > ::value; |
| 764 | BOOST_REQUIRE_EQUAL( val, false); |
| 765 | |
| 766 | //! [Check is_encap] |
| 767 | } |
| 768 | |
| 769 | { |
| 770 | //! [Usage mul_array_extents] |
| 771 | |
| 772 | size_t mul = array_extents<float>::mul(); |
| 773 | BOOST_REQUIRE_EQUAL(mul,1ul); |
| 774 | mul = array_extents<float[3]>::mul(); |
| 775 | BOOST_REQUIRE_EQUAL(mul,3ul); |
| 776 | mul = array_extents<float[3][2]>::mul(); |
| 777 | BOOST_REQUIRE_EQUAL(mul,3ul*2ul); |
| 778 | mul = array_extents<float[3][2][5]>::mul(); |
| 779 | BOOST_REQUIRE_EQUAL(mul,3ul*2ul*5ul); |
| 780 | |
| 781 | //! [Usage mul_array_extents] |
| 782 | } |
| 783 | |
| 784 | { |
| 785 | //! [Check memory layout] |
| 786 | |
| 787 | bool val = is_layout_mlin<memory_traits_lin<aggregate<float>>>::value; |
| 788 | BOOST_REQUIRE_EQUAL(val,true); |
| 789 | val = is_layout_mlin<memory_traits_inte<aggregate<float>>>::value; |
| 790 | BOOST_REQUIRE_EQUAL(val,false); |
| 791 | |
| 792 | val = is_layout_inte<memory_traits_lin<aggregate<float>>>::value; |
| 793 | BOOST_REQUIRE_EQUAL(val,false); |
| 794 | val = is_layout_inte<memory_traits_inte<aggregate<float>>>::value; |
| 795 | BOOST_REQUIRE_EQUAL(val,true); |
| 796 | |
| 797 | //! [Check memory layout] |
| 798 | } |
| 799 | |
| 800 | //! [Check has_pack_agg] |
| 801 | { |
| 802 | typedef aggregate<float,openfpm::vector<float>> aggr; |
| 803 | |
| 804 | bool val = has_pack_agg<aggr>::result::value; |
| 805 | |
| 806 | BOOST_REQUIRE_EQUAL(val,true); |
| 807 | |
| 808 | typedef aggregate<float, Point_test<float>> aggr2; |
| 809 | |
| 810 | val = has_pack_agg<aggr2>::result::value; |
| 811 | |
| 812 | BOOST_REQUIRE_EQUAL(val,false); |
| 813 | |
| 814 | typedef aggregate<sgrid_cpu<3,aggregate<int>,HeapMemory>,Box<3,float>> aggr3; |
| 815 | |
| 816 | val = has_pack_agg<aggr3>::result::value; |
| 817 | |
| 818 | BOOST_REQUIRE_EQUAL(val,true); |
| 819 | |
| 820 | } |
| 821 | //! [Check has_pack_agg] |
| 822 | |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | BOOST_AUTO_TEST_CASE( check_convert_function ) |
| 827 | { |
| 828 | { |
| 829 | //! [Convert combination to Point] |
| 830 | |
| 831 | comb<2> c; |
| 832 | c.c[0] = 1; |
| 833 | c.c[1] = -1; |
| 834 | |
| 835 | Point<2,size_t> p = toPoint<2,size_t>::convert(c); |
| 836 | |
| 837 | BOOST_REQUIRE_EQUAL(p.get(0),1ul); |
| 838 | BOOST_REQUIRE_EQUAL(p.get(1),(size_t)-1); |
| 839 | |
| 840 | //! [Convert combination to Point] |
| 841 | } |
| 842 | |
| 843 | { |
| 844 | //! [Convert combination to Point3] |
| 845 | |
| 846 | comb<3> c; |
| 847 | c.c[0] = 1; |
| 848 | c.c[1] = -1; |
| 849 | c.c[2] = 0; |
| 850 | |
| 851 | Point<3,float> p = toPoint<3,float>::convert(c); |
| 852 | |
| 853 | BOOST_REQUIRE_EQUAL(p.get(0),1); |
| 854 | BOOST_REQUIRE_EQUAL(p.get(1),-1); |
| 855 | BOOST_REQUIRE_EQUAL(p.get(2),0); |
| 856 | |
| 857 | //! [Convert combination to Point3] |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | |
| 862 | BOOST_AUTO_TEST_CASE( is_contiguos_test) |
| 863 | { |
| 864 | { |
| 865 | bool test = is_contiguos<1,2>::type::value; |
| 866 | |
| 867 | BOOST_REQUIRE_EQUAL(test,true); |
| 868 | |
| 869 | test = is_contiguos<1,3>::type::value; |
| 870 | |
| 871 | BOOST_REQUIRE_EQUAL(test,false); |
| 872 | |
| 873 | test = is_contiguos<1,2,3,4,5>::type::value; |
| 874 | |
| 875 | BOOST_REQUIRE_EQUAL(test,true); |
| 876 | |
| 877 | test = is_contiguos<1,2,3,4,5,7>::type::value; |
| 878 | |
| 879 | BOOST_REQUIRE_EQUAL(test,false); |
| 880 | |
| 881 | test = is_contiguos<1,3,2>::type::value; |
| 882 | |
| 883 | BOOST_REQUIRE_EQUAL(test,false); |
| 884 | |
| 885 | test = is_contiguos<1,5,3>::type::value; |
| 886 | |
| 887 | BOOST_REQUIRE_EQUAL(test,false); |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | BOOST_AUTO_TEST_CASE( dyn_struct_check ) |
| 892 | { |
| 893 | typedef grid_cpu<3,aggregate<int>> gs; |
| 894 | |
| 895 | bool test = isDynStruct<gs>::value(); |
| 896 | |
| 897 | BOOST_REQUIRE_EQUAL(test,false); |
| 898 | |
| 899 | typedef openfpm::vector<aggregate<int>> va; |
| 900 | |
| 901 | test = isDynStruct<gs>::value(); |
| 902 | |
| 903 | BOOST_REQUIRE_EQUAL(test,false); |
| 904 | |
| 905 | typedef sgrid_cpu<3,aggregate<int>,HeapMemory> sg; |
| 906 | |
| 907 | test = isDynStruct<sg>::value(); |
| 908 | |
| 909 | BOOST_REQUIRE_EQUAL(test,true); |
| 910 | |
| 911 | typedef openfpm::vector<int> vi; |
| 912 | |
| 913 | test = isDynStruct<vi>::value(); |
| 914 | |
| 915 | BOOST_REQUIRE_EQUAL(test,false); |
| 916 | } |
| 917 | |
| 918 | BOOST_AUTO_TEST_SUITE_END() |
| 919 | |
| 920 | #endif /* UTIL_TEST_HPP_ */ |
| 921 | |