testTaskScheduler.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "config.h"
00032
00033 #include <iostream>
00034 #include <string>
00035
00036 #include <ace/Trace.h>
00037
00038 #include "Task.hpp"
00039 #include "TaskScheduler.hpp"
00040
00041
00042
00043 #include <Exception.hpp>
00044
00045 #include <Time.hpp>
00046
00047 using namespace std;
00048 using mermaid::support::activeobject::Task;
00049 using mermaid::support::activeobject::TaskScheduler;
00050 using mermaid::support::errorhandling::Exception;
00051 using boost::shared_ptr;
00052
00053 using mermaid::support::system::Time;
00054
00055
00056 #define ACE_SYSTEM
00057
00058 int main (int argc, char * const argv[])
00059 {
00060 ACE_Trace::stop_tracing();
00061
00062 cout << "TaskScheduler test" << endl;
00063 bool success = true;
00064
00065 try {
00066 shared_ptr<TaskScheduler> ts = shared_ptr<TaskScheduler> (new TaskScheduler());
00067
00068 #ifdef ACE_SYSTEM
00069 Time time1 = ACE_Time_Value (1, 0);
00070 Time time2 = ACE_Time_Value (2, 0);
00071 Time time3 = ACE_Time_Value (3, 0);
00072 #endif
00073
00074 shared_ptr<Task> t1 = shared_ptr<Task> (new Task (time1));
00075 shared_ptr<Task> t2 = shared_ptr<Task> (new Task (time2));
00076 shared_ptr<Task> t3 = shared_ptr<Task> (new Task (time3));
00077
00078 ts->addTask (t3);
00079 ts->addTask (t2);
00080 ts->addTask (t1);
00081
00082 shared_ptr<Task> t = ts->getNextTask();
00083
00084 if (t != t1) {
00085 cout << "ERROR: expected to get task #1 from TaskScheduler" << endl;
00086 success = false;
00087 }
00088
00089 t = ts->getNextTask();
00090
00091 if (t != t2) {
00092 cout << "ERROR: expected to get task #2 from TaskScheduler" << endl;
00093 success = false;
00094 }
00095
00096 t = ts->getNextTask();
00097
00098 if (t != t3) {
00099 cout << "ERROR: expected to get task #3 from TaskScheduler" << endl;
00100 success = false;
00101 }
00102
00103
00104 {
00105 shared_ptr<Task> t = ts->getNextTask();
00106
00107 if (t) {
00108 cout << "ERROR: no more valid tasks should be available" << endl;
00109 success = false;
00110 }
00111 }
00112
00113
00114 }
00115 catch (Exception &e) {
00116 success = false;
00117 }
00118
00119
00120
00121 if (success) {
00122 cout << "Test Succeeded" << endl;
00123 return 0;
00124 }
00125 else {
00126 cout << "Test FAILED" << endl;
00127 return 1;
00128 }
00129
00130 };