Lumiera  0.pre.03
»edit your freedom«
advice-situations-test.cpp
Go to the documentation of this file.
1 /*
2  AdviceSituations(Test) - catalogue of standard Advice usage scenarios
3 
4  Copyright (C)
5  2010, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
19 #include "lib/test/run.hpp"
20 //#include "lib/test/test-helper.hpp"
21 
22 #include "common/advice.hpp"
23 
24 
25 
26 namespace lumiera {
27 namespace advice {
28 namespace test {
29 
30  namespace {
31  }
32 
33 
34 
35  /**************************************************************************************/
45  class AdviceSituations_test : public Test
46  {
47 
48  virtual void
49  run (Arg)
50  {
54  TODO ("more advice usage scenarios.....?");
55  }
56 
57 
59  void
61  {
62  Request<int> generic{"solution(life_and_universe_and_everything)"};
63  CHECK (0 == generic.getAdvice()); // the early bird gets the worm...
64 
65  Provision<int> universal{"solution(life_and_universe_and_everything)"};
66  universal.setAdvice(5);
67  CHECK (5 == generic.getAdvice()); // ...while the bad girls go everywhere
68 
69  universal.retractAdvice();
70  CHECK (0 == generic.getAdvice()); // nothing to see here, just move on
71  }
72 
73 
75  void
77  {
78  Request<int> request{"something(special)"};
79  CHECK (not request.isMatched());
80 
81  Provision<int> info{"something(special)"};
82  info.setAdvice(55);
83  CHECK (request.isMatched());
84  CHECK (55 == request.getAdvice());
85 
86  info.retractAdvice();
87  CHECK (not request.isMatched());
88  }
89 
90 
92  void
94  {
95  Provision<int> info{"something(special)"};
96  CHECK (not info.isGiven());
97 
98  Request<int> question{"something(special)"};
99  CHECK (0 == question.getAdvice());
100  CHECK (not question.isMatched());
101 
102  auto publish = [&](int i)
103  {
104  if (not info.isGiven())
105  info.setAdvice (i);
106  };
107 
108  for (uint i=0; i<5; ++i)
109  if (i % 2)
110  publish (i);
111 
112  CHECK (1 == question.getAdvice());
113  CHECK (question.isMatched());
114 
115  info.retractAdvice();
116  CHECK (not info.isGiven());
117  CHECK (not question.isMatched());
118  }
119 
120 
121 #if false
122 
123  void
124  check_SevenMoreWondersOfTheWorld()
125  {
126  UNIMPLEMENTED ("suitable advice to save the world");
127  }
128 #endif
129 
130  // more to come.....
131 
132  };
133 
134 
135 
137  LAUNCHER (AdviceSituations_test, "function common");
138 
139 
140 }}} // namespace lumiera::advice::test
Definition: run.hpp:40
Expecting Advice and giving Advice: a cross-cutting collaboration of loosely coupled participants...
Simplistic test class runner.
Lumiera public interface.
Definition: advice.cpp:104