• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #define BOOST_TEST_MODULE TestInteropQt
12 #include <boost/test/unit_test.hpp>
13 
14 #include <boost/compute/system.hpp>
15 #include <boost/compute/container/vector.hpp>
16 #include <boost/compute/detail/is_contiguous_iterator.hpp>
17 #include <boost/compute/interop/qt.hpp>
18 
19 #include <QList>
20 #include <QVector>
21 
22 #include "check_macros.hpp"
23 #include "context_setup.hpp"
24 
25 namespace bcl = boost::compute;
26 
BOOST_AUTO_TEST_CASE(qimage_format)27 BOOST_AUTO_TEST_CASE(qimage_format)
28 {
29     BOOST_CHECK(
30         bcl::qt_qimage_format_to_image_format(QImage::Format_RGB32) ==
31         bcl::image_format(CL_BGRA, CL_UNORM_INT8)
32     );
33 }
34 
BOOST_AUTO_TEST_CASE(copy_qvector_to_device)35 BOOST_AUTO_TEST_CASE(copy_qvector_to_device)
36 {
37     QList<int> qvector;
38     qvector.append(0);
39     qvector.append(2);
40     qvector.append(4);
41     qvector.append(6);
42 
43     bcl::vector<int> vector(4, context);
44     bcl::copy(qvector.begin(), qvector.end(), vector.begin(), queue);
45     CHECK_RANGE_EQUAL(int, 4, vector, (0, 2, 4, 6));
46 }
47 
BOOST_AUTO_TEST_CASE(copy_qlist_to_device)48 BOOST_AUTO_TEST_CASE(copy_qlist_to_device)
49 {
50     QList<int> list;
51     list.append(1);
52     list.append(3);
53     list.append(5);
54     list.append(7);
55 
56     bcl::vector<int> vector(4, context);
57     bcl::copy(list.begin(), list.end(), vector.begin(), queue);
58     CHECK_RANGE_EQUAL(int, 4, vector, (1, 3, 5, 7));
59 }
60 
BOOST_AUTO_TEST_CASE(qvector_of_qpoint)61 BOOST_AUTO_TEST_CASE(qvector_of_qpoint)
62 {
63     QVector<QPoint> qt_points;
64     qt_points.append(QPoint(0, 1));
65     qt_points.append(QPoint(2, 3));
66     qt_points.append(QPoint(4, 5));
67     qt_points.append(QPoint(6, 7));
68 
69     bcl::vector<QPoint> bcl_points(qt_points.size(), context);
70     bcl::copy(qt_points.begin(), qt_points.end(), bcl_points.begin(), queue);
71 }
72 
BOOST_AUTO_TEST_CASE(qvector_of_qpointf)73 BOOST_AUTO_TEST_CASE(qvector_of_qpointf)
74 {
75     QVector<QPointF> qt_points;
76     qt_points.append(QPointF(0.3f, 1.7f));
77     qt_points.append(QPointF(2.3f, 3.7f));
78     qt_points.append(QPointF(4.3f, 5.7f));
79     qt_points.append(QPointF(6.3f, 7.7f));
80 
81     bcl::vector<QPointF> bcl_points(qt_points.size(), context);
82     bcl::copy(qt_points.begin(), qt_points.end(), bcl_points.begin(), queue);
83 }
84 
BOOST_AUTO_TEST_CASE(qvector_iterator)85 BOOST_AUTO_TEST_CASE(qvector_iterator)
86 {
87     using boost::compute::detail::is_contiguous_iterator;
88 
89     BOOST_STATIC_ASSERT(is_contiguous_iterator<QVector<int>::iterator>::value == true);
90     BOOST_STATIC_ASSERT(is_contiguous_iterator<QVector<int>::const_iterator>::value == true);
91     BOOST_STATIC_ASSERT(is_contiguous_iterator<QList<int>::iterator>::value == false);
92     BOOST_STATIC_ASSERT(is_contiguous_iterator<QList<int>::const_iterator>::value == false);
93 }
94 
95 BOOST_AUTO_TEST_SUITE_END()
96