!******************************************************************************!
! Initial testing for 12-bit CJ Data Type conversion to other types
! Note: This test should be run with and without the /NONATIVE switch
!
! Arguments: TL
!
! @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

  res t1000cj       jeff1000cj.tmp
  res t1000cjfromci jeff1000cjfromci.tmp
  res t1000cjfromcl jeff1000cjfromcl.tmp
  res t1000cjfromcx jeff1000cjfromcx.tmp
  res t1000cjfromcb jeff1000cjfromcb.tmp
  res t1000cjfromcf jeff1000cjfromcf.tmp
  res t1000cjfromcd jeff1000cjfromcd.tmp
  res t1000cifromcj jeff1000cifromcj.tmp
  res t1000ci jeff1000ciforcj.tmp
  res t1000cl jeff1000clforcj.tmp
  res t1000cx jeff1000cxforcj.tmp
  res t1000cb jeff1000cbforcj.tmp
  res t1000cd jeff1000cdforcj.tmp
  res t1000cf jeff1000cfforcj.tmp
  res t1000cn jeff1000cnforcj.tmp

  res  defaultAmp 0x80
  call createAndNoopTo12Bit defaultAmp
  call checkResults

  if interAct then
    set instructions "Tests CJ DataType\n\n&
                      This needs to be run with and without the NONATIVE switch\n\n&
                      Curently NONATIVE = ^{nonative}\n\n&
                      Please check the automated results in the terminal."

    pipe on
      panel/msgid=MAIN/setup/controls=gc
      gcontrol label macro "Test MACRO"
      gcontrol menu  main "Exit with Status =" "PASS,FAIL" TABLE={ItemColors={PASS="GREEN",FAIL="RED"}} /tleft

      gcontrol text   idtext "Instructions" instructions 24 12 /title
      gcontrol lval   amp "WAVEFORM amplitude" P1=defaultAmp P2=0x10 P3=0x7000 P4=0x10
      gcontrol button test "" "Check Results"

      list2/id=list1000cj t1000cj
      list2/id=list1000ci t1000cjfromci
      list2/id=list1000cb t1000cjfromcb
      list2/id=list1000cd t1000cjfromcd
      list2/id=list1000cf t1000cjfromcf
      list2/id=list1000cn t1000cjfromcn
      list2/id=list1000cl t1000cjfromcl
      list2/id=list1000cx t1000cjfromcx

      shellgui/id=statusshell/attach
      info "status of 1000 CJ"
      status  t1000cj
      info "status of 1000 CJ created from CI"
      status  t1000cjfromci
      info "status of 1000 CJ created from CB"
      status  t1000cjfromcb
      info "status of 1000 CJ created from CD"
      status  t1000cjfromcd
      info "status of 1000 CJ created from CF"
      status  t1000cjfromcf
      info "status of 1000 CJ created from CN"
      status  t1000cjfromcn
    pipe off
  endif

  erase t1000cj t1000ci t1000cl t1000cx t1000cb t1000cd t1000cf t1000cn
  erase t1000cjfromci t1000cjfromcl t1000cjfromcx t1000cjfromcb t1000cjfromcd
  erase t1000cjfromcf t1000cjfromcn t1000cifromcj

  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
  elseif msg.name eqs "AMP" then
    call createAndNoopTo12Bit msg.data
    call updateList2
  elseif msg.name eqs "TEST" then
    call checkResults
  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

!******************************************************************************!
! Create files with different formats and convert them to CJ
!******************************************************************************!
procedure createAndNoopTo12Bit L:AMPLITUDE

    waveform t1000cj FORM="CJ" AMP=^AMPLITUDE ELEM=512
    waveform t1000ci FORM="CI" AMP=^AMPLITUDE ELEM=512
    waveform t1000cl FORM="CL" AMP=^AMPLITUDE ELEM=512
    waveform t1000cx FORM="CX" AMP=^AMPLITUDE ELEM=512
    waveform t1000cb FORM="CB" AMP=^AMPLITUDE ELEM=512
    waveform t1000cd FORM="CD" AMP=^AMPLITUDE ELEM=512
    waveform t1000cf FORM="CF" AMP=^AMPLITUDE ELEM=512
    waveform t1000cn FORM="CN" AMP=^AMPLITUDE ELEM=512
    noop t1000ci t1000cjfromci{FORM="CJ"} /TL=^TL
    noop t1000cl t1000cjfromcl{FORM="CJ"} /TL=^TL
    noop t1000cx t1000cjfromcx{FORM="CJ"} /TL=^TL
    noop t1000cb t1000cjfromcb{FORM="CJ"} /TL=^TL
    noop t1000cf t1000cjfromcf{FORM="CJ"} /TL=^TL
    noop t1000cd t1000cjfromcd{FORM="CJ"} /TL=^TL
    noop t1000cn t1000cjfromcn{FORM="CJ"} /TL=^TL
    noop t1000cj t1000cifromcj{FORM="CI"} /TL=^TL

return

!******************************************************************************!
! Update LIST2 values
!******************************************************************************!
procedure updateList2

  message send list1000cj ,,"OPENFILE" ,, t1000cj
  message send list1000ci ,,"OPENFILE" ,, t1000cjfromci
  message send list1000cb ,,"OPENFILE" ,, t1000cjfromcb
  message send list1000cd ,,"OPENFILE" ,, t1000cjfromcd
  message send list1000cf ,,"OPENFILE" ,, t1000cjfromcf
  message send list1000cn ,,"OPENFILE" ,, t1000cjfromcn
  message send list1000cl ,,"OPENFILE" ,, t1000cjfromcl
  message send list1000cx ,,"OPENFILE" ,, t1000cjfromcx

return

!******************************************************************************!
! Check results
!******************************************************************************!
procedure checkResults
  assert/text="^reg.main.name: CJ matches CI within expected tolerance" t1000ci FEQ/D/T t1000cifromcj /DELTA=0x10
  assert/text="^reg.main.name: CJ from CI matches CJ WAVEFORM"          t1000cj FEQ/D   t1000cjfromci
  assert/text="^reg.main.name: CJ from CL matches CJ WAVEFORM"          t1000cj FEQ/D   t1000cjfromcl
  assert/text="^reg.main.name: CJ from CX matches CJ WAVEFORM"          t1000cj FEQ/D   t1000cjfromcx
  assert/text="^reg.main.name: CJ from CD matches CJ WAVEFORM"          t1000cj FEQ/D   t1000cjfromcd
  assert/text="^reg.main.name: CJ from CF matches CJ WAVEFORM"          t1000cj FEQ/D   t1000cjfromcf
return


