Schedule.m
上传用户:shenzhenrh
上传日期:2013-05-12
资源大小:2904k
文件大小:2k
源码类别:

信息检索与抽取

开发平台:

Unix_Linux

  1. /*
  2. Name:         Schedule.m
  3. Description:  Simple test of Schedule. Tests scheduling of concurrent actions.
  4. Test suite:   activity
  5. */
  6. #import "Responder.h"
  7. #import <simtools.h>
  8. #import <collections.h> // Array
  9. #import <activity.h> // Schedule
  10. int 
  11. main (int argc, const char ** argv)
  12. {
  13.   id array;
  14.   id obj;
  15.   int i;
  16.   id schedule;
  17.   
  18.   initSwarmBatch (argc, argv);
  19.   init_tables ();
  20.   array = [Array create: globalZone setCount: 5];
  21.   for (i = 0; i < 5; i++)
  22.     {
  23.       obj = [Responder create:globalZone];
  24.       [obj setId: i + 1];
  25.       [array atOffset: i put: obj];
  26.     }
  27.   schedule = [Schedule createBegin: globalZone];
  28.   [schedule setAutoDrop: YES];
  29.   schedule = [schedule createEnd];
  30.   
  31.   [schedule at: 0 createActionTo: [array atOffset: 0]
  32.     message: M(mTimeId)];
  33.   [schedule at: 1 createActionTo: [array atOffset: 0]
  34.     message: M(mTimeId)];
  35.   [schedule at: 1 createActionTo: [array atOffset: 1]
  36.     message: M(mTimeId)];
  37.   [schedule at: 10 createActionTo: [array atOffset: 2]
  38.     message: M(mTimeId)];
  39.   [schedule at: 10 createActionTo: [array atOffset: 3]
  40.     message: M(mTimeId)]; 
  41.   [schedule at: 100 createActionTo: [array atOffset: 4]
  42.     message: M(mTimeId)];
  43.   [schedule at: 100 createActionTo: [array atOffset: 4]
  44.     message: M(mTimeId)];
  45.   [[schedule activateIn: nil] run];
  46.   
  47.   if (ids[0] != 1)
  48.     {
  49.       fprintf (stderr, "Error in Schedule, action scheduled for time: 0 not performed! n");
  50.       return 1;
  51.     }
  52.   if (ids[1] != 1 || ids[2] != 2 || rtimes[1] != 1 || rtimes[2] != 1)
  53.     {
  54.       fprintf (stderr, "Error in Schedule, two concurrent actions scheduled for time: 1 not performed! n ");
  55.       return 1;
  56.     }
  57.   if (ids[3] != 3 || ids[4] != 4 || rtimes[3] != 10 || rtimes[4] != 10)
  58.     {
  59.       fprintf (stderr, "Error in Schedule, two concurrent actions scheduled for time: 10 not performed! n ");
  60.       return 1;
  61.     }
  62.   if (ids[5] != 5 || ids[6] != 5 || rtimes[5] != 100 || rtimes[6] != 100)
  63.     {
  64.       fprintf (stderr, "Error in Schedule, two concurrent actions scheduled for time: 100 not performed! n");
  65.     }
  66.   return 0;
  67. }