gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r12184: Tests for InitAction executi


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r12184: Tests for InitAction execution.
Date: Mon, 10 May 2010 16:28:27 +0200
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 12184 [merge]
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Mon 2010-05-10 16:28:27 +0200
message:
  Tests for InitAction execution.
added:
  testsuite/misc-ming.all/RegisterClassTest3.c
modified:
  libcore/swf/DoInitActionTag.h
  testsuite/misc-ming.all/InitActionTest2.c
  testsuite/misc-ming.all/Makefile.am
=== modified file 'libcore/swf/DoInitActionTag.h'
--- a/libcore/swf/DoInitActionTag.h     2010-01-01 17:48:26 +0000
+++ b/libcore/swf/DoInitActionTag.h     2010-05-10 08:22:56 +0000
@@ -76,7 +76,10 @@
         }
         
         in.ensureBytes(2);
-        int cid = in.read_u16();
+        const boost::uint16_t cid = in.read_u16();
+        
+        // Tags should only be executed for exported characters, though
+        // it doesn't matter if the export is known during parsing.
         DoInitActionTag* da = new DoInitActionTag(in, m, cid);
 
         IF_VERBOSE_PARSE (
@@ -84,7 +87,6 @@
         log_parse(_("  -- init actions for sprite %d"), cid);
         );
 
-        //m->add_init_action(da, cid); // ownership transferred
         m.addControlTag(da); // ownership transferred
     }
 

=== modified file 'testsuite/misc-ming.all/InitActionTest2.c'
--- a/testsuite/misc-ming.all/InitActionTest2.c 2010-05-06 12:11:37 +0000
+++ b/testsuite/misc-ming.all/InitActionTest2.c 2010-05-10 08:34:18 +0000
@@ -12,10 +12,9 @@
 main(int argc, char** argv)
 {
     SWFMovie mo;
-    SWFMovieClip mc3, mc2, dejagnuclip;
-    SWFAction ac, ac1;
+    SWFMovieClip mc4, mc5, dejagnuclip;
     SWFDisplayItem it;
-    SWFShape sha;
+    SWFInitAction ia;
 
     const char *srcdir=".";
     if (argc > 1) srcdir = argv[1];
@@ -27,90 +26,88 @@
     Ming_init();
     mo = newSWFMovieWithVersion(OUTPUT_VERSION);
     SWFMovie_setDimension(mo, 800, 600);
+ 
     SWFMovie_setRate (mo, 12.0);
 
-    sha = newSWFShape();
-
-    // Character ID 2. Has 1 showframe. Is exported first.
-    mc2 = newSWFMovieClip();
-    SWFMovieClip_add(mc2, (SWFBlock)sha);
-    SWFMovieClip_nextFrame(mc2);
-
-    // Export it.
-    SWFMovie_addExport(mo, (SWFBlock)mc2, "C2");
-    SWFMovie_writeExports(mo);
-
-    // Main timeline actions for frame 1
-    add_actions(mo, "var c = 0; trace('frame 1'); gotoAndStop(3);");
-    
-    // ID 3 is defined here. It has no showframe. It is exported immediately.
-    mc3 = newSWFMovieClip();
-    SWFMovie_addExport(mo, (SWFBlock)mc3, "ctor");
-    SWFMovie_writeExports(mo);
-
+    // Character ID: 1, 2
     dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10,
-                   0, 0, 800, 600);
+             0, 0, 800, 600);
     SWFMovie_add(mo, (SWFBlock)dejagnuclip);
 
-    // Init actions for ID 3
-    ac = newSWFAction(
-    "   _global.ctor = function () {"
-    "       super();"
-    "       trace('Object in Frame 2 is constructed');"
-    "       c += 1;"
-    "   };"
-    );
-    SWFInitAction ia = newSWFInitAction_withId(ac, 3);
-    SWFMovie_add(mo, (SWFBlock)ia);
-    
-    // Init actions for ID 2 (registered class)
-    ac1 = newSWFAction("Object.registerClass('C2', ctor); "
-            "trace('Registered class');");
-    ia = newSWFInitAction_withId(ac1, 2);
-    SWFMovie_add(mo, (SWFBlock)ia);
-       
-    
+    // Character ID: 4
+    mc4 = newSWFMovieClip();
+    SWFMovieClip_nextFrame(mc4);
+    it = SWFMovie_add(mo, (SWFBlock)mc4);
+
+    // InitActions for ID 2 parsed here:
+    ia = newSWFInitAction_withId(
+            newSWFAction("trace('mc4'); _global.val4 = 'mc4';"), 4);
+    SWFMovie_add(mo, (SWFBlock)ia);
+
+    // Check in first frame:
+    check(mo, "_global.val4 == undefined");
+
     // Frame 2
     SWFMovie_nextFrame(mo);
-    add_actions(mo, "trace('Frame 2');");
-    
-    // Place object ID 2.
-    it = SWFMovie_add(mo, (SWFBlock)mc2);
-    SWFDisplayItem_setName(it, "mc2");
-
-    // Frame 3
-    SWFMovie_nextFrame(mo);
-
-    // Remove object ID 2
-    SWFMovie_remove(mo, it);
-
-    add_actions(mo, "trace('frame 3');");
-    
-    // The class should not be constructed if the object is removed after
-    // being placed. It should be constructed if it's not removed.
-    xcheck(mo, "c == 0");
-    check(mo, "_root.mc2 == undefined");
-    add_actions(mo, "gotoAndStop(5);");
-
-    // Frame 4
-    SWFMovie_nextFrame(mo);
-    add_actions(mo, "trace('Frame 4');");
-    
-    // Place object ID 2 again
-    it = SWFMovie_add(mo, (SWFBlock)mc2);
-    SWFDisplayItem_setName(it, "mc2a");
+    
+    // Check in next frame:
+    xcheck(mo, "_global.val4 == undefined");
+    
+    // Frame 4
+    SWFMovie_nextFrame(mo);
+
+    // Action is before export tag.
+    xcheck(mo, "_global.val4 == undefined");
+    SWFMovie_addExport(mo, (SWFBlock)mc4, "export4");
+    SWFMovie_writeExports(mo);
+    xcheck(mo, "_global.val4 == undefined");
+
+    // Frame 4
+    SWFMovie_nextFrame(mo);
+    xcheck(mo, "_global.val4 == undefined");
+
+    // Add it again
+    SWFMovie_add(mo, (SWFBlock)mc4);
+    xcheck(mo, "_global.val4 == undefined");
 
     // Frame 5
     SWFMovie_nextFrame(mo);
-
-    // This time the MovieClip was not removed before we get here,
-    // so it should be present and the constructor should be
-    // called.
-    add_actions(mo, "trace('frame 5');");
-    xcheck(mo, "c == 1");
-    check(mo, "typeof(_root.mc2a) == 'movieclip'");
-
-    SWFMovie_nextFrame(mo);
+    xcheck(mo, "_global.val4 == undefined");
+    
+    // Add it again, export it again:
+    SWFMovie_add(mo, (SWFBlock)mc4);
+    SWFMovie_addExport(mo, (SWFBlock)mc4, "export4");
+    SWFMovie_writeExports(mo);
+    xcheck(mo, "_global.val4 == undefined");
+    
+    // Frame 6
+    SWFMovie_nextFrame(mo);
+
+    // MovieClip *must be exported*, SWFInitAction *must be after export*,
+    // but not necessarily in the same frame.
+    ia = newSWFInitAction_withId(
+            newSWFAction("_global.val4 = 'mc4a';"), 4);
+    SWFMovie_add(mo, (SWFBlock)ia);
+    xcheck(mo, "_global.val4 == 'mc4a'");
+    
+    // Frame 7
+    SWFMovie_nextFrame(mo);
+    
+    // The MovieClip does not have to be placed, but must be exported.
+    mc5 = newSWFMovieClip();
+    SWFMovie_addExport(mo, (SWFBlock)mc5, "export5");
+    SWFMovie_writeExports(mo);
+    
+    // Action is before InitAction, but this does not matter. As long as it's
+    // in the same frame it will work.
+    check(mo, "_global.val5 == 'mc5'");
+    
+    ia = newSWFInitAction_withId(
+            newSWFAction("trace('mc5'); _global.val5 = 'mc5';"), 5);
+    SWFMovie_add(mo, (SWFBlock)ia);
+    check(mo, "_global.val5 == 'mc5'");
+
+    add_actions(mo, "stop();");
   
     puts("Saving " OUTPUT_FILENAME );
     SWFMovie_save(mo, OUTPUT_FILENAME);

=== modified file 'testsuite/misc-ming.all/Makefile.am'
--- a/testsuite/misc-ming.all/Makefile.am       2010-05-06 09:23:32 +0000
+++ b/testsuite/misc-ming.all/Makefile.am       2010-05-07 13:29:03 +0000
@@ -222,6 +222,7 @@
 check_PROGRAMS += \
        init_action_test \
        InitActionTest2 \
+       RegisterClassTest3 \
        registerClassTest2 \
        $(NULL)
 endif
@@ -350,6 +351,7 @@
 if MING_SUPPORTS_INIT_ACTIONS
 check_SCRIPTS += \
        InitActionTest2Runner \
+       RegisterClassTest3Runner \
        registerClassTest2runner \
        $(NULL)
 endif
@@ -1785,6 +1787,18 @@
        sh $< $(top_builddir) InitActionTest2.swf > $@
        chmod 755 $@
 
+RegisterClassTest3_SOURCES =   \
+       RegisterClassTest3.c    \
+       $(NULL)
+RegisterClassTest3_LDADD = libgnashmingutils.la
+
+RegisterClassTest3.swf: RegisterClassTest3
+       ./RegisterClassTest3 $(top_srcdir)/testsuite/media
+
+RegisterClassTest3Runner: $(srcdir)/../generic-testrunner.sh 
RegisterClassTest3.swf
+       sh $< $(top_builddir) RegisterClassTest3.swf > $@
+       chmod 755 $@
+
 init_action_test_SOURCES =     \
        init_action_test.c      \
        $(NULL)
@@ -2168,6 +2182,7 @@
        registerClassTest2runner \
        init_action_testrunner \
        InitAction2TestRunner \
+       RegisterClassTest3Runner \
        $(NULL)
 endif
 

=== added file 'testsuite/misc-ming.all/RegisterClassTest3.c'
--- a/testsuite/misc-ming.all/RegisterClassTest3.c      1970-01-01 00:00:00 
+0000
+++ b/testsuite/misc-ming.all/RegisterClassTest3.c      2010-05-10 07:58:53 
+0000
@@ -0,0 +1,120 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <ming.h>
+
+#include "ming_utils.h"
+
+#define OUTPUT_VERSION 8
+#define OUTPUT_FILENAME "RegisterClassTest3.swf"
+
+
+int
+main(int argc, char** argv)
+{
+    SWFMovie mo;
+    SWFMovieClip mc3, mc2, dejagnuclip;
+    SWFAction ac, ac1;
+    SWFDisplayItem it;
+    SWFShape sha;
+
+    const char *srcdir=".";
+    if (argc > 1) srcdir = argv[1];
+    else {
+        fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
+        return 1;
+    }
+
+    Ming_init();
+    mo = newSWFMovieWithVersion(OUTPUT_VERSION);
+    SWFMovie_setDimension(mo, 800, 600);
+    SWFMovie_setRate (mo, 12.0);
+
+    sha = newSWFShape();
+
+    // Character ID 2. Has 1 showframe. Is exported first.
+    mc2 = newSWFMovieClip();
+    SWFMovieClip_add(mc2, (SWFBlock)sha);
+    SWFMovieClip_nextFrame(mc2);
+
+    // Export it.
+    SWFMovie_addExport(mo, (SWFBlock)mc2, "C2");
+    SWFMovie_writeExports(mo);
+
+    // Main timeline actions for frame 1
+    add_actions(mo, "var c = 0; trace('frame 1'); gotoAndStop(3);");
+    
+    // ID 3 is defined here. It has no showframe. It is exported immediately.
+    mc3 = newSWFMovieClip();
+    SWFMovie_addExport(mo, (SWFBlock)mc3, "ctor");
+    SWFMovie_writeExports(mo);
+
+    dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10,
+                   0, 0, 800, 600);
+    SWFMovie_add(mo, (SWFBlock)dejagnuclip);
+
+    // Init actions for ID 3
+    ac = newSWFAction(
+    "   _global.ctor = function () {"
+    "       super();"
+    "       trace('Object in Frame 2 is constructed');"
+    "       c += 1;"
+    "   };"
+    );
+    SWFInitAction ia = newSWFInitAction_withId(ac, 3);
+    SWFMovie_add(mo, (SWFBlock)ia);
+    
+    // Init actions for ID 2 (registered class)
+    ac1 = newSWFAction("Object.registerClass('C2', ctor); "
+            "trace('Registered class');");
+    ia = newSWFInitAction_withId(ac1, 2);
+    SWFMovie_add(mo, (SWFBlock)ia);
+       
+    
+    // Frame 2
+    SWFMovie_nextFrame(mo);
+    add_actions(mo, "trace('Frame 2');");
+    
+    // Place object ID 2.
+    it = SWFMovie_add(mo, (SWFBlock)mc2);
+    SWFDisplayItem_setName(it, "mc2");
+
+    // Frame 3
+    SWFMovie_nextFrame(mo);
+
+    // Remove object ID 2
+    SWFMovie_remove(mo, it);
+
+    add_actions(mo, "trace('frame 3');");
+    
+    // The class should not be constructed if the object is removed after
+    // being placed. It should be constructed if it's not removed.
+    xcheck(mo, "c == 0");
+    check(mo, "_root.mc2 == undefined");
+    add_actions(mo, "gotoAndStop(5);");
+
+    // Frame 4
+    SWFMovie_nextFrame(mo);
+    add_actions(mo, "trace('Frame 4');");
+    
+    // Place object ID 2 again
+    it = SWFMovie_add(mo, (SWFBlock)mc2);
+    SWFDisplayItem_setName(it, "mc2a");
+
+    // Frame 5
+    SWFMovie_nextFrame(mo);
+
+    // This time the MovieClip was not removed before we get here,
+    // so it should be present and the constructor should be
+    // called.
+    add_actions(mo, "trace('frame 5');");
+    xcheck(mo, "c == 1");
+    check(mo, "typeof(_root.mc2a) == 'movieclip'");
+
+    SWFMovie_nextFrame(mo);
+  
+    puts("Saving " OUTPUT_FILENAME );
+    SWFMovie_save(mo, OUTPUT_FILENAME);
+
+    return 0;
+}
+


reply via email to

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