diff options
author | Liong Sauw Ming <ming@teluu.com> | 2014-01-16 05:30:46 +0000 |
---|---|---|
committer | Liong Sauw Ming <ming@teluu.com> | 2014-01-16 05:30:46 +0000 |
commit | e56ea14ab8531ee3cec375460577d1b89bf62e26 (patch) | |
tree | df77c3acb961514b2022ee9e030071b691145920 /pjsip-apps/src/swig/python/test.py | |
parent | bd1c47e995a3a844868f1d4dcc8f77f163ae721b (diff) |
Closed #1723: Merging pjsua2 branch into trunk
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4704 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip-apps/src/swig/python/test.py')
-rw-r--r-- | pjsip-apps/src/swig/python/test.py | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/pjsip-apps/src/swig/python/test.py b/pjsip-apps/src/swig/python/test.py new file mode 100644 index 00000000..dc805c77 --- /dev/null +++ b/pjsip-apps/src/swig/python/test.py @@ -0,0 +1,112 @@ +import pjsua2 as pj +import sys + +# +# Basic data structure test, to make sure basic struct +# and array operations work +# +def ua_data_test(): + # + # AuthCredInfo + # + print "UA data types test.." + the_realm = "pjsip.org" + ci = pj.AuthCredInfo() + ci.realm = the_realm + ci.dataType = 20 + + ci2 = ci + assert ci.dataType == 20 + assert ci2.realm == the_realm + + # + # UaConfig + # See here how we manipulate std::vector + # + uc = pj.UaConfig() + uc.maxCalls = 10 + uc.userAgent = "Python" + uc.nameserver = pj.StringVector(["10.0.0.1", "10.0.0.2"]) + uc.nameserver.append("NS1") + + uc2 = uc + assert uc2.maxCalls == 10 + assert uc2.userAgent == "Python" + assert len(uc2.nameserver) == 3 + assert uc2.nameserver[0] == "10.0.0.1" + assert uc2.nameserver[1] == "10.0.0.2" + assert uc2.nameserver[2] == "NS1" + + print " Dumping nameservers: ", + for s in uc2.nameserver: + print s, + print "" + +# +# Exception test +# +def ua_run_test_exception(): + print "Exception test.." + ep = pj.Endpoint() + ep.libCreate() + got_exception = False + try: + ep.natDetectType() + except pj.Error, e: + got_exception = True + print " Got exception: status=%u, reason=%s,\n title=%s,\n srcFile=%s, srcLine=%d" % \ + (e.status, e.reason, e.title, e.srcFile, e.srcLine) + assert e.status == 370050 + assert e.reason.find("PJNATH_ESTUNINSERVER") >= 0 + assert e.title == "pjsua_detect_nat_type()" + assert got_exception + +# +# Custom log writer +# +class MyLogWriter(pj.LogWriter): + def write(self, entry): + print "This is Python:", entry.msg + +# +# Testing log writer callback +# +def ua_run_log_test(): + print "Logging test.." + ep_cfg = pj.EpConfig() + + lw = MyLogWriter() + ep_cfg.logConfig.writer = lw + ep_cfg.logConfig.decor = ep_cfg.logConfig.decor & ~(pj.PJ_LOG_HAS_CR | pj.PJ_LOG_HAS_NEWLINE) + + ep = pj.Endpoint() + ep.libCreate() + ep.libInit(ep_cfg) + ep.libDestroy() + +# +# Simple create, init, start, and destroy sequence +# +def ua_run_ua_test(): + print "UA test run.." + ep_cfg = pj.EpConfig() + + ep = pj.Endpoint() + ep.libCreate() + ep.libInit(ep_cfg) + ep.libStart() + + print "************* Endpoint started ok, now shutting down... *************" + ep.libDestroy() + +# +# main() +# +if __name__ == "__main__": + ua_data_test() + ua_run_test_exception() + ua_run_log_test() + ua_run_ua_test() + sys.exit(0) + +
\ No newline at end of file |