[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/js/js_tests/cases/ -> object_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    <script src="../../shared/limb/Browser.js" type="text/javascript"></script>
  12    <link rel="stylesheet" href="../test.css" type="text/css" />
  13  </head>
  14  <body>
  15  <h1>Limb.Object 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(MyInterface)
  28      {
  29        delete MyInterface;
  30        MyInterface = null;
  31      }
  32  
  33      if(MySuperClass)
  34      {
  35        delete MySuperClass;
  36        MySuperClass = null;
  37      }
  38  
  39      delete MyClass;
  40      MyClass = null;
  41    },
  42  
  43    testConsturctCall: function()
  44    {
  45      Limb.Class('MyClass',
  46      {
  47        __construct: function() { this.construct_called = true; }
  48      });
  49  
  50      var test_object = new MyClass();
  51      this.assert(test_object.construct_called, '__construct not called during construction');
  52    },
  53  
  54    testConsturctCallWithArguments: function()
  55    {
  56      Limb.Class('MyClass',
  57      {
  58        __construct: function(arg1) { if(arg1) this.construct_called = true; }
  59      });
  60  
  61      var test_object = new MyClass(true);
  62      this.assert(test_object.construct_called, 'Arguments not passed to __construct');
  63    },
  64  
  65    testInheritsWithoutBody: function()
  66    {
  67      Limb.Class('MySuperClass',
  68      {
  69        returnFive: function() { return 5; }
  70      });
  71  
  72      Limb.Class('MyClass').inherits('MySuperClass');
  73  
  74      var test_object = new MyClass();
  75      this.assert(typeof(test_object.returnFive) == 'function', 'Object prototype not extended from parent class');
  76      this.assertEqual(test_object.returnFive(), 5, 'Object prototype not extended from parent class');
  77    },
  78  
  79    testInherits: function()
  80    {
  81      Limb.Class('MySuperClass',
  82      {
  83        returnFive: function() { return 5; }
  84      });
  85  
  86      Limb.Class('MyClass').inherits('MySuperClass',
  87      {
  88        returnSeven: function() { return 7; }
  89      });
  90  
  91      var test_object = new MyClass();
  92      this.assert(typeof(test_object.returnFive) == 'function', 'Object prototype not extended from parent class');
  93      this.assertEqual(test_object.returnFive(), 5, 'Object prototype not extended from parent class');
  94  
  95      this.assert(typeof(test_object.returnSeven) == 'function', 'Object prototype not extended from passed body');
  96      this.assertEqual(test_object.returnSeven(), 7, 'Object prototype not extended from passed body');
  97    },
  98  
  99    testSettingParentClass: function()
 100    {
 101      Limb.Class('MySuperClass',
 102      {
 103        returnFive: function() { return 5; }
 104      });
 105  
 106      Limb.Class('MyClass').inherits('MySuperClass',
 107      {
 108        returnFivePlusSeven: function() { return this.parent.returnFive() + 7; }
 109      });
 110  
 111      var test_object = new MyClass();
 112      this.assert(typeof(test_object.parent) == 'object', 'Parent class is not set');
 113      this.assertEqual(test_object.returnFivePlusSeven(), 12, 'Parent method not called');
 114    },
 115  
 116    testConstructParentWithArguments: function()
 117    {
 118      Limb.Class('MySuperClass',
 119      {
 120        __construct: function(arg1) { if(arg1) this.parent_constructor_called = true; }
 121      });
 122  
 123      Limb.Class('MyClass').inherits('MySuperClass');
 124  
 125      var test_object = new MyClass(true);
 126      this.assert(test_object.parent_constructor_called, 'Parent __construct called without arguments');
 127    },
 128  
 129    testMethodOverride: function()
 130    {
 131      Limb.Class('MySuperClass',
 132      {
 133        getClassName: function() { return 'MySuperClass'; }
 134      });
 135  
 136      Limb.Class('MyClass').inherits('MySuperClass',
 137      {
 138        getClassName: function() { return 'MyClass'; }
 139      });
 140  
 141      var test_object = new MyClass();
 142      this.assertEqual(test_object.getClassName(), 'MyClass', 'Child method does not override parents method');
 143  
 144      var test_super_object = new MySuperClass();
 145      this.assertEqual(test_super_object.getClassName(), 'MySuperClass', 'Child overrides method in parent class');
 146    },
 147  
 148    testImplementIterface: function()
 149    {
 150      Limb.Interface('MyInterface',
 151      {
 152        returnFive: function() {}
 153      });
 154  
 155      Limb.Class('MyClass').implements('MyInterface',
 156      {
 157        returnFive: function() { return 5; }
 158      });
 159  
 160      var test_object = new MyClass();
 161      this.assertEqual(5, test_object.returnFive(), 'Method not implemented');
 162    },
 163  
 164    testFailWhenIterfaceNotFullyImplemented: function()
 165    {
 166      Limb.Interface('MyInterface',
 167      {
 168        returnFive: function() {}
 169      });
 170  
 171      try
 172      {
 173        Limb.Class('MyClass').implements('MyInterface',
 174        {
 175          returnSeven: function() { return 7; }
 176        });
 177  
 178        this.assert(false, 'Implements not throws exception when interface not fully implemented');
 179      }
 180      catch(error)
 181      {
 182        this.assertEqual('InterfaceException', error.getType(), 'Exception type wrong');
 183        this.assertEqual('Method \'returnFive\' not implemented', error.getMessage(), 'Exception message wrong');
 184      }
 185    },
 186  
 187    testToString: function()
 188    {
 189      if(Limb.Browser.is_ie)
 190        return;
 191  
 192      Limb.Class('MyClass');
 193      var test_object = new MyClass();
 194  
 195      this.assertEqual('[ object MyClass ]', test_object.toString());
 196    }
 197  });
 198  
 199  // ]]>
 200  </script>
 201  </body>
 202  </html>


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