1 /*******************************************************************************
2 
3     Test for the TimerExt behaviour.
4 
5     Copyright:
6         Copyright (c) 2017 dunnhumby Germany GmbH.
7         All rights reserved.
8 
9     License:
10         Boost Software License Version 1.0. See LICENSE_BOOST.txt for details.
11         Alternatively, this file may be distributed under the terms of the Tango
12         3-Clause BSD License (see LICENSE_BSD.txt for details).
13 
14 
15 *******************************************************************************/
16 
17 module integrationtest.timerext.main;
18 
19 import ocean.core.Test;
20 import ocean.meta.types.Qualifiers;
21 import ocean.util.app.Application;
22 import ocean.util.app.ext.TimerExt;
23 import ocean.util.test.DirectorySandbox;
24 import ocean.io.device.File;
25 
26 class App : Application
27 {
28     import ocean.io.select.EpollSelectDispatcher;
29     import ocean.meta.types.Qualifiers;
30 
31     private EpollSelectDispatcher epoll;
32     private TimerExt timers;
33     private int trigger_count;
34 
35     public this ( )
36     {
37         super("", "");
38 
39         this.epoll = new EpollSelectDispatcher;
40         this.timers = new TimerExt(this.epoll);
41         this.registerExtension(this.timers);
42     }
43 
44     override protected int run ( istring[] args )
45     {
46         // Register some timed events
47         this.timers.register(&this.first, 0.0001);
48         this.timers.register(&this.second, 0.0002);
49         this.timers.register(&this.third, 0.0003);
50 
51         this.epoll.eventLoop();
52 
53         return 0;
54     }
55 
56     private bool first ( )
57     {
58         return false;
59     }
60 
61     private bool second ( )
62     {
63         this.trigger_count++;
64         if (this.trigger_count < 3)
65         {
66             throw new Exception("throw from the handler.");
67         }
68         else
69         {
70             return false;
71         }
72     }
73 
74     private bool third ( )
75     {
76         return false;
77     }
78 }
79 
80 version (unittest) {} else
81 void main (istring[] args)
82 {
83     auto sandbox = DirectorySandbox.create(["etc", "log"]);
84 
85     File.set("etc/config.ini", "[LOG.Root]\n" ~
86                "console = false\n");
87 
88     auto app = new App;
89 
90     test!("==")(app.main(args), 0);
91     test!("==")(app.trigger_count, 3);
92 }