]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/strings/numformatter.cpp
Recreate GtkPrintOperation every time when printing in wxGTK.
[wxWidgets.git] / tests / strings / numformatter.cpp
index 30784dd12098905fc7113eb6f3a6f1b3ab7de063..f5262b289f8211f7f8c382ba88f0d163512edbb2 100644 (file)
 class NumFormatterTestCase : public CppUnit::TestCase
 {
 public:
-    NumFormatterTestCase()
+    NumFormatterTestCase() { m_locale = NULL; }
+
+    virtual void setUp()
     {
         // We need to use a locale with known decimal point and which uses the
         // thousands separator for the tests to make sense.
-        wxLanguage lang;
-        if ( wxLocale::IsAvailable(wxLANGUAGE_ENGLISH_US) )
-            lang = wxLANGUAGE_ENGLISH_US;
-        else if ( wxLocale::IsAvailable(wxLANGUAGE_ENGLISH_UK) )
-            lang = wxLANGUAGE_ENGLISH_UK;
-        else
-        {
-            m_locale = NULL;
-            return;
-        }
-
-        m_locale = new wxLocale(lang, wxLOCALE_DONT_LOAD_DEFAULT);
+        m_locale = new wxLocale(wxLANGUAGE_ENGLISH_UK,
+                                wxLOCALE_DONT_LOAD_DEFAULT);
+        if ( !m_locale->IsOk() )
+            tearDown();
     }
 
-    virtual ~NumFormatterTestCase()
+    virtual void tearDown()
     {
         delete m_locale;
+        m_locale = NULL;
     }
 
 private:
     CPPUNIT_TEST_SUITE( NumFormatterTestCase );
         CPPUNIT_TEST( LongToString );
+#ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
+        CPPUNIT_TEST( LongLongToString );
+#endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
         CPPUNIT_TEST( DoubleToString );
         CPPUNIT_TEST( NoTrailingZeroes );
         CPPUNIT_TEST( LongFromString );
+#ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
+        CPPUNIT_TEST( LongLongFromString );
+#endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
         CPPUNIT_TEST( DoubleFromString );
     CPPUNIT_TEST_SUITE_END();
 
     void LongToString();
+#ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
+    void LongLongToString();
+#endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
     void DoubleToString();
     void NoTrailingZeroes();
     void LongFromString();
+#ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
+    void LongLongFromString();
+#endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
     void DoubleFromString();
 
     wxLocale *m_locale;
@@ -73,7 +80,7 @@ private:
 // register in the unnamed registry so that these tests are run by default
 CPPUNIT_TEST_SUITE_REGISTRATION( NumFormatterTestCase );
 
-// also include in it's own registry so that these tests can be run alone
+// also include in its own registry so that these tests can be run alone
 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( NumFormatterTestCase, "NumFormatterTestCase" );
 
 // ----------------------------------------------------------------------------
@@ -85,17 +92,45 @@ void NumFormatterTestCase::LongToString()
     if ( !m_locale )
         return;
 
-    CPPUNIT_ASSERT_EQUAL(          "1", wxNumberFormatter::ToString(         1));
-    CPPUNIT_ASSERT_EQUAL(         "12", wxNumberFormatter::ToString(        12));
-    CPPUNIT_ASSERT_EQUAL(        "123", wxNumberFormatter::ToString(       123));
-    CPPUNIT_ASSERT_EQUAL(      "1,234", wxNumberFormatter::ToString(      1234));
-    CPPUNIT_ASSERT_EQUAL(     "12,345", wxNumberFormatter::ToString(     12345));
-    CPPUNIT_ASSERT_EQUAL(    "123,456", wxNumberFormatter::ToString(    123456));
-    CPPUNIT_ASSERT_EQUAL(  "1,234,567", wxNumberFormatter::ToString(   1234567));
-    CPPUNIT_ASSERT_EQUAL( "12,345,678", wxNumberFormatter::ToString(  12345678));
-    CPPUNIT_ASSERT_EQUAL("123,456,789", wxNumberFormatter::ToString( 123456789));
+    CPPUNIT_ASSERT_EQUAL(          "1", wxNumberFormatter::ToString(         1L));
+    CPPUNIT_ASSERT_EQUAL(         "-1", wxNumberFormatter::ToString(        -1L));
+    CPPUNIT_ASSERT_EQUAL(         "12", wxNumberFormatter::ToString(        12L));
+    CPPUNIT_ASSERT_EQUAL(        "-12", wxNumberFormatter::ToString(       -12L));
+    CPPUNIT_ASSERT_EQUAL(        "123", wxNumberFormatter::ToString(       123L));
+    CPPUNIT_ASSERT_EQUAL(       "-123", wxNumberFormatter::ToString(      -123L));
+    CPPUNIT_ASSERT_EQUAL(      "1,234", wxNumberFormatter::ToString(      1234L));
+    CPPUNIT_ASSERT_EQUAL(     "-1,234", wxNumberFormatter::ToString(     -1234L));
+    CPPUNIT_ASSERT_EQUAL(     "12,345", wxNumberFormatter::ToString(     12345L));
+    CPPUNIT_ASSERT_EQUAL(    "-12,345", wxNumberFormatter::ToString(    -12345L));
+    CPPUNIT_ASSERT_EQUAL(    "123,456", wxNumberFormatter::ToString(    123456L));
+    CPPUNIT_ASSERT_EQUAL(   "-123,456", wxNumberFormatter::ToString(   -123456L));
+    CPPUNIT_ASSERT_EQUAL(  "1,234,567", wxNumberFormatter::ToString(   1234567L));
+    CPPUNIT_ASSERT_EQUAL( "-1,234,567", wxNumberFormatter::ToString(  -1234567L));
+    CPPUNIT_ASSERT_EQUAL( "12,345,678", wxNumberFormatter::ToString(  12345678L));
+    CPPUNIT_ASSERT_EQUAL("-12,345,678", wxNumberFormatter::ToString( -12345678L));
+    CPPUNIT_ASSERT_EQUAL("123,456,789", wxNumberFormatter::ToString( 123456789L));
 }
 
+#ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
+
+void NumFormatterTestCase::LongLongToString()
+{
+    if ( !m_locale )
+        return;
+
+    CPPUNIT_ASSERT_EQUAL(          "1", wxNumberFormatter::ToString(wxLL(         1)));
+    CPPUNIT_ASSERT_EQUAL(         "12", wxNumberFormatter::ToString(wxLL(        12)));
+    CPPUNIT_ASSERT_EQUAL(        "123", wxNumberFormatter::ToString(wxLL(       123)));
+    CPPUNIT_ASSERT_EQUAL(      "1,234", wxNumberFormatter::ToString(wxLL(      1234)));
+    CPPUNIT_ASSERT_EQUAL(     "12,345", wxNumberFormatter::ToString(wxLL(     12345)));
+    CPPUNIT_ASSERT_EQUAL(    "123,456", wxNumberFormatter::ToString(wxLL(    123456)));
+    CPPUNIT_ASSERT_EQUAL(  "1,234,567", wxNumberFormatter::ToString(wxLL(   1234567)));
+    CPPUNIT_ASSERT_EQUAL( "12,345,678", wxNumberFormatter::ToString(wxLL(  12345678)));
+    CPPUNIT_ASSERT_EQUAL("123,456,789", wxNumberFormatter::ToString(wxLL( 123456789)));
+}
+
+#endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
+
 void NumFormatterTestCase::DoubleToString()
 {
     if ( !m_locale )
@@ -196,6 +231,44 @@ void NumFormatterTestCase::LongFromString()
     CPPUNIT_ASSERT_EQUAL( 1234567, l );
 }
 
+#ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
+
+void NumFormatterTestCase::LongLongFromString()
+{
+    if ( !m_locale )
+        return;
+
+    WX_ASSERT_FAILS_WITH_ASSERT
+    (
+        wxNumberFormatter::FromString("123", static_cast<wxLongLong_t *>(0))
+    );
+
+    wxLongLong_t l;
+    CPPUNIT_ASSERT( !wxNumberFormatter::FromString("", &l) );
+    CPPUNIT_ASSERT( !wxNumberFormatter::FromString("foo", &l) );
+    CPPUNIT_ASSERT( !wxNumberFormatter::FromString("1.234", &l) );
+
+    CPPUNIT_ASSERT( wxNumberFormatter::FromString("123", &l) );
+    CPPUNIT_ASSERT_EQUAL( 123, l );
+
+    CPPUNIT_ASSERT( wxNumberFormatter::FromString("1234", &l) );
+    CPPUNIT_ASSERT_EQUAL( 1234, l );
+
+    CPPUNIT_ASSERT( wxNumberFormatter::FromString("1,234", &l) );
+    CPPUNIT_ASSERT_EQUAL( 1234, l );
+
+    CPPUNIT_ASSERT( wxNumberFormatter::FromString("12,345", &l) );
+    CPPUNIT_ASSERT_EQUAL( 12345, l );
+
+    CPPUNIT_ASSERT( wxNumberFormatter::FromString("123,456", &l) );
+    CPPUNIT_ASSERT_EQUAL( 123456, l );
+
+    CPPUNIT_ASSERT( wxNumberFormatter::FromString("1,234,567", &l) );
+    CPPUNIT_ASSERT_EQUAL( 1234567, l );
+}
+
+#endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG
+
 void NumFormatterTestCase::DoubleFromString()
 {
     if ( !m_locale )