]>
git.saurik.com Git - wxWidgets.git/blob - tests/graphics/measuring.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/graphics/measuring.cpp
3 // Purpose: Tests for wxGraphicsRenderer::CreateMeasuringContext
4 // Author: Kevin Ollivier
7 // Copyright: (c) 2008 Kevin Ollivier <kevino@theolliviers.com>
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
16 // wxCairoRenderer::CreateMeasuringContext() is not implement for wxX11
17 #if wxUSE_GRAPHICS_CONTEXT && !defined(__WXX11__)
26 #include "wx/window.h"
29 #include "wx/graphics.h"
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 class MeasuringContextTestCase
: public CppUnit::TestCase
37 MeasuringContextTestCase() { }
40 virtual void tearDown();
43 CPPUNIT_TEST_SUITE( MeasuringContextTestCase
);
44 CPPUNIT_TEST( GetTextExtent
);
45 CPPUNIT_TEST_SUITE_END();
51 DECLARE_NO_COPY_CLASS(MeasuringContextTestCase
)
54 // register in the unnamed registry so that these tests are run by default
55 CPPUNIT_TEST_SUITE_REGISTRATION( MeasuringContextTestCase
);
57 // also include in it's own registry so that these tests can be run alone
58 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MeasuringContextTestCase
, "MeasuringContextTestCase" );
60 // ----------------------------------------------------------------------------
61 // test initialization
62 // ----------------------------------------------------------------------------
64 void MeasuringContextTestCase::setUp()
66 m_win
= wxTheApp
->GetTopWindow();
69 void MeasuringContextTestCase::tearDown()
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
78 void MeasuringContextTestCase::GetTextExtent()
80 wxGraphicsRenderer
* renderer
= wxGraphicsRenderer::GetDefaultRenderer();
81 CPPUNIT_ASSERT(renderer
);
82 wxGraphicsContext
* context
= renderer
->CreateMeasuringContext();
83 CPPUNIT_ASSERT(context
);
84 wxFont
font(12, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
);
85 CPPUNIT_ASSERT(font
.IsOk());
86 context
->SetFont(font
, *wxBLACK
);
87 double width
, height
, descent
, externalLeading
= 0.0;
88 context
->GetTextExtent("x", &width
, &height
, &descent
, &externalLeading
);
90 // TODO: Determine a way to make these tests more robust.
91 CPPUNIT_ASSERT(width
> 0.0);
92 CPPUNIT_ASSERT(height
> 0.0);