iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test-Traits.C
Go to the documentation of this file.
1 /*! @file
2  @author Laurent Itti <itti@usc.edu>
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 
35 #include <nrt/config.h>
39 
40 #include <boost/mpl/list.hpp>
41 
42 #define BOOST_TEST_DYN_LINK
43 #define BOOST_TEST_MODULE TraitsTest
44 #include <boost/test/unit_test.hpp>
45 
46 #include <vector>
47 
48 struct E { };
49 struct D { };
50 struct A { A() { } A(A const&) { }; A(D const&) { }; explicit A(E const&) { }; };
51 struct B { };
52 struct C : public B { };
53 A operator+(A const& a1, A const& a2) { return A(); };
54 A operator-(A const& a1, A const& a2) { return A(); };
55 A operator*(A const& a1, A const& a2) { return A(); };
56 A operator/(A const& a1, A const& a2) { return A(); };
57 B operator*(A const& a, B const& b) { return B(); };
58 B operator*(B const& b, A const& a) { return B(); };
59 //also check for implicit conversion
60 
61 BOOST_AUTO_TEST_CASE(AllTraitsTest)
62 {
63  //example of function checking mechanism
65  BOOST_CHECK_EQUAL(t, true);
66 
68  BOOST_CHECK_EQUAL(t, false);
69 
71  BOOST_CHECK_EQUAL(t, true);
72 
74  BOOST_CHECK_EQUAL(t,true);
75 
77  BOOST_CHECK_EQUAL(t,true);
78 
80  BOOST_CHECK_EQUAL(t,true);
81 
83  BOOST_CHECK_EQUAL(t,false);
84 
86  BOOST_CHECK_EQUAL(t,false);
87 
88  std::string str = nrt::demangle(typeid(nrt::nrt_traits<A,B>::promote_type).name());
89  BOOST_CHECK_EQUAL(str, "B");
90 
92  BOOST_CHECK_EQUAL(str, "nrt::NotATypeError");
93 
94  //check some properties
96  BOOST_CHECK_EQUAL(t, true);
97 
99  BOOST_CHECK_EQUAL(t, true);
100 
101  t = nrt::nrt_traits<std::vector<float>>::is_pixel;
102  BOOST_CHECK_EQUAL(t, false);
103 
104  t = nrt::nrt_traits<nrt::PixRGB<float> >::is_pixel;
105  BOOST_CHECK_EQUAL(t, true);
106 
107  t = nrt::nrt_traits<nrt::PixRGB<int> >::is_arithmetic;
108  BOOST_CHECK_EQUAL(t, false);
109 
110  t = nrt::nrt_traits<nrt::PixRGB<int> >::pixel_traits::is_multi_channel;
111  BOOST_CHECK_EQUAL(t, true);
112 
113  t = nrt::nrt_traits<nrt::PixGray<int> >::pixel_traits::is_multi_channel;
114  BOOST_CHECK_EQUAL(t, false);
115 
116  t = nrt::nrt_traits<nrt::PixRGB<int> >::pixel_traits::is_single_channel;
117  BOOST_CHECK_EQUAL(t, false);
118 
119  t = nrt::nrt_traits<nrt::PixGray<int> >::pixel_traits::is_single_channel;
120  BOOST_CHECK_EQUAL(t, true);
121 
123  BOOST_CHECK_EQUAL(t, true);
124 
125  //check pixel helper
126  t = nrt::pixel_helper::are_comparable<std::vector<float>, std::vector<float>>::value;
127  BOOST_CHECK_EQUAL(t, false);
128 
129  t = nrt::pixel_helper::are_comparable<nrt::PixRGB<float>, nrt::PixRGB<float>>::value;
130  BOOST_CHECK_EQUAL(t, true);
131 
132  t = nrt::pixel_helper::are_comparable<nrt::PixRGB<nrt::byte>, nrt::PixRGB<float>>::value;
133  BOOST_CHECK_EQUAL(t, true);
134 
135  t = nrt::pixel_helper::are_comparable<nrt::PixRGB<float>, nrt::PixGray<float>>::value;
136  BOOST_CHECK_EQUAL(t, false);
137 
138  //check some promotions
140  BOOST_CHECK_EQUAL(t, true);
141 
143  BOOST_CHECK_EQUAL(t, true);
144 
146  BOOST_CHECK_EQUAL(t, true);
147 
148  t = nrt::nrt_traits<std::vector<nrt::byte>,nrt::byte>::is_promotable;
149  BOOST_CHECK_EQUAL(t, false);
150 
151  //check for operators
153  BOOST_CHECK_EQUAL(t,true);
154 
156  BOOST_CHECK_EQUAL(t,true);
157 
159  BOOST_CHECK_EQUAL(t,true);
160 
162  BOOST_CHECK_EQUAL(t,true);
163 
165  BOOST_CHECK_EQUAL(t,true);
166 
168  BOOST_CHECK_EQUAL(t,true);
169 
171  BOOST_CHECK_EQUAL(t,true);
172 
174  BOOST_CHECK_EQUAL(t,true);
175 
177  BOOST_CHECK_EQUAL(t,true);
178 
180  BOOST_CHECK_EQUAL(t,true);
181 
183  BOOST_CHECK_EQUAL(t,true);
184 
186  BOOST_CHECK_EQUAL(t,false);
187 
188  t = nrt::nrt_traits<nrt::PixRGB<nrt::byte>, nrt::byte>::has_arithmetic;
189  BOOST_CHECK_EQUAL(t,true);
190 
191  t = nrt::nrt_traits<nrt::PixRGB<nrt::byte>, nrt::byte>::is_promotable;
192  BOOST_CHECK_EQUAL(t,true);
193 
194  t = nrt::nrt_traits<nrt::PixRGB<nrt::byte>, nrt::byte>::has_assign_arithmetic;
195  BOOST_CHECK_EQUAL(t,true);
196 
197  t = nrt::nrt_traits<nrt::PixRGB<nrt::byte>, nrt::byte>::is_comparable;
198  BOOST_CHECK_EQUAL(t,false);
199 
201  BOOST_CHECK_EQUAL(t,false);
202 
204  BOOST_CHECK_EQUAL(t,false);
205 
207  BOOST_CHECK_EQUAL(t,false);
208 
210  BOOST_CHECK_EQUAL(t,true);
211 }
212 
213