DetectorGraph  2.0
graphtestutils.cpp
Go to the documentation of this file.
1 // Copyright 2017 Nest Labs, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "graphtestutils.hpp"
16 #include "dglogging.hpp"
17 
18 namespace DetectorGraph
19 {
20 
21 namespace GraphTestUtils
22 {
23 
24  /*
25  * These are quickhand utilities for composing unit tests
26  * for Detectors implemented using DetectorGraph
27  */
28 
29  void Flush(Graph& aGraph)
30  {
31  while (aGraph.HasDataPending()) { aGraph.EvaluateGraph(); }
32  }
33 
34 #if !defined(BUILD_FEATURE_DETECTORGRAPH_CONFIG_LITE)
35  void PrintOutputs(Graph& aGraph)
36  {
37  DG_LOG("-----Graph::GetOutputList() contains:-----");
38  const std::list<ptr::shared_ptr<const TopicState> > outputs = aGraph.GetOutputList();
39  for (std::list<ptr::shared_ptr<const TopicState> >::const_iterator it = outputs.begin();
40  it != outputs.end();
41  ++it)
42  {
43  DG_LOG("Output contains %s\n", (*it)->GetName());
44  }
45  DG_LOG("---------------------DONE------------------------");
46  }
47 #endif
48 
49 } // namespace GraphTestUtils
50 
51 } // namespace DetectorGraph
void PrintOutputs(Graph &aGraph)
Implements a graph of Topics & Detectors with Input/Output APIs.
Definition: graph.hpp:127
void DG_LOG(const char *aLogString,...)
Definition: dglogging.cpp:22
bool HasDataPending()
Returns true if there is data pending evaluation.
Definition: graph.cpp:97
const std::list< ptr::shared_ptr< const TopicState > > & GetOutputList() const
Returns the list of topicstates published in the last Evaluation.
Definition: graph.cpp:338
ErrorType EvaluateGraph()
Evaluate the whole graph.
Definition: graph.cpp:133