[test-enum]
;
; Test the results of a "count" function, which should tell us the number
;  of NAPTR records in total for a given technology/number. This example
;  should assume SIP as the technology.
; Should return 3.
;
exten => _X.,1,Set(ARRAY(FAILED,GOOD,TFAILED,ITERATION)=0,0,"",test1))
exten => _X.,n,Set(${ITERATION}-CORRECT=3)
exten => _X.,n,Set(${ITERATION}-RESULT=${ENUMLOOKUP(+13015611020,,c,,loligo.com)})
exten => _X.,n,Gosub(test-em,${EXTEN},1)
;
;
; Test a "count" with an explicit technology/method ("tel") 
;  Should return "2"
;
exten => _X.,n,Set(ITERATION=2)
exten => _X.,n,Set(${ITERATION}-CORRECT=2)
exten => _X.,n,Set(${ITERATION}-RESULT=${ENUMLOOKUP(+13015611020,tel,c,,loligo.com)})
exten => _X.,n,Gosub(test-em,${EXTEN},1)
;
;
; Test just a SIP lookup for an E.164-ish number in the loligo.com zone. It should
;  use the first reply back on the list of SIP NAPTRs.
; Should return "2203@sip.fox-den.com"
; 
exten => _X.,n,Set(ITERATION=3)
exten => _X.,n,Set(${ITERATION}-CORRECT=2203@sip.fox-den.com)
exten => _X.,n,Set(${ITERATION}-RESULT=${ENUMLOOKUP(+13015611020,,,,loligo.com)})
exten => _X.,n,Gosub(test-em,${EXTEN},1)
;
;
; Test for total count of all NAPTR records for +13015611020 in loligo.com zone, 
;  regardless of technology/method type or number of results in each technology/method
;  category. 
;  Should return 6.
;
exten => _X.,n,Set(ITERATION=4)
exten => _X.,n,Set(${ITERATION}-CORRECT=6)
exten => _X.,n,Set(${ITERATION}-RESULT=${ENUMLOOKUP(+13015611020,ALL,c,,loligo.com)}) 
exten => _X.,n,Gosub(test-em,${EXTEN},1)
;
;
; Test Freenum/ISN lookup format.  Does a lookup on a NAPTR for 4.3.2.1.256.freenum.org
;  Should return "1234@loligo.com"
;
;
;
; Test Freenum/ISN lookup format with explicit SIP tech/method.
;  Should return "1234@loligo.com"
;
exten => _X.,n,Set(ITERATION=5)
exten => _X.,n,Set(${ITERATION}-CORRECT=2203@loligo.com)
exten => _X.,n,Set(${ITERATION}-RESULT=${ENUMLOOKUP(1234*256,ALL,s,2,freenum.org)})
exten => _X.,n,Gosub(test-em,${EXTEN},1)
;
;
; Test Freenum/ISN lookup format with explicit SIP tech/method.
;  Should return "1234@loligo.com"
;
exten => _X.,n,Set(ITERATION=6)
exten => _X.,n,Set(${ITERATION}-CORRECT=2203@loligo.com)
exten => _X.,n,Set(${ITERATION}-RESULT=${ENUMLOOKUP(1234*256,sip,s,,freenum.org)})
exten => _X.,n,Gosub(test-em,${EXTEN},1)
;
;
; Try to get the 2nd priority "tel" method entry in a list.
;  Should return "+14155551212"
;
exten => _X.,n,Set(ITERATION=7)
exten => _X.,n,Set(${ITERATION}-CORRECT=+14155551212)
exten => _X.,n,Set(${ITERATION}-RESULT=${ENUMLOOKUP(+13015611020,tel,,2,loligo.com)})
exten => _X.,n,Gosub(test-em,${EXTEN},1)
;
;
; Get an NAPTR result without an ENUM-like reversal of digits, using a record
;  that happens to have a SIP NAPTR for unexplained reasons.  :-)
;  Should result in "2203@loligo.com"
;
exten => _X.,n,Set(ITERATION=8)
exten => _X.,n,Set(${ITERATION}-CORRECT=2203@loligo.com)
exten => _X.,n,Set(${ITERATION}-RESULT=${ENUMLOOKUP(www,sip,d,,loligo.com)})
exten => _X.,n,Gosub(test-em,${EXTEN},1)
;
;
; Get the "mailto" NAPTR from a lookup, just to test non-SIP methods.
;  Should result in "jtodd@fox-den.com"
;
exten => _X.,n,Set(ITERATION=9)
exten => _X.,n,Set(${ITERATION}-CORRECT=jtodd@fox-den.com)
exten => _X.,n,Set(${ITERATION}-RESULT=${ENUMLOOKUP(+13015611020,mailto,,,loligo.com)})
exten => _X.,n,Gosub(test-em,${EXTEN},1)
;
;
; Test a different regexp match.  The third regexp in my NAPTR SIP data
;  looks like this:  "!^\\+*([^\\*]*)!sip:\\1@sip-3.fox-den.com!" . which
;  means (basically): strip any leading "+" signs and re-write the URL. 
;  Should result in "13015611020@sip-3.fox-den.com"
;
exten => _X.,n,Set(ITERATION=10)
exten => _X.,n,Set(${ITERATION}-CORRECT=13015611020@sip-3.fox-den.com)
exten => _X.,n,Set(${ITERATION}-RESULT=${ENUMLOOKUP(+13015611020,,,3,loligo.com)}) 
exten => _X.,n,Gosub(test-em,${EXTEN},1)
;
;
; Test an actual e164.arpa number, using all defaults.
;  Should result in enum-test@sip.nemox.net
;
exten => _X.,n,Set(ITERATION=11)
exten => _X.,n,Set(${ITERATION}-CORRECT=enum-test@sip.nemox.net)
exten => _X.,n,Set(${ITERATION}-RESULT=${ENUMLOOKUP(+43780004711)})
exten => _X.,n,Gosub(test-em,${EXTEN},1)
;
;
; Test an infrastructure ENUM lookup in e164.arpa.
;  Should result in 4313061000@enum.sil.at
;
exten => _X.,n,Set(ITERATION=12)
exten => _X.,n,Set(${ITERATION}-CORRECT=4313061000@enum.sil.at)
exten => _X.,n,Set(${ITERATION}-RESULT=${ENUMLOOKUP(+4313061000,,i)})
exten => _X.,n,Gosub(test-em,${EXTEN},1)
;
;
; Test Freenum/ISN lookup format.  Does a lookup on a NAPTR for 4.3.2.1.256.freenum.org
;  Should return "@204.91.156.10/1234*256"
;
exten => _X.,n,Set(ITERATION=13)
exten => _X.,n,Set(${ITERATION}-CORRECT=@204.91.156.10/1234*256)
exten => _X.,n,Set(${ITERATION}-RESULT=${ENUMLOOKUP(1234*256,iax2,s,,freenum.org)})
exten => _X.,n,Gosub(test-em,${EXTEN},1)
;
;
; Test Freenum/ISN lookup format with explicit SIP tech/method.
;  Should return "1234*256@loligo.com"
;
exten => _X.,n,Set(ITERATION=14)
exten => _X.,n,Set(${ITERATION}-CORRECT=1234*256@loligo.com)
exten => _X.,n,Set(${ITERATION}-RESULT=${ENUMLOOKUP(1234*256,sip,s,,freenum.org)})
exten => _X.,n,Gosub(test-em,${EXTEN},1)

;
; Give summary report of tests before quiting
;
exten => _X.,n,NoOp(Overall Test Results good: ${GOOD} and failed ${FAILED})
exten => _X.,n,NoOp(Test Results FAILED: ${TFAILED})
exten => _X.,n,Hangup

exten => h,1,Hangup
;
;
;
[test-em]
; 
; This is the test subroutine to actually do all the tests above.
;
exten => _X.,1,NoOp(Comparitor is "${${ITERATION}-RESULT}" and correct value is "${${ITERATION}-CORRECT}")
exten => _X.,n,GotoIf($["${${ITERATION}-RESULT}" = "${${ITERATION}-CORRECT}"]?good:fail)
exten => _X.,n(good),NoOp(SUCCESS: ${ITERATION} gave the correct result, which was ${${ITERATION}-CORRECT}})
exten => _X.,n(gcount),Set(GOOD=$[${GOOD} +1])
exten => _X.,n(goodret),Return
exten => _X.,n(fail),NoOp(FAIL: ${ITERATION} gave the incorrect result, which was ${${ITERATION}-RESULT}.  Should have been ${${ITERATION}-CORRECT}.)
exten => _X.,n(bcount),Set(ARRAY(FAILED,TFAILED)=$[${FAILED} + 1],${IF($[ ${ISNULL(${TFAILED})} ] ? ${ITERATION} : "${TFAILED},${ITERATION}")})
