W3C home > Mailing lists > Public > www-dom-ts@w3.org > December 2003

Writing tests with multiple exception codes

From: Curt Arnold <carnold@houston.rr.com>
Date: Mon, 29 Dec 2003 20:02:18 -0600
Message-ID: <3FF0DCAA.3020600@houston.rr.com>
To: www-dom-ts@w3.org

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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 6 April 2009 12:58:49 GMT