1 /* 2 Copyright (c) 2005-2022 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 // Message based key matching is a preview feature 18 #define TBB_PREVIEW_FLOW_GRAPH_FEATURES 1 19 20 #include "common/config.h" 21 22 #include "test_join_node.h" 23 24 //! \file test_join_node_msg_key_matching.cpp 25 //! \brief Test for [preview] functionality 26 27 #if __TBB_CPP17_DEDUCTION_GUIDES_PRESENT 28 struct message_key { 29 int my_key; 30 double my_value; 31 32 int key() const { return my_key; } 33 34 operator size_t() const { return my_key; } 35 36 bool operator==(const message_key& rhs) { return my_value == rhs.my_value; } 37 }; 38 39 void test_deduction_guides() { 40 using namespace tbb::flow; 41 using tuple_type = std::tuple<message_key, message_key>; 42 43 graph g; 44 broadcast_node<message_key> bm1(g), bm2(g); 45 broadcast_node<tuple_type> bm3(g); 46 join_node<tuple_type, key_matching<int> > j0(g); 47 join_node j3(j0); 48 static_assert(std::is_same_v<decltype(j3), join_node<tuple_type, key_matching<int>>>); 49 } 50 #endif 51 52 //! Serial test with matching policies 53 //! \brief \ref error_guessing 54 TEST_CASE("Serial test") { 55 generate_test<serial_test, std::tuple<MyMessageKeyWithBrokenKey<int, double>, MyMessageKeyWithoutKey<int, float> >, message_based_key_matching<int> >::do_test(); 56 generate_test<serial_test, std::tuple<MyMessageKeyWithoutKeyMethod<std::string, double>, MyMessageKeyWithBrokenKey<std::string, float> >, message_based_key_matching<std::string> >::do_test(); 57 } 58 59 //! Parallel test with special key types 60 //! \brief \ref error_guessing 61 TEST_CASE("Parallel test"){ 62 generate_test<parallel_test, std::tuple<MyMessageKeyWithBrokenKey<int, double>, MyMessageKeyWithoutKey<int, float> >, message_based_key_matching<int> >::do_test(); 63 generate_test<parallel_test, std::tuple<MyMessageKeyWithoutKeyMethod<int, double>, MyMessageKeyWithBrokenKey<int, float> >, message_based_key_matching<int&> >::do_test(); 64 generate_test<parallel_test, std::tuple<MyMessageKeyWithoutKey<std::string, double>, MyMessageKeyWithoutKeyMethod<std::string, float> >, message_based_key_matching<std::string&> >::do_test(); 65 } 66 67 #if __TBB_CPP17_DEDUCTION_GUIDES_PRESENT 68 //! Test deduction guides 69 //! \brief \ref requirement 70 TEST_CASE("Deduction guides test"){ 71 test_deduction_guides(); 72 } 73 #endif 74