!******************************************************************************!
! Test case for limiting the size of the RAM files created by LIST2
!
!
! Note1: The standard Window (X,Y) position should be set to (25,25) in the .mmp
!        configuration file. (TODO: REMOVE this note before checkin)
!
! @bug      2585 LIST2: negativeArraySize exception with files larger than RamResource.RamFile's 2 GiB
! @bug      2168 LIST2: Out of memory errors
! @bug      1104 LIST2: out of memory error on large file (~1.3GB)
! @author:  J Bauer
!******************************************************************************!
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)

  call setDatDir

  if interAct then
    set instructions "Push the buttons and observe the Shell GUI. "

    set file "^{datDir}.apenny.prm"
    
    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

      shellgui/id=idshellgui/attach
      
      list2/id=list
      
      gcontrol line
      
      gcontrol button myButt "LIST2 tests" "/UseRamFileMaxSize=0,/UseRamFileMaxSize=10k,/UseRamFileMaxSize=10G,&
                                            /UseRamFile=f,/UseRamFile=t" /nc=1
     
      gcontrol line                                
      gcontrol button detButt "" "List Detached Header File" 

    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"
    erase/quiet/warn=n list2junk.tmp
    pipe stop
    
  elseif msg.name EQS "MYBUTT" then
    !invoke ,, reg.list.close()
    invoke ,, reg.idshellgui.clear()
    call setDefaults
    if msg.data eqs "/UseRamFileMaxSize=0" then
      invoke ,, reg.list.setRamFileMaxSize(0)
      invoke ,, reg.list.openFile(file)
      call updateText "SHOULD NOT" 0 
    elseif msg.data eqs "/UseRamFileMaxSize=10k" then
      invoke ,, reg.list.setRamFileMaxSize(10000)
      invoke ,, reg.list.openFile(file)
      call updateText "SHOULD" 0 
    elseif msg.data eqs "/UseRamFileMaxSize=10G" then
      set reg.list.RamFileMaxSize 10g
      invoke ,, reg.list.openFile(file)
      call updateText "SHOULD NOT" 1 
    elseif msg.data eqs "/UseRamFile=f" then
      set reg.list.UseRamFile false
      invoke ,, reg.list.openFile(file)
      call updateText "SHOULD NOT" 0 
    elseif msg.data eqs "/UseRamFile=t" then
      invoke ,, reg.list.UseRamFile(true)
      invoke ,, reg.list.openFile(file)
      call updateText "SHOULD NOT" 1 
    endif
   
    res ram
   
  elseif msg.name eqs "DETBUTT" then
    invoke ,, reg.idshellgui.clear()
    noop file list2junk.tmp{DET=1}
    call setDefaults
    invoke ,, reg.list.openFile(list2junk.tmp)
    set gc.idtext.value "You should see a listing of a file. There SHOULD NOT be any warnings or exceptions."
    
  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

!******************************************************************************!
! Set the dat directory
!******************************************************************************!
procedure setDatDir
  invoke nxmMajor env.nmversion.subString(0,1)
  invoke major java.lang.Integer.valueOf(nxmMajor)
  if major GE 4 then
    invoke s:datDir           nxm.sys.test.DatLocator.getDatDirLocation()
    invoke s:datDirSlash      nxm.sys.test.DatLocator.getDatDirSlashLocation()
    invoke z:sysDatFull       nxm.sys.test.DatLocator.sysDatFull()
    invoke z:sysTestDatExists nxm.sys.test.DatLocator.sysTestDatExists()
  else
    set s:datDir           "nxm.sys.dat"
    set s:datDirSlash      "nxm/sys/dat"
    set z:sysDatFull       true
    set z:sysTestDatExists false
  endif
return

!******************************************************************************!
! Set the defaults for the list2
!******************************************************************************!
procedure setDefaults
  set reg.list.UseRamFile true
  set reg.list.RamFileMaxSize 16m
return

!******************************************************************************!
! Update the macro instructions Text box 
!******************************************************************************!
procedure updateText s:warning i:numfiles
  set gc.idtext.value "In the shellgui, there ^{warning} be an INFO &
         about file size and the RAM table should have ^{numfiles} entries."
  
return