// Copyright 2016 The Android Open Source Project // // This software is licensed under the terms of the GNU General Public // License version 2, as published by the Free Software Foundation, and // may be copied, distributed, and modified under those terms. // // 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 General Public License for more details. #include "anbox/common/type_traits.h" #include #include #include #include #include namespace anbox { namespace common { TEST(TypeTraits, IsCallable) { class C; C* c = nullptr; auto lambda = [c](bool) -> C* { return nullptr; }; static_assert(is_callable_as::value, "simple function"); static_assert(is_callable_as::value, "function reference"); static_assert(is_callable_as::value, "function pointer"); static_assert(is_callable_as::value, "function with arguments and return type"); static_assert(is_callable_as::value, "lambda"); static_assert(is_callable_as, bool(int)>::value, "std::function"); static_assert(!is_callable_as::value, "int should not be callable"); static_assert(!is_callable_as::value, "incomplete type"); static_assert(!is_callable_as::value, "different arguments"); static_assert(!is_callable_as::value, "different return types"); static_assert(!is_callable_as::value, "slightly different return types"); static_assert(!is_callable_as::value, "more arguments"); static_assert(!is_callable_as::value, "less arguments"); static_assert(!is_callable_as::value, "bad required signature"); } TEST(TypeTraits, IsTemplateInstantiation) { static_assert(!is_template_instantiation_of::value, "int is not an instance of vector"); static_assert(!is_template_instantiation_of>, std::vector>::value, "list is not an instance of vector"); static_assert(is_template_instantiation_of, std::vector>::value, "std::vector is an instance of vector"); static_assert(is_template_instantiation_of>>, std::vector>::value, "nested std::vector<> is an instance of vector"); } TEST(TypeTraits, IsRange) { static_assert(is_range>::value, "vector<> should be detected as a range"); static_assert(is_range>>::value, "const list<> should be detected as a range"); static_assert(is_range, 10>>::value, "array<> should be detected as a range"); char arr[100]; static_assert(is_range::value, "C array should be detected as a range"); static_assert(is_range::value, "String literal should be detected as a range"); static_assert(!is_range::value, "int shouldn't be a range"); static_assert(!is_range::value, "int* shouldn't be a range"); static_assert(!is_range::value, "even const int* shouldn't be a range"); } } // namespace common } // namespace anbox