big merge from master, fix rpm creation, drop fetching swfdec
[gnash.git] / testsuite / misc-ming.all / eventSoundTest1-Runner.cpp
blob60faf8c8eb71e4ed02373bb9ba2839b0afd959b6
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 "eventSoundTest1.swf"
23 #include "MovieTester.h"
24 #include "MovieClip.h"
25 #include "DisplayObject.h"
26 #include "DisplayList.h"
27 #include "log.h"
28 #include "GnashException.h"
29 #include "VM.h"
31 #include "check.h"
33 #include <string>
34 #include <iostream>
35 #include <cassert>
36 #include <memory>
38 using namespace gnash;
39 using namespace std;
41 int
42 main(int /*argc*/, char** /*argv*/)
44 string filename = string(TGTDIR) + string("/") + string(INPUT_FILENAME);
45 auto_ptr<MovieTester> t;
47 try
49 t.reset(new MovieTester(filename));
51 catch (const GnashException& e)
53 std::cerr << "Error initializing MovieTester: " << e.what() << std::endl;
54 exit(EXIT_FAILURE);
57 MovieTester& tester = *t;
59 tester.advance();
61 MovieClip* root = tester.getRootMovie();
62 assert(root);
64 VM& vm = getVM(*getObject(root));
65 string_table& st = vm.getStringTable();
67 if ( ! tester.canTestSound() )
69 cout << "UNTESTED: sounds can't be tested with this build." << endl;
70 return EXIT_SUCCESS; // so testing doesn't abort
73 const int totalFrames = root->get_frame_count();
75 // Make sure you adjust this with the test!
76 cerr << "Total frames: " << totalFrames << endl;
77 assert (totalFrames == 23);
79 int numSoundsStarted[] = {
80 0,
81 4, // Multiple (+4 sounds started)
82 6, // NoMultiple (+2 sounds started)
83 9, // Trimmed (+3 sounds started)
84 14 // Attached (+5 sounds started)
87 /// Expected success for each test
88 bool testPasses[] = {
89 true,
90 true,
91 true,
92 true,
93 true
96 // Advance and check...
97 int frame = root->get_current_frame();
98 int test = 0;
99 while (frame <= totalFrames) {
100 as_value testReady;
101 if (getObject(root)->get_member(getURI(vm, "testReady"), &testReady))
103 getObject(root)->delProperty(getURI(vm, "testReady"));
105 // When a test is ready, check the result of the previous test.
106 if (testPasses[test]) {
107 check_equals(tester.soundsStarted(), numSoundsStarted[test]);
109 else {
110 xcheck_equals(tester.soundsStarted(), numSoundsStarted[test]);
113 check_equals(tester.soundsStopped(), tester.soundsStarted());
114 ++test;
115 tester.click();
118 tester.advance();
119 frame++;
122 if (testPasses[test]) {
123 check_equals(tester.soundsStarted(), numSoundsStarted[test]);
125 else {
126 xcheck_equals(tester.soundsStarted(), numSoundsStarted[test]);
129 // Consistency checking
130 as_value eot;
131 bool endOfTestFound = getObject(root)->get_member(getURI(vm, "endoftest"), &eot);
132 check(endOfTestFound);