Add automated tests on function-type FSCommand parameter passing.
[gnash.git] / testsuite / misc-ming.all / loop / loop_test-Runner.cpp
blob42f5d4ede1073240184167ad3ac8d0936b20270e
1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 * 2011 Free Software 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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
22 #define INPUT_FILENAME "loop_test.swf"
24 #include "MovieTester.h"
25 #include "MovieClip.h"
26 #include "DisplayObject.h"
27 #include "DisplayList.h"
28 #include "log.h"
29 #include "GnashException.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 TRYMAIN(_runtest);
42 int
43 trymain(int /*argc*/, char** /*argv*/)
45 string filename = string(TGTDIR) + string("/") + string(INPUT_FILENAME);
46 unique_ptr<MovieTester> t;
48 try
50 t.reset(new MovieTester(filename));
52 catch (const GnashException& e)
54 std::cerr << "Error initializing MovieTester: " << e.what() << std::endl;
55 exit(EXIT_FAILURE);
58 MovieTester& tester = *t;
60 // TODO: check why we need this !!
61 // I wouldn't want the first advance to be needed
62 //tester.advance();
64 gnash::LogFile& dbglogfile = gnash::LogFile::getDefaultInstance();
65 dbglogfile.setVerbosity(1);
66 //dbglogfile.setActionDump(1);
68 MovieClip* root = tester.getRootMovie();
69 assert(root);
71 size_t framecount = root->get_frame_count();
72 check_equals(framecount, 3);
73 check_equals(root->get_current_frame(), 0);
75 rgba black(0,0,0,255);
76 rgba red(255,0,0,255);
77 rgba white(255,255,255,255);
79 // Advance till the movie is stopped (or 10 loops are performed)
80 bool blackOverRed=false;
81 for (size_t i=0; i<=framecount*10; ++i)
83 check_equals(root->get_current_frame(), i%framecount);
85 // Out of any DisplayObject
86 check_pixel(317, 430, 2, white, 2);
88 // Fully on the red square: 317,330
89 check_pixel(317, 330, 2, red, 2);
91 // Fully on the black square: 400,330
92 check_pixel(400, 330, 2, black, 2);
94 // Intersection of the two squares: 343,330
95 // This is black or red depending on loop count
96 if ( blackOverRed )
98 check_pixel(343, 330, 2, black, 2);
100 else
102 check_pixel(343, 330, 2, red, 2);
105 tester.advance();
107 // Let's break if we stopped, as we'll print totals() thus
108 // enlarging invalidated bounds too ...
109 if (root->getPlayState() == MovieClip::PLAYSTATE_STOP) break;
111 // Compute 1-based currentFrame
112 size_t currentFrame = root->get_current_frame()+1;
114 if ( currentFrame == 3 ) // We swap depths here !
116 blackOverRed = !blackOverRed;
118 // Check the intersection of the two DisplayObjects to
119 // be invalidated
120 check( tester.getInvalidatedRanges().contains(343, 330) );
122 else if ( currentFrame == 1 ) // We restarted here !
124 assert(i > 1); // to ensure we looped back
126 // Not sure if invalidated ranges should be null here..
127 // visually, it seems so, but loop-back is too complex
128 // to be sure (ie: xtrace window text might be reset or something)
129 // I checked that it's not resetDisplayList invalidating it...
130 check( tester.getInvalidatedRanges().isNull() );
132 else // we did nothing here...
134 check( tester.getInvalidatedRanges().isNull() );
139 return 0;