#include #include #include #include using namespace llarp; TEST(traits_bottom, Smoke) { traits::Bottom bottom; (void)bottom; SUCCEED(); } template < typename T > class IsContainer : public ::testing::Test { }; TYPED_TEST_SUITE_P(IsContainer); TYPED_TEST_P(IsContainer, Smoke) { bool expected = std::tuple_element_t< 1, TypeParam >::value; bool result = traits::is_container< std::tuple_element_t< 0, TypeParam > >::value; ASSERT_EQ(expected, result); } REGISTER_TYPED_TEST_SUITE_P(IsContainer, Smoke); // clang-format off using ContainerTypes = ::testing::Types< std::tuple< std::vector< int >, std::integral_constant< bool, true > >, std::tuple< std::vector< std::string >, std::integral_constant< bool, true > >, std::tuple< std::list< std::string >, std::integral_constant< bool, true > >, std::tuple< std::string, std::integral_constant< bool, true > >, std::tuple< std::shared_ptr, std::integral_constant< bool, false > >, std::tuple< std::tuple, std::integral_constant< bool, false > >, std::tuple< int, std::integral_constant< bool, false > > >; INSTANTIATE_TYPED_TEST_SUITE_P(traits, IsContainer, ContainerTypes); struct A { }; struct B { }; struct C { }; struct D { }; struct E { }; struct F { }; struct G { }; struct H { }; struct I { }; struct J { }; char f(A) { return 'A'; } char f(B) { return 'B'; } char f(C) { return 'C'; } char f(D) { return 'D'; } char f(E) { return 'E'; } char f(F) { return 'F'; } char f(G) { return 'G'; } char f(H) { return 'H'; } char f(I) { return 'I'; } char f(J) { return 'J'; } char f(traits::Bottom) { return '0'; } // clang-format on template < typename T > class TestSwitch : public ::testing::Test { }; TYPED_TEST_SUITE_P(TestSwitch); TYPED_TEST_P(TestSwitch, Smoke) { char expected = std::tuple_element_t< 0, TypeParam >::value; using InputType = typename std::tuple_element_t< 1, TypeParam >::Type; char result = f(InputType()); ASSERT_EQ(expected, result); } REGISTER_TYPED_TEST_SUITE_P(TestSwitch, Smoke); // clang-format off using namespace traits::Switch; using SwitchTypes = ::testing::Types< std::tuple, Switch< 0, A, B, C, D, E, F, G, H, I, J > >, std::tuple, Switch< 1, A, B, C, D, E, F, G, H, I, J > >, std::tuple, Switch< 2, A, B, C, D, E, F, G, H, I, J > >, std::tuple, Switch< 3, A, B, C, D, E, F, G, H, I, J > >, std::tuple, Switch< 4, A, B, C, D, E, F, G, H, I, J > >, std::tuple, Switch< 5, A, B, C, D, E, F, G, H, I, J > >, std::tuple, Switch< 6, A, B, C, D, E, F, G, H, I, J > >, std::tuple, Switch< 7, A, B, C, D, E, F, G, H, I, J > >, std::tuple, Switch< 8, A, B, C, D, E, F, G, H, I, J > >, std::tuple, Switch< 9, A, B, C, D, E, F, G, H, I, J > >, std::tuple, Switch< 9, C, C, C, C, C, C, C, C, C, J > >, std::tuple, Switch< 6, C, C, C, C, C, C, C, C, C, J > >, std::tuple, Switch< 10, A, B, C, D, E, F, G, H, I, J > > >; INSTANTIATE_TYPED_TEST_SUITE_P(traits, TestSwitch, SwitchTypes); template using is_bool = std::is_same; template using is_char = std::is_same; template using is_string = std::is_same; char dispatch(traits::select::Case<>) { return '0'; } char dispatch(traits::select::Case) { return 'b'; } char dispatch(traits::select::Case) { return 'c'; } char dispatch(traits::select::Case) { return 's'; } template < typename Type > char selectCase() { using Selection = traits::select::Select; return dispatch(Selection()); } template < typename T > class Select : public ::testing::Test { }; TYPED_TEST_SUITE_P(Select); TYPED_TEST_P(Select, Smoke) { char expected = std::tuple_element_t< 0, TypeParam >::value; char result = selectCase >(); ASSERT_EQ(expected, result); } REGISTER_TYPED_TEST_SUITE_P(Select, Smoke); using SelectTypes = ::testing::Types< std::tuple, double >, std::tuple, bool >, std::tuple, char >, std::tuple, std::string > >; INSTANTIATE_TYPED_TEST_SUITE_P(traits, Select, SelectTypes); // clang-format on