[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/js/js_tests/cases/ -> classkit_test.html (source)

   1  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   2          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   3  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
   4  <head>
   5    <title>Limb3 JS Tests</title>
   6    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
   7    <script src="../lib/prototype.js" type="text/javascript"></script>
   8    <script src="../lib/unittest.js" type="text/javascript"></script>
   9  
  10    <script src="../../shared/limb.js" type="text/javascript"></script>
  11  
  12    <link rel="stylesheet" href="../test.css" type="text/css" />
  13  </head>
  14  <body>
  15  <h1>Limb.Classkit test</h1>
  16  
  17  <!-- Log output -->
  18  <div id="testlog"> </div>
  19  
  20  <!-- Tests follow -->
  21  <script type="text/javascript" language="javascript" charset="utf-8">
  22  // <![CDATA[
  23  
  24  new Test.Unit.Runner({
  25    tearDown: function()
  26    {
  27      if(MyIterface)
  28      {
  29        delete MyIterface;
  30        MyIterface = null;
  31      }
  32  
  33      if(MyParentClass)
  34      {
  35        delete MyParentClass;
  36        MyParentClass = null;
  37      }
  38  
  39      if(MyClass)
  40      {
  41        delete MyClass;
  42        MyClass = null;
  43      }
  44    },
  45  
  46    testCreateEmptyClass: function()
  47    {
  48      var test_class = Limb.Class('MyClass');
  49  
  50      this.assert(typeof(test_class) == 'function', 'Limb.Class returns object which is not class');
  51      this.assert(typeof(MyClass) == 'function', 'Object defined by Limb.Class is not class');
  52  
  53      var test_object = new MyClass();
  54      this.assert(typeof(test_object.__construct) == 'function', 'Defined class have not __construct method');
  55    },
  56  
  57    testCreateClassWithPrototype: function()
  58    {
  59      Limb.Class('MyClass',
  60      {
  61        returnFive: function() { return 5; }
  62      });
  63  
  64  
  65      var test_object = new MyClass();
  66      this.assert(typeof(test_object.returnFive) == 'function', 'Object prototype not extended');
  67      this.assertEqual(test_object.returnFive(), 5, 'Object prototype not extended');
  68    },
  69  
  70    testCreateInterface: function()
  71    {
  72      var test_interface = Limb.Interface('MyIterface');
  73  
  74      this.assert(typeof(test_interface) == 'function', 'Limb.Class returns interface which is not function');
  75      this.assert(typeof(MyIterface) == 'function', 'Object defined by lmbIterface is not function');
  76      this.assert(MyIterface.is_interface, 'is_interface not defined');
  77    },
  78  
  79    testFailedToCreateInstanceOfInterface: function()
  80    {
  81      var test_interface = Limb.Interface('MyIterface');
  82  
  83      try
  84      {
  85        var test_interface = new MyIterface();
  86        this.assert(false, 'Creation interface instance not throws exception');
  87      }
  88      catch(error)
  89      {
  90        this.assertEqual('InterfaceException', error.getType(), 'Exception type wrong');
  91        this.assertEqual('Can not create instance of interface', error.getMessage(), 'Exception message wrong');
  92      }
  93    },
  94  
  95    testFillInterfaceByStubMethods: function()
  96    {
  97      var test_interface = Limb.Interface('MyIterface',
  98      {
  99        testMethod: function() {}
 100      });
 101  
 102      this.assert(typeof(MyIterface.testMethod) == 'function', 'Interface not extended');
 103  
 104      try
 105      {
 106        MyIterface.testMethod();
 107        this.assert(false, 'Call interface method not throws exception');
 108      }
 109      catch(error)
 110      {
 111        this.assertEqual('InterfaceException', error.getType(), 'Exception type wrong');
 112        this.assertEqual('Interface methods can not be called', error.getMessage(), 'Exception message wrong');
 113      }
 114    },
 115  
 116    testClassStaticMethodDefinition: function()
 117    {
 118      Limb.Class('MyClass',
 119      {
 120        static: {
 121          returnFive: function() { return 5; }
 122        }
 123      });
 124  
 125      var test_object = new MyClass();
 126      this.assert(typeof(test_object.returnFive) == 'undefined', 'Static method is defined in prototype');
 127      this.assert(typeof(MyClass.returnFive) == 'function', 'Static method not added to class');
 128      this.assertEqual(MyClass.returnFive(), 5, 'Static method not added to class');
 129    },
 130  
 131    testClassStaticProperty: function()
 132    {
 133      Limb.Class('MyClass',
 134      {
 135        returnFiveInstance: function() { return this.static.returnFive(); },
 136  
 137        static: {
 138          returnFive: function() { return 5; }
 139        }
 140      });
 141  
 142      var test_object = new MyClass();
 143      this.assert(Limb.isset(test_object.static), 'Static property is not defined');
 144      this.assertEqual(5, test_object.returnFiveInstance(), 'Static property not refer to class');
 145    },
 146  
 147    testInheritance: function()
 148    {
 149      Limb.Class('MyParentClass',
 150      {
 151        setNumber: function(number) { this.number = number; }
 152      });
 153  
 154      Limb.Class('MyClass',
 155      {
 156        returnFive: function() { this.parent.setNumber(5); return this.number; }
 157      });
 158  
 159      Limb.Classkit.inherit(MyClass, MyParentClass);
 160  
 161      var test_object = new MyClass();
 162      this.assertEqual('MyClass', test_object.NAME, 'NAME attribute clones too');
 163      this.assertEqual(5, test_object.returnFive(), 'Parent method works with another this reference');
 164    },
 165  
 166    testClassToString: function()
 167    {
 168      Limb.Class('MyClass');
 169      this.assertEqual('[ class MyClass ]', MyClass.toString());
 170    },
 171  
 172    testInterfaceToString: function()
 173    {
 174      Limb.Interface('MyInterface');
 175      this.assertEqual('[ interface MyInterface ]', MyInterface.toString());
 176    }
 177  });
 178  
 179  // ]]>
 180  </script>
 181  </body>
 182  </html>


Generated: Sat Nov 22 03:48:54 2008 Cross-referenced by PHPXref 0.7