Author Topic: Error Assertions and XML Document Object Testing  (Read 1516 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Error Assertions and XML Document Object Testing
« on: August 10, 2007, 10:22:35 PM »
Anyone fancy running a couple of routines and reporting the result ?

I'm doing some work with XML and needed a suitable error reporter,
so this is the assertion tester I've been using ...
Code: [Select]
;;-------------------------------------------------------------------------------------
;;;-------------------------------------------------------------------------------------
;;
(DEFUN kdub:AssertT (quotedFunctionList / catchit returnVal)
    ;;
    ;; deleted
)
;;;-------------------------------------------------------------------------------------
;;;-------------------------------------------------------------------------------------
;;

... and this is some sample testing ..

Quote
Command: (setq result (kdub:AssertT '(/ 2 0)) )
kdub:AssertT Error: divide by zero
 Parameter : (/ 2 0)
nil

(OR GV:IAcadApplication (SETQ GV:IAcadApplication (VLAX-GET-ACAD-OBJECT)))
(OR GV:IAcadDocument (SETQ GV:IAcadDocument (VLA-GET-ACTIVEDOCUMENT GV:IAcadApplication)))
(OR GV:IAcadLayers (SETQ GV:IAcadLayers (VLA-GET-LAYERS GV:IAcadDocument)))

Command: (setq result (kdub:AssertT '(VLA-ITEM  GV:IAcadLayers "0")) )
#<VLA-OBJECT IAcadLayer 0a9a47d4>

Command: (setq result (kdub:AssertT '(VLA-ITEM  GV:IAcadLayers "NonExistantLayer")) )
kdub:AssertT Error: Automation Error. Key not found
 Parameter : (vla-Item GV:IACADLAYERS "NonExistantLayer")
nil

Then the Assertion Tester used in the XML routine ..
Code: [Select]
;;;-------------------------------------------------------------------------------------
;;;-------------------------------------------------------------------------------------
;;           
(DEFUN kdub:XML:GET-DOCUMENT (FileName XMLDomDocument /)
 ;; deleted
 )
;;;-------------------------------------------------------------------------------------
;;;-------------------------------------------------------------------------------------
;;


... and some testing
;; Edit file path\name to suit existing file         
(setq FileName "c:\\Hamlet.XML")
(kdub:XML:GET-DOCUMENT FileName 'XMLDomDocObj)
           
;-> T
(eval XMLDomDocObj)
;-> #<VLA-OBJECT IXMLDOMDocument3 01d78648>
           

(setq FileName "c:\\NonExistantFile.XML")
(kdub:XML:GET-DOCUMENT FileName 'XMLDomDocObj1)
           
;-> kdub:XML:GET-DOCUMENT Error:
;   Unable to Read File : c:\NonExistantFile.XML
;   nil           
(eval XMLDomDocObj1)
;-> #<VLA-OBJECT IXMLDOMDocument3 01d88060>


Using say this :
Code: [Select]
(setq FileName "c:\\YourLocalFile.XML")
(kdub:XML:GET-DOCUMENT FileName 'XMLDomDocObj)

(assert XMLDomDocObj)

I'm particularly interested in knowing if the variable XMLDomDocObj is assigned a value
or if you get a handled error indicating that the XML Dom is not available on your machine.






« Last Edit: August 15, 2007, 07:43:56 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Error Assertions and XML Document Object Testing
« Reply #1 on: August 16, 2007, 04:58:08 PM »
hmmm, this stuff is fun ..

Code: [Select]
(SETQ RevData (LIST (CONS "Date" (FormatDate))
                    (CONS "Tag" g:new-rev)
                    (CONS "Description" rev::Desc)
                    (CONS "Author" rev::Author)
                    (CONS "Checker" rev::Checkby)
                    (CONS "AuthorisedBy" rev::Boss)
              )
)

(SETQ sFileName "c:/Test4.XML")
(Kdub:XML:GET-DomDocument sFileName 'oXmlDoc)
(SETQ oRootElement (Kdub:xml:Get-XMLObject sFileName))
(SETQ oInfoFile (Kdub:XML:GET-Parent oXmlDoc "InfoFile"))

(IF (SETQ oNewNode (Kdub:AssertT '(VLAX-INVOKE-METHOD oXmlDoc 'createElement "Revision")))
       ;;------
       (PROGN
           (FOREACH dote RevData
               (IF (AND (SETQ oNewTitle (Kdub:AssertT '(VLAX-INVOKE-METHOD
                                                        oXmlDoc
                                                        'createElement
                                                        (CAR dote)
                                                       )
                                        )
                        )
                        (SETQ oNewText (Kdub:AssertT '(VLAX-INVOKE-METHOD
                                                       oXmlDoc
                                                       'createTextNode
                                                       (CDR dote)
                                                      )
                                       )
                        )
                   )
                   (PROGN (Kdub:AssertT '(VLAX-INVOKE-METHOD oNewTitle 'appendChild oNewText))
                          (Kdub:AssertT '(VLAX-INVOKE-METHOD oNewNode 'appendChild oNewTitle))
                   )
               )
           )
           (Kdub:AssertT '(VLAX-INVOKE-METHOD oInfoFile 'appendChild oNewNode))
           (SETQ sNewFileName (Kdub:XML:SAVEAS oXmlDoc sFileName))
       )
)

.. and the piccy ..
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.