!******************************************************************************!
! Testing for 12-bit J Data Type as a Result
! Includes CALC, IF, LOOP, DO, and TABLE
!
! @bug      NXM-3894  12-bit integer Midas Data Type needed
! @since    4.1.2
! @author:  Jeanette McCall
!******************************************************************************!
startmacro L:TL[1]
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE  ! for defects or more obscure test case(s)
  switch NONATIVE    nonative GET DEF=FALSE SDEF=TRUE  ! run with all Java

  res savedUseNative env.usenative
  if nonative then
    env set usenative |
  else
    env set usenative |IO|Math|Cast|Convert|Other|
  endif

  ! Test RESULTS and CALC
  res j:jeffjint 128
  calc j:jeffjint2 jeffjint 2 *
  assert/text="^reg.main.name: CALC with JINT" jeffjint2 eq 256
  invoke format jeffjint.getFormat()
  assert/text="^reg.main.name: JINT result correct format" format eqs "SJ"
  invoke format jeffjint2.getFormat()
  assert/text="^reg.main.name: JINT CALC result correct format" format eqs "SJ"

  ! TEST IF
  if jeffjint EQ 128 then
    assert/text="^reg.main.name: IF JINT works" true ISTRUE
  else
    assert/text="^reg.main.name: IF JINT works" false ISTRUE
  endif

  ! TEST LOOP
  res jintloop 0
  LOOP jeffjint
    calc jintloop jintloop 1 +
  ENDLOOP
  assert/text="^reg.main.name: LOOP JINT works" jintloop EQ 128

  ! Test DO
  res jintdo 0
  DO START=126 END=jeffjint INC=1
     calc jintdo jintdo 1 +
  ENDDO
  assert/text="^reg.main.name: DO JINT works" jintdo EQ 3

  ! TEST TABLE entry
  table jinttable create {J:JEFFJINT=1024,I:PLAININT=1024}
  invoke format jinttable.jeffjint.getFormat()
  assert/text="^reg.main.name: JINT in Table correct format" format eqs "SJ"
  assert/text="^reg.main.name: JINT in Table correct value" jinttable.jeffjint EQ 1024

  env set usenative savedUseNative
endmacro

!******************************************************************************!
! Main process message for this macro. Should be right after the ENDMACRO.
!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop
  else
    say "Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return

!******************************************************************************!
! If an unexpected exception is caught, mark test as failed, unless it is expected
!******************************************************************************!
procedure processException m:emsg
  if expectedException REXISTS then
    assert/text="^reg.main.name: Expected ERROR starts with: ^{expectedException}" expectedException EQSS emsg.data.message
    remove expectedException
  else
    assert/text="^reg.main.name: Caught unexpected exception ^{emsg.data}" "FALSE" isTrue
    if "Trace" SUBS ENV.DEBUG then invoke ,, emsg.data.printStackTrace()
  endif
return
