!******************************************************************************!
! This tests that the data types U and V are supported for read operation when
! setting the core io option MinimalSupportForUnsupportedDataTypes.
!
! Arguments: None
!
! Issue:   NXM-3021 minimal unsigned type support
! Since:   NeXtMidas 3.9.3
! Author:  Kevin Esterheld
!******************************************************************************!
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)

  ENV GET IOOPTIONS origIOOptions
  set filetotest "nxm.sys.test.unsigned_values_3000.prm"
  env set iooptions +MinimalSupportForUnsupportedDataTypes
  FILE/D open testfile filetotest
  call runAutomaticTest

  ! Allow most of the tests to run in a thinned NeXtMidas by skipping only ones needing missing dependencies
  invoke gcontrolExists reg.shell.M.dictionary.isDictionaryEntry(GCONTROL)

  if interAct AND gcontrolExists then
    set instructions "Should see 2 panes with the first one holding a list2 and the second with the keywords &
                      of the file.\n\n&
                      LIST2 (left pane) should show these values:\n&
                      | SR2A  | SRSL | SRSU |   SRSV    |        SRCV     |\n&
                      |FIRST  | 65536| 65535| 4294967295| ( 4294967295, 5)|\n&
                      |SECOND | 32769| 32768| 2147483648| ( 2147483648, 4)|\n&
                      \n&
                      STATUS/KEY (right pane) should show some of the subrecords having &
                      unsigned types and should have these keyword values:\n&
                      V:CVKEY            == (4294967295,1024)\n&
                      V:UINT             == 4294967295\n&
                      U:USHORT           == 65535"

    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 20 /title
      list2 filetotest
      shellgui/id=idshellgui/attach
      status/key filetotest
    pipe off

  endif
  file close testfile

  env set iooptions origIOOptions

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

procedure runAutomaticTest

  res F:testFVal 4.2949673E9 ! this value is needed to test the value against a float. It automatically tries to test against double unless it is defined as float
  res D:dval testfile.getData(0.0,"SRSU")
  assert/text="^reg.main.name: U to D value" dval eq 65535
  res F:fval testfile.getData(0.0,"SRSU")
  assert/text="^reg.main.name: U to F value" fval eq 65535
  res X:xval testfile.getData(0.0,"SRSU")
  assert/text="^reg.main.name: U to X value" xval eq 65535
  res L:lval testfile.getData(0.0,"SRSU")
  assert/text="^reg.main.name: U to L value" lval eq 65535
  res I:ival testfile.getData(0.0,"SRSU")
  assert/text="^reg.main.name: U to I value" ival eq 32767
  res B:bval testfile.getData(0.0,"SRSU")
  assert/text="^reg.main.name: U to B value" bval eq 127
  res N:nval testfile.getData(0.0,"SRSU")
  assert/text="^reg.main.name: U to N value" nval eq 7
  res P:pval testfile.getData(0.0,"SRSU")
  assert/text="^reg.main.name: U to P value" pval eq 1
  res D:dval testfile.getData(0.0,"SRSV")
  assert/text="^reg.main.name: V to D value" dval eq 4294967295
  res F:fval testfile.getData(0.0,"SRSV")
  assert/text="^reg.main.name: V to F value" fval eq testFVal
  res X:xval testfile.getData(0.0,"SRSV")
  assert/text="^reg.main.name: V to X value" xval eq 4294967295
  res L:lval testfile.getData(0.0,"SRSV")
  assert/text="^reg.main.name: V to L value" lval eq 2147483647
  res I:ival testfile.getData(0.0,"SRSV")
  assert/text="^reg.main.name: V to I value" ival eq 32767
  res B:bval testfile.getData(0.0,"SRSV")
  assert/text="^reg.main.name: V to B value" bval eq 127
  res N:nval testfile.getData(0.0,"SRSV")
  assert/text="^reg.main.name: V to N value" nval eq 7
  res P:pval testfile.getData(0.0,"SRSV")
  assert/text="^reg.main.name: V to P value" pval eq 1

  res X:expected 4294967296
  calc X:newvval dval 1 +
  calc test newvval expected EQ
  assert/text="^reg.main.name: Calc was able to work with unsigned data newvval=^newvval" test eq 1.0
return
