]> git.saurik.com Git - wxWidgets.git/blob - tests/graphics/measuring.cpp
1a2f5e16e8a6fe8918d8cee014b152154f6e31b4
[wxWidgets.git] / tests / graphics / measuring.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/graphics/measuring.cpp
3 // Purpose: Tests for wxGraphicsRenderer::CreateMeasuringContext
4 // Author: Kevin Ollivier
5 // Created: 2008-02-12
6 // RCS-ID: $Id$
7 // Copyright: (c) 2008 Kevin Ollivier <kevino@theolliviers.com>
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // ----------------------------------------------------------------------------
11 // headers
12 // ----------------------------------------------------------------------------
13
14 #include "testprec.h"
15
16 // wxCairoRenderer::CreateMeasuringContext() is not implement for wxX11
17 #if wxUSE_GRAPHICS_CONTEXT && !defined(__WXX11__)
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/app.h"
25 #include "wx/font.h"
26 #include "wx/window.h"
27 #endif // WX_PRECOMP
28
29 #include "wx/graphics.h"
30 // ----------------------------------------------------------------------------
31 // test class
32 // ----------------------------------------------------------------------------
33
34 class MeasuringContextTestCase : public CppUnit::TestCase
35 {
36 public:
37 MeasuringContextTestCase() { }
38
39 private:
40 CPPUNIT_TEST_SUITE( MeasuringContextTestCase );
41 CPPUNIT_TEST( GetTextExtent );
42 CPPUNIT_TEST_SUITE_END();
43
44 void GetTextExtent();
45
46 DECLARE_NO_COPY_CLASS(MeasuringContextTestCase)
47 };
48
49 // register in the unnamed registry so that these tests are run by default
50 CPPUNIT_TEST_SUITE_REGISTRATION( MeasuringContextTestCase );
51
52 // also include in its own registry so that these tests can be run alone
53 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MeasuringContextTestCase, "MeasuringContextTestCase" );
54
55 // ----------------------------------------------------------------------------
56 // tests themselves
57 // ----------------------------------------------------------------------------
58
59 void MeasuringContextTestCase::GetTextExtent()
60 {
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);
70
71 // TODO: Determine a way to make these tests more robust.
72 CPPUNIT_ASSERT(width > 0.0);
73 CPPUNIT_ASSERT(height > 0.0);
74
75 }
76
77 #endif