testExternalInput.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at
  2. # McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/)
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from testutils import *
  16. from pypdevs.util import DEVSException
  17. class TestExternalInput(unittest.TestCase):
  18. def setUp(self):
  19. self.sim = basicSim()
  20. self.msg = basicMsg()
  21. def tearDown(self):
  22. self.sim.run_gvt = False
  23. def test_externalInput_antimsg_unpresent(self):
  24. # Send a non-present anti message
  25. self.sim.externalInput(self.msg)
  26. self.assertTrue(self.sim.outputQueue == [])
  27. self.assertTrue(self.sim.prevtime == (0,1))
  28. def test_externalInput_antimsg_unpresent_other(self):
  29. # Send a non-present anti message
  30. self.sim.filtered = [self.msg.uuid]
  31. msg2 = NetworkMessage(self.msg.timestamp, self.msg.content, self.msg.uuid, self.msg.color, self.msg.destination)
  32. msg2.uuid = 11111
  33. self.sim.externalInput(msg2)
  34. self.assertTrue(self.sim.outputQueue == [])
  35. self.assertTrue(self.sim.prevtime == (0,1))
  36. def test_externalInput_antimsg_unpresent_multi(self):
  37. # Send a non-present anti message
  38. self.sim.filtered = [self.msg.uuid, self.msg.uuid]
  39. self.sim.externalInput(self.msg)
  40. # This message should now get filtered
  41. self.assertTrue(self.sim.outputQueue == [])
  42. self.assertTrue(self.sim.prevtime == (0,1))
  43. def test_externalInput_normal(self):
  44. self.msg.timestamp = (1, 2)
  45. self.sim.prevtime = (1, 1)
  46. self.sim.externalInput(self.msg)
  47. self.assertTrue(self.sim.outputQueue == [])
  48. self.assertTrue(self.sim.prevtime == (1, 1))
  49. def test_externalInput_revert(self):
  50. self.msg.timestamp = (1, 1)
  51. self.sim.prevtime = (10, 1)
  52. self.sim.model = Generator()
  53. self.sim.model.local_model_ids = set([0, 1])
  54. self.sim.model.rootsim = self.sim
  55. self.sim.externalInput(self.msg)
  56. self.assertTrue(self.sim.reverted)