]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/graphics/measuring.cpp
Add a test for eol-native file existence in the release script.
[wxWidgets.git] / tests / graphics / measuring.cpp
index dbf032bee0498d9d0da2be4834958ea8e92bcda9..bc83433dbbaf94a907785d450289442ec58c2650 100644 (file)
@@ -31,6 +31,8 @@
 #endif
 
 #include "wx/dcclient.h"
 #endif
 
 #include "wx/dcclient.h"
+#include "wx/dcps.h"
+#include "wx/metafile.h"
 
 // ----------------------------------------------------------------------------
 // test class
 
 // ----------------------------------------------------------------------------
 // test class
@@ -44,6 +46,7 @@ public:
 private:
     CPPUNIT_TEST_SUITE( MeasuringTextTestCase );
         CPPUNIT_TEST( DCGetTextExtent );
 private:
     CPPUNIT_TEST_SUITE( MeasuringTextTestCase );
         CPPUNIT_TEST( DCGetTextExtent );
+        CPPUNIT_TEST( LeadingAndDescent );
         CPPUNIT_TEST( WindowGetTextExtent );
         CPPUNIT_TEST( GetPartialTextExtent );
 #ifdef TEST_GC
         CPPUNIT_TEST( WindowGetTextExtent );
         CPPUNIT_TEST( GetPartialTextExtent );
 #ifdef TEST_GC
@@ -51,10 +54,8 @@ private:
 #endif // TEST_GC
     CPPUNIT_TEST_SUITE_END();
 
 #endif // TEST_GC
     CPPUNIT_TEST_SUITE_END();
 
-    template <typename T>
-    void DoTestGetTextExtent(const T& obj);
-
     void DCGetTextExtent();
     void DCGetTextExtent();
+    void LeadingAndDescent();
     void WindowGetTextExtent();
 
     void GetPartialTextExtent();
     void WindowGetTextExtent();
 
     void GetPartialTextExtent();
@@ -73,35 +74,90 @@ CPPUNIT_TEST_SUITE_REGISTRATION( MeasuringTextTestCase );
 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MeasuringTextTestCase, "MeasuringTextTestCase" );
 
 // ----------------------------------------------------------------------------
 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MeasuringTextTestCase, "MeasuringTextTestCase" );
 
 // ----------------------------------------------------------------------------
-// tests themselves
+// helper for XXXTextExtent() methods
 // ----------------------------------------------------------------------------
 
 template <typename T>
 // ----------------------------------------------------------------------------
 
 template <typename T>
-void MeasuringTextTestCase::DoTestGetTextExtent(const T& obj)
+struct GetTextExtentTester
+{
+    // Constructor runs a couple of simple tests for GetTextExtent().
+    GetTextExtentTester(const T& obj)
+    {
+        // Test that getting the height only doesn't crash.
+        int y;
+        obj.GetTextExtent("H", NULL, &y);
+
+        CPPUNIT_ASSERT( y > 1 );
+
+        wxSize size = obj.GetTextExtent("Hello");
+        CPPUNIT_ASSERT( size.x > 1 );
+        CPPUNIT_ASSERT_EQUAL( y, size.y );
+    }
+};
+
+// ----------------------------------------------------------------------------
+// tests themselves
+// ----------------------------------------------------------------------------
+
+void MeasuringTextTestCase::DCGetTextExtent()
 {
 {
-    // Test that getting the height only doesn't crash.
-    int y;
-    obj.GetTextExtent("H", NULL, &y);
+    wxClientDC dc(wxTheApp->GetTopWindow());
+
+    GetTextExtentTester<wxClientDC> testDC(dc);
+
+    int w;
+    dc.GetMultiLineTextExtent("Good\nbye", &w, NULL);
+    const wxSize sz = dc.GetTextExtent("Good");
+    CPPUNIT_ASSERT_EQUAL( sz.x, w );
 
 
-    CPPUNIT_ASSERT( y > 1 );
+    CPPUNIT_ASSERT( dc.GetMultiLineTextExtent("Good\nbye").y >= 2*sz.y );
+
+    // Test the functions with some other DC kinds also.
+#if wxUSE_PRINTING_ARCHITECTURE && wxUSE_POSTSCRIPT
+    wxPostScriptDC psdc;
+    // wxPostScriptDC doesn't have any font set by default but its
+    // GetTextExtent() requires one to be set. This is probably a bug and we
+    // should set the default font in it implicitly but for now just work
+    // around it.
+    psdc.SetFont(*wxNORMAL_FONT);
+    GetTextExtentTester<wxPostScriptDC> testPS(psdc);
+#endif
 
 
-    wxSize size = obj.GetTextExtent("Hello");
-    CPPUNIT_ASSERT( size.x > 1 );
-    CPPUNIT_ASSERT_EQUAL( y, size.y );
+#if wxUSE_ENH_METAFILE
+    wxEnhMetaFileDC metadc;
+    GetTextExtentTester<wxEnhMetaFileDC> testMF(metadc);
+#endif
 }
 
 }
 
-void MeasuringTextTestCase::DCGetTextExtent()
+void MeasuringTextTestCase::LeadingAndDescent()
 {
     wxClientDC dc(wxTheApp->GetTopWindow());
 
 {
     wxClientDC dc(wxTheApp->GetTopWindow());
 
-    DoTestGetTextExtent(dc);
+    // Retrieving just the descent should work.
+    int descent = -17;
+    dc.GetTextExtent("foo", NULL, NULL, &descent);
+    CPPUNIT_ASSERT( descent != -17 );
+
+    // Same for external leading.
+    int leading = -289;
+    dc.GetTextExtent("foo", NULL, NULL, NULL, &leading);
+    CPPUNIT_ASSERT( leading != -289 );
+
+    // And both should also work for the empty string as they retrieve the
+    // values valid for the entire font and not just this string.
+    int descent2,
+        leading2;
+    dc.GetTextExtent("", NULL, NULL, &descent2, &leading2);
+
+    CPPUNIT_ASSERT_EQUAL( descent, descent2 );
+    CPPUNIT_ASSERT_EQUAL( leading, leading2 );
 }
 
 void MeasuringTextTestCase::WindowGetTextExtent()
 {
     wxWindow* const win = wxTheApp->GetTopWindow();
 
 }
 
 void MeasuringTextTestCase::WindowGetTextExtent()
 {
     wxWindow* const win = wxTheApp->GetTopWindow();
 
-    DoTestGetTextExtent(*win);
+    GetTextExtentTester<wxWindow> testWin(*win);
 }
 
 void MeasuringTextTestCase::GetPartialTextExtent()
 }
 
 void MeasuringTextTestCase::GetPartialTextExtent()