Writing tests with multiple exception codes

One of my tasks from the last WG conference call was to describe how to 
write tests when an operation may throw more than one error code.  
Examples of such tests are nodeinsertbefore05, 06, and 10.  The basic 
formulation is like: 

<try>
    <insertBefore obj="doc" var="inserted" newChild="newDocType" 
refChild="docType"/>
     <fail id="throw_DOMException"/>
    <catch>
        <DOMException code="HIERARCHY_REQUEST_ERR"/>
        <DOMException code="NOT_SUPPORTED_ERR"/>
    </catch>
</try>


If the operation does not throw an exception, it hits the <fail/> method 
which unconditionally fails the test.  If a DOMException is thrown with 
either of the specified codes, then the try block is left.  If 
DOMException with a different code is thrown, the exception appears not 
to be caught (it is actually caught and rethrown) which will cause the 
test to fail.  The test-to-java transform produces the following code 
for that fragment:

      try {
      inserted = doc.insertBefore(newDocType, docType);
      fail("throw_DOMException");
    
      }
      catch (DOMException ex) {
                  switch (ex.code) {
      case 3 :
       break;
      case 9 :
       break;
          default:
          throw ex;
          }
      }

Received on Monday, 29 December 2003 21:02:17 UTC