aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/minicron.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/tests/minicron.cpp b/src/tests/minicron.cpp
new file mode 100644
index 0000000..715a74d
--- /dev/null
+++ b/src/tests/minicron.cpp
@@ -0,0 +1,53 @@
1#include "bu/minicron.h"
2#include "bu/sio.h"
3
4#include <unistd.h>
5
6using namespace Bu;
7
8Bu::MiniCron mCron;
9
10void job0( Bu::MiniCron::Job &job )
11{
12 sio << time( NULL ) << ": job0( id = " << job.getId() << ", count = "
13 << job.getRunCount() << ")" << sio.nl;
14}
15
16void job1( Bu::MiniCron::Job &job )
17{
18 sio << time( NULL ) << ": job1( id = " << job.getId() << ", count = "
19 << job.getRunCount() << ")" << sio.nl;
20 mCron.removeJob( 4 );
21}
22
23void job2( Bu::MiniCron::Job &job )
24{
25 sio << time( NULL ) << ": job2( id = " << job.getId() << ", count = "
26 << job.getRunCount() << ")" << sio.nl;
27}
28
29void job3( Bu::MiniCron::Job &job )
30{
31 sio << time( NULL ) << ": job3( id = " << job.getId() << ", count = "
32 << job.getRunCount() << ")" << sio.nl;
33}
34
35int main()
36{
37
38 mCron.addJob( slot( &job0 ), MiniCron::TimerInterval( time(NULL)+3, 5 ) );
39 mCron.addJob( slot( &job1 ), MiniCron::TimerInterval( time(NULL)+10, 8 ) );
40 mCron.addJob( slot( &job2 ), MiniCron::TimerBasic("weekly wed 17") );
41 mCron.addJob( slot( &job3 ), MiniCron::TimerInterval( time(NULL)+1, 2 ) );
42
43 sio << time( NULL ) << ": Program started." << sio.nl;
44
45 for(;;)
46 {
47 usleep( 50000 );
48 mCron.poll();
49 }
50
51 return 0;
52}
53