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_OVERWRITE_NODE
23 
24 #include "conformance_flowgraph.h"
25 
26 //! \file conformance_write_once_node.cpp
27 //! \brief Test for [flow_graph.write_once_node] specification
28 
29 //! Test function_node broadcast
30 //! \brief \ref requirement
31 TEST_CASE("write_once_node broadcast"){
32     conformance::test_forwarding<oneapi::tbb::flow::write_once_node<int>, int>(1);
33 }
34 
35 //! Test write_once_node buffering
36 //! \brief \ref requirement
37 TEST_CASE("write_once_node buffering"){
38     conformance::test_buffering<oneapi::tbb::flow::write_once_node<int>, int>();
39 }
40 
41 //! The node that is constructed has a reference to the same graph object as src,with an invalid internal buffer item.
42 //! The buffered value and list of successors are not copied from src.
43 //! \brief \ref requirement
44 TEST_CASE("write_once_node copy constructor"){
45     conformance::test_copy_ctor_for_buffering_nodes<oneapi::tbb::flow::write_once_node<int>>();
46 }
47 
48 //! Test inheritance relations
49 //! \brief \ref interface
50 TEST_CASE("write_once_node superclasses"){
51     conformance::test_inheritance<oneapi::tbb::flow::write_once_node<int>, int, int>();
52     conformance::test_inheritance<oneapi::tbb::flow::write_once_node<void*>, void*, void*>();
53 }
54 
55 //! Test overwrite_node node constructor
56 //! \brief \ref requirement
57 TEST_CASE("write_once_node constructor"){
58     oneapi::tbb::flow::graph g;
59     oneapi::tbb::flow::overwrite_node<int> testing_node(g);
60 
61     int tmp = -1;
62     CHECK_MESSAGE((!testing_node.is_valid()), "Constructed node has invalid internal buffer item");
63     CHECK_MESSAGE((!testing_node.try_get(tmp)), "Gets from the node are non-destructive, but the first `try_get' fails");
64 }
65 
66 //! Test write_once_node node `is_valid()` and `clear()`
67 //! \brief \ref requirement
68 TEST_CASE("write_once_node methods"){
69     oneapi::tbb::flow::graph g;
70     oneapi::tbb::flow::write_once_node<int> testing_node(g);
71 
72     CHECK_MESSAGE((!testing_node.is_valid()), "Constructed node has invalid internal buffer item");
73 
74     testing_node.try_put(1);
75 
76     CHECK_MESSAGE((testing_node.is_valid()), "Buffer must be valid after try_put call");
77 
78     testing_node.clear();
79 
80     CHECK_MESSAGE((!testing_node.is_valid()), "call `clear` invalidates the value held in the buffer.");
81 }
82 
83 //! The following test shows the possibility to connect the node to a reserving join_node,
84 //! avoiding direct calls to the try_get() method from the body of the successor node
85 //! \brief \ref requirement
86 TEST_CASE("write_once_node with reserving join_node as successor"){
87     conformance::test_with_reserving_join_node_class<oneapi::tbb::flow::write_once_node<int>>();
88 }
89