!******************************************************************************!
! Test the display of custom units in the Axis
!
! @bug      2795 PLOT: Component units displayed on Axis can be wrong for Type 5000/6000 files. 
! @author:  J Bauer / J Czechowski
!******************************************************************************!
startmacro
  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 NOTIMER     notimer  GET DEF=FALSE SDEF=TRUE  ! to disable timers

  if interAct then
    set instructions "This test will run and test itself automatically. Use /notimer to run manually."

    ! create the file and use custom units
    waveform ram:myfile form=CF
    headermod ram:myfile components=(REAL/SF/0/SF,IMAG/SF/0/IMAGINARY)

    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 8 /title
      
      ! The plot SHOULD show REAL and IMAG as the Axis labels.
      plot ram:myfile{LAYER={LT="Scatter",X="REAL",Y="IMAG"}}
  
      if notimer isFalse then
        set this.timer(0) 1
      endif
      
    pipe off

  endif
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 "TIMER" then
    assert/text="^reg.main.name: Axis X Label set correctly" reg.plot.xAxisLabel eqs "REAL"
    assert/text="^reg.main.name: Axis Y Label set correctly" reg.plot.yAxisLabel eqs "IMAG"
    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
