1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
///////////////////////////////////////////////////////////////////////////////
// Name: tests/drawing/drawing.h
// Purpose: Drawing test case header
// Author: Armel Asselin
// Created: 2014-02-26
// Copyright: (c) 2014 ElliƩ Computing <opensource@elliecomputing.com>
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_TESTS_DRAWING_H_
#define _WX_TESTS_DRAWING_H_
#include "gcfactory.h"
#if wxUSE_TEST_GC_DRAWING
#include "wx/math.h"
#if wxUSE_SVG
#include "wx/dcsvg.h"
#endif
class WXDLLIMPEXP_FWD_BASE wxDynamicLibrary;
class GraphicsContextDrawingTestCase : public CppUnit::TestCase
{
public:
GraphicsContextDrawingTestCase()
: m_drawingPluginsLoaded(false)
{
wxImage::AddHandler (new wxPNGHandler());
wxImage::AddHandler (new wxBMPHandler());
}
~GraphicsContextDrawingTestCase() {
ms_referenceDirectory.clear();
}
private:
// NB: individual test cases launchers are copied/pasted so that the CppUnit
// test case selection can be used
CPPUNIT_TEST_SUITE( GraphicsContextDrawingTestCase );
CPPUNIT_TEST( DrawToImage_Basics );
#if wxUSE_SVG
// CPPUNIT_TEST( DrawToSVG_Basics );
#endif
CPPUNIT_TEST( DrawToPlugins_Basics );
// FIXME: Reference data files are currently not found when using Unix
// build system, so these tests are failing there, fix this and remove
// this ifdef.
#ifdef __WINDOWS__
CPPUNIT_TEST( DrawToImage_Fonts );
#if wxUSE_SVG
// CPPUNIT_TEST( DrawToSVG_Fonts );
#endif
CPPUNIT_TEST( DrawToPlugins_Fonts );
#endif // __WINDOWS__
CPPUNIT_TEST_SUITE_END();
class ImageGraphicsContextLifeCycle: public DrawingTestGCFactory
{
public:
virtual ~ImageGraphicsContextLifeCycle() {}
virtual wxString GetIdForFileName () const wxOVERRIDE { return "image"; }
virtual wxString GetExtensionForFileName () const wxOVERRIDE { return "png"; }
virtual bool UseImageComparison() const wxOVERRIDE { return true; }
virtual bool PlatformIndependent() const wxOVERRIDE { return false; }
virtual wxGraphicsContext *BuildNewContext (wxSize expectedSize,
double pointsPerInch, const wxFileName &targetFileName) wxOVERRIDE;
virtual void SaveBuiltContext (wxGraphicsContext *&gc) wxOVERRIDE;
virtual void CleanUp (wxGraphicsContext *gc) wxOVERRIDE;
private:
wxImage *m_image;
wxString m_targetFileName;
};
static ImageGraphicsContextLifeCycle ms_imageLifeCycle;
#if wxUSE_SVG
class SvgGraphicsContextLifeCycle: public DrawingTestGCFactory
{
public:
virtual wxString GetIdForFileName () const wxOVERRIDE { return "svg"; }
virtual wxString GetExtensionForFileName () const wxOVERRIDE { return "svg"; }
virtual bool UseImageComparison() const wxOVERRIDE { return false; }
virtual bool PlatformIndependent() const wxOVERRIDE { return true; }
virtual wxGraphicsContext *BuildNewContext (wxSize expectedSize,
double pointsPerInch, const wxFileName &targetFileName) wxOVERRIDE;
virtual void SaveBuiltContext (wxGraphicsContext *&gc) wxOVERRIDE;
virtual void CleanUp (wxGraphicsContext *gc) wxOVERRIDE;
private:
wxSVGFileDC *m_svgFileDc;
};
static SvgGraphicsContextLifeCycle ms_svgLifeCycle;
#endif // wxUSE_SVG
struct DrawingTestCase {
unsigned caseNumber;
void (GraphicsContextDrawingTestCase::*m_drawingF) (
wxGraphicsContext *gc);
unsigned width, height;
double pointsPerInch;
// if true, it means that this test case is "simple" enough to be
// platform independent even for targets that normally are dependent
// on the platform
bool platformIndependent;
};
// test cases
static const DrawingTestCase ms_drawingBasicTc;
static const DrawingTestCase ms_drawingFontTc;
// cases functions
void DoBasicDrawings (wxGraphicsContext *gc);
void DoFontDrawings (wxGraphicsContext *gc);
void RunIndividualDrawingCase (
DrawingTestGCFactory& gcFactory,
const DrawingTestCase & testCase);
// enumerates the dll names as specified in WX_TEST_SUITE_GC_DRAWING_PLUGINS
// (coma separated list of DLL to load and test)
// each DLL should have these procedures:
// - DrawingTestGCFactory* CreateDrawingTestLifeCycle(),
// to create the life cycle object
// - DestroyDrawingTestLifeCycle(DrawingTestGCFactory *),
// to destroy the life cycle object
void RunPluginsDrawingCase (const DrawingTestCase & testCase);
void DrawToImage_Basics() {
RunIndividualDrawingCase (ms_imageLifeCycle, ms_drawingBasicTc);
}
#if wxUSE_SVG
void DrawToSVG_Basics() {
RunIndividualDrawingCase (ms_svgLifeCycle, ms_drawingBasicTc);
}
#endif
void DrawToPlugins_Basics() {
RunPluginsDrawingCase (ms_drawingBasicTc);
}
void DrawToImage_Fonts() {
RunIndividualDrawingCase (ms_imageLifeCycle, ms_drawingFontTc);
}
#if wxUSE_SVG
void DrawToSVG_Fonts() {
RunIndividualDrawingCase (ms_svgLifeCycle, ms_drawingFontTc);
}
#endif
void DrawToPlugins_Fonts() {
RunPluginsDrawingCase (ms_drawingFontTc);
}
bool GetBuildReference() const;
wxString GetTestsReferenceDirectory() const;
wxString GetPlatformTag() const;
static wxString ms_referenceDirectory;
static bool ms_buildReference, ms_buildReferenceDetermined;
bool m_drawingPluginsLoaded;
struct PluginInfo {
PluginInfo();
~PluginInfo();
wxDynamicLibrary* library;
DrawingTestGCFactory *gcFactory;
DestroyDrawingTestLifeCycleFunction destroy;
};
wxVector<PluginInfo> m_drawingPlugins;
wxDECLARE_NO_COPY_CLASS(GraphicsContextDrawingTestCase);
};
#endif // wxUSE_TEST_GC_DRAWING
#endif // _WX_TESTS_DRAWING_H_
|