initial commit
Signed-off-by: Peter Siegmund <mars3142@noreply.mars3142.dev>
This commit is contained in:
46
libs/wxWidgets-3.3.1/tests/drawing/basictest.cpp
Normal file
46
libs/wxWidgets-3.3.1/tests/drawing/basictest.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/drawing/basictest.cpp
|
||||
// Purpose: Basic tests for wxGraphicsContext
|
||||
// Author: Armel Asselin
|
||||
// Created: 2014-02-28
|
||||
// Copyright: (c) 2014 Ellié Computing <opensource@elliecomputing.com>
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/app.h"
|
||||
#include "wx/font.h"
|
||||
// #include "wx/window.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#define _WX_CURSOR_H_BASE_
|
||||
|
||||
|
||||
#include "drawing.h"
|
||||
|
||||
#if wxUSE_TEST_GC_DRAWING
|
||||
|
||||
const GraphicsContextDrawingTestCase::DrawingTestCase
|
||||
GraphicsContextDrawingTestCase::ms_drawingBasicTc = {
|
||||
1, &GraphicsContextDrawingTestCase::DoBasicDrawings, 800, 600, 72., true
|
||||
};
|
||||
|
||||
void GraphicsContextDrawingTestCase::DoBasicDrawings (wxGraphicsContext *gc)
|
||||
{
|
||||
// this test is expected to be portable, on any platform, in order to keep
|
||||
// that property, it should contain only axis aligned/integer drawings so
|
||||
// that the anti-aliasing method does not cause troubles.
|
||||
|
||||
wxGraphicsBrush gbBackground =
|
||||
gc->CreateBrush (wxBrush (wxColour (255, 255, 255)));
|
||||
|
||||
gc->SetBrush (gbBackground);
|
||||
gc->DrawRectangle (0, 0, 800, 600);
|
||||
}
|
||||
|
||||
#endif // wxUSE_TEST_GC_DRAWING
|
||||
276
libs/wxWidgets-3.3.1/tests/drawing/drawing.cpp
Normal file
276
libs/wxWidgets-3.3.1/tests/drawing/drawing.cpp
Normal file
@@ -0,0 +1,276 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/graphics/drawing.cpp
|
||||
// Purpose: Tests for wxGraphicsContent general drawing
|
||||
// Author: Armel Asselin
|
||||
// Created: 2014-02-21
|
||||
// Copyright: (c) 2014 Ellié Computing <opensource@elliecomputing.com>
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#include "drawing.h"
|
||||
|
||||
#if wxUSE_TEST_GC_DRAWING
|
||||
|
||||
#include "wx/image.h"
|
||||
#include "wx/wfstream.h"
|
||||
#include "wx/stdpaths.h"
|
||||
#include "wx/scopeguard.h"
|
||||
|
||||
#include "testimagefile.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
//// ORGANIZATION /////////////////////////////////////////////////////////////
|
||||
|
||||
// This test suite is organized around two axes:
|
||||
// - drawing test cases
|
||||
// - drawing contexts life cycle
|
||||
// => each drawing test case represent a serie of drawing primitives to execute
|
||||
// for whichever context
|
||||
// => each drawing context life cycle represent a particular class of
|
||||
// wxGraphicsContext and a way to create, dispose of and save it so that it is
|
||||
// possible to compare it with a reference file
|
||||
|
||||
// A plugin system is implemented to let developers of contributed libraries
|
||||
// test their library without the need to impact the test system and its
|
||||
// dependencies. See RunPluginsDrawingCase.
|
||||
|
||||
// The crossing of drawing case and life cycles is implemented by
|
||||
// RunIndividualDrawingCase
|
||||
|
||||
// The CPPUNIT test case class present a test per drawing case per life cycle
|
||||
// so that it is easy to run a particular test
|
||||
|
||||
// The test requires reference files and must produce them when an
|
||||
// implementation changed and new good references are known to be produced.
|
||||
// Environment variables control where reference files are located and when to
|
||||
// produce them:
|
||||
// - WX_TEST_SUITE_BUILD_REFERENCE must be "1" to request production of
|
||||
// reference files (by default only testing is done)
|
||||
// - WX_TEST_SUITE_REFERENCE_DIR must be a path to a directory containing the
|
||||
// sub-directory "gcdrawing-references" (by default the parent directory
|
||||
// of the directory of the test program is used)
|
||||
|
||||
//// WRITING NEW TEST CASES
|
||||
|
||||
// - add a new function to realize the drawing in the "cases functions" section
|
||||
// - add a case structure declaration for it in the "test cases" section
|
||||
// - use drawingbasic.cpp as a sample to add your own test case implementation
|
||||
|
||||
//// WRITING NEW FACTORIES
|
||||
|
||||
// - if the wxGraphicsContext is a class built-in wxWidgets, add a
|
||||
// DrawingTestGCFactory derived sub-class in drawing.h header
|
||||
// together with a declaration for it and its implementation
|
||||
// can be placed in drawing.cpp
|
||||
// Once this is done duplicate all the CPP UNIT test functions
|
||||
// and entries "DrawToImage_YYY" to your new GC "DrawTo<newGc>_YYYY"
|
||||
//
|
||||
// - if it is not built-in (contributed library/wxCode...), make a plugin for it
|
||||
// test.bkl contains a sample "test_drawingplugin" target, you can use
|
||||
// drawingplgsample.cpp as a start, see RunPluginsDrawingCase declaration
|
||||
// for information about how to run the tests
|
||||
|
||||
wxString GraphicsContextDrawingTestCase::ms_referenceDirectory;
|
||||
bool GraphicsContextDrawingTestCase::ms_buildReference;
|
||||
bool GraphicsContextDrawingTestCase::ms_buildReferenceDetermined;
|
||||
GraphicsContextDrawingTestCase::ImageGraphicsContextLifeCycle
|
||||
GraphicsContextDrawingTestCase::ms_imageLifeCycle;
|
||||
|
||||
#if wxUSE_SVG
|
||||
GraphicsContextDrawingTestCase::SvgGraphicsContextLifeCycle
|
||||
GraphicsContextDrawingTestCase::ms_svgLifeCycle;
|
||||
#endif // wxUSE_SVG
|
||||
|
||||
// register in the unnamed registry so that these tests are run by default
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( GraphicsContextDrawingTestCase );
|
||||
|
||||
// also include in its own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( GraphicsContextDrawingTestCase,
|
||||
"GraphicsContextDrawingTestCase" );
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// tests themselves
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void GraphicsContextDrawingTestCase::RunIndividualDrawingCase (
|
||||
DrawingTestGCFactory& gcFactory,
|
||||
const DrawingTestCase & testCase)
|
||||
{
|
||||
wxFileName fileName, refFileName;
|
||||
wxString testsOutputDirectory = wxStandardPaths::Get().GetTempDir();
|
||||
wxString refOutputDirectory = GetTestsReferenceDirectory();
|
||||
|
||||
wxString platformTag;
|
||||
if (!testCase.platformIndependent && !gcFactory.PlatformIndependent())
|
||||
platformTag = wxString::Format("_%s", GetPlatformTag());
|
||||
|
||||
fileName.Assign (testsOutputDirectory,
|
||||
wxString::Format("image_test_%s%s_%d", gcFactory.GetIdForFileName(),
|
||||
platformTag, testCase.caseNumber),
|
||||
gcFactory.GetExtensionForFileName());
|
||||
|
||||
refFileName.Assign (refOutputDirectory,
|
||||
wxString::Format("image_test_%s%s_%d_ref", gcFactory.GetIdForFileName(),
|
||||
platformTag, testCase.caseNumber),
|
||||
gcFactory.GetExtensionForFileName());
|
||||
|
||||
{
|
||||
wxGraphicsContext *gc = nullptr;
|
||||
|
||||
wxON_BLOCK_EXIT_OBJ1(gcFactory, DrawingTestGCFactory::CleanUp, gc);
|
||||
|
||||
gc = gcFactory.BuildNewContext(
|
||||
wxSize(testCase.width, testCase.height),
|
||||
testCase.pointsPerInch, fileName);
|
||||
|
||||
(this->*testCase.m_drawingF)(gc);
|
||||
|
||||
gcFactory.SaveBuiltContext(gc);
|
||||
}
|
||||
|
||||
if (GetBuildReference())
|
||||
{
|
||||
WX_ASSERT_MESSAGE(
|
||||
("Cannot copy file \"%s\" to \"%s\".",
|
||||
fileName.GetFullPath(), refFileName.GetFullPath()),
|
||||
wxCopyFile (fileName.GetFullPath(),
|
||||
refFileName.GetFullPath(), true));
|
||||
}
|
||||
else if (gcFactory.UseImageComparison())
|
||||
{
|
||||
WX_ASSERT_SAME_AS_IMAGE_FILE(fileName.GetFullPath(),
|
||||
refFileName.GetFullPath());
|
||||
}
|
||||
else
|
||||
{
|
||||
WX_ASSERT_SAME_AS_FILE(fileName.GetFullPath(),
|
||||
refFileName.GetFullPath());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool GraphicsContextDrawingTestCase::GetBuildReference() const
|
||||
{
|
||||
if (!ms_buildReferenceDetermined)
|
||||
{
|
||||
wxString value;
|
||||
if (wxGetEnv("WX_TEST_SUITE_BUILD_REFERENCE", &value))
|
||||
ms_buildReference = value == "1";
|
||||
}
|
||||
return ms_buildReference;
|
||||
}
|
||||
|
||||
wxString GraphicsContextDrawingTestCase::GetTestsReferenceDirectory() const
|
||||
{
|
||||
if (ms_referenceDirectory.empty())
|
||||
{
|
||||
wxFileName refDir;
|
||||
|
||||
if ( !wxGetEnv("WX_TEST_SUITE_REFERENCE_DIR",
|
||||
&ms_referenceDirectory) )
|
||||
{
|
||||
refDir = wxFileName(wxStandardPaths::Get().GetExecutablePath());
|
||||
refDir.RemoveLastDir();
|
||||
}
|
||||
else
|
||||
{
|
||||
refDir = wxFileName(ms_referenceDirectory, wxT(""));
|
||||
}
|
||||
refDir.AppendDir ("drawing");
|
||||
refDir.AppendDir ("references");
|
||||
ms_referenceDirectory = refDir.GetPath();
|
||||
}
|
||||
return ms_referenceDirectory;
|
||||
}
|
||||
|
||||
wxString GraphicsContextDrawingTestCase::GetPlatformTag() const
|
||||
{
|
||||
// We consider that the platform tag is the kind of default renderer plus
|
||||
// its major/minor versions.
|
||||
// The reason why including major/minor version is important, is that the
|
||||
// rendering engine typically evolves somewhat between two version
|
||||
// (i.e. font rendering is not the same in Windows XP and Windows 8)
|
||||
int major, minor;
|
||||
const wxGraphicsRenderer *defaultRenderer = wxGraphicsRenderer::GetDefaultRenderer();
|
||||
wxString rendererName = defaultRenderer->GetName();
|
||||
defaultRenderer->GetVersion (&major, &minor);
|
||||
|
||||
return wxString::Format("%s-%d.%d", rendererName, major, minor);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// BUILT-IN FACTORIES ////////////////////////////////////////////////////////
|
||||
|
||||
wxGraphicsContext *
|
||||
GraphicsContextDrawingTestCase::ImageGraphicsContextLifeCycle::
|
||||
BuildNewContext (wxSize expectedSize, double WXUNUSED(pointsPerInch),
|
||||
const wxFileName &targetFileName)
|
||||
{
|
||||
m_image = new wxImage (expectedSize);
|
||||
m_image->InitAlpha();
|
||||
|
||||
m_targetFileName = targetFileName.GetFullPath();
|
||||
|
||||
// we should probably pass the number of points per inches somewhere...
|
||||
// but I don't see where yet...
|
||||
return wxGraphicsContext::Create(*m_image);
|
||||
}
|
||||
|
||||
void
|
||||
GraphicsContextDrawingTestCase::ImageGraphicsContextLifeCycle::
|
||||
SaveBuiltContext (wxGraphicsContext *&gc)
|
||||
{
|
||||
wxDELETE(gc);
|
||||
|
||||
m_image->SaveFile (m_targetFileName);
|
||||
}
|
||||
|
||||
void
|
||||
GraphicsContextDrawingTestCase::ImageGraphicsContextLifeCycle::
|
||||
CleanUp (wxGraphicsContext *gc)
|
||||
{
|
||||
delete gc;
|
||||
m_targetFileName.clear();
|
||||
wxDELETE(m_image);
|
||||
}
|
||||
|
||||
#if wxUSE_SVG
|
||||
wxGraphicsContext *
|
||||
GraphicsContextDrawingTestCase::SvgGraphicsContextLifeCycle::
|
||||
BuildNewContext (wxSize WXUNUSED(expectedSize),
|
||||
double WXUNUSED(pointsPerInch),
|
||||
const wxFileName &WXUNUSED(targetFileName))
|
||||
{
|
||||
m_svgFileDc = nullptr;
|
||||
//m_svg_file_dc = new wxSVGFileDC (target_file_name.GetFullPath(),
|
||||
// expected_size.GetWidth(), expected_size.GetHeight(), points_per_inch);
|
||||
|
||||
// unfortunately cannot make GC over a DC yet :(
|
||||
throw std::runtime_error("SVG as no wxGC interface yet");
|
||||
}
|
||||
|
||||
void
|
||||
GraphicsContextDrawingTestCase::SvgGraphicsContextLifeCycle::
|
||||
SaveBuiltContext (wxGraphicsContext *&WXUNUSED(gc))
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
GraphicsContextDrawingTestCase::SvgGraphicsContextLifeCycle::
|
||||
CleanUp (wxGraphicsContext *WXUNUSED(gc))
|
||||
{
|
||||
wxDELETE (m_svgFileDc);
|
||||
}
|
||||
#endif // wxUSE_SVG
|
||||
|
||||
#endif // wxUSE_TEST_GC_DRAWING
|
||||
185
libs/wxWidgets-3.3.1/tests/drawing/drawing.h
Normal file
185
libs/wxWidgets-3.3.1/tests/drawing/drawing.h
Normal file
@@ -0,0 +1,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 override { return "image"; }
|
||||
virtual wxString GetExtensionForFileName () const override { return "png"; }
|
||||
virtual bool UseImageComparison() const override { return true; }
|
||||
virtual bool PlatformIndependent() const override { return false; }
|
||||
virtual wxGraphicsContext *BuildNewContext (wxSize expectedSize,
|
||||
double pointsPerInch, const wxFileName &targetFileName) override;
|
||||
virtual void SaveBuiltContext (wxGraphicsContext *&gc) override;
|
||||
virtual void CleanUp (wxGraphicsContext *gc) override;
|
||||
private:
|
||||
wxImage *m_image;
|
||||
wxString m_targetFileName;
|
||||
};
|
||||
|
||||
static ImageGraphicsContextLifeCycle ms_imageLifeCycle;
|
||||
|
||||
#if wxUSE_SVG
|
||||
class SvgGraphicsContextLifeCycle: public DrawingTestGCFactory
|
||||
{
|
||||
public:
|
||||
virtual wxString GetIdForFileName () const override { return "svg"; }
|
||||
virtual wxString GetExtensionForFileName () const override { return "svg"; }
|
||||
virtual bool UseImageComparison() const override { return false; }
|
||||
virtual bool PlatformIndependent() const override { return true; }
|
||||
virtual wxGraphicsContext *BuildNewContext (wxSize expectedSize,
|
||||
double pointsPerInch, const wxFileName &targetFileName) override;
|
||||
virtual void SaveBuiltContext (wxGraphicsContext *&gc) override;
|
||||
virtual void CleanUp (wxGraphicsContext *gc) override;
|
||||
|
||||
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_
|
||||
114
libs/wxWidgets-3.3.1/tests/drawing/fonttest.cpp
Normal file
114
libs/wxWidgets-3.3.1/tests/drawing/fonttest.cpp
Normal file
@@ -0,0 +1,114 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/drawing/basictest.cpp
|
||||
// Purpose: Basic tests for wxGraphicsContext
|
||||
// Author: Armel Asselin
|
||||
// Created: 2014-02-28
|
||||
// Copyright: (c) 2014 Ellié Computing <opensource@elliecomputing.com>
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/app.h"
|
||||
#include "wx/font.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "drawing.h"
|
||||
|
||||
#ifdef __WXGTK__
|
||||
#include "glib-object.h"
|
||||
#endif
|
||||
|
||||
#if wxUSE_TEST_GC_DRAWING
|
||||
|
||||
const GraphicsContextDrawingTestCase::DrawingTestCase
|
||||
GraphicsContextDrawingTestCase::ms_drawingFontTc = {
|
||||
2, &GraphicsContextDrawingTestCase::DoFontDrawings, 800, 600, 72., false
|
||||
};
|
||||
|
||||
void GraphicsContextDrawingTestCase::DoFontDrawings (wxGraphicsContext *gc)
|
||||
{
|
||||
#ifdef __WXGTK__
|
||||
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
|
||||
g_type_init();
|
||||
wxGCC_WARNING_RESTORE()
|
||||
#endif
|
||||
|
||||
// This test is expected to treat about fonts/texts. Fonts are a bit special
|
||||
// because we cannot expect the same rendering by several engines, and the
|
||||
// dimensions of the same text in same font will vary.
|
||||
|
||||
wxGraphicsBrush gbBackground =
|
||||
gc->CreateBrush( wxBrush ( wxColour ( 240, 240, 240 ) ) );
|
||||
|
||||
gc->SetBrush( gbBackground );
|
||||
gc->DrawRectangle(0, 0, 800, 600);
|
||||
|
||||
wxGraphicsBrush gbTextBackground =
|
||||
gc->CreateBrush( wxBrush ( wxColour ( 192, 192, 192 ) ) );
|
||||
|
||||
// set underlined font for testing
|
||||
gc->SetFont( wxFont(wxFontInfo(12).Family(wxFONTFAMILY_MODERN).Underlined()), *wxBLACK );
|
||||
gc->DrawText( wxT("This is text"), 110, 10, gbTextBackground );
|
||||
gc->DrawText( wxT("That is text"), 20, 10, wxDegToRad(-45), gbTextBackground );
|
||||
|
||||
// use wxSWISS_FONT and not wxNORMAL_FONT as the latter can't be rotated
|
||||
// (it is not TrueType)
|
||||
gc->SetFont( wxFont(wxFontInfo(12).Family(wxFONTFAMILY_SWISS)), *wxBLACK );
|
||||
|
||||
wxString text;
|
||||
|
||||
for ( int n = -180; n < 180; n += 30 )
|
||||
{
|
||||
text.Printf(wxT(" %d rotated text"), n);
|
||||
gc->DrawText(text , 400, 400, wxDegToRad(n) );
|
||||
}
|
||||
|
||||
wxFont swissDcFont( wxFontInfo(18).Family(wxFONTFAMILY_SWISS) );
|
||||
wxGraphicsFont swissFont = gc->CreateFont( swissDcFont, *wxBLACK );
|
||||
gc->SetFont( swissFont );
|
||||
|
||||
gc->DrawText( wxT("This is Swiss 18pt text."), 110, 40 );
|
||||
|
||||
wxDouble length;
|
||||
wxDouble height;
|
||||
wxDouble descent;
|
||||
gc->GetTextExtent( wxT("This is Swiss 18pt text."), &length, &height, &descent );
|
||||
text.Printf( wxT("Dimensions are length %f, height %f, descent %f"), length, height, descent );
|
||||
gc->DrawText( text, 110, 80 );
|
||||
|
||||
// (did not find equivalent to CharHeight())
|
||||
|
||||
gc->SetBrush( *wxWHITE_BRUSH );
|
||||
|
||||
gc->DrawRectangle( 100, 40, 4, height );
|
||||
|
||||
// test the logical function effect
|
||||
wxCoord y = 150;
|
||||
// text drawing should ignore logical function
|
||||
gc->DrawText( wxT("There should be a text below"), 110, 150 );
|
||||
gc->DrawRectangle( 110, y, 100, height );
|
||||
|
||||
y += height;
|
||||
gc->DrawText( wxT("Visible text"), 110, y );
|
||||
gc->DrawRectangle( 110, y, 100, height );
|
||||
gc->DrawText( wxT("Visible text"), 110, y );
|
||||
gc->DrawRectangle( 110, y, 100, height );
|
||||
|
||||
y += height;
|
||||
gc->DrawRectangle( 110, y, 100, height );
|
||||
gc->DrawText( wxT("Another visible text"), 110, y );
|
||||
|
||||
y += height;
|
||||
gc->DrawText("And\nmore\ntext on\nmultiple\nlines", 110, y);
|
||||
y += 5*height;
|
||||
|
||||
gc->SetFont( swissDcFont, *wxBLUE );
|
||||
gc->DrawText( "Rotated text\ncan have\nmultiple lines\nas well", 110, y, wxDegToRad(15) );
|
||||
}
|
||||
|
||||
#endif // wxUSE_TEST_GC_DRAWING
|
||||
71
libs/wxWidgets-3.3.1/tests/drawing/gcfactory.h
Normal file
71
libs/wxWidgets-3.3.1/tests/drawing/gcfactory.h
Normal file
@@ -0,0 +1,71 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/drawing/gcfactory.h
|
||||
// Purpose: Interface of a factory to create and destroy a wxGraphicsContext
|
||||
// and finally save the result of a rendering test
|
||||
// Author: Armel Asselin
|
||||
// Created: 2014-02-26
|
||||
// Copyright: (c) 2014 Ellié Computing <opensource@elliecomputing.com>
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_TESTS_GCFACTORY_H_
|
||||
#define _WX_TESTS_GCFACTORY_H_
|
||||
|
||||
// wxCairoRenderer::CreateMeasuringContext() is not implement for wxX11
|
||||
#if wxUSE_GRAPHICS_CONTEXT && !defined(__WXX11__)
|
||||
#include "wx/graphics.h"
|
||||
#define wxUSE_TEST_GC_DRAWING 1
|
||||
#else
|
||||
#define wxUSE_TEST_GC_DRAWING 0
|
||||
#endif
|
||||
|
||||
#if wxUSE_TEST_GC_DRAWING
|
||||
|
||||
#include "wx/filename.h"
|
||||
|
||||
class WXDLLIMPEXP_FWD_CORE wxGraphicsContext;
|
||||
|
||||
// Implement a class derived from this one to let the drawing test create
|
||||
// graphics context, save them and destroy them.
|
||||
class DrawingTestGCFactory
|
||||
{
|
||||
public:
|
||||
virtual ~DrawingTestGCFactory() {}
|
||||
|
||||
// This identifier is used in the test and reference files to distinguish
|
||||
// results produced by wxGraphicsContext generated by this factory
|
||||
// use only lower case latin letters, '_' and '-'
|
||||
virtual wxString GetIdForFileName () const = 0;
|
||||
|
||||
// This is the extension used when saving test and reference files
|
||||
virtual wxString GetExtensionForFileName () const = 0;
|
||||
|
||||
// Returns true if a pixel per pixel comparison of rendered image should
|
||||
// be used rather than a byte by byte comparison of files
|
||||
virtual bool UseImageComparison() const = 0;
|
||||
|
||||
// Returns true this target is platform independent, rendering exactly
|
||||
// the same result for whichever platform
|
||||
virtual bool PlatformIndependent() const = 0;
|
||||
|
||||
// Builds a new context of @c expected_size, expecting to save it as
|
||||
// @c target_file_name
|
||||
// NB: only one context is created as a time, so that the implementer
|
||||
// can keep internal state if necessary
|
||||
virtual wxGraphicsContext *BuildNewContext (wxSize expectedSize,
|
||||
double pointsPerInch, const wxFileName &targetFileName) = 0;
|
||||
|
||||
// Let's the opportunity to actually save the context and associated data
|
||||
// If saving requires deleting the wxGraphicsContext object the
|
||||
// implementer is free to do it but @c gc must then be nulled
|
||||
virtual void SaveBuiltContext (wxGraphicsContext *&gc) = 0;
|
||||
|
||||
// Cleans @c gc and internal data if any
|
||||
virtual void CleanUp (wxGraphicsContext *gc) = 0;
|
||||
};
|
||||
|
||||
typedef DrawingTestGCFactory * (*CreateDrawingTestLifeCycleFunction)();
|
||||
typedef void (*DestroyDrawingTestLifeCycleFunction) (DrawingTestGCFactory* lc);
|
||||
|
||||
#endif // wxUSE_TEST_GC_DRAWING
|
||||
|
||||
#endif // #ifndef _WX_TESTS_GCFACTORY_H_
|
||||
21
libs/wxWidgets-3.3.1/tests/drawing/plugin.h
Normal file
21
libs/wxWidgets-3.3.1/tests/drawing/plugin.h
Normal file
@@ -0,0 +1,21 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/drawing/plugin.h
|
||||
// Purpose: Defines the functions needed to implement a drawing test plugin
|
||||
// Author: Armel Asselin
|
||||
// Created: 2014-02-2
|
||||
// Copyright: (c) 2014 Ell8ié Computing <opensource@elliecomputing.com>
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_TESTS_DRAWINGPLG_H_
|
||||
#define _WX_TESTS_DRAWINGPLG_H_
|
||||
|
||||
#include "gcfactory.h"
|
||||
|
||||
#if wxUSE_TEST_GC_DRAWING
|
||||
|
||||
extern "C" WXEXPORT DrawingTestGCFactory * CreateDrawingTestLifeCycle();
|
||||
extern "C" WXEXPORT void DestroyDrawingTestLifeCycle (DrawingTestGCFactory* lc);
|
||||
|
||||
#endif // wxUSE_TEST_GC_DRAWING
|
||||
|
||||
#endif // #ifndef _WX_TESTS_DRAWINGPLG_H_
|
||||
96
libs/wxWidgets-3.3.1/tests/drawing/plugindriver.cpp
Normal file
96
libs/wxWidgets-3.3.1/tests/drawing/plugindriver.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/drawing/plugindriver.cpp
|
||||
// Purpose: Plugin management for the drawing tests
|
||||
// Author: Armel Asselin
|
||||
// Created: 2014-02-28
|
||||
// Copyright: (c) 2014 Ellié Computing <opensource@elliecomputing.com>
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/log.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "drawing.h"
|
||||
|
||||
#if wxUSE_TEST_GC_DRAWING
|
||||
#include "wx/dynlib.h"
|
||||
|
||||
void GraphicsContextDrawingTestCase::RunPluginsDrawingCase (
|
||||
const DrawingTestCase & testCase)
|
||||
{
|
||||
if (!m_drawingPluginsLoaded)
|
||||
{
|
||||
m_drawingPluginsLoaded = true;
|
||||
|
||||
wxString pluginsListStr;
|
||||
if (!wxGetEnv ("WX_TEST_SUITE_GC_DRAWING_PLUGINS", &pluginsListStr))
|
||||
return; // no plugins
|
||||
|
||||
wxArrayString pluginsNameArray = wxSplit (pluginsListStr, ',', '\0');
|
||||
m_drawingPlugins.resize (pluginsNameArray.size());
|
||||
|
||||
for (size_t idx=0; idx<pluginsNameArray.size(); ++idx)
|
||||
{
|
||||
PluginInfo &pluginBeingLoaded = m_drawingPlugins[idx];
|
||||
pluginBeingLoaded.library = new wxDynamicLibrary;
|
||||
if (!pluginBeingLoaded.library->Load (pluginsNameArray[idx]))
|
||||
{
|
||||
wxLogFatalError("could not load drawing plugin %s",
|
||||
pluginsNameArray[idx]);
|
||||
return;
|
||||
}
|
||||
|
||||
wxDYNLIB_FUNCTION(CreateDrawingTestLifeCycleFunction,
|
||||
CreateDrawingTestLifeCycle, *pluginBeingLoaded.library);
|
||||
wxDYNLIB_FUNCTION(DestroyDrawingTestLifeCycleFunction,
|
||||
DestroyDrawingTestLifeCycle, *pluginBeingLoaded.library);
|
||||
|
||||
if (!pfnCreateDrawingTestLifeCycle ||
|
||||
!pfnDestroyDrawingTestLifeCycle)
|
||||
{
|
||||
wxLogFatalError("could not find function"
|
||||
" CreateDrawingTestLifeCycle or "
|
||||
"DestroyDrawingTestLifeCycle in %s", pluginsNameArray[idx]);
|
||||
return;
|
||||
}
|
||||
|
||||
pluginBeingLoaded.destroy = pfnDestroyDrawingTestLifeCycle;
|
||||
pluginBeingLoaded.gcFactory = (*pfnCreateDrawingTestLifeCycle)();
|
||||
if (!pluginBeingLoaded.gcFactory)
|
||||
{
|
||||
wxLogFatalError("failed to create life-cycle object in %s",
|
||||
pluginsNameArray[idx]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// now execute the test case for each plugin
|
||||
for (size_t idxp=0; idxp<m_drawingPlugins.size(); ++idxp)
|
||||
{
|
||||
RunIndividualDrawingCase (*m_drawingPlugins[idxp].gcFactory, testCase);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// GraphicsContextDrawingTestCase::PluginInfo /////////////////////////////////
|
||||
|
||||
GraphicsContextDrawingTestCase::PluginInfo::PluginInfo()
|
||||
: library(nullptr), gcFactory(nullptr), destroy(nullptr) {
|
||||
}
|
||||
|
||||
GraphicsContextDrawingTestCase::PluginInfo::~PluginInfo()
|
||||
{
|
||||
if (destroy && gcFactory)
|
||||
(*destroy)(gcFactory);
|
||||
|
||||
delete library;
|
||||
}
|
||||
|
||||
#endif // wxUSE_TEST_GC_DRAWING
|
||||
84
libs/wxWidgets-3.3.1/tests/drawing/pluginsample.cpp
Normal file
84
libs/wxWidgets-3.3.1/tests/drawing/pluginsample.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/drawing/pluginsample.cpp
|
||||
// Purpose: Sample plugin for the wxGraphicsContext test
|
||||
// Author: Armel Asselin
|
||||
// Created: 2014-02-21
|
||||
// Copyright: (c) 2014 Ellié Computing <opensource@elliecomputing.com>
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "plugin.h"
|
||||
|
||||
#if wxUSE_TEST_GC_DRAWING
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// plugin implementation
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class SampleDrawingTestGCFactory: public DrawingTestGCFactory {
|
||||
public:
|
||||
SampleDrawingTestGCFactory() {
|
||||
wxImage::AddHandler (new wxBMPHandler());
|
||||
}
|
||||
|
||||
virtual ~SampleDrawingTestGCFactory() {
|
||||
}
|
||||
virtual wxString GetIdForFileName () const override { return "sample-plg"; }
|
||||
virtual wxString GetExtensionForFileName () const override { return "bmp"; }
|
||||
|
||||
// Bitmaps are handled by wx code they should be binarily equal
|
||||
virtual bool UseImageComparison() const override { return false; }
|
||||
|
||||
// We use wxGraphicsContext, its implementation is not platform independent
|
||||
// and returns may slightly vary
|
||||
virtual bool PlatformIndependent() const override { return false; }
|
||||
|
||||
virtual wxGraphicsContext *BuildNewContext (wxSize expectedSize,
|
||||
double WXUNUSED(pointsPerInch), const wxFileName &targetFileName) override {
|
||||
m_image = new wxImage (expectedSize);
|
||||
m_image->InitAlpha();
|
||||
|
||||
m_targetFileName = targetFileName.GetFullPath();
|
||||
|
||||
// we should probably pass the number of points per inches somewhere...
|
||||
// but I don't see where yet...
|
||||
return wxGraphicsContext::Create(*m_image);
|
||||
}
|
||||
|
||||
// Let's the opportunity to actually save the context and associated data
|
||||
// If saving requires deleting the wxGraphicsContext object the
|
||||
// implementer is free to do it but @c gc must then be nulled
|
||||
virtual void SaveBuiltContext (wxGraphicsContext *&gc) override {
|
||||
wxDELETE(gc);
|
||||
|
||||
m_image->SaveFile (m_targetFileName);
|
||||
}
|
||||
|
||||
// Cleans @c gc and internal data if any
|
||||
virtual void CleanUp (wxGraphicsContext *gc) override {
|
||||
delete gc;
|
||||
m_targetFileName.Empty();
|
||||
wxDELETE(m_image);
|
||||
}
|
||||
|
||||
wxImage *m_image;
|
||||
wxString m_targetFileName;
|
||||
};
|
||||
|
||||
extern "C" WXEXPORT DrawingTestGCFactory * CreateDrawingTestLifeCycle()
|
||||
{
|
||||
return new SampleDrawingTestGCFactory;
|
||||
}
|
||||
|
||||
extern "C" WXEXPORT void DestroyDrawingTestLifeCycle (DrawingTestGCFactory* lc)
|
||||
{
|
||||
delete lc;
|
||||
}
|
||||
|
||||
#endif // wxUSE_TEST_GC_DRAWING
|
||||
4
libs/wxWidgets-3.3.1/tests/drawing/readme.txt
Normal file
4
libs/wxWidgets-3.3.1/tests/drawing/readme.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
Drawing Test
|
||||
############
|
||||
|
||||
If you need directions, please read the top of drawing.cpp file, and the test.bkl file with the comments about test_drawing and test_drawingplugin items.
|
||||
Binary file not shown.
BIN
libs/wxWidgets-3.3.1/tests/drawing/references/image_test_image_cg-10.5_2_ref.png
LFS
Normal file
BIN
libs/wxWidgets-3.3.1/tests/drawing/references/image_test_image_cg-10.5_2_ref.png
LFS
Normal file
Binary file not shown.
Binary file not shown.
1
libs/wxWidgets-3.3.1/tests/drawing/references/readme.txt
Normal file
1
libs/wxWidgets-3.3.1/tests/drawing/references/readme.txt
Normal file
@@ -0,0 +1 @@
|
||||
This directory is expected to contain reference files and images produced by graphics/drawing.cpp test.
|
||||
97
libs/wxWidgets-3.3.1/tests/drawing/testimagefile.h
Normal file
97
libs/wxWidgets-3.3.1/tests/drawing/testimagefile.h
Normal file
@@ -0,0 +1,97 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/drawing/testimagefile.h
|
||||
// Purpose: Functions to test whether the content of files or images files
|
||||
// are equal
|
||||
// Author: Armel Asselin
|
||||
// Created: 2014-02-28
|
||||
// Copyright: (c) 2014 Ellié Computing <opensource@elliecomputing.com>
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifndef _WX_TESTS_TESTIMAGEFILE_H_
|
||||
#define _WX_TESTS_TESTIMAGEFILE_H_
|
||||
|
||||
bool AreFilesContentsEqual(const wxString &filename, const wxString &refFilename)
|
||||
{
|
||||
wxFileInputStream input(filename);
|
||||
wxFileInputStream refInput(refFilename);
|
||||
|
||||
wxFileOffset refLength = refInput.GetLength();
|
||||
if (refLength != input.GetLength())
|
||||
return false;
|
||||
|
||||
wxUint8 buffer[1024], refBuffer[sizeof(buffer)];
|
||||
|
||||
wxFileOffset remainingLength = refLength;
|
||||
while (remainingLength != 0)
|
||||
{
|
||||
input.Read (buffer, wxMin(remainingLength, sizeof(buffer)));
|
||||
refInput.Read(refBuffer, wxMin(remainingLength, sizeof(refBuffer)));
|
||||
|
||||
size_t refLastRead = refInput.LastRead();
|
||||
if (input.LastRead() != refLastRead)
|
||||
return false;
|
||||
|
||||
if (memcmp (buffer, refBuffer, refLastRead) != 0)
|
||||
return false;
|
||||
|
||||
remainingLength -= refLastRead;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#define WX_ASSERT_SAME_AS_FILE(filename1, filename2) \
|
||||
WX_ASSERT_MESSAGE(\
|
||||
("Files \"%s\" and \"%s\" differ.",\
|
||||
filename1, filename2),\
|
||||
AreFilesContentsEqual(filename1, filename2))
|
||||
|
||||
bool AreImagesFilesContentsEqual(const wxString &filename,
|
||||
const wxString &refFilename)
|
||||
{
|
||||
wxImage input(filename);
|
||||
wxImage refInput(refFilename);
|
||||
|
||||
// assertion_traits<wxImage> could do part of the job or maybe the contrary
|
||||
// there should probably be somethin common at least
|
||||
|
||||
if (!input.Ok() || !refInput.Ok())
|
||||
return false;
|
||||
if (input.GetSize() != refInput.GetSize())
|
||||
return false;
|
||||
if (input.HasAlpha() != refInput.HasAlpha())
|
||||
return false;
|
||||
if (input.HasMask() != refInput.HasMask())
|
||||
return false;
|
||||
|
||||
long pixelsCount = input.GetSize().GetWidth() * input.GetSize().GetHeight();
|
||||
const unsigned char *data = input.GetData();
|
||||
const unsigned char *refData = refInput.GetData();
|
||||
if (memcmp (data, refData, pixelsCount*3) != 0)
|
||||
return false;
|
||||
|
||||
if (input.HasAlpha())
|
||||
{
|
||||
const unsigned char *alpha = input.GetAlpha();
|
||||
const unsigned char *refAlpha = refInput.GetAlpha();
|
||||
if (memcmp (alpha, refAlpha, pixelsCount) != 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (input.HasMask() &&
|
||||
(input.GetMaskRed() != refInput.GetMaskRed() ||
|
||||
input.GetMaskGreen() != refInput.GetMaskGreen() ||
|
||||
input.GetMaskBlue() != refInput.GetMaskBlue()))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#define WX_ASSERT_SAME_AS_IMAGE_FILE(filename1, filename2) \
|
||||
WX_ASSERT_MESSAGE(\
|
||||
("Image files \"%s\" and \"%s\" differ.",\
|
||||
filename1, filename2),\
|
||||
AreImagesFilesContentsEqual(filename1, filename2))
|
||||
|
||||
#endif // _WX_TESTS_TESTIMAGEFILE_H_
|
||||
Reference in New Issue
Block a user