"Fossies" - the Fresh Open Source Software Archive

Member "gnash-0.8.10/testsuite/misc-ming.all/action_order/action_execution_order_test.c" (19 Jan 2012, 5102 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, 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  * Test the execution order of actions within different movieClips
   23  *
   24  * set a variable with a new value under _root, then set it again under anther movieClip.
   25  *   the variable will only record the later assignment. Checking the final result of the
   26  *   variable will tell us which action(assignment) is executed first.
   27  *
   28  * Expected result is:
   29  *   In the frame placing mc_red,  actions in mc_red is executed *after* actions in _root
   30  *   In subsequent frames, actions in mc_red is executed *before* actions in _root
   31  */
   32 
   33 #include <stdlib.h>
   34 #include <stdio.h>
   35 #include <ming.h>
   36 
   37 #include "ming_utils.h"
   38 
   39 #define OUTPUT_VERSION 6
   40 #define OUTPUT_FILENAME "action_execution_order_test.swf"
   41 
   42 
   43 int
   44 main(int argc, char** argv)
   45 {
   46   SWFMovie mo;
   47   SWFMovieClip  mc_red, mc_blu, dejagnuclip;
   48   SWFShape  sh_red, sh_blu;
   49   SWFDisplayItem it_red, it_blu;
   50 
   51   const char *srcdir=".";
   52   if ( argc>1 ) 
   53     srcdir=argv[1];
   54   else
   55   {
   56       fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
   57       return 1;
   58   }
   59 
   60   Ming_init();
   61   mo = newSWFMovieWithVersion(OUTPUT_VERSION);
   62   SWFMovie_setDimension(mo, 800, 600);
   63   SWFMovie_setRate (mo, 1.0);
   64 
   65   dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
   66   SWFMovie_add(mo, (SWFBlock)dejagnuclip);
   67   add_actions(mo, " trace('as in frame0 of root');"); // can't use 'note' here, as it's not been defined yet
   68   SWFMovie_nextFrame(mo);  /* 1st frame */
   69 
   70   mc_blu = newSWFMovieClip();
   71   sh_blu = make_fill_square (20, 320, 20, 20, 0, 0, 255, 0, 0, 255);
   72   SWFMovieClip_add(mc_blu, (SWFBlock)sh_blu);  
   73   add_clip_actions(mc_blu, " onUnload = function () { "
   74           "_root.note('onUnload of mc_blu'); "
   75           "_root.mc_unload_executed++; "
   76           "_root.x3 = 'as_in_mc_blu_unload'; "
   77           "};");
   78   add_clip_actions(mc_blu, " _root.note('as in frame1 of mc_blu'); _root.x1 = \"as_in_mc_blu\"; ");
   79   SWFMovieClip_nextFrame(mc_blu); /* 1st frame */
   80   add_clip_actions(mc_blu, " _root.note('as in frame2 of mc_blu'); _root.x2 = \"as_in_mc_blu\"; stop(); ");
   81   SWFMovieClip_nextFrame(mc_blu); /* 2nd frame */
   82   
   83   mc_red = newSWFMovieClip();
   84   sh_red = make_fill_square (0, 300, 60, 60, 255, 0, 0, 255, 0, 0);
   85   SWFMovieClip_add(mc_red, (SWFBlock)sh_red);  
   86   /* Add mc_blu to mc_red and name it as "mc_blu" */
   87   it_blu = SWFMovieClip_add(mc_red, (SWFBlock)mc_blu);  
   88   SWFDisplayItem_setDepth(it_blu, 3); 
   89   SWFDisplayItem_setName(it_blu, "mc_blu");
   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'; _root.x3 = 'as_in_mc_red_frame2'; stop(); ");
   94   SWFDisplayItem_remove(it_blu);
   95   SWFMovieClip_nextFrame(mc_red); /* 2nd frame */
   96   
   97   /* Add mc_red to _root and name it as "mc_red" */
   98   it_red = SWFMovie_add(mo, (SWFBlock)mc_red);  
   99   SWFDisplayItem_setDepth(it_red, 3); 
  100   SWFDisplayItem_setName(it_red, "mc_red");
  101   
  102   add_actions(mo, " note('as in frame1 of root'); var x1 = \"as_in_root\"; ");
  103   /*
  104    * Check that the DisplayList is initialized deep to the mc_blue level
  105    * Even if their actions are not expected to be executed yet
  106    */
  107   check_equals(mo, "typeOf(_root.mc_red)", "'movieclip'");
  108   check_equals(mo, "typeOf(_root.mc_red.func)", "'undefined'");
  109   check_equals(mo, "typeOf(_root.mc_red.mc_blu)", "'movieclip'");
  110   SWFMovie_nextFrame(mo); /* 2nd frame */
  111   add_actions(mo, " note('as in frame2 of root'); _root.x2 = \"as_in_root\"; ");
  112   check_equals(mo, "typeOf(_root.mc_red.func)", "'function'");
  113   SWFMovie_nextFrame(mo); /* 3rd frame */
  114 
  115   /* In the frame placing mc_red,  actions in mc_red is executed *after* actions in _root */
  116   check_equals(mo, "_root.x1", "'as_in_mc_blu'");
  117   /* In subsequent frames, actions in mc_red is executed *before* actions in _root */
  118   check_equals(mo, "_root.x2", "'as_in_root'");
  119   check_equals(mo, "_root.x3", "'as_in_mc_blu_unload'");
  120   check_equals(mo, "_root.mc_unload_executed", "1");
  121   add_actions(mo, " _root.totals(); stop(); ");
  122   SWFMovie_nextFrame(mo); /* 4th frame */
  123 
  124   /* Output movie */
  125   puts("Saving " OUTPUT_FILENAME );
  126   SWFMovie_save(mo, OUTPUT_FILENAME);
  127 
  128   return 0;
  129 }
  130 
  131 
  132