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