Changeset 5638 for pjproject/trunk/pjsip-apps/src/swig/python/test.py
- Timestamp:
- Aug 2, 2017 9:45:09 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/swig/python/test.py
r4845 r5638 2 2 import sys 3 3 import time 4 5 write=sys.stdout.write 4 6 5 7 # … … 8 10 # 9 11 def ua_data_test(): 10 # 11 # AuthCredInfo 12 # 13 print "UA data types test.." 14 the_realm = "pjsip.org" 15 ci = pj.AuthCredInfo() 16 ci.realm = the_realm 17 ci.dataType = 20 18 19 ci2 = ci 20 assert ci.dataType == 20 21 assert ci2.realm == the_realm 22 23 # 24 # UaConfig 25 # See here how we manipulate std::vector 26 # 27 uc = pj.UaConfig() 28 uc.maxCalls = 10 29 uc.userAgent = "Python" 30 uc.nameserver = pj.StringVector(["10.0.0.1", "10.0.0.2"]) 31 uc.nameserver.append("NS1") 32 33 uc2 = uc 34 assert uc2.maxCalls == 10 35 assert uc2.userAgent == "Python" 36 assert len(uc2.nameserver) == 3 37 assert uc2.nameserver[0] == "10.0.0.1" 38 assert uc2.nameserver[1] == "10.0.0.2" 39 assert uc2.nameserver[2] == "NS1" 12 # 13 # AuthCredInfo 14 # 15 write("UA data types test..") 16 the_realm = "pjsip.org" 17 ci = pj.AuthCredInfo() 18 ci.realm = the_realm 19 ci.dataType = 20 40 20 41 print " Dumping nameservers: ", 42 for s in uc2.nameserver: 43 print s, 44 print "" 21 ci2 = ci 22 assert ci.dataType == 20 23 assert ci2.realm == the_realm 24 25 # 26 # UaConfig 27 # See here how we manipulate std::vector 28 # 29 uc = pj.UaConfig() 30 uc.maxCalls = 10 31 uc.userAgent = "Python" 32 uc.nameserver = pj.StringVector(["10.0.0.1", "10.0.0.2"]) 33 uc.nameserver.append("NS1") 34 35 uc2 = uc 36 assert uc2.maxCalls == 10 37 assert uc2.userAgent == "Python" 38 assert len(uc2.nameserver) == 3 39 assert uc2.nameserver[0] == "10.0.0.1" 40 assert uc2.nameserver[1] == "10.0.0.2" 41 assert uc2.nameserver[2] == "NS1" 42 43 write(" Dumping nameservers: " + "\r\n") 44 for s in uc2.nameserver: 45 write(s + "\r\n") 46 write("\r\n") 45 47 46 48 # … … 48 50 # 49 51 def ua_run_test_exception(): 50 print "Exception test.." 51 ep = pj.Endpoint() 52 ep.libCreate() 53 got_exception = False 54 try: 55 ep.natDetectType() 56 except pj.Error, e: 57 got_exception = True 58 print " Got exception: status=%u, reason=%s,\n title=%s,\n srcFile=%s, srcLine=%d" % \ 59 (e.status, e.reason, e.title, e.srcFile, e.srcLine) 60 assert e.status == 370050 61 assert e.reason.find("PJNATH_ESTUNINSERVER") >= 0 62 assert e.title == "pjsua_detect_nat_type()" 63 assert got_exception 52 write("Exception test.." + "\r\n") 53 ep = pj.Endpoint() 54 ep.libCreate() 55 got_exception = False 56 try: 57 ep.natDetectType() 58 except pj.Error as e: 59 #t, e = sys.exc_info()[:2] 60 got_exception = True 61 write(" Got exception: status=%u, reason=%s,\n title=%s,\n srcFile=%s, srcLine=%d" % \ 62 (e.status, e.reason, e.title, e.srcFile, e.srcLine) + "\r\n") 63 assert e.status == 370050 64 assert e.reason.find("PJNATH_ESTUNINSERVER") >= 0 65 assert e.title == "pjsua_detect_nat_type()" 66 assert got_exception 64 67 65 68 # … … 67 70 # 68 71 class MyLogWriter(pj.LogWriter): 69 70 print "This is Python:", entry.msg 71 72 def write(self, entry): 73 write("This is Python:" + entry.msg + "\r\n") 74 72 75 # 73 76 # Testing log writer callback 74 77 # 75 78 def ua_run_log_test(): 76 print "Logging test.." 77 78 79 80 81 ep_cfg.logConfig.decor = ep_cfg.logConfig.decor & ~(pj.PJ_LOG_HAS_CR | pj.PJ_LOG_HAS_NEWLINE) 82 83 84 85 86 87 79 write("Logging test.." + "\r\n") 80 ep_cfg = pj.EpConfig() 81 82 lw = MyLogWriter() 83 ep_cfg.logConfig.writer = lw 84 ep_cfg.logConfig.decor = ep_cfg.logConfig.decor & ~(pj.PJ_LOG_HAS_CR | pj.PJ_LOG_HAS_NEWLINE) 85 86 ep = pj.Endpoint() 87 ep.libCreate() 88 ep.libInit(ep_cfg) 89 ep.libDestroy() 90 88 91 # 89 92 # Simple create, init, start, and destroy sequence 90 93 # 91 94 def ua_run_ua_test(): 92 print "UA test run.." 93 94 95 96 97 98 99 100 print "************* Endpoint started ok, now shutting down... *************" 101 95 write("UA test run.." + "\r\n") 96 ep_cfg = pj.EpConfig() 97 98 ep = pj.Endpoint() 99 ep.libCreate() 100 ep.libInit(ep_cfg) 101 ep.libStart() 102 103 write("************* Endpoint started ok, now shutting down... *************" + "\r\n") 104 ep.libDestroy() 102 105 103 106 # … … 105 108 # 106 109 def ua_tonegen_test(): 107 print "UA tonegen test.."108 110 write("UA tonegen test.." + "\r\n") 111 ep_cfg = pj.EpConfig() 109 112 110 ep = pj.Endpoint() 111 ep.libCreate() 112 ep.libInit(ep_cfg) 113 ep.libStart() 114 115 tonegen = pj.ToneGenerator() 116 tonegen.createToneGenerator() 113 ep = pj.Endpoint() 114 ep.libCreate() 115 ep.libInit(ep_cfg) 116 ep.libStart() 117 117 118 tone = pj.ToneDesc() 119 tone.freq1 = 400 120 tone.freq2 = 600 121 tone.on_msec = 1000 122 tone.off_msec = 1000 123 tones = pj.ToneDescVector() 124 tones.append(tone) 118 tonegen = pj.ToneGenerator() 119 tonegen.createToneGenerator() 125 120 126 digit = pj.ToneDigit() 127 digit.digit = '0' 128 digit.on_msec = 1000 129 digit.off_msec = 1000 130 digits = pj.ToneDigitVector() 131 digits.append(digit) 121 tone = pj.ToneDesc() 122 tone.freq1 = 400 123 tone.freq2 = 600 124 tone.on_msec = 1000 125 tone.off_msec = 1000 126 tones = pj.ToneDescVector() 127 tones.append(tone) 132 128 133 adm = ep.audDevManager() 134 spk = adm.getPlaybackDevMedia() 129 digit = pj.ToneDigit() 130 digit.digit = '0' 131 digit.on_msec = 1000 132 digit.off_msec = 1000 133 digits = pj.ToneDigitVector() 134 digits.append(digit) 135 135 136 tonegen.play(tones, True) 137 tonegen.startTransmit(spk) 138 time.sleep(5) 136 adm = ep.audDevManager() 137 spk = adm.getPlaybackDevMedia() 139 138 140 tonegen.stop()141 tonegen.playDigits(digits, True)142 139 tonegen.play(tones, True) 140 tonegen.startTransmit(spk) 141 time.sleep(5) 143 142 144 dm = tonegen.getDigitMap() 145 print dm[0].digit 146 dm[0].freq1 = 400 147 dm[0].freq2 = 600 148 tonegen.setDigitMap(dm) 149 150 tonegen.stop() 151 tonegen.playDigits(digits, True) 152 time.sleep(5) 153 154 tonegen = None 143 tonegen.stop() 144 tonegen.playDigits(digits, True) 145 time.sleep(5) 155 146 156 ep.libDestroy() 147 dm = tonegen.getDigitMap() 148 write(dm[0].digit + "\r\n") 149 dm[0].freq1 = 400 150 dm[0].freq2 = 600 151 tonegen.setDigitMap(dm) 152 153 tonegen.stop() 154 tonegen.playDigits(digits, True) 155 time.sleep(5) 156 157 tonegen = None 158 159 ep.libDestroy() 157 160 158 161 # … … 160 163 # 161 164 if __name__ == "__main__": 162 163 164 165 166 167 165 ua_data_test() 166 ua_run_test_exception() 167 ua_run_log_test() 168 ua_run_ua_test() 169 ua_tonegen_test() 170 sys.exit(0) 168 171 169 172
Note: See TracChangeset
for help on using the changeset viewer.