]>
git.saurik.com Git - wxWidgets.git/blob - tests/graphics/measuring.cpp
1a2f5e16e8a6fe8918d8cee014b152154f6e31b4
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 CPPUNIT_TEST_SUITE( MeasuringContextTestCase
);
41 CPPUNIT_TEST( GetTextExtent
);
42 CPPUNIT_TEST_SUITE_END();
46 DECLARE_NO_COPY_CLASS(MeasuringContextTestCase
)
49 // register in the unnamed registry so that these tests are run by default
50 CPPUNIT_TEST_SUITE_REGISTRATION( MeasuringContextTestCase
);
52 // also include in its own registry so that these tests can be run alone
53 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MeasuringContextTestCase
, "MeasuringContextTestCase" );
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 void MeasuringContextTestCase::GetTextExtent()
61 wxGraphicsRenderer
* renderer
= wxGraphicsRenderer::GetDefaultRenderer();
62 CPPUNIT_ASSERT(renderer
);
63 wxGraphicsContext
* context
= renderer
->CreateMeasuringContext();
64 CPPUNIT_ASSERT(context
);
65 wxFont
font(12, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
);
66 CPPUNIT_ASSERT(font
.IsOk());
67 context
->SetFont(font
, *wxBLACK
);
68 double width
, height
, descent
, externalLeading
= 0.0;
69 context
->GetTextExtent("x", &width
, &height
, &descent
, &externalLeading
);
71 // TODO: Determine a way to make these tests more robust.
72 CPPUNIT_ASSERT(width
> 0.0);
73 CPPUNIT_ASSERT(height
> 0.0);