"Fossies" - the Fresh Open Source Software Archive

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