Lumiera  0.pre.03
»edit your freedom«
life-cycle-test.cpp
Go to the documentation of this file.
1 /*
2  LifeCycle(Test) - checking the lifecycle callback hooks provided by AppState
3 
4  Copyright (C) Lumiera.org
5  2008, 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 
29 #include "lib/test/run.hpp"
30 #include "lib/util.hpp"
31 
32 #include "include/lifecycle.h"
33 
34 
35 
36 
37 namespace lumiera{
38 namespace test {
39 
40  uint basicInit (0);
41  uint customCallback (0);
42 
43  void basicInitHook () { ++basicInit; }
44  void myCallback() { ++customCallback; }
45 
46  const char* MY_DEADLY_EVENT = "dial M for murder";
47 
48 
49  namespace // register them to be invoked by lifecycle event id
50  {
51  LifecycleHook _schedule1 (ON_BASIC_INIT, &basicInitHook);
52  LifecycleHook _schedule2 (MY_DEADLY_EVENT, &myCallback);
53  }
54 
55 
60  class LifeCycle_test : public Test
61  {
62  virtual void
63  run (Arg)
64  {
65  CHECK (basicInit, "the basic-init callback hasn't been invoked automatically");
66  CHECK (1 == basicInit, "the basic-init callback has been invoked more than once");
67 
68  CHECK (!customCallback);
69  LifecycleHook::trigger (MY_DEADLY_EVENT);
70  CHECK ( 1 == customCallback);
71  }
72 
73  };
74 
75  LAUNCHER (LifeCycle_test, "function common");
76 
77 
78 
79 
80 }} // namespace util::test
81 
const char * ON_BASIC_INIT
automatic static init. treated specially to run as soon as possible
Installing and invoking of application lifecycle event callbacks.
Definition: run.hpp:49
static void trigger(Symbol eventLabel)
trigger lifecycle callbacks registered under the given label
Definition: lifecycle.cpp:82
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
define and register a callback for a specific lifecycle event.
Definition: lifecycle.h:76
Lumiera public interface.
Definition: advice.cpp:113