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) Lumiera.org
5  2010, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
28 #include "lib/test/run.hpp"
29 //#include "lib/test/test-helper.hpp"
30 
31 #include "common/advice.hpp"
32 
33 
34 
35 namespace lumiera {
36 namespace advice {
37 namespace test {
38 
39  namespace {
40  }
41 
42 
43 
44  /**************************************************************************************/
54  class AdviceSituations_test : public Test
55  {
56 
57  virtual void
58  run (Arg)
59  {
63  TODO ("more advice usage scenarios.....?");
64  }
65 
66 
68  void
70  {
71  Request<int> generic{"solution(life_and_universe_and_everything)"};
72  CHECK (0 == generic.getAdvice()); // the early bird gets the worm...
73 
74  Provision<int> universal{"solution(life_and_universe_and_everything)"};
75  universal.setAdvice(5);
76  CHECK (5 == generic.getAdvice()); // ...while the bad girls go everywhere
77 
78  universal.retractAdvice();
79  CHECK (0 == generic.getAdvice()); // nothing to see here, just move on
80  }
81 
82 
84  void
86  {
87  Request<int> request{"something(special)"};
88  CHECK (not request.isMatched());
89 
90  Provision<int> info{"something(special)"};
91  info.setAdvice(55);
92  CHECK (request.isMatched());
93  CHECK (55 == request.getAdvice());
94 
95  info.retractAdvice();
96  CHECK (not request.isMatched());
97  }
98 
99 
101  void
103  {
104  Provision<int> info{"something(special)"};
105  CHECK (not info.isGiven());
106 
107  Request<int> question{"something(special)"};
108  CHECK (0 == question.getAdvice());
109  CHECK (not question.isMatched());
110 
111  auto publish = [&](int i)
112  {
113  if (not info.isGiven())
114  info.setAdvice (i);
115  };
116 
117  for (uint i=0; i<5; ++i)
118  if (i % 2)
119  publish (i);
120 
121  CHECK (1 == question.getAdvice());
122  CHECK (question.isMatched());
123 
124  info.retractAdvice();
125  CHECK (not info.isGiven());
126  CHECK (not question.isMatched());
127  }
128 
129 
130 #if false
131 
132  void
133  check_SevenMoreWondersOfTheWorld()
134  {
135  UNIMPLEMENTED ("suitable advice to save the world");
136  }
137 #endif
138 
139  // more to come.....
140 
141  };
142 
143 
144 
146  LAUNCHER (AdviceSituations_test, "function common");
147 
148 
149 }}} // namespace lumiera::advice::test
Definition: run.hpp:49
Expecting Advice and giving Advice: a cross-cutting collaboration of loosely coupled participants...
Simple test class runner.
Lumiera public interface.
Definition: advice.cpp:113