source_module_test.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import os, sys
  2. sys.path.append(os.path.split(os.path.realpath(__file__))[0] + "/../lib")
  3. from cnstream import *
  4. from cnstream_cpptest import *
  5. class CustomSourceModule(SourceModule):
  6. def __init__(self, name):
  7. SourceModule.__init__(self, name)
  8. def open(self, params):
  9. return True
  10. def close(self):
  11. return
  12. class CustomSourceHandler(SourceHandler):
  13. def __init__(self, source_module, name):
  14. SourceHandler.__init__(self, source_module, name)
  15. def open(self):
  16. return True
  17. def close(self):
  18. print("handler close")
  19. return
  20. def test_source():
  21. source = CustomSourceModule("source_test")
  22. handler0 = CustomSourceHandler(source, "stream_id_0")
  23. handler1 = CustomSourceHandler(source, "stream_id_1")
  24. handler2 = CustomSourceHandler(source, "stream_id_2")
  25. assert handler0.open()
  26. assert "stream_id_0" == handler0.get_stream_id()
  27. data = handler0.create_frame_info()
  28. assert handler0.send_data(data)
  29. assert 0 == source.add_source(handler0)
  30. assert 0 == source.add_source(handler1)
  31. assert 0 == source.add_source(handler2)
  32. assert handler0 == source.get_source_handler("stream_id_0")
  33. assert 0 == source.remove_source("stream_id_0")
  34. assert None == source.get_source_handler("stream_id_0")
  35. assert handler1 == source.get_source_handler("stream_id_1")
  36. assert 0 == source.remove_source(handler1)
  37. assert None == source.get_source_handler("stream_id_1")
  38. assert handler2 == source.get_source_handler("stream_id_2")
  39. assert 0 == source.remove_sources()
  40. assert None == source.get_source_handler("stream_id_2")