USING Progress.Lang.*.
USING OpenEdge.Core.Assert.
/*using support.test.AssertExt from propath.*/

BLOCK-LEVEL ON ERROR UNDO, THROW.

class tests.base_language.xml.dom.x_document.methods.TestI18n:
    define variable xDocument as handle no-undo.
    
    @SetUp.
    method public void SetUp ( ):
        session:suppress-warnings = false no-error.
        create x-document xDocument no-error.
        Assert:IsTrue(valid-handle (xDocument)).
    end method.

    @Test.
    method public void LoadNoArgsNoSuppress ( ):
        define variable errMsg as character no-undo extent 2.
        xDocument:load("", "", no) no-error.
        assign
            errMsg[1] = 'Argument for LOAD/SAVE must be ~'file~', ~'stream~', ~'stream-handle~' or ~'memptr~'. (9170)'.
            errMsg[2] = '~*~*The LOAD attribute on the X-DOCUMENT widget has invalid arguments. (4065)'.

        Assert:Equals(2, error-status:NUM-MESSAGES).
        Assert:Equals(9170, error-status:GET-NUMBER(1)).
        Assert:Equals(4065, error-status:GET-NUMBER(2)).
        Assert:Equals(errMsg[1], error-status:GET-MESSAGE(1)).
        Assert:Equals(errMsg[2], error-status:GET-MESSAGE(2)).
/*        CATCH ex AS Progress.Lang.Error :            */
/*            Assert:Equals(2, ex:NumMessages).        */
/*            Assert:Equals(9170, ex:GetMessageNum(1)).*/
/*            Assert:Equals(4065, ex:GetMessageNum(2)).*/
/*        END CATCH.                                   */
    end method.
        
    @Test.
    method public void LoadNoArgsSuppress ( ):
        define variable errMsg as character no-undo.
        define variable lok as logical no-undo initial true.
        errMsg = 'Argument for LOAD/SAVE must be ~'file~', ~'stream~', ~'stream-handle~' or ~'memptr~'. (9170)'.
        session:suppress-warnings = true no-error. 
        xDocument:load("", "", no).
        Assert:isFalse(lok).
        
        CATCH ex AS Progress.Lang.Error :
            Assert:Equals(1, ex:NumMessages).
            Assert:Equals(9170, ex:GetMessageNum(1)).
            Assert:Equals(errMsg, ex:GetMessage(1)).
        END CATCH.
        
        FINALLY:
            	session:suppress-warnings = false no-error.	
        END FINALLY.
    end method.
    
    @Test.
    method public void LoadNoArgsWithI18n ():
        define variable xmlFilePath as char no-undo initial "".
        define variable errMsg as char no-undo.
        session:suppress-warnings = true no-error.
        
        errMsg = '~*~* "' + xmlFilePath + '" was not found. (293)'.
        xDocument:load("file", xmlFilePath, no).
        
        CATCH ex AS Progress.Lang.Error :
            Assert:Equals(293, ex:GetMessageNum(1)).
            Assert:Equals(errMsg, ex:GetMessage(1)).
        END CATCH. 
        
        FINALLY:
            session:suppress-warnings = false no-error.
        END FINALLY.
    end method.
    
    @Test.
    method public void LoadFileWithI18n ():
        define variable fileXml as char no-undo initial "support/i18nEncoding.xml".
        define variable hNode as HANDLE no-undo.
        CREATE X-NODEREF hNode.
        
        xDocument:load ("file", fileXml, no).
        Assert:Equals (xDocument:ENCODING, "ISO-8859-1").
        Assert:IsTrue (xDocument:GET-CHILD (hNode, 1)).
        Assert:IsTrue (hNode:GET-CHILD (hNode, 1)).
        Assert:Equals (hNode:NODE-VALUE, '"á é í ó ú ñ à ê"').
    end method.
    
    @Test.
    method public void LoadCharWithI18n ():
        define variable hNode as HANDLE no-undo.
        define variable memptrXml as memptr no-undo.
        CREATE X-NODEREF hNode.
        
        set-size(memptrXml) = 150.
        put-string(memptrXml, 1) =   '<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><references>"á é í ó ú ñ à ê"</references>'.
        xDocument:load("memptr", memptrXml, no).
        
        Assert:Equals (xDocument:ENCODING, "ISO-8859-1").
        Assert:IsTrue (xDocument:GET-CHILD (hNode, 1)).
        Assert:IsTrue (hNode:GET-CHILD (hNode, 1)).
        Assert:Equals (hNode:NODE-VALUE, '"á é í ó ú ñ à ê"').
    end method.
    
    @TearDown.
    method public void TearDown ( ):
        delete object xDocument no-error.
    end method.
END CLASS.
