!******************************************************************************!
! Macro to test ability for gcontrol to take in an html text string and display
! it using STEXT.
!
! @bug      2534 HTML gcontrol text capability
! @author:  Edward R. Cable
! @version: $Id: test_gcontrol_stext.mm,v 1.2 2015/07/02 16:55:42 jtm Exp $
!******************************************************************************!
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)

  res htmlstr1 "<html>&
             <body BGCOLOR="#000000" TEXT="#80c0c0" LINK="#ff8080" VLINK="#ff0000" ALINK="#a05050">&
             <div ALIGN="left">&
             <table BGCOLOR="#000080" BORDER=3 BORDERCOLOR="#0000ff"><tr>&
             <td><h1><font FACE="courier" SIZE=3><font SIZE=4>T</font>ESTING GSTEXT WITH HTML!</font></h1></td>&
             </tr></table>&
             </div><br><br>&
             <p>&nbsp;&nbsp;Hi there! If you are reading this<br>&
             then html has been properly rendered in the jlabel! That's good news!<br>&
             Below should be plenty of examples of different font and style within the text.<br></p><br>&
             <div>&nbsp;&nbsp;<b><font SIZE=3 COLOR="#ffffff">A</font>random poem </b>&
             is written below. It should be in bold print. The text should be green.</div>&
             <h2><font SIZE=4 COLOR="#00ff00"> A poem about <em><b>SOME</b></em> flowers:</font></h2><ul>&
             <li><font SIZE=4 COLOR="#00ff00"><b>'Violets are blue'</b></font></li>&
             <li><font SIZE=4 COLOR="#00ff00"><b>'Roses are red'</b></font></li>&
             <li><font SIZE=4 COLOR="#00ff00"><b>Ummm....I forget the rest</b></font><ul>&
             <li><font SIZE=3><i> 'Was the font and style as predicted?'</li>&
             </ul></li></ul>&
             <table BGCOLOR="#000080"><tr>&
             <td WIDTH=50>&nbsp;</td>&
             <td><font COLOR="#00ff00">How many examples of font and style have you spotted so far?</tr></table>&
             <div><b>&nbsp;&nbsp;<font SIZE=3 COLOR="#ffffff">W</font>&
             hen you are done looking through all the examples, I encourage you to let me know of any problems you might find!! </b></div>&
             <table style="color:purple" bgcolor=gray BORDER=2 BORDERCOLOR="#0000ff"><tr>&
             <td WIDTH=5>&nbsp;</td>&
             <td><font SIZE=3>WARNING</font> This is yet another example! It should contain a white frame surrounded by a border.</td>&
             </tr></table>&
             </body></html>"

  res htmlstr2 "<html><body><font COLOR=green>Testing HTML String in a green color.</font></body></html>"

  res htmlstr3 "<html><body><font color=red>Testing HTML String #3 in red.</font></body></html>"


  if interAct then
    set instructions "HTML, along with various font styles, should be clearly readable inside the widget pane. &
        Ensure a scroll bar is visible and that it operates as expected.  Press all three buttons to ensure that &
        different HTML is displayed when they are pressed. A second test case should show the use of the /wtheme &
        switch with the specified font colors in the text."

    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 4 /title
      gcontrol button mybtn  "Change Value" "HTML1,HTML2,HTML3" "HTML1"

      ! HTML styled text string passed to STEXT command
      gcontrol STEXT gstext "HTML/Styled Text Below" htmlstr1 24 20 /title

      gcontrol STEXT gstext2 "" "<body>/WTheme with a yellow foreground and a blue background</body>" 24 1 /wtheme={CWFG=YELLOW,CWBG=BLUE}
    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 "MYBTN" then
    if msg.data eqs "HTML1" then
      set gc.gstext.value htmlstr1

    elseif msg.data eqs "HTML2" then
      set gc.gstext.value htmlstr2

    elseif msg.data eqs "HTML3" then
      set gc.gstext.value htmlstr3

    endif
  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

