update copyright date
[gnash.git] / testsuite / misc-ming.all / loading / loadMovieTestRunner.cpp
blobcfd92474d0757a4cef700c846102b80c655199ce
1 /*
2 * Copyright (C) 2007, 2008, 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.
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
19 */
21 #define INPUT_FILENAME "loadMovieTest.swf"
23 #include "MovieTester.h"
24 #include "MovieClip.h"
25 #include "DisplayObject.h"
26 #include "DisplayList.h"
27 #include "log.h"
28 #include "URL.h"
29 #include "VM.h"
30 #include "string_table.h"
32 #include "check.h"
33 #include <string>
34 #include <cassert>
35 #include "GnashSystemIOHeaders.h"
37 using namespace gnash;
38 using namespace std;
40 std::auto_ptr<MovieTester> tester;
41 MovieClip* root;
43 MovieClip*
44 getCoverArt()
46 DisplayObject* coverartch = const_cast<DisplayObject*>(tester->findDisplayItemByName(*root, "coverart"));
47 MovieClip* coverart = coverartch->to_movie();
49 //log_debug("Coverart is %p, displaylist is:", coverart);
50 //coverart->getDisplayList().dump();
52 return coverart;
55 void
56 checkScribbling()
58 MovieClip* coverart = getCoverArt();
60 size_t initial_child_count = coverart->getDisplayList().size();
62 tester->movePointerTo(73, 204); // the "Scribble" button
63 check(tester->isMouseOverMouseEntity());
64 for (int i=1; i<=5; ++i) {
65 tester->click();
66 check_equals(coverart->getDisplayList().size(), initial_child_count+i);
69 tester->movePointerTo(59, 225); // the "clear" button
70 check(tester->isMouseOverMouseEntity());
71 tester->click();
72 check_equals(coverart->getDisplayList().size(), initial_child_count);
75 int
76 main(int /*argc*/, char** /*argv*/)
78 gnash::LogFile& dbglogfile = gnash::LogFile::getDefaultInstance();
79 dbglogfile.setVerbosity(1);
81 string filename = string(TGTDIR) + string("/") + string(INPUT_FILENAME);
82 tester.reset(new MovieTester(filename));
84 URL baseURL(filename);
85 URL mediaURL(MEDIADIR"/");
86 URL lynchURL("lynch.swf", mediaURL);
87 URL greenURL("green.jpg", mediaURL);
88 URL offspringURL("offspring.swf", mediaURL);
89 std::string url;
91 gnash::RcInitFile& rc = gnash::RcInitFile::getDefaultInstance();
92 rc.addLocalSandboxPath(MEDIADIR);
96 root = tester->getRootMovie();
97 assert(root);
99 check_equals(root->get_frame_count(), 2);
100 check_equals(root->get_current_frame(), 0);
102 tester->advance();
103 check_equals(root->get_current_frame(), 1);
105 // Verify that 'coverart' exists and is empty
106 DisplayObject* coverartch = const_cast<DisplayObject*>(tester->findDisplayItemByName(*root, "coverart"));
107 MovieClip* coverart = coverartch->to_movie();
108 check(coverart);
109 url = coverart->get_root()->url();
110 check_equals(coverart->get_root()->url(), baseURL.str());
112 // Check scribbling on the empty canvas
113 checkScribbling();
115 // Click on the first (lynch)
116 tester->movePointerTo(80, 80);
117 check(tester->isMouseOverMouseEntity());
118 tester->pressMouseButton();
120 // Wait for the movie to load
121 // TODO: drop this test and use a self-containment instead
122 do {
123 usleep(500); // give it some time...
124 tester->advance(); // loads (should) happen on next advance
125 coverartch = const_cast<DisplayObject*>(tester->findDisplayItemByName(*root, "coverart"));
126 } while (coverartch->to_movie() == coverart);
128 coverart = coverartch->to_movie();
129 check_equals(coverart->get_root()->url(), lynchURL.str());
131 tester->depressMouseButton();
133 // Check scribbling on the lynch
134 checkScribbling();
136 // Run 'coverart' tests..
137 tester->movePointerTo(640,180);
138 tester->click(); tester->advance();
140 // Click on the second (green)
141 tester->movePointerTo(280, 80);
142 check(tester->isMouseOverMouseEntity());
143 tester->click();
145 // Wait for the movie to load
146 // TODO: drop this test and use a self-containment instead
147 do {
148 usleep(500); // give it some time...
149 tester->advance(); // loads (should) happen on next advance
150 coverartch = const_cast<DisplayObject*>(tester->findDisplayItemByName(*root, "coverart"));
151 } while (coverartch->to_movie() == coverart);
153 coverart = coverartch->to_movie();
154 check_equals(coverart->get_root()->url(), greenURL.str());
155 // TODO: find a way to test if the jpeg is really displayed
156 // (like turn it into a mouse-event-handling char and use isMouseOverActiveEntity ?)
158 // Check scribbling on the jpeg
159 checkScribbling();
161 // Run 'coverart' tests..
162 tester->movePointerTo(640,180);
163 tester->click(); tester->advance();
165 // Click on the third (offspring)
166 tester->movePointerTo(480, 80);
167 check(tester->isMouseOverMouseEntity());
168 tester->click();
170 // Wait for the movie to load
171 // TODO: drop this test and use a self-containment instead
172 do {
173 usleep(500); // give it some time...
174 tester->advance(); // loads (should) happen on next advance
175 coverartch = const_cast<DisplayObject*>(tester->findDisplayItemByName(*root, "coverart"));
176 } while (coverartch->to_movie() == coverart);
178 coverart = coverartch->to_movie();
179 check_equals(coverart->get_root()->url(), offspringURL.str());
181 // Check scribbling on the offspring
182 checkScribbling();
184 // Run 'coverart' tests..
185 tester->movePointerTo(640,180);
186 tester->click(); tester->advance();
188 // Get summary ...
189 tester->pressKey(key::SHIFT);
190 tester->click(); tester->advance();
191 tester->releaseKey(key::SHIFT);
193 // Consistency checking
194 VM& vm = getVM(*getObject(root));
195 as_value eot;
196 // It's an swf6, so lowercase 'END_OF_TEST'
197 bool endOfTestFound = getObject(root)->get_member(getURI(vm, "end_of_test"), &eot);
198 check(endOfTestFound);
199 if ( endOfTestFound )
201 check_equals(eot.to_bool(8), true);