!******************************************************************************!
! test_gcontrol_datepicker: An interactive test case designed to allow the user
! to test various configuration options for the DATEPICKER control.
!
! Arguments: None
!
! @bug      1999  Implement an enhanced Date/Time selector
! @author:  Chris Simons
!******************************************************************************!
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 COREGRAPHICS coreGraphics GET DEF=FALSE SDEF=TRUE ! for a quick check of graphics - more extreme tests - since 3.8.1

! Start Interactive test section
  if interAct or coreGraphics then
    pipe init
      panel/msgid=MAIN/id=panel/setup/controls=gc

      set instructions "You should see five Bean Date Pickers. &
                        The first should be set to the current date/time. &
                        The second should be set to January 1st, 2011 at 12:00 UTC. &
                        The third should be empty. &
                        The fourth should get set to a new current date/time &
                        from a command run automatically from the shell. &
                        The fifth should also be set to the current date/time. &
                        You should see 2 INFO statements in the shell: &
                        1) A printout of timex now, set to y. &
                        2) An assert that Date Picker #4 has the same value as y. &
                        Test that the calendar button opens the popup and that &
                        the Cancel button closes the popup without adjusting &
                        date/time. Lastly, you should see a message from each &
                        picker when you select a new date and/or time."

      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

      ! Time objects
      timex day s:currentday
      timex now s:currentstr
      timex now d:currentdouble
      timex now currentobj
      timex day currentday
      res d:firstday 2011:01:01::12:00:00.000

      ! The following DATEPICKER BEAN is created without an initial Date/Time.
      gcontrol label lbl1 "Current Date/Time (Time Object)"
      gcontrol bean picker1 "test" P1=nxm.ucl.libg.GDatePicker TABLE={StartTime=^currentobj}

      gcontrol label lbl2 "January 1st, 2011 @ 12:00 UTC (Double)"
      gcontrol bean picker2 P1=nxm.ucl.libg.GDatePicker TABLE={StartTime=^firstday}

      gcontrol label lbl3 "No StartTime Argument (Defaults to Now)"
      gcontrol bean picker3 P1=nxm.ucl.libg.GDatePicker TABLE={StartTime=}

      gcontrol label lbl4 "Current Date/Time Set via Shell"
      gcontrol bean picker4 P1=nxm.ucl.libg.GDatePicker TABLE={StartTime=}

      gcontrol label lbl4 "Current Date/Time (String)"
      gcontrol bean picker5 P1=nxm.ucl.libg.GDatePicker TABLE={StartTime=^currentstr}


      shellgui/id=idshellgui/msgid=MAIN/attach/wait/WW=1000
      timex now y
      info "y is ^y"
      set gc.picker4.val y
      assert/text="Picker4.val equals y" gc.picker4.val eq y


    pipe off
  endif

endmacro

!****************************************************************************!
! process messages for interactive tests
!****************************************************************************!
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 "PICKER1" then
    say "Date Picker #1 is now ^gc.picker1.val"

  elseif msg.name eqs "PICKER2" then
    say "Date Picker #2 is now ^gc.picker2.val"

  elseif msg.name eqs "PICKER3" then
    say "Date Picker #3 is now ^gc.picker3.val"

  elseif msg.name eqs "PICKER4" then
    say "Date Picker #4 is now ^gc.picker4.val"

  elseif msg.name eqs "PICKER5" then
    say "Date Picker #5 is now ^gc.picker5.val"

  else
    say "Unhandled Message: ^msg.name, ^msg.data"
  endif
return
