]> git.saurik.com Git - wxWidgets.git/commitdiff
Add a test to ensure that CreateMeasuringContext creates a valid context
authorKevin Ollivier <kevino@theolliviers.com>
Wed, 15 Apr 2009 22:38:53 +0000 (22:38 +0000)
committerKevin Ollivier <kevino@theolliviers.com>
Wed, 15 Apr 2009 22:38:53 +0000 (22:38 +0000)
that can measure text.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60187 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

tests/graphics/measuring.cpp [new file with mode: 0644]
tests/test.bkl

diff --git a/tests/graphics/measuring.cpp b/tests/graphics/measuring.cpp
new file mode 100644 (file)
index 0000000..b5e8419
--- /dev/null
@@ -0,0 +1,95 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        tests/controls/clientsize.cpp
+// Purpose:     Client vs. window size handling unit test
+// Author:      Vaclav Slavik
+// Created:     2008-02-12
+// RCS-ID:      $Id: clientsize.cpp 53740 2008-05-25 02:56:22Z VZ $
+// Copyright:   (c) 2008 Vaclav Slavik <vslavik@fastmail.fm>
+///////////////////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "testprec.h"
+
+#if wxUSE_GRAPHICS_CONTEXT
+
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+    #include "wx/app.h"
+    #include "wx/font.h"
+    #include "wx/window.h"
+#endif // WX_PRECOMP
+
+#include "wx/graphics.h"
+// ----------------------------------------------------------------------------
+// test class
+// ----------------------------------------------------------------------------
+
+class MeasuringContextTestCase : public CppUnit::TestCase
+{
+public:
+    MeasuringContextTestCase() { }
+
+    virtual void setUp();
+    virtual void tearDown();
+
+private:
+    CPPUNIT_TEST_SUITE( MeasuringContextTestCase );
+        CPPUNIT_TEST( GetTextExtent );
+    CPPUNIT_TEST_SUITE_END();
+
+    void GetTextExtent();
+
+    wxWindow *m_win;
+
+    DECLARE_NO_COPY_CLASS(MeasuringContextTestCase)
+};
+
+// register in the unnamed registry so that these tests are run by default
+CPPUNIT_TEST_SUITE_REGISTRATION( MeasuringContextTestCase );
+
+// also include in it's own registry so that these tests can be run alone
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MeasuringContextTestCase, "MeasuringContextTestCase" );
+
+// ----------------------------------------------------------------------------
+// test initialization
+// ----------------------------------------------------------------------------
+
+void MeasuringContextTestCase::setUp()
+{
+    m_win = wxTheApp->GetTopWindow();
+}
+
+void MeasuringContextTestCase::tearDown()
+{
+    m_win = NULL;
+}
+
+// ----------------------------------------------------------------------------
+// tests themselves
+// ----------------------------------------------------------------------------
+
+void MeasuringContextTestCase::GetTextExtent()
+{
+    wxGraphicsRenderer* renderer = wxGraphicsRenderer::GetDefaultRenderer();
+    CPPUNIT_ASSERT(renderer);
+    wxGraphicsContext* context = renderer->CreateMeasuringContext();
+    CPPUNIT_ASSERT(context);
+    wxFont font(12, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
+    CPPUNIT_ASSERT(font.IsOk());
+    context->SetFont(font, *wxBLACK);
+    double width, height, descent, externalLeading = 0.0;
+    context->GetTextExtent("x", &width, &height, &descent, &externalLeading);
+
+    // TODO: Determine a way to make these tests more robust.
+    CPPUNIT_ASSERT(width > 0.0);
+    CPPUNIT_ASSERT(height > 0.0);
+
+}
+
+#endif
index 868899f3a2b276a99ac3ca8c97239a054341764c..31507cdf569d99177ec7c7a3e1aff1ce15eecb84 100644 (file)
             geometry/rect.cpp
             geometry/size.cpp
             geometry/point.cpp
             geometry/rect.cpp
             geometry/size.cpp
             geometry/point.cpp
+            graphics/measuring.cpp
             config/config.cpp
             controls/comboboxtest.cpp
             controls/headerctrltest.cpp
             config/config.cpp
             controls/comboboxtest.cpp
             controls/headerctrltest.cpp