# Copyright (c) 2016 Sippy Software, Inc. All rights reserved.
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from test_cases.t1 import a_test1, b_test1

from sippy.Timeout import Timeout

class a_test_reinvite(a_test1):
    cld = 'bob_reinvite'
    cli = 'alice_reinvite'
    compact_sip = False

    def connected(self, ua, rtime, origin):
        Timeout(self.reinvite, self.disconnect_ival / 2, 1, ua)
        a_test1.connected(self, ua, rtime, origin)

    def alldone(self, ua):
        if not self.reinvite_done or not self.disconnect_done or self.nerrs > 0:
            print '%s: subclass %s failed, acct=%s' % (self.my_name(), \
              str(self.__class__), str(self.acct))
        else:
            self.rval = 0
        self.tccfg.done_cb(self)

class b_test_reinvite(b_test1):
    cli = 'bob_reinvite'
    compact_sip = True
    ring_ival = 1.0
    answer_ival = 5.0
    disconnect_ival = 16

@@ -1436,16 +1436,198 @@
 imeout%0A%0A
+class test_reinvite(object):%0A    reinvite = None%0A%0A    def connected(self, ua):%0A        if self.reinvite != None:%0A            Timeout(self.reinvite, self.disconnect_ival / 2, 1, ua)%0A%0A
 class a_
@@ -1643,24 +1643,39 @@
 vite(a_test1
+, test_reinvite
 ):%0A    cld =
@@ -1798,58 +1798,36 @@
     
-Timeout(self.reinvite, self.disconnect_ival / 2, 1
+test_reinvite.connected(self
 , ua
@@ -1988,16 +1988,56 @@
 rs %3E 0:%0A
+            if self.debug_lvl %3E -1:%0A    
         
@@ -2101,16 +2101,20 @@
 me(), %5C%0A
+    
         
@@ -2259,16 +2259,31 @@
 (b_test1
+, test_reinvite
 ):%0A    c
@@ -2367,16 +2367,16 @@
 l = 5.0%0A
-
     disc
@@ -2392,8 +2392,146 @@
 al = 16%0A
+%0A    def connected(self, ua, rtime, origin):%0A        test_reinvite.connected(self, ua)%0A        b_test1.connected(self, ua, rtime, origin)%0A

Unify code to allows Bob to reinvite as well.