/***************************************************************

    Description: Conference of 5, 1 connected MT call and 2 incoming MT calls

    1. Make a conference of 2 calls
    2. Create new call and add it to the conference
    3. Repeat step 2 until there are 5 calls in conference
    4. Create new incoming PS call
       Expected: Call is Queued
    5. Answer call
       Expected: Conference is put automatically on Hold
    6. Create new incoming PS call
       Expected: Call is Queued
    7. Create new incoming CS call
       Expected: Call is rejected automatically, no events
    8. Reject queued call
       Exptected: Call is set to Idle state
    9. Hangup connected call
   10. Disconnect conference
***************************************************************/

[StifSettings]
CheckHeapBalance= on
[EndStifSettings]

[Test]
title 9.12 Conference, and 2 incoming calls
timeout 20000
create ccetester test
test Delay 1000

// Step 1
print Step_1

// Calls 1 and 2
test OpenNewCall 1 0 ConfcallOne 2 ECCECallTypePS ECCELineTypePrimary
test Dial 1 0 SubAddress Bearer
test WaitEvent 1 Dialling
test WaitEvent 1 Connecting
test WaitEvent 1 Connected
test Hold 1 0
test WaitEvents 1 Hold, 1 LocalHold

test OpenNewCall 2 0 ConfcallTwo 2 ECCECallTypePS ECCELineTypePrimary
test Dial 2 0 SubAddress Bearer
test WaitEvent 2 Dialling
test WaitEvent 2 Connecting
test WaitEvent 2 Connected

// Add calls to conference
test AddToConference 1 0
test WaitEvent ConferenceCallAdded 1

test AddToConference 2 0
// Plugin sets call to match conference state:
test WaitEvents ConferenceCallAdded 2, ConferenceActive, 1 Connected

// Step 2
print Step_2

// Call [3]
test OpenNewCall 3 0 ConfcallThree 2 ECCECallTypePS ECCELineTypePrimary
test Dial 3 0 SubAddress Bearer
// Conference autohold, plugin changes states to match conference
test WaitEvents 1 Hold, 2 Hold, ConferenceHold, 3 Dialling, 3 Connecting, 3 Connected, ConferenceCallSwapped

test AddToConference 3 0
// Plugin changes added call's state to match conference
// Conference autoresume, plugin changes states to match conference
test WaitEvents ConferenceCallAdded 3, 3 Hold, 1 Connected, 2 Connected, 3 Connected, ConferenceActive, ConferenceCallSwapped

// Step 3
print Step_3

// Call [4]
test OpenNewCall 4 0 ConfcallFour 2 ECCECallTypePS ECCELineTypePrimary
test Dial 4 0 SubAddress Bearer
// Conference autohold, plugin changes states to match conference
test WaitEvents 1 Hold, 2 Hold, 3 Hold, ConferenceHold, 4 Dialling, 4 Connecting, 4 Connected, ConferenceCallSwapped

test AddToConference 4 0
// Plugin changes added call's state to match conference
// Conference autoresume, plugin changes states to match conference
test WaitEvents ConferenceCallAdded 4, 4 Hold, 1 Connected, 2 Connected, 3 Connected, 4 Connected, ConferenceActive, ConferenceCallSwapped

// Call [5]
test OpenNewCall 5 0 ConfCallFive 2 ECCECallTypePS ECCELineTypePrimary
test Dial 5 0 SubAddress Bearer
// Conference autohold, plugin changes states to match conference
test WaitEvents 1 Hold, 2 Hold, 3 Hold, 4 Hold, ConferenceHold, 5 Dialling, 5 Connecting, 5 Connected, ConferenceCallSwapped

// Add call to conference
test AddToConference 5 0
// Plugin changes added call's state to match conference
// Conference autoresume, plugin changes states to match conference
test WaitEvents ConferenceCallAdded 5, 5 Hold, 1 Connected, 2 Connected, 3 Connected, 4 Connected, 5 Connected, ConferenceActive, ConferenceCallSwapped

// Step 4
print Step_4

// Send plugin command, MT call with CallID 6 is created
test SendPluginRequest CreateCall 2
test WaitEvent 0 IncomingCall
test WaitEvent 6 Queued

// Step 5
print Step_5

test Answer 6 0

test WaitEvents 1 Hold, 2 Hold, 3 Hold, 4 Hold, 5 Hold, ConferenceHold, 6 Answering, 6 Connected, ConferenceCallSwapped

// Step 6
print Step_6

// Send plugin command, MT call with CallID 7 is created
test SendPluginRequest CreateCall 2
test WaitEvent 0 IncomingCall
test WaitEvent 7 Queued

// Step 7
print Step_7

// Send plugin command, call is automatically rejected
test SendPluginRequest 2 CreateCall 1
// Wait for plugin commmand to execute, no events generated
test Delay 500

// Step 8
print Step_8

test HangUp 7 0
test WaitEvent 7 Disconnecting
test WaitEvent 7 Idle

// Step 9
print Step_9

test HangUp 6 0
test WaitEvent 6 Disconnecting
test WaitEvent 6 Idle

test Release 6 0

// Step 10
print Step_10

test HangupConference 0

test WaitEvents ConferenceCallRemoved 1, ConferenceCallRemoved 2, ConferenceCallRemoved 3, ConferenceCallRemoved 4, ConferenceCallRemoved 5, ConferenceIdle, 1 Disconnecting, 1 Idle, 2 Disconnecting, 2 Idle, 3 Disconnecting, 3 Idle, 4 Disconnecting, 4 Idle, 5 Disconnecting, 5 Idle

test ReleaseConference 0

test VerifyTest
delete test
[Endtest]
