OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <gtest/gtest.h> | 5 #include <gtest/gtest.h> |
6 | 6 |
7 #include "update_engine/update_attempter_mock.h" | 7 #include "update_engine/update_attempter_mock.h" |
8 #include "update_engine/update_check_scheduler.h" | 8 #include "update_engine/update_check_scheduler.h" |
9 | 9 |
10 using std::string; | 10 using std::string; |
(...skipping 22 matching lines...) Expand all Loading... |
33 : UpdateCheckScheduler(update_attempter) {} | 33 : UpdateCheckScheduler(update_attempter) {} |
34 | 34 |
35 MOCK_METHOD2(GTimeoutAddSeconds, guint(guint seconds, GSourceFunc function)); | 35 MOCK_METHOD2(GTimeoutAddSeconds, guint(guint seconds, GSourceFunc function)); |
36 MOCK_METHOD0(IsBootDeviceRemovable, bool()); | 36 MOCK_METHOD0(IsBootDeviceRemovable, bool()); |
37 MOCK_METHOD0(IsOfficialBuild, bool()); | 37 MOCK_METHOD0(IsOfficialBuild, bool()); |
38 MOCK_METHOD0(IsOOBEComplete, bool()); | 38 MOCK_METHOD0(IsOOBEComplete, bool()); |
39 }; | 39 }; |
40 | 40 |
41 class UpdateCheckSchedulerTest : public ::testing::Test { | 41 class UpdateCheckSchedulerTest : public ::testing::Test { |
42 public: | 42 public: |
43 UpdateCheckSchedulerTest() : scheduler_(&attempter_) {} | 43 UpdateCheckSchedulerTest() : scheduler_(&attempter_), attempter_(&dbus_) {} |
44 | 44 |
45 protected: | 45 protected: |
46 virtual void SetUp() { | 46 virtual void SetUp() { |
47 test_ = this; | 47 test_ = this; |
48 loop_ = NULL; | 48 loop_ = NULL; |
49 EXPECT_EQ(&attempter_, scheduler_.update_attempter_); | 49 EXPECT_EQ(&attempter_, scheduler_.update_attempter_); |
50 EXPECT_FALSE(scheduler_.enabled_); | 50 EXPECT_FALSE(scheduler_.enabled_); |
51 EXPECT_FALSE(scheduler_.scheduled_); | 51 EXPECT_FALSE(scheduler_.scheduled_); |
52 EXPECT_EQ(0, scheduler_.last_interval_); | 52 EXPECT_EQ(0, scheduler_.last_interval_); |
53 EXPECT_EQ(0, scheduler_.poll_interval_); | 53 EXPECT_EQ(0, scheduler_.poll_interval_); |
54 } | 54 } |
55 | 55 |
56 virtual void TearDown() { | 56 virtual void TearDown() { |
57 test_ = NULL; | 57 test_ = NULL; |
58 loop_ = NULL; | 58 loop_ = NULL; |
59 } | 59 } |
60 | 60 |
61 static gboolean SourceCallback(gpointer data) { | 61 static gboolean SourceCallback(gpointer data) { |
62 g_main_loop_quit(test_->loop_); | 62 g_main_loop_quit(test_->loop_); |
63 // Forwards the call to the function mock so that expectations can be set. | 63 // Forwards the call to the function mock so that expectations can be set. |
64 return test_->source_callback_.Call(data); | 64 return test_->source_callback_.Call(data); |
65 } | 65 } |
66 | 66 |
67 UpdateCheckSchedulerUnderTest scheduler_; | 67 UpdateCheckSchedulerUnderTest scheduler_; |
| 68 MockDbusGlib dbus_; |
68 UpdateAttempterMock attempter_; | 69 UpdateAttempterMock attempter_; |
69 MockFunction<gboolean(gpointer data)> source_callback_; | 70 MockFunction<gboolean(gpointer data)> source_callback_; |
70 GMainLoop* loop_; | 71 GMainLoop* loop_; |
71 static UpdateCheckSchedulerTest* test_; | 72 static UpdateCheckSchedulerTest* test_; |
72 }; | 73 }; |
73 | 74 |
74 UpdateCheckSchedulerTest* UpdateCheckSchedulerTest::test_ = NULL; | 75 UpdateCheckSchedulerTest* UpdateCheckSchedulerTest::test_ = NULL; |
75 | 76 |
76 TEST_F(UpdateCheckSchedulerTest, CanScheduleTest) { | 77 TEST_F(UpdateCheckSchedulerTest, CanScheduleTest) { |
77 EXPECT_FALSE(scheduler_.CanSchedule()); | 78 EXPECT_FALSE(scheduler_.CanSchedule()); |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 &interval_min, | 289 &interval_min, |
289 &interval_max); | 290 &interval_max); |
290 scheduler_.enabled_ = true; | 291 scheduler_.enabled_ = true; |
291 EXPECT_CALL(scheduler_, | 292 EXPECT_CALL(scheduler_, |
292 GTimeoutAddSeconds(AllOf(Ge(interval_min), Le(interval_max)), | 293 GTimeoutAddSeconds(AllOf(Ge(interval_min), Le(interval_max)), |
293 scheduler_.StaticCheck)).Times(1); | 294 scheduler_.StaticCheck)).Times(1); |
294 UpdateCheckSchedulerUnderTest::StaticCheck(&scheduler_); | 295 UpdateCheckSchedulerUnderTest::StaticCheck(&scheduler_); |
295 } | 296 } |
296 | 297 |
297 } // namespace chromeos_update_engine | 298 } // namespace chromeos_update_engine |
OLD | NEW |