]>
git.saurik.com Git - wxWidgets.git/blob - tests/graphics/measuring.cpp
9affc9882c96c477a31cab41e7928cebd9fdf088
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/graphics/measuring.cpp
3 // Purpose: Tests for wxGraphicsRenderer::CreateMeasuringContext
4 // Author: Kevin Ollivier
6 // RCS-ID: $Id: clientsize.cpp 53740 2008-05-25 02:56:22Z VZ $
7 // Copyright: (c) 2008 Kevin Ollivier <kevino@theolliviers.com>
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
16 #if wxUSE_GRAPHICS_CONTEXT
25 #include "wx/window.h"
28 #include "wx/graphics.h"
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 class MeasuringContextTestCase
: public CppUnit::TestCase
36 MeasuringContextTestCase() { }
39 virtual void tearDown();
42 CPPUNIT_TEST_SUITE( MeasuringContextTestCase
);
43 CPPUNIT_TEST( GetTextExtent
);
44 CPPUNIT_TEST_SUITE_END();
50 DECLARE_NO_COPY_CLASS(MeasuringContextTestCase
)
53 // register in the unnamed registry so that these tests are run by default
54 CPPUNIT_TEST_SUITE_REGISTRATION( MeasuringContextTestCase
);
56 // also include in it's own registry so that these tests can be run alone
57 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MeasuringContextTestCase
, "MeasuringContextTestCase" );
59 // ----------------------------------------------------------------------------
60 // test initialization
61 // ----------------------------------------------------------------------------
63 void MeasuringContextTestCase::setUp()
65 m_win
= wxTheApp
->GetTopWindow();
68 void MeasuringContextTestCase::tearDown()
73 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
77 void MeasuringContextTestCase::GetTextExtent()
79 wxGraphicsRenderer
* renderer
= wxGraphicsRenderer::GetDefaultRenderer();
80 CPPUNIT_ASSERT(renderer
);
81 wxGraphicsContext
* context
= renderer
->CreateMeasuringContext();
82 CPPUNIT_ASSERT(context
);
83 wxFont
font(12, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
);
84 CPPUNIT_ASSERT(font
.IsOk());
85 context
->SetFont(font
, *wxBLACK
);
86 double width
, height
, descent
, externalLeading
= 0.0;
87 context
->GetTextExtent("x", &width
, &height
, &descent
, &externalLeading
);
89 // TODO: Determine a way to make these tests more robust.
90 CPPUNIT_ASSERT(width
> 0.0);
91 CPPUNIT_ASSERT(height
> 0.0);