[Define]
ONLINE 3
OFFLINE 1
BUSY 2
UNKNOWN 0
TIME_FOR_SHUTDOWN 2500
MINOR_WAIT 500
[Enddefine]

[Test]
title Create tester v1
create ClientSrvTester client
delete client
[Endtest]

[Test]
title Save only
create ClientSrvTester client
client SaveBuddyL Buddy: sip:tester1@test.com Atext: available Avalue: ONLINE Newkey: x-location Newvalue: kitchen
pause MINOR_WAIT
delete client
[Endtest]

[Test]
title Save and Fetch
create ClientSrvTester client
client SaveBuddyL Buddy: sip:tester1@test.com Atext: available Avalue: ONLINE Newkey: x-location Newvalue: kitchen
client FetchBuddyL Buddy: sip:tester1@test.com Atext: available Avalue: ONLINE Newkey: x-location Newvalue: kitchen Nbr_keys: 2
pause MINOR_WAIT
delete client
[Endtest]

[Test]
title Save and Subscribe
create ClientSrvTester client
// We do not get notification until the data is subscribed and re-saved
// Consider the Atext that is not changing. 
client SetNextDataL Buddy: sip:tester1@test.com Atext: available Avalue: ONLINE Newkey: x-location Newvalue: outdoor Nbr_keys: 2 Check: 1
client SaveBuddyL Buddy: sip:tester1@test.com Atext: available Avalue: OFFLINE Newkey: x-location Newvalue: kitchen
client SubscribeBuddyL Buddy: sip:tester1@test.com
client SaveBuddyL Buddy: sip:tester1@test.com Atext: available Avalue: ONLINE Newkey: x-location Newvalue: outdoor
waittestclass client
pause MINOR_WAIT
delete client
[Endtest]

[Test]
title Subscribe and Save
create ClientSrvTester client
client SubscribeBuddyL Buddy: sip:tester1@test.com
client SetNextDataL Buddy: sip:tester1@test.com Atext: available Avalue: BUSY Newkey: x-location Newvalue: kitchen Nbr_keys: 2 Check: 1
client SaveBuddyL Buddy: sip:tester1@test.com Atext: available Avalue: BUSY Newkey: x-location Newvalue: kitchen
waittestclass client
pause MINOR_WAIT
delete client
[Endtest]

[Test]
title Subscribe and Update partly
create ClientSrvTester client
// We do not get notification until the data is subscribed and re-saved
client SetNextDataL Buddy: sip:tester1@test.com Atext: available Avalue: ONLINE Newkey: x-location Newvalue: outdoor Statustext: status1 Nbr_keys: 3 Check: 1
client SubscribeBuddyL Buddy: sip:tester1@test.com
client SaveBuddyL Buddy: sip:tester1@test.com   Atext: available Avalue: ONLINE Newkey: x-location Newvalue: outdoor Statustext: status1
waittestclass client
// availability text is written always, even zero length, that's why there are still 2 keys. Status text is now missing.
client SetNextDataL Buddy: sip:tester1@test.com Avalue: BUSY Newkey: x-location Newvalue: kitchen Nbr_keys: 2 Check: 1
client SaveBuddyL   Buddy: sip:tester1@test.com Avalue: BUSY Newkey: x-location Newvalue: kitchen
waittestclass client
pause MINOR_WAIT
delete client
[Endtest]

[Test]
title Subscribe and Unsubscribe
create ClientSrvTester client
client SubscribeBuddyL Buddy: sip:tester1@test.com
client SetNextDataL Buddy: sip:tester1@test.com Atext: available Avalue: BUSY Newkey: x-location Newvalue: kitchen Nbr_keys: 2 Check: 1
client SaveBuddyL Buddy: sip:tester1@test.com Atext: available Avalue: BUSY Newkey: x-location Newvalue: kitchen
waittestclass client
client UnsubscribeBuddyL Buddy: sip:tester1@test.com
client SaveBuddyL Buddy: sip:tester1@test.com Atext: available Avalue: ONLINE Newkey: x-location Newvalue: kitchen
pause MINOR_WAIT
delete client
[Endtest]

[Test]
title Subscribe and Cancel
create ClientSrvTester client
client SaveBuddyL Buddy: sip:tester1@test.com   Atext: available Avalue: ONLINE Newkey: x-location Newvalue: outdoor Statustext: status1
client SubscribeBuddyL Buddy: sip:tester1@test.com DeleteWriter: 1
pause MINOR_WAIT
delete client
[Endtest]

[Test]
title Delete buddy
create ClientSrvTester client
client SaveBuddyL Buddy: sip:tester1@test.com   Atext: notavailable Avalue: OFFLINE Newkey: x-location Newvalue: outdoor Statustext: status1
client SaveBuddyL Buddy: sip:tester2@test.com   Atext: available Avalue: ONLINE Newkey: x-location Newvalue: outdoor Statustext: status1
client SubscribeBuddyL Buddy: sip:tester1@test.com
client SubscribeBuddyL Buddy: sip:tester2@test.com
client SetNextDataL Buddy: sip:tester1@test.com Avalue: UNKNOWN Nbr_keys: 0 Check: 1
client DeleteBuddyL Buddy: sip:tester1@test.com
waittestclass client
// Verify that another buddy is still working
client SetNextDataL Buddy: sip:tester2@test.com  Atext: busy Avalue: BUSY Newkey: x-location Newvalue: outdoor Nbr_keys: 2 Check: 1
client SaveBuddyL   Buddy: sip:tester2@test.com  Atext: busy Avalue: BUSY Newkey: x-location Newvalue: outdoor 
waittestclass client
pause MINOR_WAIT
delete client
[Endtest]

[Test]
title Write presences
create ClientSrvTester client
client SaveBuddyL Buddy: sip:tester1@test.com Atext: available Avalue: ONLINE Newkey: x-location Newvalue: kitchen
client SaveBuddyL Buddy: sip:tester2@test.com Atext: huh       Avalue: BUSY   Newkey: x-location Newvalue: kitchen
client FetchBuddyL Buddy: sip:tester1@test.com Atext: available Avalue: ONLINE Newkey: x-location Newvalue: kitchen Nbr_keys: 2
client FetchBuddyL Buddy: sip:tester2@test.com Atext: huh       Avalue: BUSY  Newkey: x-location  Newvalue: kitchen Nbr_keys: 2
pause MINOR_WAIT
delete client
[Endtest]

[Test]
title Write multiple presence
create ClientSrvTester client
client SaveBuddyL Buddy: sip:tester1@test.com Atext: available Avalue: ONLINE Newkey: x-location Newvalue: kitchen Multiple: 1
client SaveBuddyL Buddy: sip:tester2@test.com Atext: huh       Avalue: BUSY   Newkey: x-location Newvalue: kitchen Multiple: 1
client WriteMultiplePresenceL
waittestclass client
client FetchBuddyL Buddy: sip:tester1@test.com Atext: available Avalue: ONLINE Newkey: x-location Newvalue: kitchen Nbr_keys: 2
client FetchBuddyL Buddy: sip:tester2@test.com Atext: huh       Avalue: BUSY  Newkey: x-location  Newvalue: kitchen Nbr_keys: 2
pause MINOR_WAIT
delete client
[Endtest]

[Test]
// This test also empty notifications when the service is deleted
title Nbr of services
// Time for server to go down
pause TIME_FOR_SHUTDOWN
create ClientSrvTester client
client CheckCountersL Services: 0 Buddies: 0
client SaveBuddyL Buddy: sip:tester1@test.com   Atext: available Avalue: ONLINE Newkey: x-location Newvalue: outdoor Statustext: status1
client CheckCountersL Services: 1
client SaveBuddyL Buddy: msn:testerx@test.com   Atext: available Avalue: ONLINE Newkey: x-location Newvalue: outdoor Statustext: status1
client CheckCountersL Services: 2 Buddies: 2
client SubscribeBuddyL Buddy: sip:tester1@test.com
client DeleteServiceL Service: nonexists
client CheckCountersL Services: 2 Buddies: 2
client SetNextDataL Buddy: sip:tester1@test.com Avalue: UNKNOWN Nbr_keys: 0 Check: 1
client DeleteServiceL Service: sip
waittestclass client
client CheckCountersL Services: 1 Buddies: 1
// Service name is not case sensitive anymore
client DeleteServiceL Service: MSN
client CheckCountersL Services: 0 Buddies: 0
pause MINOR_WAIT
delete client
[Endtest]

[Test]
title Nbr of buddies
pause TIME_FOR_SHUTDOWN
pause MINOR_WAIT
create ClientSrvTester client
pause MINOR_WAIT
client CheckCountersL Services: 0 Buddies: 0 BuddiesInService: 0 Service: sip
client SaveBuddyL Buddy: sip:tester1@test.com   Atext: available Avalue: ONLINE Newkey: x-location Newvalue: outdoor Statustext: status1
client CheckCountersL Services: 1 Buddies: 1 BuddiesInService: 1 Service: sip
client CheckCountersL Services: 1 Buddies: 1 BuddiesInService: 0 Service: MSN
client SaveBuddyL Buddy: MSN:testerx@test.com   Atext: available Avalue: ONLINE Newkey: x-location Newvalue: outdoor Statustext: status1
client SaveBuddyL Buddy: MSN:testery@test.com   Atext: available Avalue: ONLINE Newkey: x-location Newvalue: outdoor Statustext: status1
client CheckCountersL Services: 2 Buddies: 3 BuddiesInService: 2 Service: MSN
client DeleteBuddyL Buddy: sip:tester1@test.com
client CheckCountersL Services: 1 Buddies: 2 BuddiesInService: 0 Service: sip
client CheckCountersL Services: 1 Buddies: 2 BuddiesInService: 2 Service: MSN
pause MINOR_WAIT
delete client
[Endtest]

[Test]
title Get all buddies in service
pause TIME_FOR_SHUTDOWN
create ClientSrvTester client
client SaveBuddyL Buddy: sip:tester1@test.com Atext: available Avalue: ONLINE Newkey: x-location Newvalue: kitchen
client SaveBuddyL Buddy: sip:monster@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client FetchAllBuddiesL Service: sip Nbr_buddies: 2
waittestclass client
client FetchAllBuddiesL Service: MSN Nbr_buddies: 0
waittestclass client
client SaveBuddyL Buddy: MSN:tester1@test.com Atext: available Avalue: ONLINE Newkey: x-location Newvalue: kitchen
client FetchAllBuddiesL Service: MSN Nbr_buddies: 1
waittestclass client
client FetchAllBuddiesL Service: sip Nbr_buddies: 2
waittestclass client
pause MINOR_WAIT
delete client
[Endtest]

[Test]
title Get all buddies, cancel
create ClientSrvTester client
client SaveBuddyL Buddy: sip:tester1@test.com Atext: available Avalue: ONLINE Newkey: x-location Newvalue: kitchen
client SaveBuddyL Buddy: sip:monster@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client FetchAllBuddiesL Service: sip Nbr_buddies: 0 Cancel: 1
pause MINOR_WAIT
delete client
[Endtest]

[Test]
title Subscribe and heavy update
pause TIME_FOR_SHUTDOWN
create ClientSrvTester client
client SubscribeBuddyL Buddy: sip:tester1@test.com
client SetNextDataL Buddy: sip:tester1@test.com Atext: available Avalue: BUSY Newkey: x-location Newvalue: kitchen Nbr_keys: 2 Check: 0
client SaveBuddyL Buddy: sip:tester1@test.com Atext: available Avalue: BUSY ManyTimes: 3 Newkey: x-location Newvalue: kitchen
waittestclass client
waittestclass client
waittestclass client
pause MINOR_WAIT
delete client
[Endtest]

[Test]
title Get all buddies, mass test
pause TIME_FOR_SHUTDOWN
create ClientSrvTester client
client SaveBuddyL Buddy: sip:tester1@test.com Atext: available Avalue: ONLINE Newkey: x-location Newvalue: kitchen
client SaveBuddyL Buddy: sip:monster2@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster3@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster4@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster5@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster6@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster7@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster8@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster9@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster10@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster11@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster12@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster13@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster@14test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster@15test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster16@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster17@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster18@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster19@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster20@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster21@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster22@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster23@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster24@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster25@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster26@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster27@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster28@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster29@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster30@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster31@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster32@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster33@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster34@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster35@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster36@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster37@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster38@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster39@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster40@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster41@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster42@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster43@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster44@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster45@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster46@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster47@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster48@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster49@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client SaveBuddyL Buddy: sip:monster50@test.com Atext: auts Avalue: BUSY Newkey: x-location Newvalue: outdoor
client FetchAllBuddiesL Service: sip Nbr_buddies: 50
waittestclass client
pause MINOR_WAIT
delete client
[Endtest]

[Test]
title Expiry-mechanism test
create ClientSrvTester client
// no expiry value
client SaveBuddyL Buddy: sip:tester1@test.com Atext: available Avalue: ONLINE Newkey: x-location Newvalue: kitchen
// with long expiry value
client SaveBuddyL Buddy: sip:tester2@test.com Atext: huh       Avalue: BUSY   Newkey: x-location Newvalue: kitchen Expiry: 100000000
// with short expiry value
client SaveBuddyL Buddy: tst:tester33@test.com Atext: huh       Avalue: BUSY   Newkey: x-location Newvalue: kitchen Expiry: 2000000
client SubscribeBuddyL Buddy: tst:tester33@test.com Expiry: 1
// with short expiry value
client SaveBuddyL Buddy: sip:tester4@test.com Atext: huh       Avalue: BUSY   Newkey: x-location Newvalue: kitchen Expiry: 1000000
// wait that "tst:tester33@test.com" is expired
pause 2500
client SaveBuddyL Buddy: tst:tester11@test.com Atext: huh       Avalue: BUSY Newkey: x-location Newvalue: kitchen
waittestclass client
// wait that "sip:tester4@test.com" is expired
client FetchBuddyL Buddy: sip:tester1@test.com Atext: available Avalue: ONLINE Newkey: x-location Newvalue: kitchen Nbr_keys: 2
client FetchBuddyL Buddy: sip:tester2@test.com Atext: huh       Avalue: BUSY  Newkey: x-location  Newvalue: kitchen Nbr_keys: 3 Expiry: 100000000
client VerifyThatBuddyNotFoundL Buddy: sip:tester4@test.com 
client VerifyThatBuddyNotFoundL Buddy: tst:tester33@test.com 
client FetchBuddyL Buddy: tst:tester11@test.com Atext: huh       Avalue: BUSY Newkey: x-location Newvalue: kitchen Nbr_keys: 2
pause MINOR_WAIT
delete client
[Endtest]


