test_interop_qt.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #define BOOST_TEST_MODULE TestInteropQt
  11. #include <boost/test/unit_test.hpp>
  12. #include <boost/compute/system.hpp>
  13. #include <boost/compute/container/vector.hpp>
  14. #include <boost/compute/detail/is_contiguous_iterator.hpp>
  15. #include <boost/compute/interop/qt.hpp>
  16. #include <QList>
  17. #include <QVector>
  18. #include "check_macros.hpp"
  19. #include "context_setup.hpp"
  20. namespace bcl = boost::compute;
  21. BOOST_AUTO_TEST_CASE(qimage_format)
  22. {
  23. BOOST_CHECK(
  24. bcl::qt_qimage_format_to_image_format(QImage::Format_RGB32) ==
  25. bcl::image_format(CL_BGRA, CL_UNORM_INT8)
  26. );
  27. }
  28. BOOST_AUTO_TEST_CASE(copy_qvector_to_device)
  29. {
  30. QList<int> qvector;
  31. qvector.append(0);
  32. qvector.append(2);
  33. qvector.append(4);
  34. qvector.append(6);
  35. bcl::vector<int> vector(4, context);
  36. bcl::copy(qvector.begin(), qvector.end(), vector.begin(), queue);
  37. CHECK_RANGE_EQUAL(int, 4, vector, (0, 2, 4, 6));
  38. }
  39. BOOST_AUTO_TEST_CASE(copy_qlist_to_device)
  40. {
  41. QList<int> list;
  42. list.append(1);
  43. list.append(3);
  44. list.append(5);
  45. list.append(7);
  46. bcl::vector<int> vector(4, context);
  47. bcl::copy(list.begin(), list.end(), vector.begin(), queue);
  48. CHECK_RANGE_EQUAL(int, 4, vector, (1, 3, 5, 7));
  49. }
  50. BOOST_AUTO_TEST_CASE(qvector_of_qpoint)
  51. {
  52. QVector<QPoint> qt_points;
  53. qt_points.append(QPoint(0, 1));
  54. qt_points.append(QPoint(2, 3));
  55. qt_points.append(QPoint(4, 5));
  56. qt_points.append(QPoint(6, 7));
  57. bcl::vector<QPoint> bcl_points(qt_points.size(), context);
  58. bcl::copy(qt_points.begin(), qt_points.end(), bcl_points.begin(), queue);
  59. }
  60. BOOST_AUTO_TEST_CASE(qvector_of_qpointf)
  61. {
  62. QVector<QPointF> qt_points;
  63. qt_points.append(QPointF(0.3f, 1.7f));
  64. qt_points.append(QPointF(2.3f, 3.7f));
  65. qt_points.append(QPointF(4.3f, 5.7f));
  66. qt_points.append(QPointF(6.3f, 7.7f));
  67. bcl::vector<QPointF> bcl_points(qt_points.size(), context);
  68. bcl::copy(qt_points.begin(), qt_points.end(), bcl_points.begin(), queue);
  69. }
  70. BOOST_AUTO_TEST_CASE(qvector_iterator)
  71. {
  72. using boost::compute::detail::is_contiguous_iterator;
  73. BOOST_STATIC_ASSERT(is_contiguous_iterator<QVector<int>::iterator>::value == true);
  74. BOOST_STATIC_ASSERT(is_contiguous_iterator<QVector<int>::const_iterator>::value == true);
  75. BOOST_STATIC_ASSERT(is_contiguous_iterator<QList<int>::iterator>::value == false);
  76. BOOST_STATIC_ASSERT(is_contiguous_iterator<QList<int>::const_iterator>::value == false);
  77. }
  78. BOOST_AUTO_TEST_SUITE_END()