iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tests/test-Traits.C
/*! @file
@author Laurent Itti <itti@usc.edu>
@copyright GNU Public License (GPL v3)
@section License
@verbatim
// ////////////////////////////////////////////////////////////////////////
// The iLab Neuromorphic Robotics Toolkit (NRT) //
// Copyright 2010-2012 by the University of Southern California (USC) //
// and the iLab at USC. //
// //
// iLab - University of Southern California //
// Hedco Neurociences Building, Room HNB-10 //
// Los Angeles, Ca 90089-2520 - USA //
// //
// See http://ilab.usc.edu for information about this project. //
// ////////////////////////////////////////////////////////////////////////
// This file is part of The iLab Neuromorphic Robotics Toolkit. //
// //
// The iLab Neuromorphic Robotics Toolkit is free software: you can //
// redistribute it and/or modify it under the terms of the GNU General //
// Public License as published by the Free Software Foundation, either //
// version 3 of the License, or (at your option) any later version. //
// //
// The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
// that it will be useful, but WITHOUT ANY WARRANTY; without even the //
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
// PURPOSE. See the GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with The iLab Neuromorphic Robotics Toolkit. If not, see //
// <http://www.gnu.org/licenses/>. //
// ////////////////////////////////////////////////////////////////////////
@endverbatim */
#include <nrt/config.h>
#include <boost/mpl/list.hpp>
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE TraitsTest
#include <boost/test/unit_test.hpp>
#include <vector>
struct E { };
struct D { };
struct A { A() { } A(A const&) { }; A(D const&) { }; explicit A(E const&) { }; };
struct B { };
struct C : public B { };
A operator+(A const& a1, A const& a2) { return A(); };
A operator-(A const& a1, A const& a2) { return A(); };
A operator*(A const& a1, A const& a2) { return A(); };
A operator/(A const& a1, A const& a2) { return A(); };
B operator*(A const& a, B const& b) { return B(); };
B operator*(B const& b, A const& a) { return B(); };
//also check for implicit conversion
BOOST_AUTO_TEST_CASE(AllTraitsTest)
{
//example of function checking mechanism
BOOST_CHECK_EQUAL(t, true);
BOOST_CHECK_EQUAL(t, false);
BOOST_CHECK_EQUAL(t, true);
BOOST_CHECK_EQUAL(t,true);
BOOST_CHECK_EQUAL(t,true);
BOOST_CHECK_EQUAL(t,true);
BOOST_CHECK_EQUAL(t,false);
BOOST_CHECK_EQUAL(t,false);
std::string str = nrt::demangle(typeid(nrt::nrt_traits<A,B>::promote_type).name());
BOOST_CHECK_EQUAL(str, "B");
BOOST_CHECK_EQUAL(str, "nrt::NotATypeError");
//check some properties
BOOST_CHECK_EQUAL(t, true);
BOOST_CHECK_EQUAL(t, true);
BOOST_CHECK_EQUAL(t, false);
BOOST_CHECK_EQUAL(t, true);
t = nrt::nrt_traits<nrt::PixRGB<int> >::is_arithmetic;
BOOST_CHECK_EQUAL(t, false);
t = nrt::nrt_traits<nrt::PixRGB<int> >::pixel_traits::is_multi_channel;
BOOST_CHECK_EQUAL(t, true);
t = nrt::nrt_traits<nrt::PixGray<int> >::pixel_traits::is_multi_channel;
BOOST_CHECK_EQUAL(t, false);
t = nrt::nrt_traits<nrt::PixRGB<int> >::pixel_traits::is_single_channel;
BOOST_CHECK_EQUAL(t, false);
t = nrt::nrt_traits<nrt::PixGray<int> >::pixel_traits::is_single_channel;
BOOST_CHECK_EQUAL(t, true);
BOOST_CHECK_EQUAL(t, true);
//check pixel helper
t = nrt::pixel_helper::are_comparable<std::vector<float>, std::vector<float>>::value;
BOOST_CHECK_EQUAL(t, false);
t = nrt::pixel_helper::are_comparable<nrt::PixRGB<float>, nrt::PixRGB<float>>::value;
BOOST_CHECK_EQUAL(t, true);
t = nrt::pixel_helper::are_comparable<nrt::PixRGB<nrt::byte>, nrt::PixRGB<float>>::value;
BOOST_CHECK_EQUAL(t, true);
t = nrt::pixel_helper::are_comparable<nrt::PixRGB<float>, nrt::PixGray<float>>::value;
BOOST_CHECK_EQUAL(t, false);
//check some promotions
BOOST_CHECK_EQUAL(t, true);
BOOST_CHECK_EQUAL(t, true);
BOOST_CHECK_EQUAL(t, true);
t = nrt::nrt_traits<std::vector<nrt::byte>,nrt::byte>::is_promotable;
BOOST_CHECK_EQUAL(t, false);
//check for operators
BOOST_CHECK_EQUAL(t,true);
BOOST_CHECK_EQUAL(t,true);
BOOST_CHECK_EQUAL(t,true);
BOOST_CHECK_EQUAL(t,true);
BOOST_CHECK_EQUAL(t,true);
BOOST_CHECK_EQUAL(t,true);
BOOST_CHECK_EQUAL(t,true);
BOOST_CHECK_EQUAL(t,true);
BOOST_CHECK_EQUAL(t,true);
BOOST_CHECK_EQUAL(t,true);
BOOST_CHECK_EQUAL(t,true);
BOOST_CHECK_EQUAL(t,false);
t = nrt::nrt_traits<nrt::PixRGB<nrt::byte>, nrt::byte>::has_arithmetic;
BOOST_CHECK_EQUAL(t,true);
t = nrt::nrt_traits<nrt::PixRGB<nrt::byte>, nrt::byte>::is_promotable;
BOOST_CHECK_EQUAL(t,true);
t = nrt::nrt_traits<nrt::PixRGB<nrt::byte>, nrt::byte>::has_assign_arithmetic;
BOOST_CHECK_EQUAL(t,true);
t = nrt::nrt_traits<nrt::PixRGB<nrt::byte>, nrt::byte>::is_comparable;
BOOST_CHECK_EQUAL(t,false);
BOOST_CHECK_EQUAL(t,false);
BOOST_CHECK_EQUAL(t,false);
BOOST_CHECK_EQUAL(t,false);
BOOST_CHECK_EQUAL(t,true);
}