// ------------------------------------------------------------------

// Cast.cs: Represents OCL testing for casting expressions

// ------------------------------------------------------------------

// Project: C# and OCL Compiler

// Module:  Testing

// Author:  Dave Arnold

// Version: 1.0

// ------------------------------------------------------------------

 

// ------------------------------------------------------------------

// Imports

// ------------------------------------------------------------------

using System;

using System.Collections;

// ------------------------------------------------------------------

 

// ------------------------------------------------------------------

// DaveArnold.OCLTesting Namespace

// ------------------------------------------------------------------

namespace DaveArnold.OCLTesting

{

       // A Class to test the casting  expressions

       class CastTests

       {

      

              private object p = null;

              OCL

              [

                     "context CastTests::Length(o : System::Object) : Integer"

                     "pre: not o.oclIsUndefined()"

                     "pre: o.oclIsInState(o)"

                     "pre: o.oclIsTypeOf(Object)"

                     "pre: o.oclIsKindOf(String)"

                     "post: result = o.oclAsType(String).Length"

                     "post: p.oclIsNew()"

              ]

              public int Length(object o)

              {

                     p = new object();

                     return (o as String).Length;

              }

      

              public void RunTests()

              {

                     Console.WriteLine("---------------- CAST TESTS -----------------");

                     Console.WriteLine("C1 (Length((object)Hello)): {0}", Length((object)"Hello"));

                     Console.WriteLine("------------ CAST TESTS COMPLETE ------------");

              }

       }

}

 

// ------------------------------------------------------------------

// EOF