edu.vub.at.objects.natives
Class ExceptionHandlingTest

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byedu.vub.at.AmbientTalkTestCase
              extended byedu.vub.at.objects.natives.ExceptionHandlingTest
All Implemented Interfaces:
junit.framework.Test

public class ExceptionHandlingTest
extends AmbientTalkTestCase

This test documents and tests the behaviour of the exception handling primitives provided in Ambienttalk. In AmbientTalk any object can be used and thrown as an exception. Moreover, by relying on in stripes, all subtyping issues regarding to handler selection are handled by the isStripedWith meta operation.

Author:
smostinc

Field Summary
 
Fields inherited from class edu.vub.at.AmbientTalkTestCase
ctx_, unittest_
 
Fields inherited from class junit.framework.TestCase
 
Constructor Summary
ExceptionHandlingTest()
           
 
Method Summary
static void main(java.lang.String[] args)
           
 void setUp()
           
private  void setUpTestStripes(ATObject testScope)
           
 void testAllObjectsCanBeUsedAsExceptions()
          Any AmbientTalk Language value can be used as an exception, proving there is nothing special about exceptions.
 void testInterpreterExceptionHandling()
          The exceptions thrown by the interpreter can be intercepted by a program as they are also striped objects, striped to identify their function.
 void testInterpreterExceptionThrowing()
          To avoid improper interference with the interpreter, user code should never throw interpreter exceptions.
 void testRethrownExceptions()
          When rethrowing an exception from a handler, the expected semantics apply : no handlers from the same try block are tried, even if they also match the thrown exception.
 void testStripeBasedHandlerSelection()
          Handler selection in AmbientTalk is purely based on the stripes an object is branded with.
 
Methods inherited from class edu.vub.at.AmbientTalkTestCase
evaluateInput, tearDown
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExceptionHandlingTest

public ExceptionHandlingTest()
Method Detail

testAllObjectsCanBeUsedAsExceptions

public void testAllObjectsCanBeUsedAsExceptions()
Any AmbientTalk Language value can be used as an exception, proving there is nothing special about exceptions. This test demonstrates this for a number of language values, such as numbers, tables, closures and stripes themselves. This test also shows that objects can be caught using the stripe they are branded with. Note that most often, exceptions will be isolates, as these are objects (which can be made arbitrarily complex) which are passed by copy between actors. However, as the stripes of a far reference are identical to the one of the original object, this semantics is a default upon which can be varied.


testStripeBasedHandlerSelection

public void testStripeBasedHandlerSelection()
Handler selection in AmbientTalk is purely based on the stripes an object is branded with. As such the correct handler selection can be delegated to the stripe system which ensures correct handler selection.


testInterpreterExceptionHandling

public void testInterpreterExceptionHandling()
The exceptions thrown by the interpreter can be intercepted by a program as they are also striped objects, striped to identify their function. This test illustrates how to use this mechanism to build a python-like object model where non-existant field are silently added to the object upon use. Note that an altogether cleaner mechanism can be conceived by using the doesNotUnderstand meta hook to achieve similar behaviour.


testInterpreterExceptionThrowing

public void testInterpreterExceptionThrowing()
To avoid improper interference with the interpreter, user code should never throw interpreter exceptions. However, in the light that various components of the language may be reimplemented in the language itself, this functionality is supported by the interpreter anyhow. Note that given the ability to catch interpreter exceptions, the programmer automatically has the right to throw them as well, either by rethrowing them, or by storing it as a prototype, of which new clones can be instatiated whenever he feels like it. This test consist of an object model where access to a field can be forbidden by throwing an interpreter exception (striped with SelectorNotFound)


testRethrownExceptions

public void testRethrownExceptions()
When rethrowing an exception from a handler, the expected semantics apply : no handlers from the same try block are tried, even if they also match the thrown exception. Handlers from a try block higher up the stack can however apply.


main

public static void main(java.lang.String[] args)

setUpTestStripes

private void setUpTestStripes(ATObject testScope)
                       throws java.lang.Exception
Throws:
java.lang.Exception

setUp

public void setUp()
           throws java.lang.Exception
Overrides:
setUp in class AmbientTalkTestCase
Throws:
java.lang.Exception