testTaskScheduler.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright 2007, 2008, 2009, 2010, 2011 Instituto de Sistemas e Robotica, Instituto Superior Tecnico
00003 
00004 This file is part of MeRMaID.
00005 
00006 MeRMaID is free software: you can redistribute it and/or modify
00007 it under the terms of the GNU Lesser General Public License as published by
00008 the Free Software Foundation, either version 3 of the License, or
00009 (at your option) any later version.
00010 
00011 MeRMaID is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU Lesser General Public License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public License
00017 along with MeRMaID.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 
00021 
00022 /**
00023  * @Filename testTaskScheduler.cpp
00024  * @Description Tests TaskScheduler class
00025  * @Status unknown
00026  * @Version $Id: testTaskScheduler.cpp 1 2011-03-04 18:13:18Z jreis $
00027  * @Maintainer Nelson Ramos (nmsra@mega.ist.utl.pt)
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 //#include <ServiceInterfaceMethod.hpp>
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 //using mermaid::support::service::ServiceInterfaceMethod;
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 }; // main
Generated on Fri Mar 4 22:14:58 2011 for MeRMaID::support by  doxygen 1.6.3