Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 1 | # $Id$ |
Benny Prijono | cc1ada5 | 2008-06-15 19:43:43 +0000 | [diff] [blame] | 2 | import random |
Nanang Izzuddin | acb3e32 | 2008-06-25 18:18:32 +0000 | [diff] [blame] | 3 | from config_site import * |
Benny Prijono | cc1ada5 | 2008-06-15 19:43:43 +0000 | [diff] [blame] | 4 | |
| 5 | DEFAULT_ECHO = True |
| 6 | DEFAULT_TRACE = True |
| 7 | DEFAULT_START_SIP_PORT = 50000 |
| 8 | |
| 9 | # Individual pjsua instance configuration class |
| 10 | class InstanceParam: |
| 11 | # Name to identify this pjsua instance (e.g. "caller", "callee", etc.) |
| 12 | name = "" |
| 13 | # pjsua command line arguments, concatenated in string |
| 14 | arg = "" |
| 15 | # Specify whether pjsua output should be echoed to stdout |
| 16 | echo_enabled = DEFAULT_ECHO |
| 17 | # Enable/disable test tracing |
| 18 | trace_enabled = DEFAULT_TRACE |
| 19 | # SIP URI to send request to this instance |
| 20 | uri = "" |
| 21 | # SIP port number, zero to automatically assign |
| 22 | sip_port = 0 |
| 23 | # Does this have registration? If yes then the test function will |
| 24 | # wait until the UA is registered before doing anything else |
| 25 | have_reg = False |
| 26 | # Does this have PUBLISH? |
| 27 | have_publish = False |
| 28 | def __init__( self, |
| 29 | name, # Instance name |
| 30 | arg, # Cmd-line arguments |
| 31 | uri="", # URI |
| 32 | uri_param="", # Additional URI param |
| 33 | sip_port=0, # SIP port |
| 34 | have_reg=False, # Have registration? |
| 35 | have_publish=False, # Have publish? |
| 36 | echo_enabled=DEFAULT_ECHO, |
| 37 | trace_enabled=DEFAULT_TRACE): |
| 38 | # Instance name |
| 39 | self.name = name |
| 40 | # Give random sip_port if it's not specified |
| 41 | if sip_port==0: |
| 42 | self.sip_port = random.randint(DEFAULT_START_SIP_PORT, 65534) |
| 43 | else: |
| 44 | self.sip_port = sip_port |
| 45 | # Autogenerate URI if it's empty. |
| 46 | self.uri = uri |
| 47 | if self.uri=="": |
| 48 | self.uri = "sip:pjsip@127.0.0.1:" + str(self.sip_port) |
| 49 | # Add uri_param to the URI |
| 50 | self.uri = self.uri + uri_param |
| 51 | # Add bracket to the URI |
| 52 | if self.uri[0] != "<": |
| 53 | self.uri = "<" + self.uri + ">" |
| 54 | # Add SIP local port to the argument |
| 55 | self.arg = arg + " --local-port=" + str(self.sip_port) |
| 56 | self.have_reg = have_reg |
| 57 | self.have_publish = have_publish |
| 58 | if not ("--publish" in self.arg): |
| 59 | self.arg = self.arg + " --publish" |
| 60 | self.echo_enabled = echo_enabled |
| 61 | self.trace_enabled = trace_enabled |
| 62 | |
| 63 | |
| 64 | ############################################ |
| 65 | # Test parameter class |
| 66 | class TestParam: |
| 67 | title = "" |
| 68 | # params is list containing InstanceParams objects |
| 69 | inst_params = [] |
| 70 | # list of Expect instances, to be filled at run-time by |
| 71 | # the test program |
| 72 | process = [] |
| 73 | # the function for test body |
| 74 | test_func = None |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 75 | post_func = None |
| 76 | user_data = None |
Benny Prijono | cc1ada5 | 2008-06-15 19:43:43 +0000 | [diff] [blame] | 77 | def __init__( self, |
| 78 | title, # Test title |
| 79 | inst_params, # InstanceParam's as list |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 80 | func=None, |
| 81 | post_func=None, |
| 82 | user_data=None): |
Benny Prijono | cc1ada5 | 2008-06-15 19:43:43 +0000 | [diff] [blame] | 83 | self.title = title |
| 84 | self.inst_params = inst_params |
| 85 | self.test_func = func |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 86 | self.post_func = post_func |
| 87 | self.user_data = user_data |
Benny Prijono | cc1ada5 | 2008-06-15 19:43:43 +0000 | [diff] [blame] | 88 | |
| 89 | |
Benny Prijono | 7d578a7 | 2008-06-20 00:25:55 +0000 | [diff] [blame] | 90 | ################################### |
| 91 | # TestError exception |
| 92 | class TestError: |
| 93 | desc = "" |
| 94 | def __init__(self, desc): |
| 95 | self.desc = desc |
| 96 | |
Benny Prijono | cc1ada5 | 2008-06-15 19:43:43 +0000 | [diff] [blame] | 97 | |