]> git.saurik.com Git - wxWidgets.git/blob - tests/graphics/measuring.cpp
Implement cut / copy / paste in osx webkit and fix the function stubs.
[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 virtual void setUp();
40 virtual void tearDown();
41
42 private:
43 CPPUNIT_TEST_SUITE( MeasuringContextTestCase );
44 CPPUNIT_TEST( GetTextExtent );
45 CPPUNIT_TEST_SUITE_END();
46
47 void GetTextExtent();
48
49 wxWindow *m_win;
50
51 DECLARE_NO_COPY_CLASS(MeasuringContextTestCase)
52 };
53
54 // register in the unnamed registry so that these tests are run by default
55 CPPUNIT_TEST_SUITE_REGISTRATION( MeasuringContextTestCase );
56
57 // also include in its own registry so that these tests can be run alone
58 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MeasuringContextTestCase, "MeasuringContextTestCase" );
59
60 // ----------------------------------------------------------------------------
61 // test initialization
62 // ----------------------------------------------------------------------------
63
64 void MeasuringContextTestCase::setUp()
65 {
66 m_win = wxTheApp->GetTopWindow();
67 }
68
69 void MeasuringContextTestCase::tearDown()
70 {
71 m_win = NULL;
72 }
73
74 // ----------------------------------------------------------------------------
75 // tests themselves
76 // ----------------------------------------------------------------------------
77
78 void MeasuringContextTestCase::GetTextExtent()
79 {
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);
89
90 // TODO: Determine a way to make these tests more robust.
91 CPPUNIT_ASSERT(width > 0.0);
92 CPPUNIT_ASSERT(height > 0.0);
93
94 }
95
96 #endif