1 /* 2 Copyright (c) 2005-2020 Intel Corporation 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 #define MAX_TUPLE_TEST_SIZE 10 18 #include "common/config.h" 19 20 #include "test_join_node.h" 21 22 23 //! \file test_join_node_key_matching.cpp 24 //! \brief Test for [flow_graph.join_node] specification 25 26 27 #if __TBB_CPP17_DEDUCTION_GUIDES_PRESENT 28 void test_deduction_guides() { 29 using namespace tbb::flow; 30 using tuple_type = std::tuple<int, int, double>; 31 32 graph g; 33 auto body_int = [](const int&)->int { return 1; }; 34 auto body_double = [](const double&)->int { return 1; }; 35 36 join_node j1(g, body_int, body_int, body_double); 37 static_assert(std::is_same_v<decltype(j1), join_node<tuple_type, key_matching<int>>>); 38 39 #if __TBB_PREVIEW_FLOW_GRAPH_NODE_SET 40 broadcast_node<int> b1(g), b2(g); 41 broadcast_node<double> b3(g); 42 broadcast_node<tuple_type> b4(g); 43 44 join_node j2(follows(b1, b2, b3), body_int, body_int, body_double); 45 static_assert(std::is_same_v<decltype(j2), join_node<tuple_type, key_matching<int>>>); 46 47 join_node j3(precedes(b4), body_int, body_int, body_double); 48 static_assert(std::is_same_v<decltype(j3), join_node<tuple_type, key_matching<int>>>); 49 #endif 50 51 join_node j4(j1); 52 static_assert(std::is_same_v<decltype(j4), join_node<tuple_type, key_matching<int>>>); 53 } 54 #endif 55 56 template <typename T1, typename T2> 57 using make_tuple = decltype(std::tuple_cat(T1(), std::tuple<T2>())); 58 using T1 = std::tuple<MyKeyFirst<std::string, double>>; 59 using T2 = make_tuple<T1, MyKeySecond<std::string, int>>; 60 using T3 = make_tuple<T2, MyKeyFirst<std::string, int>>; 61 using T4 = make_tuple<T3, MyKeyWithBrokenMessageKey<std::string, size_t>>; 62 using T5 = make_tuple<T4, MyKeyWithBrokenMessageKey<std::string, int>>; 63 using T6 = make_tuple<T5, MyKeySecond<std::string, short>>; 64 using T7 = make_tuple<T6, MyKeySecond<std::string, threebyte>>; 65 using T8 = make_tuple<T7, MyKeyFirst<std::string, int>>; 66 using T9 = make_tuple<T8, MyKeySecond<std::string, threebyte>>; 67 using T10 = make_tuple<T9, MyKeyWithBrokenMessageKey<std::string, size_t>>; 68 69 //! Test serial key matching on special input types 70 //! \brief \ref error_guessing 71 TEST_CASE("Serial test on tuples") { 72 INFO("key_matching\n"); 73 generate_test<serial_test, std::tuple<MyKeyFirst<int, double>, MyKeySecond<int, float> >, tbb::flow::key_matching<int> >::do_test(); 74 generate_test<serial_test, std::tuple<MyKeyFirst<std::string, double>, MyKeySecond<std::string, float> >, tbb::flow::key_matching<std::string> >::do_test(); 75 generate_test<serial_test, std::tuple<MyKeyFirst<std::string, double>, MyKeySecond<std::string, float>, MyKeyWithBrokenMessageKey<std::string, int> >, tbb::flow::key_matching<std::string&> >::do_test(); 76 } 77 78 //! Serial test with different tuple sizes 79 //! \brief \ref error_guessing 80 TEST_CASE_TEMPLATE("Serial N tests on tuples", T, T2, T3, T4, T5, T6, T7, T8, T9, T10) { 81 generate_test<serial_test, T, tbb::flow::key_matching<std::string&>>::do_test(); 82 } 83 84 #if __TBB_CPP17_DEDUCTION_GUIDES_PRESENT 85 //! Test deduction guides 86 //! \brief \ref requirement 87 TEST_CASE("Test deduction guides"){ 88 test_deduction_guides(); 89 } 90 #endif 91 92 //! Test parallel key matching on special input types 93 //! \brief \ref error_guessing 94 TEST_CASE("Parallel test on tuples"){ 95 generate_test<parallel_test, std::tuple<MyKeyFirst<int, double>, MyKeySecond<int, float> >, tbb::flow::key_matching<int> >::do_test(); 96 generate_test<parallel_test, std::tuple<MyKeyFirst<int, double>, MyKeySecond<int, float> >, tbb::flow::key_matching<int&> >::do_test(); 97 generate_test<parallel_test, std::tuple<MyKeyFirst<std::string, double>, MyKeySecond<std::string, float> >, tbb::flow::key_matching<std::string&> >::do_test(); 98 } 99 100 //! Parallel test with different tuple sizes 101 //! \brief \ref error_guessing 102 TEST_CASE_TEMPLATE("Parallel N tests on tuples", T, T2, T3, T4, T5, T6, T7, T8, T9, T10) { 103 generate_test<parallel_test, T, tbb::flow::key_matching<std::string&>>::do_test(); 104 } 105