]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/longlong/longlongtest.cpp
Applied patch #15540: wxRichTextTable: crashes due to an invalid focus object (dghart)
[wxWidgets.git] / tests / longlong / longlongtest.cpp
index f93030996a45922f13f2afd9782b761bb8771f74..aaad64c942f5af924d16c4fb4bf5362990a042a1 100644 (file)
@@ -3,7 +3,6 @@
 // Purpose:     wxLongLong unit test
 // Author:      Vadim Zeitlin, Wlodzimierz ABX Skiba
 // Created:     2004-04-01
 // Purpose:     wxLongLong unit test
 // Author:      Vadim Zeitlin, Wlodzimierz ABX Skiba
 // Created:     2004-04-01
-// RCS-ID:      $Id$
 // Copyright:   (c) 2004 Vadim Zeitlin, Wlodzimierz Skiba
 ///////////////////////////////////////////////////////////////////////////////
 
 // Copyright:   (c) 2004 Vadim Zeitlin, Wlodzimierz Skiba
 ///////////////////////////////////////////////////////////////////////////////
 
@@ -24,6 +23,8 @@
 #include "wx/longlong.h"
 #include "wx/timer.h"
 
 #include "wx/longlong.h"
 #include "wx/timer.h"
 
+#if wxUSE_LONGLONG
+
 // ----------------------------------------------------------------------------
 // helpers for testing
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // helpers for testing
 // ----------------------------------------------------------------------------
@@ -66,6 +67,8 @@ private:
         CPPUNIT_TEST( Division );
         CPPUNIT_TEST( BitOperations );
         CPPUNIT_TEST( ToString );
         CPPUNIT_TEST( Division );
         CPPUNIT_TEST( BitOperations );
         CPPUNIT_TEST( ToString );
+        CPPUNIT_TEST( LoHi );
+        CPPUNIT_TEST( Limits );
     CPPUNIT_TEST_SUITE_END();
 
     void Conversion();
     CPPUNIT_TEST_SUITE_END();
 
     void Conversion();
@@ -75,6 +78,8 @@ private:
     void Division();
     void BitOperations();
     void ToString();
     void Division();
     void BitOperations();
     void ToString();
+    void LoHi();
+    void Limits();
 
     DECLARE_NO_COPY_CLASS(LongLongTestCase)
 };
 
     DECLARE_NO_COPY_CLASS(LongLongTestCase)
 };
@@ -82,7 +87,7 @@ private:
 // register in the unnamed registry so that these tests are run by default
 CPPUNIT_TEST_SUITE_REGISTRATION( LongLongTestCase );
 
 // register in the unnamed registry so that these tests are run by default
 CPPUNIT_TEST_SUITE_REGISTRATION( LongLongTestCase );
 
-// 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( LongLongTestCase, "LongLongTestCase" );
 
 LongLongTestCase::LongLongTestCase()
 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( LongLongTestCase, "LongLongTestCase" );
 
 LongLongTestCase::LongLongTestCase()
@@ -233,37 +238,37 @@ void LongLongTestCase::Division()
 
 void LongLongTestCase::BitOperations()
 {
 
 void LongLongTestCase::BitOperations()
 {
-    for ( size_t n = 0; n < ITEMS; n++ )
+    for ( size_t m = 0; m < ITEMS; m++ )
     {
         wxLongLong a = RAND_LL();
 
         for ( size_t n = 0; n < 33; n++ )
         {
             wxLongLong b(a.GetHi(), a.GetLo()), c, d = b, e;
     {
         wxLongLong a = RAND_LL();
 
         for ( size_t n = 0; n < 33; n++ )
         {
             wxLongLong b(a.GetHi(), a.GetLo()), c, d = b, e;
-            d >>= n; 
-            c = b >> n; 
+            d >>= n;
+            c = b >> n;
             CPPUNIT_ASSERT( c == d );
             CPPUNIT_ASSERT( c == d );
-            d <<= n; 
-            e = c << n; 
+            d <<= n;
+            e = c << n;
             CPPUNIT_ASSERT( d == e );
 
 #if wxUSE_LONGLONG_WX
             wxLongLongWx b1(a.GetHi(), a.GetLo()), c1, d1 = b1, e1;
             CPPUNIT_ASSERT( d == e );
 
 #if wxUSE_LONGLONG_WX
             wxLongLongWx b1(a.GetHi(), a.GetLo()), c1, d1 = b1, e1;
-            d1 >>= n; 
-            c1 = b1 >> n; 
+            d1 >>= n;
+            c1 = b1 >> n;
             CPPUNIT_ASSERT( c1 == d1 );
             CPPUNIT_ASSERT( c1 == d1 );
-            d1 <<= n; 
-            e1 = c1 << n; 
+            d1 <<= n;
+            e1 = c1 << n;
             CPPUNIT_ASSERT( d1 == e1 );
 #endif
 
 #if wxUSE_LONGLONG_NATIVE
             wxLongLongNative b2(a.GetHi(), a.GetLo()), c2, d2 = b2, e2;
             CPPUNIT_ASSERT( d1 == e1 );
 #endif
 
 #if wxUSE_LONGLONG_NATIVE
             wxLongLongNative b2(a.GetHi(), a.GetLo()), c2, d2 = b2, e2;
-            d2 >>= n; 
-            c2 = b2 >> n; 
+            d2 >>= n;
+            c2 = b2 >> n;
             CPPUNIT_ASSERT( c2 == d2 );
             CPPUNIT_ASSERT( c2 == d2 );
-            d2 <<= n; 
-            e2 = c2 << n; 
+            d2 <<= n;
+            e2 = c2 << n;
             CPPUNIT_ASSERT( d2 == e2 );
 #endif
         }
             CPPUNIT_ASSERT( d2 == e2 );
 #endif
         }
@@ -277,10 +282,14 @@ void LongLongTestCase::ToString()
     for ( size_t n = 0; n < WXSIZEOF(testLongs); n++ )
     {
         wxLongLong a = testLongs[n];
     for ( size_t n = 0; n < WXSIZEOF(testLongs); n++ )
     {
         wxLongLong a = testLongs[n];
-        s1 = wxString::Format(_T("%ld"), testLongs[n]);
+        s1 = wxString::Format(wxT("%ld"), testLongs[n]);
         s2 = a.ToString();
         CPPUNIT_ASSERT( s1 == s2 );
 
         s2 = a.ToString();
         CPPUNIT_ASSERT( s1 == s2 );
 
+        s2 = wxEmptyString;
+        s2 << a;
+        CPPUNIT_ASSERT( s1 == s2 );
+
 #if wxUSE_LONGLONG_WX
         wxLongLongWx a1 = testLongs[n];
         s2 = a1.ToString();
 #if wxUSE_LONGLONG_WX
         wxLongLongWx a1 = testLongs[n];
         s2 = a1.ToString();
@@ -295,23 +304,53 @@ void LongLongTestCase::ToString()
     }
 
     wxLongLong a(0x12345678, 0x87654321);
     }
 
     wxLongLong a(0x12345678, 0x87654321);
-    CPPUNIT_ASSERT( a.ToString() == _T("1311768467139281697") );
+    CPPUNIT_ASSERT( a.ToString() == wxT("1311768467139281697") );
     a.Negate();
     a.Negate();
-    CPPUNIT_ASSERT( a.ToString() == _T("-1311768467139281697") );
+    CPPUNIT_ASSERT( a.ToString() == wxT("-1311768467139281697") );
+
+    wxLongLong llMin(-2147483647L - 1L, 0);
+    CPPUNIT_ASSERT( llMin.ToString() == wxT("-9223372036854775808") );
 
 #if wxUSE_LONGLONG_WX
     wxLongLongWx a1(a.GetHi(), a.GetLo());
 
 #if wxUSE_LONGLONG_WX
     wxLongLongWx a1(a.GetHi(), a.GetLo());
-    CPPUNIT_ASSERT( a1.ToString() == _T("-1311768467139281697") );
+    CPPUNIT_ASSERT( a1.ToString() == wxT("-1311768467139281697") );
     a1.Negate();
     a1.Negate();
-    CPPUNIT_ASSERT( a1.ToString() == _T("1311768467139281697") );
+    CPPUNIT_ASSERT( a1.ToString() == wxT("1311768467139281697") );
 #endif
 
 #if wxUSE_LONGLONG_NATIVE
     wxLongLongNative a2(a.GetHi(), a.GetLo());
 #endif
 
 #if wxUSE_LONGLONG_NATIVE
     wxLongLongNative a2(a.GetHi(), a.GetLo());
-    CPPUNIT_ASSERT( a2.ToString() == _T("-1311768467139281697") );
+    CPPUNIT_ASSERT( a2.ToString() == wxT("-1311768467139281697") );
     a2.Negate();
     a2.Negate();
-    CPPUNIT_ASSERT( a2.ToString() == _T("1311768467139281697") );
+    CPPUNIT_ASSERT( a2.ToString() == wxT("1311768467139281697") );
 #endif
 
 }
 
 #endif
 
 }
 
+void LongLongTestCase::LoHi()
+{
+    wxLongLong ll(123, 456);
+    CPPUNIT_ASSERT_EQUAL( 456u, ll.GetLo() );
+    CPPUNIT_ASSERT_EQUAL( 123, ll.GetHi() );
+
+    wxULongLong ull(987, 654);
+    CPPUNIT_ASSERT_EQUAL( 654u, ull.GetLo() );
+    CPPUNIT_ASSERT_EQUAL( 987u, ull.GetHi() );
+}
+
+void LongLongTestCase::Limits()
+{
+    // VC6 doesn't specialize numeric_limits<> for __int64 so skip this test
+    // for it.
+#ifndef __VISUALC6__
+#if wxUSE_LONGLONG_NATIVE
+    CPPUNIT_ASSERT( std::numeric_limits<wxLongLong>::is_specialized );
+    CPPUNIT_ASSERT( std::numeric_limits<wxULongLong>::is_specialized );
+
+    wxULongLong maxval = std::numeric_limits<wxULongLong>::max();
+    CPPUNIT_ASSERT( maxval.ToDouble() > 0 );
+#endif // wxUSE_LONGLONG_NATIVE
+#endif // !__VISUALC6__
+}
+
+#endif // wxUSE_LONGLONG