Update with current status
[gnash.git] / testsuite / misc-ming.all / unload_movieclip_test1.c
blobc6f16302c6b5985015e66a2013bf77d1c6e3f2c4
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
17 */
20 * zou lunkai zoulunkai@gmail.com
22 * Test "this" context in the UNLOAD event handler.
24 * run as ./unload_movieclip_test1
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <ming.h>
32 #include "ming_utils.h"
34 #define OUTPUT_VERSION 6
35 #define OUTPUT_FILENAME "unload_movieclip_test1.swf"
37 SWFDisplayItem add_static_mc(SWFMovie mo, const char* name, int depth);
39 SWFDisplayItem
40 add_static_mc(SWFMovie mo, const char* name, int depth)
42 SWFMovieClip mc;
43 SWFDisplayItem it;
45 mc = newSWFMovieClip();
46 SWFMovieClip_nextFrame(mc);
48 it = SWFMovie_add(mo, (SWFBlock)mc);
49 SWFDisplayItem_setDepth(it, depth);
50 SWFDisplayItem_setName(it, name);
52 return it;
55 int
56 main(int argc, char** argv)
58 SWFMovie mo;
59 SWFMovieClip dejagnuclip;
60 SWFDisplayItem it;
62 const char *srcdir=".";
63 if ( argc>1 )
64 srcdir=argv[1];
65 else
67 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
68 return 1;
71 Ming_init();
72 Ming_useSWFVersion (OUTPUT_VERSION);
74 mo = newSWFMovie();
75 SWFMovie_setDimension(mo, 800, 600);
76 SWFMovie_setRate(mo, 2);
78 // Frame 1: Place dejagnu clip and init testing variables
80 dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
81 SWFMovie_add(mo, (SWFBlock)dejagnuclip);
82 add_actions(mo, "_root.x = 0;");
83 SWFMovie_nextFrame(mo);
85 // Frame 2: Place a static mc and define onUnload for it
87 it = add_static_mc(mo, "mc", 3);
88 add_actions(mo, "mc.onUnload = function () { "
89 " _root.x = this._currentframe; "
90 " _root.check_equals(typeof(this), 'movieclip'); "
91 " _root.check_equals(this, _root.mc); "
92 "};");
93 SWFMovie_nextFrame(mo);
95 // Frame 3: Remove the mc to trigger onUnload
97 SWFDisplayItem_remove(it);
98 SWFMovie_nextFrame(mo);
100 // Frame 4: checks
102 check_equals(mo, "_root.x", "1");
104 add_actions(mo, "_root.totals(); stop(); ");
105 SWFMovie_nextFrame(mo);
107 //Output movie
108 puts("Saving " OUTPUT_FILENAME );
109 SWFMovie_save(mo, OUTPUT_FILENAME);
111 return 0;