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