/test/acceptance/as3/Definitions/Classes/Ext/DynExtDefaultClass.as

https://github.com/bsdf/trx · ActionScript · 297 lines · 81 code · 55 blank · 161 comment · 0 complexity · 4a0334831e15e4d71a41cb8db47a43ca MD5 · raw file

  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3. *
  4. * The contents of this file are subject to the Mozilla Public License Version
  5. * 1.1 (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. * http://www.mozilla.org/MPL/
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. * for the specific language governing rights and limitations under the
  12. * License.
  13. *
  14. * The Original Code is [Open Source Virtual Machine.].
  15. *
  16. * The Initial Developer of the Original Code is
  17. * Adobe System Incorporated.
  18. * Portions created by the Initial Developer are Copyright (C) 2004-2006
  19. * the Initial Developer. All Rights Reserved.
  20. *
  21. * Contributor(s):
  22. * Adobe AS3 Team
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. package DefaultClass{
  38. /** These lines have to be commented out.
  39. * The compiler requires only the parent Class to be imported and not the Subclass folder.
  40. * Hence change in the import statements required.
  41. * import Definitions.Classes.DefaultClass;
  42. * import Definitions.Classes.Ext.DynExtDefaultClass;
  43. */
  44. import DefaultClass.*;
  45. var SECTION = "Definitions"; // provide a document reference (ie, ECMA section)
  46. var VERSION = "AS 3.0"; // Version of JavaScript or ECMA
  47. var TITLE = "Dynamic Class Extends Default Class"; // Provide ECMA section title or a description
  48. //var BUGNUMBER = "";
  49. startTest(); // leave this alone
  50. /**
  51. * Calls to AddTestCase here. AddTestCase is a function that is defined
  52. * in shell.js and takes three arguments:
  53. * - a string representation of what is being tested
  54. * - the expected result
  55. * - the actual result
  56. *
  57. * For example, a test might look like this:
  58. *
  59. * var helloWorld = "Hello World";
  60. *
  61. * AddTestCase(
  62. * "var helloWorld = 'Hello World'", // description of the test
  63. * "Hello World", // expected result
  64. * helloWorld ); // actual result
  65. *
  66. */
  67. // *******************************************
  68. // access default method from
  69. // outside of class
  70. // *******************************************
  71. var DYNEXTDCLASS = new DynExtDefaultClass();
  72. var arr:Array;
  73. arr = new Array(10, 15, 20, 25, 30);
  74. AddTestCase( "*** Access Default Method from Default method of sub class ***", 1, 1 );
  75. AddTestCase( "DYNEXTDCLASS.testSubGetSetArray(arr)", arr, (DYNEXTDCLASS.testSubGetSetArray(arr)) );
  76. // ********************************************
  77. // access default method from a public
  78. // method of a sub class
  79. //
  80. // ********************************************
  81. arr = new Array(1, 5);
  82. DYNEXTDCLASS = new DynExtDefaultClass();
  83. AddTestCase( "DYNEXTDCLASS.pubSubSetArray(arr), DYNEXTDCLASS.pubSubGetArray()", arr, (DYNEXTDCLASS.pubSubSetArray(arr), DYNEXTDCLASS.pubSubGetArray()) );
  84. // ********************************************
  85. // access default method from a private
  86. // method of a sub class
  87. //
  88. // ********************************************
  89. arr = new Array(2, 4, 6);
  90. DYNEXTDCLASS = new DynExtDefaultClass();
  91. AddTestCase( "DYNEXTDCLASS.testPrivSubArray(arr)", arr, DYNEXTDCLASS.testPrivSubArray(arr) );
  92. // ********************************************
  93. // access default method from a final
  94. // method of a sub class
  95. // ********************************************
  96. DYNEXTDCLASS = new DynExtDefaultClass();
  97. AddTestCase( "access 'default' method from 'final' method of sub class", arr, (DYNEXTDCLASS.testFinSubArray(arr)) );
  98. // ********************************************
  99. // access default method from a static
  100. // method of a sub class
  101. // ********************************************
  102. DYNEXTDCLASS = new DynExtDefaultClass();
  103. var thisError10 = "no Exception thrown";
  104. try{
  105. DYNEXTDCLASS.testStatSubArray(arr);
  106. } catch (e) {
  107. thisError10 = e.toString();
  108. } finally {
  109. AddTestCase( "access 'default' method from 'static' method of sub class",
  110. "ReferenceError: Error #1065",
  111. referenceError( thisError10 ) );
  112. }
  113. // ********************************************
  114. // access default method from a static
  115. // method of a sub class
  116. //
  117. // ********************************************
  118. /*
  119. arr = new Array(1, 5);
  120. DYNEXTDCLASS = new DynExtDefaultClass();
  121. AddTestCase( "*** Access default method from static method of sub class ***", 1, 1 );
  122. AddTestCase( "DYNEXTDCLASS.testStatSubArray(arr)", arr, (DYNEXTDCLASS.testStatSubArray(arr)) );
  123. */
  124. // ********************************************
  125. // access default method from a public
  126. // final method of a sub class
  127. // ********************************************
  128. arr = new Array( 1, 2, 3 );
  129. DYNEXTDCLASS = new DynExtDefaultClass();
  130. AddTestCase( "access 'default' method from 'public final' method of sub class", arr,
  131. (DYNEXTDCLASS.pubFinSubSetArray(arr), DYNEXTDCLASS.pubFinSubGetArray()) );
  132. // ********************************************
  133. // access default method from a final
  134. // private method of a sub class
  135. // ********************************************
  136. arr = new Array( 4, 5 );
  137. DYNEXTDCLASS = new DynExtDefaultClass();
  138. AddTestCase( "access 'default' method from 'private final' method of sub class", arr, (DYNEXTDCLASS.testPrivFinSubArray(arr)) );
  139. // ********************************************
  140. // access default method from a private
  141. // method of a sub class
  142. // ********************************************
  143. arr = new Array( 6, 7 );
  144. DYNEXTDCLASS = new DynExtDefaultClass();
  145. AddTestCase( "access 'default' method from 'private' method of sub class", arr, DYNEXTDCLASS.testPrivSubArray(arr) );
  146. // ********************************************
  147. // access default method from a virtual
  148. // method of a sub class
  149. // ********************************************
  150. AddTestCase( "access 'default' method from 'virtual' method of sub class", arr,
  151. DYNEXTDCLASS.testVirtSubArray(arr) );
  152. // ********************************************
  153. // access default method from a virtual
  154. // public method of a sub class
  155. // ********************************************
  156. AddTestCase( "access 'default' method from 'public virtual' method of sub class", arr,
  157. (DYNEXTDCLASS.pubVirtSubSetArray(arr), DYNEXTDCLASS.pubVirtSubGetArray()) );
  158. // ********************************************
  159. // access default method from a virtual
  160. // private method of a sub class
  161. // ********************************************
  162. AddTestCase( "access 'default' method from 'private virtual' method of sub class", arr,
  163. DYNEXTDCLASS.testPrivVirtSubArray(arr) );
  164. /* Access properties of parent class */
  165. // ********************************************
  166. // access default property from
  167. // default method in sub class
  168. // ********************************************
  169. DYNEXTDCLASS = new DynExtDefaultClass();
  170. AddTestCase( "access 'default' property from 'default' method of sub class", arr,
  171. (DYNEXTDCLASS.testSubGetSetDPArray(arr)) );
  172. // ********************************************
  173. // access default property from
  174. // final method in sub class
  175. // ********************************************
  176. DYNEXTDCLASS = new DynExtDefaultClass();
  177. AddTestCase( "access 'default' property from 'final' method of sub class", arr,
  178. (DYNEXTDCLASS.testFinSubDPArray(arr)) );
  179. // ********************************************
  180. // access default property from
  181. // virtual method in sub class
  182. // ********************************************
  183. DYNEXTDCLASS = new DynExtDefaultClass();
  184. AddTestCase( "access 'default' property from 'virtual' method of sub class", arr,
  185. (DYNEXTDCLASS.testVirtSubDPArray(arr)) );
  186. // ********************************************
  187. // access default property from
  188. // public method in sub class
  189. // ********************************************
  190. DYNEXTDCLASS = new DynExtDefaultClass();
  191. AddTestCase( "access 'default' property from 'public' method of sub class", arr,
  192. (DYNEXTDCLASS.pubSubSetDPArray(arr), DYNEXTDCLASS.pubSubGetDPArray()) );
  193. // ********************************************
  194. // access default property from
  195. // private method in sub class
  196. // ********************************************
  197. DYNEXTDCLASS = new DynExtDefaultClass();
  198. AddTestCase( "access 'default' property from 'private' method of sub class", arr,
  199. (DYNEXTDCLASS.testPrivSubDPArray(arr)) );
  200. // ********************************************
  201. // access default property from
  202. // public final method in sub class
  203. // ********************************************
  204. DYNEXTDCLASS = new DynExtDefaultClass();
  205. AddTestCase( "access 'default' property from 'public final' method of sub class", arr,
  206. (DYNEXTDCLASS.pubFinSubSetDPArray(arr), DYNEXTDCLASS.pubFinSubGetDPArray()) );
  207. // ********************************************
  208. // access default property from
  209. // public virtual method in sub class
  210. // ********************************************
  211. DYNEXTDCLASS = new DynExtDefaultClass();
  212. AddTestCase( "access 'default' property from 'public virtual' method of sub class", arr,
  213. (DYNEXTDCLASS.pubVirtSubSetDPArray(arr), DYNEXTDCLASS.pubVirtSubGetDPArray()) );
  214. // ********************************************
  215. // access default property from
  216. // private final method in sub class
  217. // ********************************************
  218. DYNEXTDCLASS = new DynExtDefaultClass();
  219. AddTestCase( "access 'default' property from 'private final' method of sub class", arr,
  220. (DYNEXTDCLASS.testPrivFinSubDPArray(arr)) );
  221. // ********************************************
  222. // access default property from
  223. // private virtual method in sub class
  224. // ********************************************
  225. DYNEXTDCLASS = new DynExtDefaultClass();
  226. AddTestCase( "access 'default' property from 'private virtual' method of sub class", arr,
  227. (DYNEXTDCLASS.testPrivVirtSubDPArray(arr)) );
  228. // ********************************************
  229. // Class Prototype Testing
  230. // ********************************************
  231. //Add new property to parent through prototype object, verify child inherits it
  232. var child = new DynExtDefaultClass();
  233. DefaultClassInner.prototype.fakeProp = 100;
  234. AddTestCase("*** Add new property to parent prototype object, verify child class inherits it ***", 100, child.fakeProp);
  235. //Try overriding parent property through prototype object, verify child object has correct value
  236. DefaultClassInner.prototype.pObj = 2;
  237. child = new DynExtDefaultClass();
  238. AddTestCase("*** Try overriding parent property through prototype object, verify child object has correct value ***", 1, child.pObj);
  239. test(); // Leave this function alone.
  240. // This function is for executing the test case and then
  241. // displaying the result on to the console or the LOG file.
  242. }