***
***	Test time API.
***

set show timing off .

load time
load file

mod TEST is
  inc TIME .
  inc STD-STREAM .

  op myClass : -> Cid .
  ops me : -> Oid .
  op firstTimer : Oid -> Attribute .
  op secondTimer : Oid -> Attribute .
  op thirdTimer : Oid -> Attribute .
  op run : -> Configuration .
  eq run = <> < me : myClass | none > createTimer(timeManager, me) .

vars O O2 O3 O4 O5 : Oid .
var N : Nat .
  rl < O : myClass | none > createdTimer(O, O2, O3) =>
     < O : myClass | firstTimer(O3) > createTimer(timeManager, me) .
     
  rl < O : myClass | firstTimer(O3) > createdTimer(O, O2, O4) =>
     < O : myClass | firstTimer(O3), secondTimer(O4) > createTimer(timeManager, me) .

  rl < O : myClass | firstTimer(O3), secondTimer(O4) > createdTimer(O, O2, O5) =>
     < O : myClass | firstTimer(O3), secondTimer(O4), thirdTimer(O5) >
     startTimer(O3, me, periodic, 500 ms)
     startTimer(O4, me, oneShot, 1250 ms)
     startTimer(O5, me, oneShot, 3250 ms).

  rl < O : myClass | firstTimer(O3), secondTimer(O4), thirdTimer(O5) >
     timeOut(O, O3) =>
     < O : myClass | firstTimer(O3), secondTimer(O4), thirdTimer(O5) >
     write(stdout, O, "time out for first timer\n") .

  rl < O : myClass | firstTimer(O3), secondTimer(O4), thirdTimer(O5) >
     timeOut(O, O4) =>
     < O : myClass | firstTimer(O3), secondTimer(O4), thirdTimer(O5) >
     write(stdout, O, "time out for second timer\n") .

  rl < O : myClass | firstTimer(O3), secondTimer(O4), thirdTimer(O5) >
     timeOut(O, O5) =>
     < O : myClass | firstTimer(O3), secondTimer(O4), thirdTimer(O5) >
     write(stdout, O, "time out for third timer\n")
     stopTimer(O3, O) .

  rl < O : myClass | firstTimer(O3), secondTimer(O4), thirdTimer(O5) >
     stoppedTimer(O, O3) =>
     < O : myClass | none >
     deleteTimer(O3, O) deleteTimer(O4, O) deleteTimer(O5, O) .
endm

erew run .
