update copyright date
[gnash.git] / testsuite / misc-ming.all / duplicate_movie_clip_test.c
blobaaedc7413fc68f13203b34d59ccb47ecafd8b832
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
17 */
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <ming.h>
24 #include "ming_utils.h"
26 #define OUTPUT_VERSION 6
27 #define OUTPUT_FILENAME "duplicate_movie_clip_test.swf"
30 int
31 main(int argc, char** argv)
33 SWFMovie mo;
34 SWFMovieClip mc1, mc2, dejagnuclip;
35 SWFDisplayItem it1, it2;
36 SWFShape sh_red;
38 /* For the button duplication test */
39 #if MING_VERSION_CODE >= 00040400
40 SWFButton but;
41 SWFButtonRecord br;
42 #endif
44 const char *srcdir=".";
45 if ( argc>1 )
46 srcdir=argv[1];
47 else
49 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
50 return 1;
53 Ming_init();
54 mo = newSWFMovieWithVersion(OUTPUT_VERSION);
55 SWFMovie_setDimension(mo, 800, 600);
56 SWFMovie_setRate (mo, 12.0);
58 dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
59 SWFMovie_add(mo, (SWFBlock)dejagnuclip);
60 add_actions(mo, "x1=0; x2=0; x3=0;");
61 SWFMovie_nextFrame(mo); /* 1st frame */
64 mc1 = newSWFMovieClip();
65 sh_red = make_fill_square (100, 300, 60, 60, 255, 0, 0, 255, 0, 0);
66 SWFMovieClip_add(mc1, (SWFBlock)sh_red);
67 add_clip_actions(mc1, "stop();");
68 SWFMovieClip_nextFrame(mc1);
70 mc2 = newSWFMovieClip();
71 sh_red = make_fill_square (100, 200, 60, 60, 255, 0, 0, 255, 0, 0);
72 SWFMovieClip_add(mc2, (SWFBlock)sh_red);
73 add_clip_actions(mc2, "stop();");
74 SWFMovieClip_nextFrame(mc2);
76 it1 = SWFMovie_add(mo, (SWFBlock)mc1);
77 SWFDisplayItem_setDepth(it1, 10);
78 SWFDisplayItem_setName(it1, "mc1");
80 it2 = SWFMovie_add(mo, (SWFBlock)mc2);
81 SWFDisplayItem_setDepth(it2, 20);
82 SWFDisplayItem_setName(it2, "mc2");
83 SWFDisplayItem_addAction(it2,
84 compileSWFActionCode(" _root.note('onClipLoad triggered'); "
85 " _root.x1 = _root.x1 + 1; "),
86 SWFACTION_ONLOAD);
87 SWFDisplayItem_addAction(it2,
88 compileSWFActionCode(" _root.note('onClipEnterFrame triggered'); "
89 " _root.x2 = _root.x2 + 1; "),
90 SWFACTION_ENTERFRAME);
91 SWFDisplayItem_addAction(it2,
92 compileSWFActionCode(" _root.note('onClipUnload triggered'); "
93 " _root.x3 = _root.x3 + 1; "),
94 SWFACTION_UNLOAD);
96 add_actions(mo, " mc1.onLoad = function () {}; "
97 " mc1.prop1 = 10; "
98 " duplicateMovieClip('mc1', 'dup1', 1); "
99 " mc2.onLoad = function () {}; "
100 " duplicateMovieClip('mc2', 'dup2', 2); " );
101 SWFMovie_nextFrame(mo); /* 2nd frame */
104 check_equals(mo, "mc1.prop1", "10");
105 check_equals(mo, "typeof(mc1.onLoad)", "'function'");
106 check_equals(mo, "mc1.getDepth()", "-16374");
107 /* user defined property will not be duplicated */
108 check_equals(mo, "dup1.prop1", "undefined");
109 /* user defined event handler will not be duplicated */
110 check_equals(mo, "typeof(dup1.onLoad)", "'undefined'");
111 check_equals(mo, "dup1.getDepth()", "1");
112 /* check user defined onLoad */
113 check_equals(mo, "typeof(mc2.onLoad)", "'function'");
114 /* onClipEvent does not define a function */
115 check_equals(mo, "typeof(mc2.onEnterFrame)", "'undefined'");
116 /* user defined event handler will not be duplicated */
117 check_equals(mo, "typeof(dup2.onLoad)", "'undefined'");
118 check_equals(mo, "_root.x1", "2");
119 check_equals(mo, "_root.x2", "2");
120 SWFMovie_nextFrame(mo); /* 3rd frame */
122 SWFDisplayItem_remove(it1);
123 SWFDisplayItem_remove(it2);
124 add_actions(mo, " dup2.removeMovieClip(); ");
126 SWFMovie_nextFrame(mo); /* 4th frame */
128 #if MING_VERSION_CODE >= 00040400
130 /* Create a button, add it to mc1 */
131 but = newSWFButton();
132 br = SWFButton_addCharacter(but, (SWFCharacter)sh_red, SWFBUTTON_UP);
133 SWFButtonRecord_setDepth(br, 10);
134 it1 = SWFMovie_add(mo, (SWFBlock)but);
135 SWFDisplayItem_setName(it1, "button");
137 /* Sanity check */
138 check_equals(mo, "typeof(button)", "'object'");
140 add_actions(mo,
141 "trace(button);"
142 "dupl = MovieClip.prototype.duplicateMovieClip;"
143 "button.dupl = dupl;"
144 "o = { x: 4 };"
145 "d = button.dupl('buttdup', 201, o);"
148 xcheck_equals(mo, "typeof(d)", "'object'");
149 xcheck_equals(mo, "'' + _root.buttdup", "'_level0.buttdup'");
150 check_equals(mo, "_root.buttdup", "d");
152 /* initobj not used */
153 check_equals(mo, "_root.buttdup.x", "undefined");
154 #endif
156 add_actions(mo,
157 "t = new Object();"
158 "t.dupl = dupl;"
159 "o2 = { x: 44 };"
160 "d2 = t.dupl('objdup', 202, o2);"
161 "trace(_root.objdup);"
164 /* Does not work on plain objects */
165 check_equals(mo, "typeof(d2)", "'undefined'");
166 check_equals(mo, "typeof(_root.objdup)", "'undefined'");
168 SWFMovie_nextFrame(mo); /* 5th frame */
170 check_equals(mo, "_root.x1", "2");
171 check_equals(mo, "_root.x2", "3");
172 check_equals(mo, "_root.x3", "2");
173 add_actions(mo, " _root.totals(); stop(); ");
174 SWFMovie_nextFrame(mo); /* 5th frame */
175 //Output movie
176 puts("Saving " OUTPUT_FILENAME );
177 SWFMovie_save(mo, OUTPUT_FILENAME);
179 return 0;