• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

MovieTester.h

Go to the documentation of this file.
00001 /* 
00002  *   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
00003  * 
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 3 of the License, or
00007  * (at your option) any later version.
00008  * 
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017  *
00018  *
00019  */ 
00020 
00021 #ifndef GNASH_MOVIETESTER_H
00022 #define GNASH_MOVIETESTER_H
00023 
00024 #ifdef HAVE_CONFIG_H
00025 # include "gnashconfig.h" // For exp2 test
00026 #endif
00027 
00028 #include "Range2d.h"
00029 #include "GnashKey.h"
00030 #include "sound_handler.h" // for creating the "test" sound handlers
00031 #include "Renderer.h" // for dtor visibility by auto_ptr
00032 #include "Movie.h" 
00033 #include "ManualClock.h" // for composition
00034 #include "RunResources.h" // For initialization.
00035 #include "movie_root.h"
00036 
00037 #include <boost/intrusive_ptr.hpp>
00038 #include <vector>
00039 #include <memory> // for auto_ptr
00040 #include <string> 
00041 #include <boost/shared_ptr.hpp>
00042 #include <cmath>
00043 
00044 #define check_pixel(x, y, radius, color, tolerance) \
00045         {\
00046                 std::stringstream ss; \
00047                 ss << "[" << __FILE__ << ":" << __LINE__ << "]"; \
00048                 tester.checkPixel(x, y, radius, color, tolerance, ss.str(), false); \
00049         }
00050 
00051 #define xcheck_pixel(x, y, radius, color, tolerance) \
00052         {\
00053                 std::stringstream ss; \
00054                 ss << "[" << __FILE__ << ":" << __LINE__ << "]"; \
00055                 tester.checkPixel(x, y, radius, color, tolerance, ss.str(), true); \
00056         }
00057 
00058 // Forward declarations
00059 namespace gnash {
00060         class movie_definition;
00061         class movie_root;
00062         class MovieClip;
00063         class DisplayObject;
00064         class FuzzyPixel;
00065         class VirtualClock;
00066         class rgba;
00067 }
00068 
00069 namespace gnash {
00070 
00072 //
00074 class TestingRenderer
00075 {
00076 
00077 public:
00078 
00079         TestingRenderer(boost::shared_ptr<Renderer> renderer,
00080             const std::string& name)
00081                 :
00082                 _name(name),
00083                 _renderer(renderer)
00084         {}
00085 
00086         const std::string& getName() const { return _name; }
00087 
00089     boost::shared_ptr<Renderer> getRenderer() const { return _renderer; }
00090 
00091 private:
00092 
00093         std::string _name;
00094     boost::shared_ptr<Renderer> _renderer;
00095 };
00096 
00098 //
00105 class MovieTester
00106 {
00107 public:
00115         MovieTester(const std::string& filespec);
00116 
00118         //
00125         void advance(bool updateClock=true);
00126 
00128         void advanceClock(unsigned long ms);
00129 
00131         //
00135         void redraw();
00136 
00138         //
00141         geometry::SnappingRanges2d<int> getInvalidatedRanges() const;
00142 
00144         //
00148         const DisplayObject* findDisplayItemByName(const MovieClip& mc,
00149                         const std::string& name);
00150 
00152         //
00156         const DisplayObject* findDisplayItemByDepth(const MovieClip& mc,
00157                         int depth);
00158 
00160     //
00162         gnash::MovieClip* getRootMovie() {
00163                 return const_cast<Movie*>(&_movie_root->getRootMovie());
00164         }
00165 
00167         //
00170         void movePointerTo(int x, int y);
00171 
00173         //
00207         void checkPixel(int x, int y, unsigned radius, const rgba& color,
00208                         short unsigned tolerance, const std::string& label, bool expectFailure=false) const;
00209 
00211         void pressMouseButton();
00212 
00214         void depressMouseButton();
00215 
00217         void click();
00218 
00220     //
00223     void scrollMouse(int delta);
00224 
00226         //
00229         void pressKey(key::code k);
00230 
00232         //
00235         void releaseKey(key::code k);
00236 
00240         bool isMouseOverMouseEntity();
00241 
00245         //
00246         int soundsStopped();
00247 
00251         //
00252         int soundsStarted();
00253 
00255         //
00258         bool canTestSound() const { return _sound_handler.get() != NULL; }
00259 
00261         //
00266         bool canTestRendering() const { return ! _testingRenderers.empty(); }
00267 
00269         bool canTestVideo() const;
00270 
00272         //
00277         void restart();
00278 
00280     //
00283     void resizeStage(int x, int y) ; 
00284 
00285 private:
00286 
00288         void initTestingRenderers();
00289 
00291         //
00296         void initTestingSoundHandlers();
00297 
00299         //
00304         void initTestingMediaHandlers();
00305 
00307         //
00310         void render();
00311 
00313         //
00321         void render(boost::shared_ptr<Renderer> renderer,
00322             InvalidatedRanges& invalidated);
00323 
00325     //viewport size
00326         void addTestingRenderer(boost::shared_ptr<Renderer> h,
00327             const std::string& name);
00328 
00329         gnash::movie_root* _movie_root;
00330 
00331         boost::intrusive_ptr<gnash::movie_definition> _movie_def;
00332 
00333     boost::shared_ptr<sound::sound_handler> _sound_handler;
00334 
00335     boost::shared_ptr<media::MediaHandler> _mediaHandler;
00336 
00337     std::auto_ptr<RunResources> _runResources;
00339         int _x;
00340 
00342         int _y;
00343 
00345         unsigned _width;
00346 
00348         unsigned _height;
00349 
00354         InvalidatedRanges _invalidatedBounds;
00355 
00356     typedef std::vector<TestingRenderer> TestingRenderers;
00357 
00358         TestingRenderers _testingRenderers;
00359 
00360         // When true, pass world invalidated ranges
00361         // to the renderer(s) at ::render time.
00362         bool _forceRedraw;
00363 
00366         ManualClock _clock;
00367         //std::auto_ptr<VirtualClock> _clock;
00368 };
00369 
00370 // exp2 isn't part of standard C++, so is defined here in case the compiler
00371 // doesn't supply it (e.g. in BSD)
00372 #ifndef HAVE_EXP2
00373 inline double   exp2(double x) { return std::pow((double)2, double(x)); }
00374 #endif
00375 
00376 } // namespace gnash
00377 
00378 #endif // _GNASH_MOVIETESTER_H

Generated on Thu Sep 30 2010 14:35:01 for Gnash by  doxygen 1.7.1