[svn-commits] mmichelson: branch mmichelson/phone-testsuite r3123 - in /asterisk/team/mmich...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Mar 21 17:13:04 CDT 2012


Author: mmichelson
Date: Wed Mar 21 17:13:00 2012
New Revision: 3123

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3123
Log:
Add presencestate test.

This tests func_presencestate to be sure that all values
are settable and retrievable as expected.

There were several major setbacks when attempting to write
tests.

* The base64-encoded write version of func_presencestate works very
  differently from how I had initially understood it. The test is
  written quite differently from how I had initially outlined it.

* I cannot accurately test setting a presence state, reading it, setting
  a new presence state, and then reading the new state. The final read
  will sometimes fail because setting presence state is an asynchronous
  operation. The final read will grab the cached presence state, which
  has not yet been overwritten by the second set operation.

* The tests for invalid input to func_presencestate have no way to accurately
  deduce what value func_presencestate returns. Unless I modify the C code
  to set some sort of result channel variable, it remains a mystery to the
  dialplan whether the function succeeded or failed.


Added:
    asterisk/team/mmichelson/phone-testsuite/tests/func_presencestate/configs/ast1/
    asterisk/team/mmichelson/phone-testsuite/tests/func_presencestate/configs/ast1/extensions.conf
      - copied, changed from r3110, asterisk/team/mmichelson/phone-testsuite/tests/func_presencestate/configs/extensions.conf
Removed:
    asterisk/team/mmichelson/phone-testsuite/tests/func_presencestate/configs/extensions.conf
Modified:
    asterisk/team/mmichelson/phone-testsuite/tests/func_presencestate/run-test

Copied: asterisk/team/mmichelson/phone-testsuite/tests/func_presencestate/configs/ast1/extensions.conf (from r3110, asterisk/team/mmichelson/phone-testsuite/tests/func_presencestate/configs/extensions.conf)
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mmichelson/phone-testsuite/tests/func_presencestate/configs/ast1/extensions.conf?view=diff&rev=3123&p1=asterisk/team/mmichelson/phone-testsuite/tests/func_presencestate/configs/extensions.conf&r1=3110&p2=asterisk/team/mmichelson/phone-testsuite/tests/func_presencestate/configs/ast1/extensions.conf&r2=3123
==============================================================================
--- asterisk/team/mmichelson/phone-testsuite/tests/func_presencestate/configs/extensions.conf (original)
+++ asterisk/team/mmichelson/phone-testsuite/tests/func_presencestate/configs/ast1/extensions.conf Wed Mar 21 17:13:00 2012
@@ -1,38 +1,46 @@
 [nominal1]
-exten => 1,1,Set(pass=1)
-same => n,Set(PRESENCESTATE(CustomPresence:bob)=away,down the hall,Quarterly financial meeting)
-same => n,GotoIf($[${PRESENCESTATE(CustomPresence:bob,value)} = away]?:fail)
-same => n,GotoIf($[${PRESENCESTATE(CustomPresence:bob,subtype)} = down the hall]?:fail)
-same => n,GotoIf($[${PRESENCESTATE(CustomPresence:bob,message)} = Quarterly financial meeting]?:fail
+exten => 1,1,Answer
+same => n,Set(pass=1)
+same => n,Set(PRESENCE_STATE(CustomPresence:${CONTEXT})=away,down the hall,Quarterly financial meeting)
+same => n,GotoIf($[${PRESENCE_STATE(CustomPresence:${CONTEXT},value)} = away]?:fail)
+same => n,GotoIf($["${PRESENCE_STATE(CustomPresence:${CONTEXT},subtype)}" = "down the hall"]?:fail)
+same => n,GotoIf($["${PRESENCE_STATE(CustomPresence:${CONTEXT},message)}" = "Quarterly financial meeting"]?:fail)
 same => n,Hangup
 same => n(fail),Set(pass=0)
 same => n,Hangup
  
 exten => h,1,UserEvent(Presence,Pass: ${pass})
 
-[nominal2]
-exten => 1,1,Set(pass=1)
-same => N,Set(PRESENCESTATE(CustomPresence:bob)=away,down the hall,Quarterly financial meeting)
-same => n,GotoIf($[${PRESENCESTATE(CustomPresence:bob,value)} = away]?:fail)
-same => n,GotoIf($[${PRESENCESTATE(CustomPresence:bob,subtype)} = down the hall]?:fail)
-same => n,GotoIf($[${PRESENCESTATE(CustomPresence:bob,message)} = Quarterly financial meeting]?:fail
-same => n,Set(PRESENCESTATE(CustomPresence:bob)=available)
-same => n,GotoIf($[${PRESENCESTATE(CustomPresence:bob,value)} = away]?:fail)
-same => n,GotoIf($["${PRESENCESTATE(CustomPresence:bob,subtype)}" = ""]?:fail)
-same => n,GotoIf($["${PRESENCESTATE(CustomPresence:bob,message)}" = ""]?:fail
-same => n,Hangup
-same => n(fail),Set(pass=0)
-same => n,Hangup
- 
-exten => h,1,UserEvent(Presence,Pass: ${pass})
+;This test is invalid, at least for now. The reason is that setting presence is asynchronous.
+;This means that after the second time we set presence state, we may actually attempt to read the
+;presence state before it has been set internally. The result is that we get the old state read
+;out. We don't have a reliable way to make sure that we wait for the presence state change to
+;take effect before continuing in the dialplan.
+;[nominal2]
+;exten => 1,1,Answer
+;same => n,Set(pass=1)
+;same => n,Set(PRESENCE_STATE(CustomPresence:${CONTEXT})=away,down the hall,Quarterly financial meeting)
+;same => n,GotoIf($[${PRESENCE_STATE(CustomPresence:${CONTEXT},value)} = away]?:fail)
+;same => n,GotoIf($["${PRESENCE_STATE(CustomPresence:${CONTEXT},subtype)}" = "down the hall"]?:fail)
+;same => n,GotoIf($["${PRESENCE_STATE(CustomPresence:${CONTEXT},message)}" = "Quarterly financial meeting"]?:fail)
+;same => n,Set(PRESENCE_STATE(CustomPresence:${CONTEXT})=available)
+;same => n,GotoIf($[${PRESENCE_STATE(CustomPresence:${CONTEXT},value)} = available]?:fail)
+;same => n,GotoIf($["${PRESENCE_STATE(CustomPresence:${CONTEXT},subtype)}" = ""]?:fail)
+;same => n,GotoIf($["${PRESENCE_STATE(CustomPresence:${CONTEXT},message)}" = ""]?:fail)
+;same => n,Hangup
+;same => n(fail),Set(pass=0)
+;same => n,Hangup
+; 
+;exten => h,1,UserEvent(Presence,Pass: ${pass})
 
 [base64read]
-exten => 1,1,Set(pass=1)
-same => n,Set(PRESENCESTATE(CustomPresence:bob)=away,down the hall,Quarterly financial meeting)
+exten => 1,1,Answer
+same => n,Set(pass=1)
+same => n,Set(PRESENCE_STATE(CustomPresence:${CONTEXT})=away,down the hall,Quarterly financial meeting)
 ;Note the value is not base64-encoded even if 'e' is specified as an option.
-same => n,GotoIf($[${PRESENCESTATE(CustomPresence:bob,value,e)} = away]?:fail)
-same => n,GotoIf($[${PRESENCESTATE(CustomPresence:bob,subtype,e)} = ${BASE64_ENCODE(down the hall)}]?:fail)
-same => n,GotoIf($[${PRESENCESTATE(CustomPresence:bob,message,e)} = ${BASE64_ENCODE(Quarterly financial meeting)}]?:fail
+same => n,GotoIf($[${PRESENCE_STATE(CustomPresence:${CONTEXT},value,e)} = away]?:fail)
+same => n,GotoIf($["${PRESENCE_STATE(CustomPresence:${CONTEXT},subtype,e)}" = "${BASE64_ENCODE(down the hall)}"]?:fail)
+same => n,GotoIf($["${PRESENCE_STATE(CustomPresence:${CONTEXT},message,e)}" = "${BASE64_ENCODE(Quarterly financial meeting)}"]?:fail)
 same => n,Hangup
 same => n(fail),Set(pass=0)
 same => n,Hangup
@@ -40,45 +48,60 @@
 exten => h,1,UserEvent(Presence,Pass: ${pass})
 
 [base64write]
-exten => 1,1,Set(pass=1)
-same => n,Set(PRESENCESTATE(CustomPresence:bob,e)=away,down the hall,Quarterly financial meeting)
-same => n,GotoIf($[${DB_EXISTS(CustomPresence/bob)} = 0]?:fail)
-same => n,Set(ARRAY(value,subtype,message)=${DB(CustomPresence/bob)})
-same => n,GotoIf($[${value)} = away]?:fail)
-same => n,GotoIf($[${subtype)} = ${BASE64_ENCODE(down the hall)}]?:fail)
-same => n,GotoIf($[${message)} = ${BASE64_ENCODE(Quarterly financial meeting)}]?:fail
+exten => 1,1,Answer
+same => n,Set(pass=1)
+same => n,Set(PRESENCE_STATE(CustomPresence:${CONTEXT})=away,${BASE64_ENCODE(down the hall)},${BASE64_ENCODE(Quarterly financial meeting)},e)
+same => n,GotoIf($[${DB_EXISTS(CustomPresence/${CONTEXT})} = 1]?:fail)
+same => n,Set(ARRAY(value,subtype,message)=${DB(CustomPresence/${CONTEXT})})
+same => n,GotoIf($[${value} = away]?:fail)
+same => n,GotoIf($["${subtype}" = "${BASE64_ENCODE(down the hall)}"]?:fail)
+same => n,GotoIf($["${message}" = "${BASE64_ENCODE(Quarterly financial meeting)}"]?:fail)
+;Even though the DB has the data base64-encoded, reading should decode...
+same => n,GotoIf($[${PRESENCE_STATE(CustomPresence:${CONTEXT},value)} = away]?:fail)
+same => n,GotoIf($["${PRESENCE_STATE(CustomPresence:${CONTEXT},subtype)}" = "down the hall"]?:fail)
+same => n,GotoIf($["${PRESENCE_STATE(CustomPresence:${CONTEXT},message)}" = "Quarterly financial meeting"]?:fail)
 same => n,Hangup
 same => n(fail),Set(pass=0)
 same => n,Hangup
 
 exten => h,1,UserEvent(Presence,Pass: ${pass})
 
-[no_parameter]
-exten => 1,1,Set(pass=1)
-same => n,Set(PRESENCESTATE()=away,down the hall,Quarterly financial meeting)
-same => n,Set(pass=0)
- 
-exten => h,1,UserEvent(Presence,Pass: ${pass})
-
-[invalid_provider]
-exten => 1,1,Set(pass=1)
-same => n,Set(PRESENCESTATE(CostumePresence:bob)=away,down the hall,Quarterly financial meeting)
-same => n,Set(pass=0)
- 
-exten => h,1,UserEvent(Presence,Pass: ${pass})
-
-[no_field]
-exten => 1,1,Set(pass=1)
-same => n,Set(PRESENCESTATE(CustomPresence:bob)=away,down the hall,Quarterly financial meeting)
-same => n,Set(invalid=PRESENCESTATE(CustomPresence:bob))
-same => n,Set(pass=0)
- 
-exten => h,1,UserEvent(Presence,Pass: ${pass})
-
-[invalid_field]
-exten => 1,1,Set(pass=1)
-same => n,Set(PRESENCESTATE(CustomPresence:bob)=away,down the hall,Quarterly financial meeting)
-same => n,Set(invalid=PRESENCESTATE(CustomPresence:bob,mood))
-same => n,Set(pass=0)
- 
-e
+;The following are tests that are intended to give bad input to func_presencestate.
+;The problem is that giving bad data to func_presencestate doesn't result in the call
+;being hung up immediately as I expected. Instead, it results in no change happening
+;to presence state. I also have no idea how I can check the return value of a dialplan function
+;within the dialplan. As of now, I have no way of ensuring that these bad scenarios
+;behave properly.
+;[no_parameter]
+;exten => 1,1,Answer
+;same => n,Set(pass=1)
+;same => n,Set(PRESENCE_STATE()=away,down the hall,Quarterly financial meeting)
+;same => n,Set(pass=0)
+; 
+;exten => h,1,UserEvent(Presence,Pass: ${pass})
+;
+;[invalid_provider]
+;exten => 1,1,Answer
+;same => n,Set(pass=1)
+;same => n,Set(PRESENCE_STATE(CostumePresence:${CONTEXT})=away,down the hall,Quarterly financial meeting)
+;same => n,Set(pass=0)
+; 
+;exten => h,1,UserEvent(Presence,Pass: ${pass})
+;
+;[no_field]
+;exten => 1,1,Answer
+;same => n,Set(pass=1)
+;same => n,Set(PRESENCE_STATE(CustomPresence:${CONTEXT})=away,down the hall,Quarterly financial meeting)
+;same => n,Set(invalid=PRESENCE_STATE(CustomPresence:${CONTEXT}))
+;same => n,Set(pass=0)
+; 
+;exten => h,1,UserEvent(Presence,Pass: ${pass})
+;
+;[invalid_field]
+;exten => 1,1,Answer
+;same => n,Set(pass=1)
+;same => n,Set(PRESENCE_STATE(CustomPresence:${CONTEXT})=away,down the hall,Quarterly financial meeting)
+;same => n,Set(invalid=PRESENCE_STATE(CustomPresence:${CONTEXT},mood))
+;same => n,Set(pass=0)
+; 
+;exten => h,1,UserEvent(Presence,Pass: ${pass})

Modified: asterisk/team/mmichelson/phone-testsuite/tests/func_presencestate/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/mmichelson/phone-testsuite/tests/func_presencestate/run-test?view=diff&rev=3123&r1=3122&r2=3123
==============================================================================
--- asterisk/team/mmichelson/phone-testsuite/tests/func_presencestate/run-test (original)
+++ asterisk/team/mmichelson/phone-testsuite/tests/func_presencestate/run-test Wed Mar 21 17:13:00 2012
@@ -21,23 +21,27 @@
         self.create_asterisk()
         self.contexts = [
             "nominal1",
-            "nominal2",
             "base64read",
-            "base64write",
-            "no_parameter",
-            "invalid_parameter",
-            "no_field",
-            "invalid_field"]
+            "base64write"]
+        self.passes = []
+        self.passed = False
     
-    def passOrFail(self):
-        if not event.get("userevent").lower == "presence":
+    def passOrFail(self, ami, event):
+        if not event.get("userevent") == "Presence":
             return
 
-        if event.get("Pass") == "0":
-            self.passed = False
-            reactor.stop()
-		else:
-			print("Test case passed")
+        self.passes.append(event.get("pass"))
+
+        if len(self.passes) != len(self.contexts):
+            return
+
+        for result in self.passes:
+            if result == "0":
+                reactor.stop()
+                return
+
+        self.passed = True
+        reactor.stop()
 
     def ami_connect(self, ami):
         self.ami[0].registerEvent("UserEvent", self.passOrFail)




More information about the svn-commits mailing list