"Fossies" - the Fresh Open Source Software Archive

Member "gnash-0.8.10/testsuite/misc-ming.all/action_order/ActionOrderTest4.c" (19 Jan 2012, 7511 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 #include <stdlib.h>
   20 #include <stdio.h>
   21 #include <ming.h>
   22 
   23 #include "ming_utils.h"
   24 
   25 #define OUTPUT_VERSION 8
   26 #define OUTPUT_FILENAME "ActionOrderTest4.swf"
   27 
   28 // A relatively simple looping test checking order of load and unload events.
   29 //
   30 // See InitActionsTest4 and InitActionsTest5 for similar tests. This test
   31 // has a static onLoad handler.
   32 
   33 int main(int argc, char* argv[])
   34 {
   35 
   36     SWFMovie mo;
   37     SWFMovieClip mc1, mc2, mc3, mc4, dejagnuclip;
   38     SWFDisplayItem it;
   39     SWFAction ac;
   40     SWFInitAction initac;
   41 
   42     const char *srcdir=".";
   43     if (argc > 1) srcdir = argv[1];
   44     else {
   45         fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
   46         return 1;
   47     }
   48 
   49     Ming_init();
   50     mo = newSWFMovieWithVersion(OUTPUT_VERSION);
   51     SWFMovie_setDimension(mo, 800, 600);
   52     SWFMovie_setRate (mo, 12.0);
   53 
   54     add_actions(mo,
   55             "if (!_global.hasOwnProperty('arr')) { _global.arr = []; };"
   56             "_global.ch = function(a, b) {"
   57             "   trace(a);"
   58             "   if (typeof(b)=='undefined' || (typeof(b)=='boolean' && b)) {"
   59             "       _global.arr.push(a);"
   60             "   };"
   61             "};"
   62             "this.onEnterFrame = function() { "
   63             "   _global.ch('onEnterFrame', false);"
   64             "};"
   65             );
   66 
   67     SWFMovie_nextFrame(mo);
   68 
   69     //  MovieClip 1 
   70     mc1 = newSWFMovieClip(); // 1 frames 
   71 
   72     // SWF_EXPORTASSETS 
   73     SWFMovie_addExport(mo, (SWFBlock)mc1, "Segments_Name");
   74     SWFMovie_writeExports(mo);
   75 
   76     //  MovieClip mc3 has two frames. In each frame a different MovieClip
   77     //  is placed with the name Segments.
   78     mc3 = newSWFMovieClip(); // 2 frames 
   79 
   80     //  MovieClip 2 
   81     mc2 = newSWFMovieClip(); // 1 frames 
   82 
   83     // Add mc2
   84     it = SWFMovieClip_add(mc3, (SWFBlock)mc2);
   85     SWFDisplayItem_setDepth(it, 1);
   86     SWFDisplayItem_setName(it, "Segments");
   87     // Set static load handler
   88     SWFDisplayItem_addAction(it,
   89         newSWFAction("_global.ch('static load: ' + this.c);"),
   90         SWFACTION_ONLOAD);
   91 
   92     // Frame 2
   93     SWFMovieClip_nextFrame(mc3);
   94 
   95     // Remove mc2
   96     SWFDisplayItem_remove(it);
   97 
   98     // Add mc1
   99     it = SWFMovieClip_add(mc3, (SWFBlock)mc1);
  100     SWFDisplayItem_setDepth(it, 1);
  101     SWFDisplayItem_setName(it, "Segments");
  102     // Set static load handler
  103     SWFDisplayItem_addAction(it,
  104         newSWFAction("_global.ch('static load: ' + this.c);"),
  105         SWFACTION_ONLOAD);
  106 
  107     SWFMovieClip_nextFrame(mc3);
  108 
  109     // End mc3
  110 
  111 
  112     // This is frame 1 of the main timeline
  113 
  114     // Put our sprite mc3 on stage.
  115     it = SWFMovie_add(mo, (SWFBlock)mc3);
  116     SWFDisplayItem_setDepth(it, 1);
  117     SWFDisplayItem_setName(it, "mc");
  118 
  119     //  mc4 is just for executing init actions.
  120     mc4 = newSWFMovieClip(); 
  121     SWFMovie_addExport(mo, (SWFBlock)mc4, "__Packages.Bug");
  122     SWFMovie_writeExports(mo);
  123     
  124     dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10,
  125                 0, 0, 800, 600);
  126     SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  127 
  128     ac = newSWFAction(
  129         "_global.loops = 0;"
  130         "_global.c = 0;"
  131         "if( !_global.Bug ) {"
  132         "   _global.Bug = function () {"
  133         "       this.onUnload = function() { "
  134         "           _global.ch('dynamic unload: ' + this.c);"
  135         "       }; "
  136         "       this.onLoad = function() { "
  137         "           _global.ch('dynamic load: ' + this.c);"
  138         "       }; "
  139         "       this.c = _global.c;"
  140         "       _global.ch('ctor: ' + _global.c);"
  141         "       _global.c++;"
  142         "   };"
  143         "};"
  144     );
  145 
  146     initac = newSWFInitAction_withId(ac, 4);
  147     SWFMovie_add(mo, (SWFBlock)initac);
  148     
  149     ac = newSWFAction("Object.registerClass('Segments_Name',Bug);");
  150     initac = newSWFInitAction_withId(ac, 1);
  151     SWFMovie_add(mo, (SWFBlock)initac);
  152     add_actions(mo, "_global.ch('Frame ' + "
  153                             "_level0._currentframe + ' actions: ' "
  154                             "+ _level0.mc.Segments.c);");
  155 
  156     // Frame 2 of the main timeline
  157     SWFMovie_nextFrame(mo);
  158     add_actions(mo, "_global.ch('Frame ' + "
  159                             "_level0._currentframe + ' actions: ' "
  160                             "+ _level0.mc.Segments.c);");
  161     
  162     add_actions(mo,
  163         "    if (_global.loops < 5) {"
  164         "        _global.loops++;"
  165         "        gotoAndPlay(2);"
  166         "   }"
  167         "   else {"
  168         "      delete this.onEnterFrame;"
  169         "      gotoAndPlay(4);"
  170         "   };"
  171         );
  172     
  173     SWFMovie_nextFrame(mo);
  174     
  175     check_equals(mo, "_global.arr.length", "24");
  176     check_equals(mo, "_global.arr[0]", "'Frame 2 actions: undefined'");
  177     check_equals(mo, "_global.arr[1]", "'static load: undefined'");
  178     check_equals(mo, "_global.arr[2]", "'ctor: 0'");
  179     check_equals(mo, "_global.arr[3]", "'static load: 0'");
  180     check_equals(mo, "_global.arr[4]", "'dynamic load: 0'");
  181     check_equals(mo, "_global.arr[5]", "'Frame 3 actions: 0'");
  182     check_equals(mo, "_global.arr[6]", "'Frame 2 actions: 0'");
  183     check_equals(mo, "_global.arr[7]", "'Frame 3 actions: 0'");
  184     check_equals(mo, "_global.arr[8]", "'Frame 2 actions: 0'");
  185     check_equals(mo, "_global.arr[9]", "'ctor: 1'");
  186     check_equals(mo, "_global.arr[10]", "'dynamic unload: 0'");
  187     check_equals(mo, "_global.arr[11]", "'static load: 1'");
  188     check_equals(mo, "_global.arr[12]", "'dynamic load: 1'");
  189     check_equals(mo, "_global.arr[13]", "'Frame 3 actions: 0'");
  190     check_equals(mo, "_global.arr[14]", "'Frame 2 actions: 0'");
  191     check_equals(mo, "_global.arr[15]", "'Frame 3 actions: 1'");
  192     check_equals(mo, "_global.arr[16]", "'Frame 2 actions: 1'");
  193     check_equals(mo, "_global.arr[17]", "'ctor: 2'");
  194     check_equals(mo, "_global.arr[18]", "'dynamic unload: 1'");
  195     check_equals(mo, "_global.arr[19]", "'static load: 2'");
  196     check_equals(mo, "_global.arr[20]", "'dynamic load: 2'");
  197     check_equals(mo, "_global.arr[21]", "'Frame 3 actions: 1'");
  198     check_equals(mo, "_global.arr[22]", "'Frame 2 actions: 1'");
  199     check_equals(mo, "_global.arr[23]", "'Frame 3 actions: 2'");
  200     check_equals(mo, "_global.arr.toString()", "'Frame 2 actions: undefined,static load: undefined,ctor: 0,static load: 0,dynamic load: 0,Frame 3 actions: 0,Frame 2 actions: 0,Frame 3 actions: 0,Frame 2 actions: 0,ctor: 1,dynamic unload: 0,static load: 1,dynamic load: 1,Frame 3 actions: 0,Frame 2 actions: 0,Frame 3 actions: 1,Frame 2 actions: 1,ctor: 2,dynamic unload: 1,static load: 2,dynamic load: 2,Frame 3 actions: 1,Frame 2 actions: 1,Frame 3 actions: 2'");
  201 
  202     SWFMovie_nextFrame(mo);
  203     add_actions(mo, "totals(26); stop();");
  204     
  205     SWFMovie_nextFrame(mo);
  206 
  207     // SWF_END 
  208     SWFMovie_save(mo, OUTPUT_FILENAME);
  209 
  210     return 0;
  211 }
  212