[Asterisk-code-review] app_if: Add tests for conditional branch apps (testsuite[18])
Friendly Automation
asteriskteam at digium.com
Fri Dec 9 06:58:31 CST 2022
Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/testsuite/+/19676 )
Change subject: app_if: Add tests for conditional branch apps
......................................................................
app_if: Add tests for conditional branch apps
Adds tests for If, ElseIf, Else, ExitIf, and
EndIf applications.
ASTERISK-29497
Change-Id: Iff228c42c9338e1461950ab9fb85f3edf404daae
---
A tests/apps/if/configs/ast1/extensions.conf
A tests/apps/if/test-config.yaml
M tests/apps/tests.yaml
3 files changed, 211 insertions(+), 0 deletions(-)
Approvals:
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
diff --git a/tests/apps/if/configs/ast1/extensions.conf b/tests/apps/if/configs/ast1/extensions.conf
new file mode 100644
index 0000000..450821c
--- /dev/null
+++ b/tests/apps/if/configs/ast1/extensions.conf
@@ -0,0 +1,135 @@
+
+[default]
+exten => s,1,Answer()
+ ; test If true
+ same => n,If(1)
+ same => n,UserEvent(IfSuccess,Result: Pass)
+ same => n,EndIf()
+ ; test If false
+ same => n,If(0)
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,EndIf()
+ ; test If false
+ same => n,If(1)
+ same => n,NoOp()
+ same => n,Else() ; shouldn't execute this
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,EndIf()
+ ; test ExitIf
+ same => n,If(1)
+ same => n,ExitIf()
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,EndIf()
+ ; test Else
+ same => n,If(0)
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,Else()
+ same => n,Goto(after)
+ same => n,EndIf()
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n(after),NoOp()
+ ; test ElseIf
+ same => n,If(0)
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,ElseIf(0)
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,ElseIf(0)
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,Goto(after)
+ same => n,ElseIf(1)
+ same => n,UserEvent(IfSuccess,Result: Pass)
+ same => n,Else()
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,EndIf()
+ same => n(after),NoOp()
+ ; test ElseIf #2
+ same => n,If(0)
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,ElseIf(0)
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,ElseIf(0)
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,ElseIf(1)
+ same => n,Goto(after2)
+ same => n,Else()
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,EndIf()
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n(after2),NoOp()
+ ; test nested If
+ same => n,If(1)
+ same => n,If(1)
+ same => n,UserEvent(IfSuccess,Result: Pass)
+ same => n,ExitIf()
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,EndIf()
+ same => n,UserEvent(IfSuccess,Result: Pass)
+ same => n,ExitIf()
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,EndIf()
+ same => n,UserEvent(IfSuccess,Result: Pass)
+ ; test really nested
+ same => n,If(1)
+ same => n,If(1)
+ same => n,If(0)
+ same => n,Else()
+ same => n,UserEvent(IfSuccess,Result: Pass)
+ same => n,ExitIf()
+ same => n,EndIf()
+ same => n,UserEvent(IfSuccess,Result: Pass)
+ same => n,ExitIf()
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,EndIf()
+ same => n,UserEvent(IfSuccess,Result: Pass)
+ same => n,ExitIf()
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,EndIf()
+ ; test that Else doesn't execute after true If
+ same => n,If(1)
+ same => n,NoOp()
+ same => n,Else()
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,EndIf()
+ ; test that ElseIf doesn't execute after true If
+ same => n,If(1)
+ same => n,NoOp()
+ same => n,ExitIf()
+ same => n,ElseIf(1) ; needed to exit If before ElseIf (but not before Else)
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,EndIf()
+ ; test that Else/ElseIf doesn't execute after true If
+ same => n,If(1)
+ same => n,NoOp()
+ same => n,ExitIf()
+ same => n,ElseIf(1)
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,Else()
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,EndIf()
+ ; test that If matches Else only if it's before its EndIf
+ same => n,If(0)
+ same => n,NoOp()
+ same => n,EndIf()
+ same => n,If(1)
+ same => n,NoOp()
+ same => n,Else()
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,EndIf()
+ ; test that If matches ElseIf only if it's before its EndIf
+ same => n,If(0)
+ same => n,NoOp()
+ same => n,EndIf()
+ same => n,If(1)
+ same => n,NoOp()
+ same => n,ExitIf() ; needed to exit If before ElseIf (but not before Else)
+ same => n,ElseIf(1)
+ same => n,UserEvent(IfSuccess,Result: Fail)
+ same => n,EndIf()
+ ; all tests succeeded
+ same => n,UserEvent(IfSuccess,Result: Pass)
+ same => n,Hangup()
+
+[nothing]
+exten => 0,1,Answer()
+ same => n,Wait(10)
+ same => n,Hangup()
diff --git a/tests/apps/if/test-config.yaml b/tests/apps/if/test-config.yaml
new file mode 100644
index 0000000..ac0f892
--- /dev/null
+++ b/tests/apps/if/test-config.yaml
@@ -0,0 +1,61 @@
+testinfo:
+ summary: 'Ensure that app_if functions correctly.'
+ description: |
+ 'This tests the If, ElseIf, Else, EndIf, and ExitIf applications to make sure
+ that they work correctly. This includes nesting application calls to ensure
+ that nesting behavior is correct and that different combos of app calls use
+ the appropriate logic.'
+
+test-modules:
+ test-object:
+ config-section: test-object-config
+ typename: 'test_case.TestCaseModule'
+ modules:
+ -
+ config-section: caller-originator
+ typename: 'pluggable_modules.Originator'
+ -
+ config-section: hangup-monitor
+ typename: 'pluggable_modules.HangupMonitor'
+ -
+ config-section: ami-config
+ typename: 'pluggable_modules.EventActionModule'
+
+test-object-config:
+ connect-ami: True
+
+caller-originator:
+ channel: 'Local/s at default'
+ context: 'nothing'
+ exten: '0'
+ priority: '1'
+ trigger: 'ami_connect'
+
+hangup-monitor:
+ ids: '0'
+
+ami-config:
+ -
+ ami-events:
+ conditions:
+ match:
+ Event: 'UserEvent'
+ UserEvent: 'IfSuccess'
+ requirements:
+ match:
+ Result: 'Pass'
+ count: 9
+ stop_test:
+
+properties:
+ tags:
+ - dial
+ - apps
+ dependencies:
+ - python: 'twisted'
+ - python: 'starpy'
+ - asterisk: 'app_dial'
+ - asterisk: 'app_userevent'
+ - asterisk: 'app_originate'
+ - asterisk: 'app_if'
+ - asterisk: 'pbx_config'
diff --git a/tests/apps/tests.yaml b/tests/apps/tests.yaml
index 6dd267f..f74ba8e 100644
--- a/tests/apps/tests.yaml
+++ b/tests/apps/tests.yaml
@@ -29,3 +29,4 @@
- test: 'mf'
- test: 'sf'
- test: 'read'
+ - test: 'if'
--
To view, visit https://gerrit.asterisk.org/c/testsuite/+/19676
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: testsuite
Gerrit-Branch: 18
Gerrit-Change-Id: Iff228c42c9338e1461950ab9fb85f3edf404daae
Gerrit-Change-Number: 19676
Gerrit-PatchSet: 1
Gerrit-Owner: N A <asterisk at phreaknet.org>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20221209/98f72dad/attachment-0001.html>
More information about the asterisk-code-review
mailing list