! Tests the accessing of X-Midas results from NeXtMidas.
!
! @author  J. Czechowski IV
! @version $Id: test_results.txt,v 1.9 2011/01/06 23:14:46 ntn Exp $
!
startmacro/ps=128k u:resTests["numTested"] u:resFails["numFailed"]

  !---------- INITIALIZATION -----------------------------------------------------------------------
  local fs,fwidth,form,pass,item,test_count,fail_count
  res test_count 0
  res fail_count 0

  local baseln       ! Baseline testing?
  local interAct     ! Interactive?

  switch BASELINE    baseln GET               ! Baseline testing?
  switch INTERACTIVE interAct GET             ! Interactive?
  if baseln   eq -1 then res baseln    1      ! switch not specified, default to enable Baseline testing
  if interAct eq -1 then res interAct ^baseln ! switch not specified, default to ^baseline

  result form "SF"

  !---------- PART 1: Basic results tests ----------------------------------------------------------
  nm/on/bg/id=999
  result test_val0 "NORMAL"
  result test_val1 "SF"
  nm set xm."test_val0" "HIDDEN"
  nm set   xm.test_val2 "VD"
  nm set   xm.test_val3 3.14
  nm set   xm.test_val4 "0123"
  nm set S:xm.test_val5 0123
  nm set L:xm.test_val6 0123
  nm set L:xm.test_val7 3.14

  ! Use 1 for mode (1=LD_wait) to work around *possible* X-Midas issue, see Bug 1469 for details.
  nm invoke ,, nxm.sys.libxm.XmShell.dispatch("res l:test_val8 100",1,0) /verbose=false

  call assert_str "Write X-Midas results from NeXtMidas (string)" test_count fail_count "VD" test_val2
  call assert_num "Write X-Midas results from NeXtMidas (number)" test_count fail_count 3.14 test_val3

  nm assert/STAT="STATUS"/DEBUG=NO xm.test_val1 eqs "SF"
  nm set xm.status status
  call assert_str "Read X-Midas results from NeXtMidas" test_count fail_count "PASS" status

  ! Note that test_val6 and test_val7 use string checks to make sure that there is no decimal
  ! places. (JC4: This is not the best way of doing this, but I guess it will work for now.)
  call assert_str "Able to set hidden result"    test_count fail_count "NORMAL" "^test_val0"
  call assert_str "Quoted string remains string" test_count fail_count "0123"     test_val4
  call assert_str "S: string remains string"     test_count fail_count "0123"     test_val5
  call assert_str "L: string becomes long"       test_count fail_count "123"    "^test_val6"
  call assert_str "L: double becomes long"       test_count fail_count "3"      "^test_val7"
  call assert_num "Test for XmShell.dispatch"    test_count fail_count 100        test_val8
  nm/off


  !---------- PART 2: Tests with widgets and controls ----------------------------------------------
if interAct le 0 then
  info "Run %test_results/baseline or with /interactive to enable additional tests that requires X11 display"
else
  nm/on/bg/id=999
  xpipe/controls/np=10 on
    waveform/tl=1k/rt/ctag=3:SFREQ _wave ^form 1e5 SIN 1e4,,,1/1e5
    mfft/rs/fftp=3 _wave _wavep 1k hann 0.0
    status/quiet _wavep ,,,,, fs
    magnitude/tl=fs _wavep _waveb(ft=b) 20 log
  xpipe off
  nm/off
endif

  !---------- CLEANUP ------------------------------------------------------------------------------
  rem/quiet test_val*
  rem/quiet SFREQ
  rem/quiet STATUS

  res ^resTests test_count
  res ^resFails fail_count
endmacro


!===================================================================================================
startcontrols
  label initialentry
    xcontrol/lab=domenu1 menu item ,, "Testing;Cancel"

    nm assert/STAT="STATUS"/DEBUG=NO xm.sfreq eqt 0.01
    nm set xm.status status
    call assert_str "Read X-Midas control value from NeXtMidas" test_count fail_count "PASS" status

    stop
  return

  label domenu1
    if item eq 1 then
      stop
    endif
  return

endcontrols

!===================================================================================================
include "%xm_assert" ! Includes the assertion subroutines
