Some more tests (minor)
[gnash.git] / testsuite / misc-swfc.all / registerclass_test3.sc
blob8536c556bd0f26c212a7dcf7c95d52039f15c6f5
1 /*
2  *   Copyright (C) 2007, 2009, 2010 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  */ 
20  * Zou Lunkai, zoulunkai@gmail.com
21  * 
22  * Test registerClass
23  *
24  * Description:
25  *   frame1: tests simulate the layout of youtube player2.swf
26  *   frame2: export libItem1, export libItem2
27  *   frame3: DoInitAction(libItem1), DoInitAction(libItem2), PlaceObject(libItem2)
28  *           "Object.registerClass('libItem1', theClass1)" is called in DoInitAction(libItem1)
29  *           "Object.registerClass('libItem2', theClass2)" is called in DoInitAction(libItem2)
30  * Observed:
31  *   the effect of "Object.registerClass('libItem2', theClass2)" is not visible
32  *   in DoInitAction(libItem2). Note: there's no attachMovie for libItem2 in DoInitAction(libItem2)
33  */
35 // use swf6 for case sensitiviness
36 .flash  bbox=800x600 filename="registerclass_test3.sc" background=white version=6 fps=12
38 .frame 1
39   .box b1 fill=green width=100 height=100
40   
41   .sprite xxx
42   .end
43   
44   .initaction xxx:
45     // make sure Dejagnu is available in the first frame
46     #include "Dejagnu.sc"
47   .end
48   
49   // Define fullDisplay and export it
50   .sprite fullDisplay
51   .end
52   
53   .action:  
54     note("root DoAction of frame1");
55     check_equals(typeof(player.movie), 'movieclip');
56     check_equals(player.movie.__proto__, logic_Movie.prototype);
57     player.movie.setMovie();
58     check_equals(_root.testvar, 100);
59   .end
60   
61   .sprite id141
62     // Place a child sprite name it as 'movie'
63     .put movie=fullDisplay
64   .end
66   .initaction id141:
67     note("root first InitAction of frame1 (where we check if object placed after is visible)");
68     check_equals(typeof(player.movie), 'movieclip');
69     check_equals(player.movie.__proto__, MovieClip.prototype);
70   .end
71   
72   // Place sprite id141 and name it as 'player'
73   .put player=id141
74   
75   // Define _Packages.logic.Movie and export it
76   .sprite _Packages.logic.Movie
77   .end
78   
79   // Define class logic_Movie
80   .initaction _Packages.logic.Movie:
81     note("root second InitAction of frame1 (where the class is defined)");
82     check_equals(typeof(player.movie), 'movieclip');
83     check_equals(player.movie.__proto__, MovieClip.prototype);
84     logic_Movie = function() {};
85     logic_Movie.prototype = new MovieClip();
86     logic_Movie.prototype.setMovie = function () { _root.testvar = 100; };
87   .end
88   
89   // register sprite player.movie to class logic_Movie
90   .initaction fullDisplay:
91     note("root third InitAction of frame1 (where registerClass is invoked)");
92     Object.registerClass("fullDisplay", logic_Movie);
93   .end
96 .frame 2
97   .sprite child1
98     .put b1  x=100 y=100
99   .end
100   
101   .sprite child2
102     .put b1  x=100 y=200
103   .end
104   
105   .sprite libItem1 // Define a sprite libItem1
106       .put child1
107   .end 
108   .sprite libItem2 // Define a sprite libItem2
109       .put child2
110   .end 
111   
113 .frame 3
115   .action:
116      // registerClass effects are visible here
117      check_equals(libItem2.__proto__, theClass2.prototype);
118   .end
119     
120   .initaction libItem1:
121      theClass1 = function() { this.testvar = 60;};
122      theClass1.prototype = new MovieClip();
123      Object.registerClass('libItem1', theClass1);
124      
125      _root.attachMovie('libItem1', 'clip1', 10);
126      check_equals(typeof(clip1), 'movieclip');
127      check_equals(clip1.__proto__, theClass1.prototype);
128      
129      clip1.duplicateMovieClip("dup1", 10);
130      check_equals(typeof(dup1), 'movieclip');
131      check_equals(dup1.__proto__, theClass1.prototype);
132      check_equals(dup1.testvar, 60);
133      
134      // sprite libItem1 never placed.
135      check_equals(typeof(libItem1), 'undefined');
136   .end
137   .initaction  libItem2:
138      theClass2 = function() { this.testvar = 60;};
139      theClass2.prototype = new MovieClip();
140      Object.registerClass('libItem2', theClass2);
141      
142      // Gnash failed by executing init actions before DLIST tags.
143      check_equals(typeof(libItem2), 'movieclip');
144      check_equals(libItem2.__proto__, MovieClip.prototype);
145      check_equals(libItem2.__proto__, MovieClip.prototype);
147      // Childs of libItem2 have also been placed already
148      // Gnash fails by executing init actions before frame0 tags
149      check_equals(typeof(libItem2.child2), 'movieclip');
150   .end
151   
152   .put libItem2
154 .frame 4
155   .action:
156      check_equals(libItem2.__proto__, theClass2.prototype);
157   .end
158    
159 .frame 5
160   .action:
161     totals(19);
162     stop();
163   .end
165   
166 .end // end of the file