summaryrefslogtreecommitdiffstats
path: root/base/watchdog_unittest.cc
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-25 22:46:59 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-25 22:46:59 +0000
commit95ab1553ce02175cf23278d80b8440b27740159c (patch)
tree56fc9eb4c803368b24b191c108f143c8009eb03c /base/watchdog_unittest.cc
parentd8375fdbe8d32ad3562152ecd53378383e393971 (diff)
downloadchromium_src-95ab1553ce02175cf23278d80b8440b27740159c.zip
chromium_src-95ab1553ce02175cf23278d80b8440b27740159c.tar.gz
chromium_src-95ab1553ce02175cf23278d80b8440b27740159c.tar.bz2
Port base/watchdog to Linux.
BUG=4632 Review URL: http://codereview.chromium.org/11326 Patch from Pawel Hajdan Jr. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6004 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/watchdog_unittest.cc')
-rw-r--r--base/watchdog_unittest.cc42
1 files changed, 15 insertions, 27 deletions
diff --git a/base/watchdog_unittest.cc b/base/watchdog_unittest.cc
index c4a664f..887311a 100644
--- a/base/watchdog_unittest.cc
+++ b/base/watchdog_unittest.cc
@@ -5,9 +5,10 @@
// Tests for Watchdog class.
#include "base/logging.h"
-#include "base/watchdog.h"
+#include "base/platform_thread.h"
#include "base/spin_wait.h"
#include "base/time.h"
+#include "base/watchdog.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::TimeDelta;
@@ -17,12 +18,11 @@ namespace {
//------------------------------------------------------------------------------
// Provide a derived class to facilitate testing.
-// TODO(JAR): Remove default argument from constructor, and make mandatory.
class WatchdogCounter : public Watchdog {
public:
WatchdogCounter(const TimeDelta& duration,
- const std::wstring& thread_watched_name,
- bool enabled = true)
+ const std::string& thread_watched_name,
+ bool enabled)
: Watchdog(duration, thread_watched_name, enabled), alarm_counter_(0) {
}
@@ -38,7 +38,7 @@ class WatchdogCounter : public Watchdog {
private:
int alarm_counter_;
- DISALLOW_EVIL_CONSTRUCTORS(WatchdogCounter);
+ DISALLOW_COPY_AND_ASSIGN(WatchdogCounter);
};
class WatchdogTest : public testing::Test {
@@ -50,40 +50,28 @@ class WatchdogTest : public testing::Test {
// Minimal constructor/destructor test.
TEST(WatchdogTest, StartupShutdownTest) {
- Watchdog watchdog1(TimeDelta::FromMilliseconds(300), L"Disabled", false);
- Watchdog watchdog2(TimeDelta::FromMilliseconds(300), L"Enabled", true);
-
- // The following test is depricated, and should be removed when the
- // default argument constructor is no longer accepted.
- Watchdog watchdog3(TimeDelta::FromMilliseconds(300), L"Default");
+ Watchdog watchdog1(TimeDelta::FromMilliseconds(300), "Disabled", false);
+ Watchdog watchdog2(TimeDelta::FromMilliseconds(300), "Enabled", true);
}
// Test ability to call Arm and Disarm repeatedly.
TEST(WatchdogTest, ArmDisarmTest) {
- Watchdog watchdog1(TimeDelta::FromMilliseconds(300), L"Disabled", false);
+ Watchdog watchdog1(TimeDelta::FromMilliseconds(300), "Disabled", false);
watchdog1.Arm();
watchdog1.Disarm();
watchdog1.Arm();
watchdog1.Disarm();
- Watchdog watchdog2(TimeDelta::FromMilliseconds(300), L"Enabled", true);
+ Watchdog watchdog2(TimeDelta::FromMilliseconds(300), "Enabled", true);
watchdog2.Arm();
watchdog2.Disarm();
watchdog2.Arm();
watchdog2.Disarm();
-
- // The following test is depricated, and should be removed when the
- // default argument constructor is no longer accepted.
- Watchdog watchdog3(TimeDelta::FromMilliseconds(300), L"Default");
- watchdog3.Arm();
- watchdog3.Disarm();
- watchdog3.Arm();
- watchdog3.Disarm();
}
// Make sure a basic alarm fires when the time has expired.
TEST(WatchdogTest, AlarmTest) {
- WatchdogCounter watchdog(TimeDelta::FromMilliseconds(10), L"Enabled", true);
+ WatchdogCounter watchdog(TimeDelta::FromMilliseconds(10), "Enabled", true);
watchdog.Arm();
SPIN_FOR_TIMEDELTA_OR_UNTIL_TRUE(TimeDelta::FromSeconds(1),
watchdog.alarm_counter() > 0);
@@ -100,21 +88,21 @@ TEST(WatchdogTest, AlarmTest) {
// Make sure a disable alarm does nothing, even if we arm it.
TEST(WatchdogTest, ConstructorDisabledTest) {
- WatchdogCounter watchdog(TimeDelta::FromMilliseconds(10), L"Disabled", false);
+ WatchdogCounter watchdog(TimeDelta::FromMilliseconds(10), "Disabled", false);
watchdog.Arm();
// Alarm should not fire, as it was disabled.
- Sleep(500);
+ PlatformThread::Sleep(500);
EXPECT_EQ(0, watchdog.alarm_counter());
}
// Make sure Disarming will prevent firing, even after Arming.
TEST(WatchdogTest, DisarmTest) {
- WatchdogCounter watchdog(TimeDelta::FromSeconds(1), L"Enabled", true);
+ WatchdogCounter watchdog(TimeDelta::FromSeconds(1), "Enabled", true);
watchdog.Arm();
- Sleep(100); // Don't sleep too long
+ PlatformThread::Sleep(100); // Don't sleep too long
watchdog.Disarm();
// Alarm should not fire.
- Sleep(1500);
+ PlatformThread::Sleep(1500);
EXPECT_EQ(0, watchdog.alarm_counter());
// ...but even after disarming, we can still use the alarm...