/*! * \file Tinvoke.cpp * * Copyright (C) 2018-2019 Christos Choutouridis * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * This program 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * */ #include #include #include namespace test_meta { using namespace utl; /* * Types to behave like Fixtures */ int Ifun(int i) { return i; } struct Ifoo { int operator() (int i) { return i; } }; struct Ibar { Ibar(int num) : num_(num) {} int echo(int i) const { return i; } int get() const { return num_; } int num_; }; /* * Test invoke() */ TEST(Tinvoke, Invoke) { Ifoo ifoo{}; const Ibar ibar{42}; EXPECT_EQ (42, invoke(Ifun, 42)); EXPECT_EQ (42, invoke([] () { return Ifun(42); })); EXPECT_EQ (42, invoke(Ifoo{}, 42)); EXPECT_EQ (42, invoke(ifoo, 42)); EXPECT_EQ (42, invoke(&Ibar::echo, ibar, 42)); EXPECT_EQ (42, invoke(&Ibar::get, ibar)); EXPECT_EQ (true, (is_invocable::value)); EXPECT_EQ (false, (is_invocable::value)); EXPECT_EQ (false, (is_invocable::value)); EXPECT_EQ (false, (is_invocable::value)); EXPECT_EQ (true, (is_invocable_r::value)); EXPECT_EQ (false, (is_invocable_r::value)); EXPECT_EQ (false, (is_invocable_r::value)); EXPECT_EQ (true, (std::is_same>())); EXPECT_EQ (true, (std::is_same>())); EXPECT_EQ (true, (std::is_same>())); } }