"Fossies" - the Fresh Open Source Software Archive

Member "gnash-0.8.10/testsuite/misc-ming.all/action_order/action_execution_order_extend_test.c" (19 Jan 2012, 8041 Bytes) of package /linux/www/old/gnash-0.8.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  *   Copyright (C) 2005, 2006, 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
    3  * 
    4  * This program is free software; you can redistribute it and/or modify
    5  * it under the terms of the GNU General Public License as published by
    6  * the Free Software Foundation; either version 3 of the License, or
    7  * (at your option) any later version.
    8  * 
    9  * This program is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12  * GNU General Public License for more details.
   13  * You should have received a copy of the GNU General Public License
   14  * along with this program; if not, write to the Free Software
   15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   16  *
   17  */ 
   18 
   19 /*
   20  * Zou Lunkai, zoulunkai@gmail.com
   21  *
   22  * movieClip hiberarchy:
   23  * main timeline  (5 frames)
   24  *     |----dejagnuclip(placed at 1st frame of main timeline)
   25  *     |----mc_red     (placed at 2nd frame of main timeline, and removed at 4th frame)
   26  *             |----mc_blu(placed at 1st frame of mc_red)
   27  */
   28 
   29 #include <stdlib.h>
   30 #include <stdio.h>
   31 #include <ming.h>
   32 
   33 #include "ming_utils.h"
   34 
   35 #define OUTPUT_VERSION 6
   36 #define OUTPUT_FILENAME "action_execution_order_extend_test.swf"
   37 
   38 
   39 int
   40 main(int argc, char** argv)
   41 {
   42   SWFMovie mo;
   43   SWFMovieClip  mc_red, mc_blu, dejagnuclip;
   44   SWFShape  sh_red, sh_blu;
   45   SWFDisplayItem it_red, it_blu;
   46 
   47   const char *srcdir=".";
   48   if ( argc>1 ) 
   49     srcdir=argv[1];
   50   else
   51   {
   52       fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
   53       return 1;
   54   }
   55 
   56   Ming_init();
   57   mo = newSWFMovieWithVersion(OUTPUT_VERSION);
   58   SWFMovie_setDimension(mo, 800, 600);
   59   SWFMovie_setRate (mo, 1.0);
   60 
   61   dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
   62   SWFMovie_add(mo, (SWFBlock)dejagnuclip);
   63   add_actions(mo, " trace('as in frame1 of root');"); // can't use 'note' here, as it's not been defined yet
   64   SWFMovie_nextFrame(mo); /* 1st frame */
   65 
   66   mc_blu = newSWFMovieClip();
   67   sh_blu = make_fill_square (20, 320, 20, 20, 0, 0, 255, 0, 0, 255);
   68   SWFMovieClip_add(mc_blu, (SWFBlock)sh_blu);  
   69   add_clip_actions(mc_blu, " _root.note('as in frame1 of mc_blu'); _root.x1 = \"as_in_mc_blu\"; ");
   70   SWFMovieClip_nextFrame(mc_blu); /* 1st frame */
   71   add_clip_actions(mc_blu, " _root.note('as in frame2 of mc_blu'); _root.x2 = \"as_in_mc_blu\"; stop();");
   72   SWFMovieClip_nextFrame(mc_blu); /* 2nd frame */
   73   
   74   mc_red = newSWFMovieClip();
   75   sh_red = make_fill_square (0, 300, 60, 60, 255, 0, 0, 255, 0, 0);
   76   SWFMovieClip_add(mc_red, (SWFBlock)sh_red);  
   77   /* Add mc_blu to mc_red and name it as "mc_blu" */
   78   it_blu = SWFMovieClip_add(mc_red, (SWFBlock)mc_blu);  
   79 #if 0 // adding *any* clip-event handler makes user-defined onLoad execute !
   80   SWFDisplayItem_addAction(it_blu,
   81         compileSWFActionCode("_root.note('mc_blu clip unload executed'); "
   82         ), SWFACTION_UNLOAD);
   83 #endif
   84   SWFDisplayItem_setDepth(it_blu, 1000); 
   85   SWFDisplayItem_setName(it_blu, "mc_blu");
   86 #if 1 /* setting ratio doesn't change the fact we won't execute user-defined onLoad event handler
   87        * if no clip handlers are defined */
   88   SWFDisplayItem_setRatio(it_blu, 0);
   89 #endif
   90   add_clip_actions(mc_red, "_root.note('as in frame1 of mc_red'); _root.x1 = \"as_in_mc_red\"; ");
   91   add_clip_actions(mc_red, " func = function() {}; ");
   92   SWFMovieClip_nextFrame(mc_red); /* 1st frame */
   93   add_clip_actions(mc_red, " _root.note('as in frame2 of mc_red'); _root.x2 = \"as_in_mc_red\"; stop();");
   94   SWFMovieClip_nextFrame(mc_red); /* 2nd frame */
   95   
   96   /* Add mc_red to _root and name it as "mc_red" */
   97   it_red = SWFMovie_add(mo, (SWFBlock)mc_red);  
   98   SWFDisplayItem_setDepth(it_red, 20); 
   99   SWFDisplayItem_setName(it_red, "mc_red");
  100   SWFDisplayItem_addAction(it_red,
  101         compileSWFActionCode("_root.note('mc_red clip load executed'); "
  102             "_root.y1bis = 'mc_red onClipLoad called';"),
  103         SWFACTION_ONLOAD);
  104   /* Woo, the PlaceObject tag hasn't defined an 'onLoad' function.
  105          maybe just pushed something to the action list???
  106     */
  107   check_equals(mo, "typeOf(_root.mc_red.onLoad)", "'undefined'");
  108   add_actions(mo, " note('as in frame2 of root'); var x1 = \"as_in_root\"; ");
  109   add_actions(mo, " _root.mc_red.onLoad = function () \
  110                    { \
  111                        note('mc_red load executed'); \
  112                        _root.y1 = 'mc_red onLoad called'; \
  113                    }; \
  114                    _root.mc_red.onEnterFrame = function () \
  115                    { \
  116                        note('mc_red enterFrame executed'); \
  117                        _root.y2 = 'mc_red onEnterFrame called'; \
  118                    }; \
  119                    _root.mc_red.onUnload = function () \
  120                    { \
  121                        note('mc_red unload executed'); \
  122                         _root.y3 = 'mc_red onUnload called'; \
  123                    }; \
  124                    _root.mc_red.mc_blu.onLoad = function () \
  125                    { \
  126                        note('mc_blu load executed'); \
  127                        _root.y4 = 'mc_blu onLoad called'; \
  128                    }; \
  129                    _root.mc_red.mc_blu.onEnterFrame = function () \
  130                    { \
  131                        note('mc_blu enterFrame executed'); \
  132                         _root.y5 = 'mc_blu onEnterFrame called'; \
  133                    }; \
  134                    _root.mc_red.mc_blu.onUnload = function () \
  135                    { \
  136                        note('mc_blu user-defined UNLOAD executed'); \
  137                        _root.y6 = 'mc_blu onUnload called'; \
  138                    };");
  139 
  140   /*
  141    * Check that the DisplayList is initialized deep to the mc_blu level
  142    * Even if their actions are not expected to be executed yet
  143    */
  144   check_equals(mo, "typeOf(_root.mc_red)", "'movieclip'");
  145   check_equals(mo, "typeOf(_root.mc_red.func)", "'undefined'");
  146   check_equals(mo, "typeOf(_root.mc_red.mc_blu)", "'movieclip'");
  147   SWFMovie_nextFrame(mo); /* 2nd frame */
  148   
  149   
  150   add_actions(mo, " note('as in frame3 of root'); \
  151                     _root.x2 = 'as_in_root'; \
  152                     _root.y2 = 'as_in_root'; \
  153                     _root.y5 = 'as_in_root';");
  154   check_equals(mo, "typeOf(_root.mc_red.func)", "'function'");
  155   SWFMovie_nextFrame(mo); /* 3rd frame */
  156   
  157   
  158   SWFDisplayItem_remove(it_red);
  159   add_actions(mo, " note('as in frame4 of root'); \
  160                     _root.y3 = 'as_in_root'; \
  161                     _root.y6 = 'as_in_root'; ");
  162   /* In the frame placing mc_red,  actions in mc_red is executed *after* actions in _root */
  163   check_equals(mo, "_root.x1", "'as_in_mc_blu'");
  164   /* In subsequent frames, actions in mc_red is executed *before* actions in _root */
  165   check_equals(mo, "_root.x2", "'as_in_root'");
  166   SWFMovie_nextFrame(mo); /* 4th frame */
  167   
  168   /* mc_red onload is only called IFF onClipEvent(load) is also defined! */
  169   check_equals(mo, "_root.y1", "'mc_red onLoad called'");
  170   check_equals(mo, "_root.y1bis", "'mc_red onClipLoad called'");
  171   /* actions in main timeline is executed *after* mc_red.onEnterFrame */
  172   check_equals(mo, "_root.y2", "'as_in_root'");
  173   /* actions in main timeline is executed *before* mc_red.onUnload in
  174      this testcase, but I don't believe it is alway true. The actually order
  175      may dependent on order of tags. It seems that Ming always place REMOVE_OBJECT
  176      tag after DO_ACTION Tag. What if the order is reversed(I can't perform this 
  177      with Ming)?? */
  178   check_equals(mo, "_root.y3", "'mc_red onUnload called'");
  179   /* mc_blu Onload is not called */
  180   check_equals(mo, "_root.y4", "undefined");
  181   /* actions in main timeline is executed *after* mc_blu.onEnterFrame */
  182   check_equals(mo, "_root.y5", "'as_in_root'");
  183   /* actions in main timeline is executed *before* mc_blu.onUnload */
  184   check_equals(mo, "_root.y6", "'mc_blu onUnload called'");
  185   add_actions(mo, " _root.totals(); stop(); ");
  186   SWFMovie_nextFrame(mo); /* 5th frame */
  187   
  188   /* Output movie */
  189   puts("Saving " OUTPUT_FILENAME );
  190   SWFMovie_save(mo, OUTPUT_FILENAME);
  191 
  192   return 0;
  193 }
  194 
  195 
  196