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_queue_node.cpp
27 //! \brief Test for [flow_graph.queue_node] specification
28 
29 //! Test queue_node single_push
30 //! \brief \ref requirement
31 TEST_CASE("queue_node single_push"){
32     conformance::test_forwarding_single_push<oneapi::tbb::flow::queue_node<int>>();
33 }
34 
35 //! Test function_node buffering
36 //! \brief \ref requirement
37 TEST_CASE("queue_node buffering"){
38     conformance::test_buffering<oneapi::tbb::flow::queue_node<int>, int>();
39 }
40 
41 //! Constructs an empty 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("queue_node copy constructor"){
45     conformance::test_copy_ctor_for_buffering_nodes<oneapi::tbb::flow::queue_node<int>>();
46 }
47 
48 //! Test inheritance relations
49 //! \brief \ref interface
50 TEST_CASE("queue_node superclasses"){
51     conformance::test_inheritance<oneapi::tbb::flow::queue_node<int>, int, int>();
52     conformance::test_inheritance<oneapi::tbb::flow::queue_node<void*>, void*, void*>();
53 }
54 
55 //! Test queue_node node `try_put()` and `try_get()`
56 //! \brief \ref requirement
57 TEST_CASE("queue_node methods"){
58     oneapi::tbb::flow::graph g;
59     oneapi::tbb::flow::queue_node<int> testing_node(g);
60 
61     int tmp1 = -1;
62     int tmp2 = -1;
63 
64     CHECK_MESSAGE((!testing_node.try_get(tmp1) && tmp1 == -1), "`try_get` must returns false if there is no non-reserved item currently in the node.");
65 
66     testing_node.try_put(1);
67     testing_node.try_put(2);
68     g.wait_for_all();
69 
70     testing_node.try_get(tmp1);
71     CHECK_MESSAGE((tmp1 == 1), "Messages must be an FIFO order");
72 
73     testing_node.try_get(tmp2);
74     CHECK_MESSAGE((tmp2 == 2), "Additional `try_get()' does not receive the same value as previous");
75 }
76