00001 #include <iostream>
00002
00003 #include "SenseHandler.h"
00004 #include "ActionScheduler.h"
00005 #include "WorldModel.h"
00006
00007 using namespace std;
00008
00009
00010
00011
00012
00013
00014
00015
00016 ActionScheduler *as;
00017 int a1_dispatched;
00018 int a1_cleanedup;
00019
00020 void action_callback1(WorldModel* wm, ServerSettings* ss, PlayerSettings* ps, void* params, int params_size) {
00021 LOG_PRINT(LOG_DEBUG, "Executing action_callback");
00022 a1_dispatched = 0;
00023 }
00024
00025 void cleanup_callback1(void* params, int params_size) {
00026 LOG_PRINT(LOG_DEBUG, "Executing cleanup_callback");
00027 a1_cleanedup = 0;
00028 }
00029
00030 void setup() {
00031 a1_dispatched = -1;
00032 a1_cleanedup = -1;
00033 as = new ActionScheduler(NULL, NULL, NULL);
00034 }
00035
00036 void cleanup() {
00037 if(as != NULL)
00038 delete as;
00039 }
00040
00041 int testScheduleAction() {
00042 as->scheduleAction(3, &action_callback1, &cleanup_callback1, NULL, 0);
00043 as->dispatchAction(3);
00044 if(a1_dispatched != 0)
00045 return -1;
00046
00047 a1_dispatched = -1;
00048 as->dispatchAction(3);
00049 if(a1_dispatched == 0)
00050 return -1;
00051
00052 return 0;
00053 }
00054
00055 int testCleanupAction() {
00056 as->scheduleAction(3, &action_callback1, &cleanup_callback1, NULL, 0);
00057 as->dispatchAction(3);
00058 if(a1_cleanedup != 0)
00059 return -1;
00060
00061 a1_cleanedup = -1;
00062 as->dispatchAction(3);
00063 if(a1_cleanedup == 0)
00064 return -1;
00065
00066 return 0;
00067 }
00068
00069 int test1() {
00070 as->scheduleAction(3, &action_callback1, &cleanup_callback1, NULL, 0);
00071 }
00072
00073 int main( int argc, char* argv[] ) {
00074 Log.addLogRange(0,1500);
00075
00076 cout << "TEST RUN" << endl << "===========" << endl;
00077 setup();
00078 int t_scheduleActionRes = testScheduleAction();
00079 cleanup();
00080
00081 cout << "TEST RUN" << endl << "===========" << endl;
00082 setup();
00083 int t_cleanupActionRes = testCleanupAction();
00084 cleanup();
00085
00086
00087 cout << endl;
00088 cout << "RESULTS" << endl;
00089 cout << "================" << endl;
00090 cout << "testScheduleAction : " << (t_scheduleActionRes == 0 ? "OK" : "FAILED") << endl;
00091 cout << "testCleanupAction : " << (t_cleanupActionRes == 0 ? "OK" : "FAILED") << endl;
00092 return 0;
00093 }