Add automated tests on function-type FSCommand parameter passing.
[gnash.git] / testsuite / misc-ming.all / new_child_in_unload_test.c
blobd8e87869d4abf04255a0fa45e806797e7be29207
1 /*
2 * Copyright (C) 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
17 */
20 *---case1---
22 * Description:
23 * (1) step1: create a dynamic child in an onClipUnload handler of static_mc1;
24 * (2) step2: define a onUnload handler for the child;
25 * (3) step3: remove static_mc1;
27 * Observed:
28 * after step3:
29 * (1) onClipUnload for static_mc1 is triggered.
30 * (2) user defined onUnload for the dynamic child is NOT triggered.
31 * (3) the dynamic child is destroyed even without onUnload triggered.
33 *---case2---
34 * (1) step1: create a dynamic child in an onClipLoad handler of static_mc2;
35 * (2) step2: define a onUnload handler for the child;
36 * (3) step3: remove static_mc2;
38 * Observed:
39 * after step3:
40 * (1)onClipUnload for static_mc2 is triggered.
41 * (2)user defined onUnload for the dynamic child is triggered.
43 * TODO:
44 * seems createEmptyMovieClip() does not work in an user defined onUnload handler,
45 * not sure why, need more inspect later.
48 #include <stdlib.h>
49 #include <stdio.h>
50 #include <ming.h>
52 #include "ming_utils.h"
54 #define OUTPUT_VERSION 6
55 #define OUTPUT_FILENAME "new_child_in_unload_test.swf"
59 int
60 main(int argc, char** argv)
62 SWFMovie mo;
63 SWFMovieClip mc1, mc2, dejagnuclip;
64 SWFDisplayItem it1, it2;
66 const char *srcdir=".";
67 if ( argc>1 )
68 srcdir=argv[1];
69 else
71 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
72 return 1;
75 Ming_init();
76 mo = newSWFMovieWithVersion(OUTPUT_VERSION);
77 SWFMovie_setDimension(mo, 800, 600);
78 SWFMovie_setRate (mo, 12.0);
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, "testvar1 = 0; testvar2 = 0;");
83 SWFMovie_nextFrame(mo); // frame1
86 mc1 = newSWFMovieClip();
87 SWFMovieClip_nextFrame(mc1);
88 it1 = SWFMovie_add(mo, (SWFBlock)mc1);
89 SWFDisplayItem_setName(it1, "static_mc1");
90 SWFDisplayItem_addAction(it1,
91 newSWFAction(
92 " this.createEmptyMovieClip('dyn1', 100); "
93 " _root.check_equals(dyn1.getDepth(), 100);"
94 " _root.dyn1Ref = dyn1;"
95 // shouldn't be executed.
96 " dyn1.onUnload = function () { _root.check(false); } ;"
97 "trace(this);"
99 SWFACTION_UNLOAD);
101 mc2 = newSWFMovieClip();
102 SWFMovieClip_nextFrame(mc2);
103 it2 = SWFMovie_add(mo, (SWFBlock)mc2);
104 SWFDisplayItem_setName(it2, "static_mc2");
105 SWFDisplayItem_addAction(it2,
106 newSWFAction(
107 " this.createEmptyMovieClip('dyn2', 200); "
108 " _root.check_equals(dyn2.getDepth(), 200);"
109 " dyn2.onUnload = function () {_root.dyn2testvar = 'executed'; } ;"
111 SWFACTION_ONLOAD);
112 SWFDisplayItem_addAction(it2,
113 newSWFAction(
114 " _root.check_equals(_level0.dyn1Ref.getDepth(), 100);"
115 " _level0.dyn1Ref.swapDepths(101); "
116 // Check that we can still swap the new child created in onClipUnload(mc1)
117 // Note mc1 is already unloaded(this is in mc2.unload).
118 " _root.check_equals(_level0.dyn1Ref.getDepth(), 101);"
120 SWFACTION_UNLOAD);
121 SWFMovie_nextFrame(mo); // frame2
123 SWFDisplayItem_remove(it1);
124 SWFDisplayItem_remove(it2);
125 SWFMovie_nextFrame(mo); // frame3
127 check_equals(mo, "typeof(_root.dyn1Ref)", "'movieclip'");
128 check_equals(mo, "_root.dyn1Ref.valueof()", "null");
129 // check that dyn2.onUnload was triggered
130 check_equals(mo, "_root.dyn2testvar", "'executed'");
131 SWFMovie_nextFrame(mo); // frame4
133 add_actions(mo, " _root.totals(7); stop(); ");
134 SWFMovie_nextFrame(mo); // frame5
136 //Output movie
137 puts("Saving " OUTPUT_FILENAME );
138 SWFMovie_save(mo, OUTPUT_FILENAME);
140 return 0;