gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/trunk r11239: Improve tests for ContextMen


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r11239: Improve tests for ContextMenu and ContextMenuItem.
Date: Thu, 09 Jul 2009 16:30:54 +0200
User-agent: Bazaar (1.13.1)

------------------------------------------------------------
revno: 11239
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Thu 2009-07-09 16:30:54 +0200
message:
  Improve tests for ContextMenu and ContextMenuItem.
  
  Minor cleanup, minor fix.
modified:
  libcore/as_environment.cpp
  libcore/asobj/Global.cpp
  testsuite/actionscript.all/ContextMenu.as
    ------------------------------------------------------------
    revno: 11236.1.1
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Thu 2009-07-09 12:32:41 +0200
    message:
      Make message more accurate.
    modified:
      libcore/as_environment.cpp
    ------------------------------------------------------------
    revno: 11236.1.2
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Thu 2009-07-09 16:04:30 +0200
    message:
      Test ContextMenu and ContextMenuItem properly.
    modified:
      testsuite/actionscript.all/ContextMenu.as
    ------------------------------------------------------------
    revno: 11236.1.3
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Thu 2009-07-09 16:06:30 +0200
    message:
      The ContextMenu constructor is not hidden in version 5.
    modified:
      libcore/asobj/Global.cpp
    ------------------------------------------------------------
    revno: 11236.1.4
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Thu 2009-07-09 16:10:16 +0200
    message:
      xcheck for Gnash fails.
    modified:
      testsuite/actionscript.all/ContextMenu.as
    ------------------------------------------------------------
    revno: 11236.1.5
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Thu 2009-07-09 16:11:47 +0200
    message:
      Also fails totals because of builtInItems property.
    modified:
      testsuite/actionscript.all/ContextMenu.as
=== modified file 'libcore/as_environment.cpp'
--- a/libcore/as_environment.cpp        2009-07-01 10:40:30 +0000
+++ b/libcore/as_environment.cpp        2009-07-09 10:32:41 +0000
@@ -941,17 +941,14 @@
     // TODO: override from gnashrc.
     
     // A stack size of 0 is apparently legitimate.
-    const boost::uint16_t maxstacksize = 
+    const boost::uint16_t recursionLimit = 
         func->getVM().getRoot().getRecursionLimit();
 
-    // Doesn't proceed if the stack size would reach the limit; should
-    // this check be done somewhere after adding to the stack? Would
-    // it make any difference?
-    if ( _localFrames.size() + 1 >= maxstacksize )
-    {
+    // Don't proceed if local call frames would reach the recursion limit.
+    if (_localFrames.size() + 1 >= recursionLimit) {
+
         std::ostringstream ss;
-        ss << boost::format(_("Max stack count reached (%u)")) % 
-            _localFrames.size();
+        ss << boost::format(_("Recursion limit reached (%u)")) % 
recursionLimit;
 
         // throw something
         throw ActionLimitException(ss.str()); 

=== modified file 'libcore/asobj/Global.cpp'
--- a/libcore/asobj/Global.cpp  2009-07-06 13:39:37 +0000
+++ b/libcore/asobj/Global.cpp  2009-07-09 14:06:30 +0000
@@ -364,7 +364,7 @@
         (N(NetStream_as::init, NSV::CLASS_NET_STREAM, NSV::CLASS_OBJECT,
            NS_GLOBAL, 6))
         (N(contextmenu_class_init, NSV::CLASS_CONTEXTMENU, NSV::CLASS_OBJECT,
-           NS_GLOBAL, 7))
+           NS_GLOBAL, 5))
         (N(moviecliploader_class_init, NSV::CLASS_MOVIE_CLIP_LOADER,
            NSV::CLASS_OBJECT, NS_GLOBAL, 7))
         (N(Error_class_init, NSV::CLASS_ERROR, NSV::CLASS_OBJECT, NS_GLOBAL, 
5))

=== modified file 'testsuite/actionscript.all/ContextMenu.as'
--- a/testsuite/actionscript.all/ContextMenu.as 2009-02-25 22:33:03 +0000
+++ b/testsuite/actionscript.all/ContextMenu.as 2009-07-09 14:11:47 +0000
@@ -22,60 +22,174 @@
 // execute it like this gnash -1 -r 0 -v out.swf
 
 
+// This could be tested properly with any Gnash hosting application
+// like gprocessor by checking that the instructions to the context menu
+// match what the pp displays.
+
 rcsid="$Id: ContextMenu.as,v 1.14 2008/03/11 19:31:47 strk Exp $";
 #include "check.as"
 
 #if OUTPUT_VERSION < 7
 
-note("You can't rely on availability of ContextMenu class with an SWF < 7");
-
-#else // OUTPUT_VERSION >= 7
-
-// there was no ContextMenu before SWF7
-check_equals(typeof(ContextMenu), 'function');
-
-var contextmenuObj = new ContextMenu;
-
-// test the ContextMenu constuctor
-check_equals (typeof(contextmenuObj), 'object');
-
-// test the ContextMenu::copy method
-check_equals (typeof(contextmenuObj.copy), 'function');
-
-// test the ContextMenu::hideBuiltinItems method
-check_equals (typeof(contextmenuObj.hideBuiltInItems), 'function');
-
-// test existance of ContextMenu::builtInItems object
-xcheck_equals (typeof(contextmenuObj.builtInItems), 'object');
-check ( ! contextmenuObj.builtInItems instanceOf Array );
-check_equals (typeof(contextmenuObj.builtInItems.length), 'undefined');
-
-// test existance of ContextMenu::customItems object
-xcheck_equals (typeof(contextmenuObj.customItems), 'object');
-check ( ! contextmenuObj.builtInItems instanceOf Array );
-xcheck_equals (typeof(contextmenuObj.customItems.length), 'number');
-
-// test existance of ContextMenu::onSelect object
-check_equals (typeof(contextmenuObj.onSelect), 'undefined');
-
-//----------------------------------------------
-// Test onSelect
-//----------------------------------------------
-
-function callback() { }
-var contextMenuObj2 = new ContextMenu(callback);
-check_equals(typeof(contextMenuObj2.onSelect), 'function');
-check_equals(contextMenuObj2.onSelect, callback);
-function callback2() { }
-contextMenuObj2.onSelect = callback2;
-check_equals(typeof(contextMenuObj2.onSelect), 'function');
-check_equals(contextMenuObj2.onSelect, callback2);
-contextMenuObj2.onSelect = null;
-check_equals(typeof(contextMenuObj2.onSelect), 'null');
-contextMenuObj2.onSelect = undefined;
-check_equals(typeof(contextMenuObj2.onSelect), 'undefined');
-contextMenuObj2.onSelect = 4;
-check_equals(typeof(contextMenuObj2.onSelect), 'number');
+  check_equals(typeof(ContextMenu), 'function');
+  totals(1);
+
+#else
+
+  check_equals(typeof(ContextMenu), 'function');
+
+  check(ContextMenu.prototype.hasOwnProperty("copy"));  
+  check(ContextMenu.prototype.hasOwnProperty("hideBuiltInItems"));  
+
+  check(!ContextMenu.prototype.hasOwnProperty("builtInItems"));  
+  check(!ContextMenu.prototype.hasOwnProperty("customItems"));
+  check(!ContextMenu.prototype.hasOwnProperty("onSelect"));  
+
+  var cm = new ContextMenu;
+  
+  check_equals (typeof(cm), 'object');
+  check(cm instanceof ContextMenu);
+
+  check(!cm.hasOwnProperty("copy"));  
+  check(!cm.hasOwnProperty("hideBuiltInItems"));  
+
+  check_equals(typeof(cm.copy), "function");
+  check_equals(typeof(cm.hideBuiltInItems), "function");
+
+  xcheck(cm.hasOwnProperty("builtInItems"));  
+  xcheck(cm.hasOwnProperty("customItems"));
+  xcheck(cm.hasOwnProperty("onSelect"));  
+
+  xcheck_equals(typeof(cm.builtInItems), "object");  
+  check(!cm.builtInItems instanceof Array);
+  check_equals(typeof(cm.builtInItems.length), 'undefined');
+
+  xcheck_equals(typeof(cm.customItems), "object");
+  xcheck(cm.customItems instanceof Array);
+  xcheck_equals(typeof(cm.customItems.length), 'number');
+
+  // There are no custom items by default.
+  xcheck_equals(cm.customItems.length, 0);
+
+  check_equals(typeof(cm.onSelect), "undefined");
+ 
+  // Check the built-in items. 
+  o = cm.builtInItems;
+  s = "";
+  for (i in o) {
+     check_equals(typeof(i), "string");
+     check_equals(typeof(o[i]), "boolean");
+     s += i + ",";
+  }
+  xcheck_equals(s, "save,zoom,quality,play,loop,rewind,forward_back,print,");
+
+
+  // Test ContextMenuItem
+  
+  xcheck_equals(typeof(ContextMenuItem), "function");
+
+  xcheck(ContextMenuItem.prototype.hasOwnProperty("copy"));
+
+  check(!ContextMenuItem.prototype.hasOwnProperty("caption"));
+  check(!ContextMenuItem.prototype.hasOwnProperty("enabled"));
+  check(!ContextMenuItem.prototype.hasOwnProperty("separatorBefore"));
+  check(!ContextMenuItem.prototype.hasOwnProperty("visible"));
+
+  it = new ContextMenuItem();
+  xcheck_equals(typeof(it), "object");
+  xcheck(it instanceof ContextMenuItem);
+
+  check(!it.hasOwnProperty("copy"));
+  xcheck(it.hasOwnProperty("caption"));
+  xcheck(it.hasOwnProperty("enabled"));
+  xcheck(it.hasOwnProperty("separatorBefore"));
+  xcheck(it.hasOwnProperty("visible"));
+
+  check_equals(typeof(it.caption), "undefined");
+  check_equals(it.caption, undefined);
+  xcheck_equals(typeof(it.enabled), "boolean");
+  xcheck_equals(it.enabled, true);
+  xcheck_equals(typeof(it.separatorBefore), "boolean");
+  xcheck_equals(it.separatorBefore, false);
+  xcheck_equals(typeof(it.visible), "boolean");
+  xcheck_equals(it.visible, true);
+
+  f = function () { trace("f"); return "f"; };
+  g = function () { trace("g"); return "g"; };
+  
+
+  it = new ContextMenuItem("name1", f);
+  xcheck_equals(typeof(it.caption), "string");
+  xcheck_equals(it.caption, "name1");
+  xcheck_equals(typeof(it.onSelect), "function");
+  xcheck_equals(it.onSelect(), "f");
+  xcheck_equals(typeof(it.enabled), "boolean");
+  xcheck_equals(it.enabled, true);
+  xcheck_equals(typeof(it.separatorBefore), "boolean");
+  xcheck_equals(it.separatorBefore, false);
+  xcheck_equals(typeof(it.visible), "boolean");
+  xcheck_equals(it.visible, true);
+
+  // Add a test object to the ContextMenu
+  cm.customItems.push(it);
+  xcheck_equals(cm.customItems.length, 1);
+  _root.menu = cm;
+
+  // An object is added to the menu if:
+  // (a) it has both a caption and an onSelect member that is a function.
+  // (b) it does not have a visible property that evaluates to false.
+  //
+  // The item is enabled unless the enabled property evaluates to false.
+  o = {};
+  o.caption = "fake item";
+  o.onSelect = f;
+  o.enabled = true;
+  o.visible = true;
+  cm.customItems.push(o);
+
+  o1 = {};
+  o1.caption = "fake item 2";
+  cm.customItems.push(o1);
+  o1.onSelect = f;
+
+  // This isn't added because onSelect isn't a function.
+  o2 = it.copy();
+  xcheck_equals(o2.caption, "name1");
+  xcheck_equals(o2.onSelect(), "f");
+  o2.onSelect = 6;
+  o2.caption = "name2";
+  cm.customItems.push(o2);
+
+  o3 = o2.copy();
+  o3.onSelect = g;
+  o3.caption = "name3";
+  cm.customItems.push(o3);
+
+  // If two objects have the same caption, only the first is added to the menu.
+  o4 = it.copy();
+  xcheck_equals(o4.caption, "name1");
+  o4.onSelect = g;
+  cm.customItems.push(o4);
+
+  //----------------------------------------------
+  // Test onSelect
+  //----------------------------------------------
+  
+  function callback() { }
+  var contextMenuObj2 = new ContextMenu(callback);
+  check_equals(typeof(contextMenuObj2.onSelect), 'function');
+  check_equals(contextMenuObj2.onSelect, callback);
+  function callback2() { }
+  contextMenuObj2.onSelect = callback2;
+  check_equals(typeof(contextMenuObj2.onSelect), 'function');
+  check_equals(contextMenuObj2.onSelect, callback2);
+  contextMenuObj2.onSelect = null;
+  check_equals(typeof(contextMenuObj2.onSelect), 'null');
+  contextMenuObj2.onSelect = undefined;
+  check_equals(typeof(contextMenuObj2.onSelect), 'undefined');
+  contextMenuObj2.onSelect = 4;
+  check_equals(typeof(contextMenuObj2.onSelect), 'number');
+  
+  xtotals(82);
 
 #endif
-totals();


reply via email to

[Prev in Thread] Current Thread [Next in Thread]