Committing TBB 2019 Update 9 source code
[platform/upstream/tbb.git] / src / test / test_join_node_msg_key_matching.cpp
1 /*
2     Copyright (c) 2005-2019 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 // This preview feature depends on
21 // TBB_PREVIEW_FLOW_GRAPH_FEATURES macro, and should not accidentally be dependent on
22 // this deprecated feature
23 #define TBB_DEPRECATED_FLOW_NODE_EXTRACTION 0
24
25 #include "test_join_node.h"
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
48 #if __TBB_PREVIEW_FLOW_GRAPH_NODE_SET
49     join_node j1(follows(bm1, bm2), key_matching<int>());
50     static_assert(std::is_same_v<decltype(j1), join_node<tuple_type, key_matching<int>>>);
51
52     join_node j2(precedes(bm3), key_matching<int>());
53     static_assert(std::is_same_v<decltype(j2), join_node<tuple_type, key_matching<int>>>);
54 #endif
55
56     join_node j3(j0);
57     static_assert(std::is_same_v<decltype(j3), join_node<tuple_type, key_matching<int>>>);
58 }
59 #endif
60
61 int TestMain() {
62 #if __TBB_USE_TBB_TUPLE
63     REMARK("  Using TBB tuple\n");
64 #else
65     REMARK("  Using platform tuple\n");
66 #endif
67
68 #if !__TBB_MIC_OFFLOAD_TEST_COMPILATION_BROKEN
69     generate_test<serial_test, tbb::flow::tuple<MyMessageKeyWithBrokenKey<int, double>, MyMessageKeyWithoutKey<int, float> >, message_based_key_matching<int> >::do_test();
70     generate_test<serial_test, tbb::flow::tuple<MyMessageKeyWithoutKeyMethod<std::string, double>, MyMessageKeyWithBrokenKey<std::string, float> >, message_based_key_matching<std::string> >::do_test();
71 #if MAX_TUPLE_TEST_SIZE >= 3
72     generate_test<serial_test, tbb::flow::tuple<MyMessageKeyWithoutKey<std::string, double>, MyMessageKeyWithoutKeyMethod<std::string, float>, MyMessageKeyWithBrokenKey<std::string, int> >, message_based_key_matching<std::string&> >::do_test();
73 #endif
74 #if MAX_TUPLE_TEST_SIZE >= 7
75     generate_test<serial_test, tbb::flow::tuple<
76         MyMessageKeyWithoutKey<std::string, double>,
77         MyMessageKeyWithoutKeyMethod<std::string, int>,
78         MyMessageKeyWithBrokenKey<std::string, int>,
79         MyMessageKeyWithoutKey<std::string, size_t>,
80         MyMessageKeyWithoutKeyMethod<std::string, int>,
81         MyMessageKeyWithBrokenKey<std::string, short>,
82         MyMessageKeyWithoutKey<std::string, threebyte>
83     >, message_based_key_matching<std::string&> >::do_test();
84 #endif
85
86     generate_test<parallel_test, tbb::flow::tuple<MyMessageKeyWithBrokenKey<int, double>, MyMessageKeyWithoutKey<int, float> >, message_based_key_matching<int> >::do_test();
87     generate_test<parallel_test, tbb::flow::tuple<MyMessageKeyWithoutKeyMethod<int, double>, MyMessageKeyWithBrokenKey<int, float> >, message_based_key_matching<int&> >::do_test();
88     generate_test<parallel_test, tbb::flow::tuple<MyMessageKeyWithoutKey<std::string, double>, MyMessageKeyWithoutKeyMethod<std::string, float> >, message_based_key_matching<std::string&> >::do_test();
89
90
91 #if __TBB_CPP17_DEDUCTION_GUIDES_PRESENT
92     test_deduction_guides();
93 #endif
94
95 #if MAX_TUPLE_TEST_SIZE >= 10
96     generate_test<parallel_test, tbb::flow::tuple<
97         MyMessageKeyWithoutKeyMethod<std::string, double>,
98         MyMessageKeyWithBrokenKey<std::string, int>,
99         MyMessageKeyWithoutKey<std::string, int>,
100         MyMessageKeyWithoutKeyMethod<std::string, size_t>,
101         MyMessageKeyWithBrokenKey<std::string, int>,
102         MyMessageKeyWithoutKeyMethod<std::string, short>,
103         MyMessageKeyWithoutKeyMethod<std::string, threebyte>,
104         MyMessageKeyWithBrokenKey<std::string, int>,
105         MyMessageKeyWithoutKeyMethod<std::string, threebyte>,
106         MyMessageKeyWithBrokenKey<std::string, size_t>
107     >, message_based_key_matching<std::string&> >::do_test();
108 #endif
109 #endif /* __TBB_MIC_OFFLOAD_TEST_COMPILATION_BROKEN */
110
111     generate_test<serial_test, tbb::flow::tuple<MyMessageKeyWithBrokenKey<int, double>, MyMessageKeyWithoutKey<int, float> >, message_based_key_matching<int> >::do_test();
112     generate_test<serial_test, tbb::flow::tuple<MyMessageKeyWithoutKeyMethod<std::string, double>, MyMessageKeyWithBrokenKey<std::string, float> >, message_based_key_matching<std::string> >::do_test();
113
114     return Harness::Done;
115 }