1 /*
2     Copyright (c) 2020-2021 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 #if __INTEL_COMPILER && _MSC_VER
18 #pragma warning(disable : 2586) // decorated name length exceeded, name was truncated
19 #endif
20 
21 #define CONFORMANCE_BUFFERING_NODES
22 #define CONFORMANCE_QUEUE_NODE
23 
24 #include "conformance_flowgraph.h"
25 
26 //! \file conformance_priority_queue_node.cpp
27 //! \brief Test for [flow_graph.priority_queue_node] specification
28 
29 //! Test priority_queue_node single_push
30 //! \brief \ref requirement
31 TEST_CASE("priority_queue_node single_push"){
32     conformance::test_forwarding_single_push<oneapi::tbb::flow::priority_queue_node<int>>();
33 }
34 
35 //! Test function_node buffering
36 //! \brief \ref requirement
37 TEST_CASE("priority_queue_node buffering"){
38     conformance::test_buffering<oneapi::tbb::flow::priority_queue_node<int>, int>();
39 }
40 
41 //! Constructs an empty priority_queue_node that belongs to the same graph g as src.
42 //! Any intermediate state of src, including its links to predecessors and successors, is not copied.
43 //! \brief \ref requirement
44 TEST_CASE("priority_queue_node copy constructor"){
45     conformance::test_copy_ctor_for_buffering_nodes<oneapi::tbb::flow::priority_queue_node<int>>();
46 }
47 
48 //! Test inheritance relations
49 //! \brief \ref interface
50 TEST_CASE("priority_queue_node superclasses"){
51     conformance::test_inheritance<oneapi::tbb::flow::priority_queue_node<int>, int, int>();
52     conformance::test_inheritance<oneapi::tbb::flow::priority_queue_node<void*>, void*, void*>();
53 }
54 
55 //! Test priority_queue_node node `try_put()` and `try_get()`
56 //! \brief \ref requirement
57 TEST_CASE("priority_queue_node methods"){
58     oneapi::tbb::flow::graph g;
59 
60     oneapi::tbb::flow::priority_queue_node<int, std::greater<int>> testing_node(g);
61 
62     testing_node.try_put(2);
63     testing_node.try_put(3);
64     testing_node.try_put(1);
65     g.wait_for_all();
66 
67     int tmp = -1;
68     CHECK_MESSAGE((testing_node.try_get(tmp)), "Get should succeed");
69     CHECK_MESSAGE((tmp == 1), "Values should get sorted");
70     CHECK_MESSAGE((testing_node.try_get(tmp)), "Get should succeed");
71     CHECK_MESSAGE((tmp == 2), "Values should get sorted");
72     CHECK_MESSAGE((testing_node.try_get(tmp)), "Get should succeed");
73     CHECK_MESSAGE((tmp == 3), "Values should get sorted");
74 }
75