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.
        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)).
    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 LoadMemptrSameEncoding ():
        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 ("ISO-8859-1", xDocument:ENCODING).
        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 LoadMemptrDiffContent ():
        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>"àáâãäåx"</references>'.
        xDocument:load("memptr", memptrXml, no).

        Assert:Equals ("ISO-8859-1", xDocument:ENCODING).
        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 LoadMemptrDiffEncoding ():
        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-2" standalone="no"?><references>"àáâãäå"</references>'.
        xDocument:load("memptr", memptrXml, no).

        Assert:Equals ("ISO-8859-1", xDocument:ENCODING).
        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 LoadMemptrDiffContentDiffEncoding ():
        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-2" standalone="no"?><references>"àáâãäåx"</references>'.
        xDocument:load("memptr", memptrXml, no).

        Assert:Equals ("ISO-8859-1", xDocument:ENCODING).
        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.
