1 /******************************************************************************* 2 3 Copyright: 4 Copyright (c) 2017 dunnhumby Germany GmbH. 5 All rights reserved. 6 7 License: 8 Boost Software License Version 1.0. See LICENSE_BOOST.txt for details. 9 Alternatively, this file may be distributed under the terms of the Tango 10 3-Clause BSD License (see LICENSE_BSD.txt for details). 11 12 *******************************************************************************/ 13 14 module ocean.task.util.Event_test; 15 16 import ocean.task.util.Event; 17 import ocean.task.Task; 18 import ocean.task.util.Timer; 19 import ocean.task.Scheduler; 20 import ocean.core.Test; 21 22 unittest 23 { 24 TaskEvent event; 25 int state = 0; 26 27 class Task1 : Task 28 { 29 override public void run ( ) 30 { 31 state = 1; 32 event.wait(); 33 state = 3; 34 } 35 } 36 37 class Task2 : Task 38 { 39 override public void run ( ) 40 { 41 state = 2; 42 .wait(100); 43 event.trigger(); 44 } 45 } 46 47 initScheduler(SchedulerConfiguration.init); 48 theScheduler.schedule(new Task1); 49 test!("==")(state, 1); 50 theScheduler.schedule(new Task2); 51 test!("==")(state, 2); 52 theScheduler.eventLoop(); 53 test!("==")(state, 3); 54 } 55 56 unittest 57 { 58 TaskEvent event; 59 int state = 0; 60 61 class Task1 : Task 62 { 63 override public void run ( ) 64 { 65 state = 1; 66 event.wait(); 67 state = 3; 68 } 69 } 70 71 class Task2 : Task 72 { 73 override public void run ( ) 74 { 75 state = 2; 76 event.trigger(); 77 } 78 } 79 80 initScheduler(SchedulerConfiguration.init); 81 theScheduler.schedule(new Task2); 82 test!("==")(state, 2); 83 theScheduler.schedule(new Task1); 84 test!("==")(state, 3); 85 theScheduler.eventLoop(); 86 } 87 88