瀏覽代碼

2008-10-06 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Added test for Time::elapsed(time_t).
	* test/TimeTest.cc
Tatsuhiro Tsujikawa 17 年之前
父節點
當前提交
bb1ee91509
共有 2 個文件被更改,包括 38 次插入2 次删除
  1. 5 0
      ChangeLog
  2. 33 2
      test/TimeTest.cc

+ 5 - 0
ChangeLog

@@ -1,3 +1,8 @@
+2008-10-06  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Added test for Time::elapsed(time_t).
+	* test/TimeTest.cc
+
 2008-10-05  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Fixed the bug in Time::elapsed(): Util::difftvsec() is used where

+ 33 - 2
test/TimeTest.cc

@@ -1,9 +1,12 @@
 #include "TimeA2.h"
-#include "Exception.h"
-#include "Util.h"
+
 #include <iostream>
+
 #include <cppunit/extensions/HelperMacros.h>
 
+#include "Exception.h"
+#include "Util.h"
+
 namespace aria2 {
 
 class TimeTest:public CppUnit::TestFixture {
@@ -14,6 +17,7 @@ class TimeTest:public CppUnit::TestFixture {
   CPPUNIT_TEST(testParseRFC850Ext);
   CPPUNIT_TEST(testParseHTTPDate);
   CPPUNIT_TEST(testOperatorLess);
+  CPPUNIT_TEST(testElapsed);
   CPPUNIT_TEST_SUITE_END();
 public:
   void setUp() {}
@@ -25,6 +29,7 @@ public:
   void testParseRFC850Ext();
   void testParseHTTPDate();
   void testOperatorLess();
+  void testElapsed();
 };
 
 
@@ -82,4 +87,30 @@ void TimeTest::testOperatorLess()
   CPPUNIT_ASSERT(Time(tv2) < Time(tv1));
 }
 
+void TimeTest::testElapsed()
+{
+  struct timeval now;
+  gettimeofday(&now, 0);
+  {
+    struct timeval tv = now;
+    CPPUNIT_ASSERT(!Time(tv).elapsed(1));
+  }
+  {
+    struct timeval tv;
+    suseconds_t usec = now.tv_usec+500000;
+    if(usec > 999999) {
+      tv.tv_sec = now.tv_sec+usec/1000000;
+      tv.tv_usec = usec%1000000;
+    } else {
+      tv.tv_sec = now.tv_sec;
+      tv.tv_usec = usec;
+    }
+    CPPUNIT_ASSERT(!Time(tv).elapsed(1));
+  }
+  {
+    struct timeval tv = { now.tv_sec-1, now.tv_usec };
+    CPPUNIT_ASSERT(Time(tv).elapsed(1));
+  }
+}
+
 } // namespace aria2