!******************************************************************************!
! Initial testing for 12-bit sj Data Type conversion to other types
! Note: This test should be run with and without the /NONATIVE switch
!
! Arguments: TL (must be even)
!
! @bug      NXM-3894  12-bit integer Midas Data Type needed
! @since    4.1.2
! @author:  Jeanette McCall
!******************************************************************************!
startmacro L:TL[2]
  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 t1000sj       jeff1000sj.tmp
  res t1000sjfromsi jeff1000sjfromsi.tmp
  res t1000sjfromsl jeff1000sjfromsl.tmp
  res t1000sjfromsx jeff1000sjfromsx.tmp
  res t1000sjfromsb jeff1000sjfromsb.tmp
  res t1000sjfromsf jeff1000sjfromsf.tmp
  res t1000sjfromsd jeff1000sjfromsd.tmp
  res t1000sifromsj jeff1000sifromsj.tmp
  res t1000si jeff1000siforsj.tmp
  res t1000sl jeff1000slforsj.tmp
  res t1000sx jeff1000sxforsj.tmp
  res t1000sb jeff1000sbforsj.tmp
  res t1000sd jeff1000sdforsj.tmp
  res t1000sf jeff1000sfforsj.tmp
  res t1000sn jeff1000snforsj.tmp

  res  defaultAmp 0x1270
  call createAndNoopTo12Bit defaultAmp
  call checkResults

  if interAct then
    set instructions "Tests SJ 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=list1000sj t1000sj
      list2/id=list1000si t1000sjfromsi
      list2/id=list1000sb t1000sjfromsb
      list2/id=list1000sd t1000sjfromsd
      list2/id=list1000sf t1000sjfromsf
      list2/id=list1000sn t1000sjfromsn
      list2/id=list1000sl t1000sjfromsl
      list2/id=list1000sx t1000sjfromsx

      shellgui/id=statusshell/attach
      info "status of 1000 SJ"
      status  t1000sj
      info "status of 1000 SI NOOP to SJ"
      status  t1000sjfromsi
      info "status of 1000 SL NOOP to SJ"
      status  t1000sjfromsl
      info "status of 1000 SX NOOP to SJ"
      status  t1000sjfromsx
      info "status of 1000 SD NOOP to SJ"
      status  t1000sjfromsd
      info "status of 1000 SF NOOP to SJ"
      status  t1000sjfromsf
    pipe off

  endif

  erase t1000sj t1000si t1000sl t1000sx t1000sb t1000sd t1000sf t1000sn
  erase t1000sjfromsi t1000sjfromsl t1000sjfromsx t1000sjfromsb t1000sjfromsd
  erase t1000sjfromsf t1000sjfromsn t1000sifromsj

  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 SJ
!******************************************************************************!
procedure createAndNoopTo12Bit L:AMPLITUDE
    waveform t1000sj FORM="SJ" AMP=^AMPLITUDE ELEM=512
    waveform t1000si FORM="SI" AMP=^AMPLITUDE ELEM=512
    waveform t1000sl FORM="SL" AMP=^AMPLITUDE ELEM=512
    waveform t1000sx FORM="SX" AMP=^AMPLITUDE ELEM=512
    waveform t1000sd FORM="SD" AMP=^AMPLITUDE ELEM=512
    waveform t1000sf FORM="SF" AMP=^AMPLITUDE ELEM=512
    waveform t1000sb FORM="SB" AMP=0x80   ELEM=512
    waveform t1000sn FORM="SN" AMP=0x6    ELEM=512
    noop t1000si t1000sjfromsi{FORM="SJ"} /TL=^TL
    noop t1000sl t1000sjfromsl{FORM="SJ"} /TL=^TL
    noop t1000sx t1000sjfromsx{FORM="SJ"} /TL=^TL
    noop t1000sb t1000sjfromsb{FORM="SJ"} /TL=^TL
    noop t1000sf t1000sjfromsf{FORM="SJ"} /TL=^TL
    noop t1000sd t1000sjfromsd{FORM="SJ"} /TL=^TL
    noop t1000sn t1000sjfromsn{FORM="SJ"} /TL=^TL
    noop t1000sj t1000sifromsj{FORM="SI"} /TL=^TL

return

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

  message send list1000sj ,,"OPENFILE" ,, t1000sj
  message send list1000si ,,"OPENFILE" ,, t1000sjfromsi
  message send list1000sb ,,"OPENFILE" ,, t1000sjfromsb
  message send list1000sd ,,"OPENFILE" ,, t1000sjfromsd
  message send list1000sf ,,"OPENFILE" ,, t1000sjfromsf
  message send list1000sn ,,"OPENFILE" ,, t1000sjfromsn
  message send list1000sl ,,"OPENFILE" ,, t1000sjfromsl
  message send list1000sx ,,"OPENFILE" ,, t1000sjfromsx

return

!******************************************************************************!
! Check results
!******************************************************************************!
procedure checkResults
  assert/text="^reg.main.name: SJ matches SI within expected tolerance" t1000si FEQ/D/T t1000sifromsj /DELTA=0x10
  assert/text="^reg.main.name: SJ from SI matches SJ WAVEFORM"          t1000sj FEQ/D   t1000sjfromsi
  assert/text="^reg.main.name: SJ from SL matches SJ WAVEFORM"          t1000sj FEQ/D   t1000sjfromsl
  assert/text="^reg.main.name: SJ from SX matches SJ WAVEFORM"          t1000sj FEQ/D   t1000sjfromsx
  assert/text="^reg.main.name: SJ from SD matches SJ WAVEFORM"          t1000sj FEQ/D   t1000sjfromsd
  assert/text="^reg.main.name: SJ from SF matches SJ WAVEFORM"          t1000sj FEQ/D   t1000sjfromsf
return

!******************************************************************************!
! Check SJ data within range SI data
!******************************************************************************!
procedure checkDataSJ

return
