"Fossies" - the Fresh Open Source Software Archive

Member "gnash-0.8.10/testsuite/misc-ming.all/action_order/action_execution_order_test4.c" (19 Jan 2012, 8980 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,
    3  *   2011 Free Software Foundation, Inc.
    4  * 
    5  * This program is free software; you can redistribute it and/or modify
    6  * it under the terms of the GNU General Public License as published by
    7  * the Free Software Foundation; either version 3 of the License, or
    8  * (at your option) any later version.
    9  * 
   10  * This program is distributed in the hope that it will be useful,
   11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13  * GNU General Public License for more details.
   14  * You should have received a copy of the GNU General Public License
   15  * along with this program; if not, write to the Free Software
   16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   17  *
   18  */ 
   19 
   20 /*
   21  * Zou Lunkai, zoulunkai@gmail.com
   22  *
   23  * To verify that for all movieClips within the same timeline: 
   24  *    (1) OnLoad: first added first called; 
   25  *    (2) OnUnload: first removed first called; 
   26  *    (3) OnEnterFrame: last added first called; 
   27  *
   28  * 1st frame of _root: 
   29  *    place mc1 at depth 10
   30  *    place mc2 at depth 12
   31  *    place mc3 at depth 11
   32  *
   33  * 4th frame of _root:
   34  *     remove mc1
   35  *     remove mc2 
   36  *     remove mc3 
   37  *
   38  * expected actions order:
   39  *     actions in 1st frame of _root; _root.OnLoad;
   40  * (advanced to 2nd frame of _root)
   41  *     mc1.OnConstruct; mc2.OnConstruct; mc3.OnConstruct;
   42  *     mc1.OnLoad; actions in 1st frame of mc1;
   43  *     mc2.OnLoad; actions in 1st frame of mc2;
   44  *     mc3.OnLoad; actions in 1st frame of mc3;
   45  *     mc3.OnEnterFrame; actions in 2nd frame of mc3;
   46  *     mc2.OnEnterFrame; actions in 2nd frame of mc2;
   47  *     mc1.OnEnterFrame; actions in 2nd frame of mc1;
   48  *     mc1.OnUnload; 
   49  *     mc2.OnUnload; 
   50  *     mc3.OnUnload; 
   51  *
   52  * The actual order of tags are dependent on compiler, so you need to 
   53  * verify first if the order of tags is what you expect. 
   54  */
   55 
   56 #include <stdlib.h>
   57 #include <stdio.h>
   58 #include <ming.h>
   59 
   60 #include "ming_utils.h"
   61 
   62 #define OUTPUT_VERSION 6
   63 #define OUTPUT_FILENAME "action_execution_order_test4.swf"
   64 
   65 
   66 int
   67 main(int argc, char** argv)
   68 {
   69   SWFMovie mo;
   70   SWFMovieClip  mc1, mc2, mc3, dejagnuclip;
   71   SWFDisplayItem it1, it2, it3;
   72   SWFShape  sh_red;
   73 
   74   const char *srcdir=".";
   75   if ( argc>1 ) 
   76     srcdir=argv[1];
   77   else
   78   {
   79       fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
   80       return 1;
   81   }
   82 
   83   Ming_init();
   84   mo = newSWFMovieWithVersion(OUTPUT_VERSION);
   85   SWFMovie_setDimension(mo, 800, 600);
   86   SWFMovie_setRate (mo, 12.0);
   87 
   88   dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
   89   SWFMovie_add(mo, (SWFBlock)dejagnuclip);
   90   add_actions(mo, " x2 += 'as_start+'; "
   91                   " _root.OnLoad = function () { _root.note('_root onLoad called'); x2 += 'load_called+'; }; "
   92                   " x2 += 'as_end+'; "
   93                   " _root.onEnterFrame = function () { x3 += 'enterFrame_called+'; }; ");
   94   SWFMovie_nextFrame(mo); /* 1st frame */
   95 
   96   
   97   mc1 = newSWFMovieClip();
   98   sh_red = make_fill_square (0, 300, 60, 60, 255, 0, 0, 255, 0, 0);
   99   SWFMovieClip_add(mc1, (SWFBlock)sh_red);  
  100   add_clip_actions(mc1, " _root.note('actions in 1st frame of mc1'); "
  101             // Defining onLoad in first frame of a sprite doesn't work, but works for root
  102             " this.onLoad = function() { _root.note('mc1 onLoad called'); _root.x1 += 'YY'; };"
  103                         " _root.x1 += '2+'; ");
  104   SWFMovieClip_nextFrame(mc1); /* mc1, 1st frame */
  105   add_clip_actions(mc1, " _root.note('actions in 2nd frame of mc1'); "
  106                         " _root.x1 += '12+'; "
  107                         " stop(); ");
  108   SWFMovieClip_nextFrame(mc1); /* mc1, 2nd frame */
  109  
  110   mc2 = newSWFMovieClip();
  111   sh_red = make_fill_square (80, 300, 60, 60, 255, 0, 0, 255, 0, 0);
  112   SWFMovieClip_add(mc2, (SWFBlock)sh_red); 
  113   add_clip_actions(mc2, " _root.note('actions in 1st frame of mc2'); "
  114             // Defining onLoad in first frame of a sprite doesn't work, but works for root
  115             " this.onLoad = function() { _root.note('mc2 onLoad called'); _root.x1 += 'XX'; };"
  116                         " _root.x1 += '4+'; "); 
  117   SWFMovieClip_nextFrame(mc2); /* mc2, 1st frame */
  118   add_clip_actions(mc2, " _root.note('actions in 2nd frame of mc2'); "
  119                         " _root.x1 += '10+'; "
  120                         " stop(); "); 
  121   SWFMovieClip_nextFrame(mc2); /* mc2, 2nd frame */
  122   
  123   mc3 = newSWFMovieClip();
  124   sh_red = make_fill_square (160, 300, 60, 60, 255, 0, 0, 255, 0, 0);
  125   SWFMovieClip_add(mc3, (SWFBlock)sh_red);  
  126   add_clip_actions(mc3, " _root.note('actions in 1st frame of mc3'); "
  127             // Defining onLoad in first frame of a sprite doesn't work, but works for root
  128             " this.onLoad = function() { _root.note('mc3 onLoad called'); _root.x1 += 'ZZ'; };"
  129                         " _root.x1 += '6+';"); 
  130   SWFMovieClip_nextFrame(mc3); /* mc3, 1st frame */
  131   add_clip_actions(mc3, " _root.note('actions in 2nd frame of mc3'); "
  132                         " _root.x1 += '8+'; "
  133                         " stop(); "); 
  134   SWFMovieClip_nextFrame(mc3); /* mc3, 2nd frame */
  135   
  136   
  137   /* add mc1 to _root and name it as "mc1" */
  138   it1 = SWFMovie_add(mo, (SWFBlock)mc1);  
  139   SWFDisplayItem_setDepth(it1, 10); 
  140   SWFDisplayItem_setName(it1, "mc1"); 
  141   /* Define Construct ClipEvent */
  142   SWFDisplayItem_addAction(it1,
  143     compileSWFActionCode(" _root.note('mc1 Construct called');"
  144                          " _root.x0 += '01+'; "),
  145     SWFACTION_CONSTRUCT);
  146   /* Define Load ClipEvent */
  147   SWFDisplayItem_addAction(it1,
  148     compileSWFActionCode(" _root.note('mc1 Load called');"
  149                          " _root.x1 += '1+'; "),
  150     SWFACTION_ONLOAD);
  151   /* Define Unload ClipEvent */
  152   SWFDisplayItem_addAction(it1,
  153     compileSWFActionCode(" _root.note('mc1 Unload called'); "
  154                          " _root.x1 += '13+'; "),
  155     SWFACTION_UNLOAD);
  156   /* Define EnterFrame ClipEvent */
  157   SWFDisplayItem_addAction(it1,
  158     compileSWFActionCode(" _root.note('mc1 EnterFrame called'); "
  159                          " _root.x1 += '11+'; "),
  160     SWFACTION_ENTERFRAME);
  161     
  162   /* add mc2 to _root and name it as "mc2" */
  163   it2 = SWFMovie_add(mo, (SWFBlock)mc2);  
  164   SWFDisplayItem_setDepth(it2, 12); 
  165   SWFDisplayItem_setName(it2, "mc2"); 
  166   /* Define Construct ClipEvent */
  167   SWFDisplayItem_addAction(it2,
  168     compileSWFActionCode(" _root.note('mc2 Construct called');"
  169                          " _root.x0 += '02+'; "),
  170     SWFACTION_CONSTRUCT);
  171   /* Define Load ClipEvent */
  172   SWFDisplayItem_addAction(it2,
  173     compileSWFActionCode(" _root.note('mc2 Load called'); "
  174                          " _root.x1 += '3+'; "),
  175     SWFACTION_ONLOAD);
  176   /* Define Unload ClipEvent */
  177   SWFDisplayItem_addAction(it2,
  178     compileSWFActionCode(" _root.note('mc2 Unload called'); "
  179                          " _root.x1 += '14+'; "),
  180     SWFACTION_UNLOAD);
  181   /* Define EnterFrame ClipEvent */
  182   SWFDisplayItem_addAction(it2,
  183     compileSWFActionCode(" _root.note('mc2 EnterFrame called'); "
  184                          " _root.x1 += '9+'; "),
  185     SWFACTION_ENTERFRAME);
  186     
  187   /* add mc3 to _root and name it as "mc3" */
  188   it3 = SWFMovie_add(mo, (SWFBlock)mc3);  
  189   SWFDisplayItem_setDepth(it3, 11); 
  190   SWFDisplayItem_setName(it3, "mc3"); 
  191   /* Define Construct ClipEvent */
  192   SWFDisplayItem_addAction(it3,
  193     compileSWFActionCode(" _root.note('mc3 Construct called');"
  194                          " _root.x0 += '03+'; "),
  195     SWFACTION_CONSTRUCT);
  196   /* Define Load ClipEvent */
  197   SWFDisplayItem_addAction(it3,
  198     compileSWFActionCode(" _root.note('mc3 Load called'); "
  199                          " _root.x1 += '5+'; "),
  200     SWFACTION_ONLOAD);
  201   /* Define Unload ClipEvent */
  202   SWFDisplayItem_addAction(it3,
  203     compileSWFActionCode(" _root.note('mc3 Unload called'); "
  204                          " _root.x1 += '15+';" ),
  205     SWFACTION_UNLOAD);
  206   /* Define EnterFrame ClipEvent */
  207   SWFDisplayItem_addAction(it3,
  208     compileSWFActionCode(" _root.note('mc3 EnterFrame called'); "
  209                          " _root.x1 += '7+'; "),
  210     SWFACTION_ENTERFRAME);
  211   
  212   add_actions(mo, " _root.x3 += '_root_frm2_as+'; ");
  213   SWFMovie_nextFrame(mo); /* 2nd frame */
  214 
  215   add_actions(mo, " _root.x3 += '_root_frm3_as+'; ");
  216   check_equals(mo, "_root.x3", "'enterFrame_called+_root_frm2_as+enterFrame_called+_root_frm3_as+'");
  217   SWFMovie_nextFrame(mo); /* 3rd frame */
  218   
  219   /* It's no use to change the order below.
  220   After compile, Ming will re-organize them as 
  221   remove mc1; remove mc2; remove mc3;*/
  222   SWFDisplayItem_remove(it3);  
  223   SWFDisplayItem_remove(it1);
  224   SWFDisplayItem_remove(it2);
  225   SWFMovie_nextFrame(mo); /* 4th frame */
  226 
  227   check_equals(mo, "_root.x0", "'01+02+03+'");
  228   check_equals(mo, "_root.x1", "'1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+'");
  229   check_equals(mo, "_root.x2", "'as_start+as_end+load_called+'");
  230   add_actions(mo, " _root.totals(); stop(); ");
  231   SWFMovie_nextFrame(mo); /* 5th frame */
  232   
  233   
  234   //Output movie
  235   puts("Saving " OUTPUT_FILENAME );
  236   SWFMovie_save(mo, OUTPUT_FILENAME);
  237 
  238   return 0;
  239 }
  240 
  241 
  242