]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/datetime/datetimetest.cpp
Fixed a couple Doxygen warnings, patch from Tim Stahlhut.
[wxWidgets.git] / tests / datetime / datetimetest.cpp
index 2da45ba1d160ff6be3e1ec75148c75eca19c780a..70dd191b99530e19900476c1fe8cc616a34603da 100644 (file)
@@ -32,6 +32,8 @@ static std::ostream& operator<<(std::ostream& ostr, const wxDateTime& dt)
     return ostr;
 }
 
+WX_CPPUNIT_ALLOW_EQUALS_TO_INT(wxDateTime::wxDateTime_t)
+
 // to test Today() meaningfully we must be able to change the system date which
 // is not usually the case, but if we're under Win32 we can try it -- define
 // the macro below to do it
@@ -281,10 +283,10 @@ void DateTimeTestCase::TestTimeJDN()
         // JDNs must be computed for UTC times
         double jdn = dt.FromUTC().GetJulianDayNumber();
 
-        CPPUNIT_ASSERT( jdn == d.jdn );
+        CPPUNIT_ASSERT_EQUAL( d.jdn, jdn );
 
         dt.Set(jdn);
-        CPPUNIT_ASSERT( dt.GetJulianDayNumber() == jdn );
+        CPPUNIT_ASSERT_EQUAL( jdn, dt.GetJulianDayNumber() );
     }
 }
 
@@ -645,7 +647,7 @@ void DateTimeTestCase::TestTimeFormat()
             const char *result = dt2.ParseFormat(s, fmt);
             if ( !result )
             {
-                // converion failed - should it have?
+                // conversion failed - should it have?
                 CPPUNIT_ASSERT( kind == CompareNone );
             }
             else // conversion succeeded
@@ -684,6 +686,37 @@ void DateTimeTestCase::TestTimeFormat()
             }
         }
     }
+
+    wxDateTime dt;
+
+    // test partially specified dates too
+    wxDateTime dtDef(26, wxDateTime::Sep, 2008);
+    CPPUNIT_ASSERT( dt.ParseFormat("17", "%d") );
+    CPPUNIT_ASSERT_EQUAL( 17, dt.GetDay() );
+
+    // test compilation of some calls which should compile (and not result in
+    // ambiguity because of char*<->wxCStrData<->wxString conversions)
+    wxString s("foo");
+    CPPUNIT_ASSERT( !dt.ParseFormat("foo") );
+    CPPUNIT_ASSERT( !dt.ParseFormat(wxT("foo")) );
+    CPPUNIT_ASSERT( !dt.ParseFormat(s) );
+    CPPUNIT_ASSERT( !dt.ParseFormat(s.c_str()) );
+
+    CPPUNIT_ASSERT( !dt.ParseFormat("foo", "%c") );
+    CPPUNIT_ASSERT( !dt.ParseFormat(wxT("foo"), "%c") );
+    CPPUNIT_ASSERT( !dt.ParseFormat(s, "%c") );
+    CPPUNIT_ASSERT( !dt.ParseFormat(s.c_str(), "%c") );
+
+    CPPUNIT_ASSERT( !dt.ParseFormat("foo", wxT("%c")) );
+    CPPUNIT_ASSERT( !dt.ParseFormat(wxT("foo"), wxT("%c")) );
+    CPPUNIT_ASSERT( !dt.ParseFormat(s, "%c") );
+    CPPUNIT_ASSERT( !dt.ParseFormat(s.c_str(), wxT("%c")) );
+
+    wxString spec("%c");
+    CPPUNIT_ASSERT( !dt.ParseFormat("foo", spec) );
+    CPPUNIT_ASSERT( !dt.ParseFormat(wxT("foo"), spec) );
+    CPPUNIT_ASSERT( !dt.ParseFormat(s, spec) );
+    CPPUNIT_ASSERT( !dt.ParseFormat(s.c_str(), spec) );
 }
 
 void DateTimeTestCase::TestTimeSpanFormat()
@@ -707,13 +740,15 @@ void DateTimeTestCase::TestTimeSpanFormat()
         {  219,  0,  0,   0, "%H",            "219"                   },
         {  219,  0,  0,   0, "%D, %H",        "9, 03"                 },
         {  219,  0,  0,   0, "%E, %D, %H",    "1, 2, 03"              },
+        {    0, -1,  0,   0, "%H:%M:%S",      "-00:01:00"             },
+        {    0,  0, -1,   0, "%H:%M:%S",      "-00:00:01"             },
     };
 
     for ( size_t n = 0; n < WXSIZEOF(testSpans); n++ )
     {
         const TimeSpanFormatTestData& td = testSpans[n];
         wxTimeSpan ts(td.h, td.min, td.sec, td.msec);
-        CPPUNIT_ASSERT_EQUAL( wxString(td.result), ts.Format(td.fmt) );
+        CPPUNIT_ASSERT_EQUAL( td.result, ts.Format(td.fmt) );
     }
 }
 
@@ -736,14 +771,14 @@ void DateTimeTestCase::TestTimeTicks()
 
         // GetValue() returns internal UTC-based representation, we need to
         // convert it to local TZ before comparing
-        long ticks = (dt.GetValue() / 1000).ToLong() + TZ_LOCAL.GetOffset();
+        time_t ticks = (dt.GetValue() / 1000).ToLong() + TZ_LOCAL.GetOffset();
         if ( dt.IsDST() )
             ticks += 3600;
-        WX_ASSERT_TIME_T_EQUAL( d.gmticks, ticks + tzOffset );
+        CPPUNIT_ASSERT_EQUAL( d.gmticks, ticks + tzOffset );
 
         dt = d.DT().FromTimezone(wxDateTime::UTC);
         ticks = (dt.GetValue() / 1000).ToLong();
-        WX_ASSERT_TIME_T_EQUAL( d.gmticks, ticks );
+        CPPUNIT_ASSERT_EQUAL( d.gmticks, ticks );
     }
 }
 
@@ -848,7 +883,6 @@ void DateTimeTestCase::TestDateParse()
 
     for ( size_t n = 0; n < WXSIZEOF(parseTestDates); n++ )
     {
-        wxDateTime dt;
         if ( dt.ParseDate(parseTestDates[n].str) )
         {
             CPPUNIT_ASSERT( parseTestDates[n].good );
@@ -953,7 +987,6 @@ void DateTimeTestCase::TestDateTimeParse()
     wxDateTime dt;
     for ( size_t n = 0; n < WXSIZEOF(parseTestDates); n++ )
     {
-        wxDateTime dt;
         if ( dt.ParseDateTime(parseTestDates[n].str) )
         {
             CPPUNIT_ASSERT( parseTestDates[n].good );