Add automated tests on function-type FSCommand parameter passing.
[gnash.git] / testsuite / misc-ming.all / duplicate_movie_clip_test.c
blobdb619ab57460bcde3cbf2dc82b3c0a5c92416553
1 /*
2 * Copyright (C) 2005, 2006, 2007, 2009, 2010, 2011, 2017 Free Software
3 * 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
18 */
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <ming.h>
25 #include "ming_utils.h"
27 #define OUTPUT_VERSION 6
28 #define OUTPUT_FILENAME "duplicate_movie_clip_test.swf"
31 int
32 main(int argc, char** argv)
34 SWFMovie mo;
35 SWFMovieClip mc1, mc2, dejagnuclip;
36 SWFDisplayItem it1, it2;
37 SWFShape sh_red;
39 /* For the button duplication test */
40 #if MING_VERSION_CODE >= 40400
41 SWFButton but;
42 SWFButtonRecord br;
43 #endif
45 const char *srcdir=".";
46 if ( argc>1 )
47 srcdir=argv[1];
48 else
50 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
51 return 1;
54 Ming_init();
55 mo = newSWFMovieWithVersion(OUTPUT_VERSION);
56 SWFMovie_setDimension(mo, 800, 600);
57 SWFMovie_setRate (mo, 12.0);
59 dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
60 SWFMovie_add(mo, (SWFBlock)dejagnuclip);
61 add_actions(mo, "x1=0; x2=0; x3=0;");
62 SWFMovie_nextFrame(mo); /* 1st frame */
65 mc1 = newSWFMovieClip();
66 sh_red = make_fill_square (100, 300, 60, 60, 255, 0, 0, 255, 0, 0);
67 SWFMovieClip_add(mc1, (SWFBlock)sh_red);
68 add_clip_actions(mc1, "stop();");
69 SWFMovieClip_nextFrame(mc1);
71 mc2 = newSWFMovieClip();
72 sh_red = make_fill_square (100, 200, 60, 60, 255, 0, 0, 255, 0, 0);
73 SWFMovieClip_add(mc2, (SWFBlock)sh_red);
74 add_clip_actions(mc2, "stop();");
75 SWFMovieClip_nextFrame(mc2);
77 it1 = SWFMovie_add(mo, (SWFBlock)mc1);
78 SWFDisplayItem_setDepth(it1, 10);
79 SWFDisplayItem_setName(it1, "mc1");
81 it2 = SWFMovie_add(mo, (SWFBlock)mc2);
82 SWFDisplayItem_setDepth(it2, 20);
83 SWFDisplayItem_setName(it2, "mc2");
84 SWFDisplayItem_addAction(it2,
85 compileSWFActionCode(" _root.note('onClipLoad triggered'); "
86 " _root.x1 = _root.x1 + 1; "),
87 SWFACTION_ONLOAD);
88 SWFDisplayItem_addAction(it2,
89 compileSWFActionCode(" _root.note('onClipEnterFrame triggered'); "
90 " _root.x2 = _root.x2 + 1; "),
91 SWFACTION_ENTERFRAME);
92 SWFDisplayItem_addAction(it2,
93 compileSWFActionCode(" _root.note('onClipUnload triggered'); "
94 " _root.x3 = _root.x3 + 1; "),
95 SWFACTION_UNLOAD);
97 add_actions(mo, " mc1.onLoad = function () {}; "
98 " mc1.prop1 = 10; "
99 " duplicateMovieClip('mc1', 'dup1', 1); "
100 " mc2.onLoad = function () {}; "
101 " duplicateMovieClip('mc2', 'dup2', 2); " );
102 SWFMovie_nextFrame(mo); /* 2nd frame */
105 check_equals(mo, "mc1.prop1", "10");
106 check_equals(mo, "typeof(mc1.onLoad)", "'function'");
107 check_equals(mo, "mc1.getDepth()", "-16374");
108 /* user defined property will not be duplicated */
109 check_equals(mo, "dup1.prop1", "undefined");
110 /* user defined event handler will not be duplicated */
111 check_equals(mo, "typeof(dup1.onLoad)", "'undefined'");
112 check_equals(mo, "dup1.getDepth()", "1");
113 /* check user defined onLoad */
114 check_equals(mo, "typeof(mc2.onLoad)", "'function'");
115 /* onClipEvent does not define a function */
116 check_equals(mo, "typeof(mc2.onEnterFrame)", "'undefined'");
117 /* user defined event handler will not be duplicated */
118 check_equals(mo, "typeof(dup2.onLoad)", "'undefined'");
119 check_equals(mo, "_root.x1", "2");
120 check_equals(mo, "_root.x2", "2");
121 SWFMovie_nextFrame(mo); /* 3rd frame */
123 SWFDisplayItem_remove(it1);
124 SWFDisplayItem_remove(it2);
125 add_actions(mo, " dup2.removeMovieClip(); ");
127 SWFMovie_nextFrame(mo); /* 4th frame */
129 #if MING_VERSION_CODE >= 40400
131 /* Create a button, add it to mc1 */
132 but = newSWFButton();
133 br = SWFButton_addCharacter(but, (SWFCharacter)sh_red, SWFBUTTON_UP);
134 SWFButtonRecord_setDepth(br, 10);
135 it1 = SWFMovie_add(mo, (SWFBlock)but);
136 SWFDisplayItem_setName(it1, "button");
138 /* Sanity check */
139 check_equals(mo, "typeof(button)", "'object'");
141 add_actions(mo,
142 "trace(button);"
143 "dupl = MovieClip.prototype.duplicateMovieClip;"
144 "button.dupl = dupl;"
145 "o = { x: 4 };"
146 "d = button.dupl('buttdup', 201, o);"
149 xcheck_equals(mo, "typeof(d)", "'object'");
150 xcheck_equals(mo, "'' + _root.buttdup", "'_level0.buttdup'");
151 check_equals(mo, "_root.buttdup", "d");
153 /* initobj not used */
154 check_equals(mo, "_root.buttdup.x", "undefined");
155 #endif
157 add_actions(mo,
158 "t = new Object();"
159 "t.dupl = dupl;"
160 "o2 = { x: 44 };"
161 "d2 = t.dupl('objdup', 202, o2);"
162 "trace(_root.objdup);"
165 /* Does not work on plain objects */
166 check_equals(mo, "typeof(d2)", "'undefined'");
167 check_equals(mo, "typeof(_root.objdup)", "'undefined'");
169 SWFMovie_nextFrame(mo); /* 5th frame */
171 check_equals(mo, "_root.x1", "2");
172 check_equals(mo, "_root.x2", "3");
173 check_equals(mo, "_root.x3", "2");
174 add_actions(mo, " _root.totals(); stop(); ");
175 SWFMovie_nextFrame(mo); /* 5th frame */
176 //Output movie
177 puts("Saving " OUTPUT_FILENAME );
178 SWFMovie_save(mo, OUTPUT_FILENAME);
180 return 0;