mod_pres.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import time
  2. import sys
  3. import inc_const as const
  4. import inc_util as util
  5. from inc_cfg import *
  6. # Load configuration
  7. cfg_file = util.load_module_from_file("cfg_file", ARGS[1])
  8. # Test body function
  9. def test_func(t):
  10. u1 = t.process[0]
  11. uri1 = cfg_file.test_param.inst_params[0].uri
  12. acc1 = "-1"
  13. u2 = t.process[1]
  14. uri2 = cfg_file.test_param.inst_params[1].uri
  15. acc2 = "-1"
  16. # if have_reg then wait for couple of seconds for PUBLISH
  17. # to complete (just in case pUBLISH is used)
  18. if u1.inst_param.have_reg:
  19. time.sleep(1)
  20. if u2.inst_param.have_reg:
  21. time.sleep(1)
  22. # U1 adds U2 as buddy
  23. if u1.use_telnet:
  24. u1.send("im add_b " + uri2)
  25. else:
  26. u1.send("+b")
  27. u1.send(uri2)
  28. u1.expect("Subscription state changed NULL --> SENT")
  29. u1.expect("Presence subscription.*is ACCEPTED")
  30. if not u2.inst_param.have_publish:
  31. # Process incoming SUBSCRIBE in U2
  32. # Finds out which account gets the subscription in U2
  33. line = u2.expect("pjsua_pres.*subscription.*using account")
  34. acc2 = line.split("using account ")[1]
  35. # wait until we've got Online notification
  36. u1.expect(uri2 + ".*Online")
  37. # Synchronize stdout
  38. u1.sync_stdout()
  39. u2.sync_stdout()
  40. # U2 adds U1 as buddy
  41. if u2.use_telnet:
  42. u2.send("im add_b " + uri1)
  43. else:
  44. u2.send("+b")
  45. u2.send(uri1)
  46. u2.expect("Subscription state changed NULL --> SENT")
  47. # sometime it is NULL->SENT->ACCEPTED->ACTIVE
  48. # some othertime NULL->SENT->ACTIVE
  49. #u2.expect("Presence subscription.*is ACCEPTED")
  50. u2.expect("Presence subscription.*is ACTIVE")
  51. if not u1.inst_param.have_publish:
  52. # Process incoming SUBSCRIBE in U1
  53. # Finds out which account gets the subscription in U1
  54. line = u1.expect("pjsua_pres.*subscription.*using account")
  55. acc1 = line.split("using account ")[1]
  56. # wait until we've got Online notification
  57. u2.expect(uri1 + ".*Online")
  58. # Synchronize stdout
  59. u1.sync_stdout()
  60. u2.sync_stdout()
  61. # Set current account in both U1 and U2
  62. if acc1!="-1":
  63. if u1.use_telnet:
  64. u1.send("acc prev " + acc1)
  65. else:
  66. u1.send(">")
  67. u1.send(acc1)
  68. u1.expect("Current account changed")
  69. if acc2!="-1":
  70. if u2.use_telnet:
  71. u2.send("acc prev " + acc2)
  72. else:
  73. u2.send(">")
  74. u2.send(acc2)
  75. u2.expect("Current account changed")
  76. # Synchronize stdout
  77. u1.sync_stdout()
  78. u2.sync_stdout()
  79. # u2 toggles online status
  80. if u2.use_telnet:
  81. u2.send("im tog_state")
  82. else:
  83. u2.send("t")
  84. u1.expect(uri2 + ".*status.*Offline")
  85. u2.expect("offline")
  86. # Synchronize stdout
  87. u1.sync_stdout()
  88. u2.sync_stdout()
  89. # u1 toggles online status
  90. if u1.use_telnet:
  91. u1.send("im tog_state")
  92. else:
  93. u1.send("t")
  94. u2.expect(uri1 + ".*status.*Offline")
  95. u1.expect("offline")
  96. # Synchronize stdout
  97. u1.sync_stdout()
  98. u2.sync_stdout()
  99. # u2 set online status to On the phone
  100. if u2.use_telnet:
  101. u2.send("im pre_text 3")
  102. else:
  103. u2.send("T")
  104. u2.send("3")
  105. u1.expect(uri2 + ".*status.*On the phone")
  106. u2.expect("On the phone")
  107. # Synchronize stdout
  108. u1.sync_stdout()
  109. u2.sync_stdout()
  110. # Synchronize stdout
  111. u1.sync_stdout()
  112. u2.sync_stdout()
  113. # U1 send IM
  114. if u1.use_telnet:
  115. im_text = "Hello-World-from-U1"
  116. u1.send("im send_im %s %s" % (uri2, im_text))
  117. else:
  118. im_text = "Hello World from U1"
  119. u1.send("i")
  120. u1.send(uri2)
  121. u2.expect(" is typing")
  122. u1.send(im_text)
  123. u1.expect(im_text+".*delivered successfully")
  124. u2.expect("MESSAGE from.*"+im_text)
  125. # Synchronize stdout
  126. u1.sync_stdout()
  127. u2.sync_stdout()
  128. # Here where it all comes together
  129. test = cfg_file.test_param
  130. test.test_func = test_func