Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(297)

Side by Side Diff: base/test/mock_time_provider.h

Issue 7232023: Added last_modified field to TemplateURL and database. Updated unit tests, including refactoring ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/base.gyp ('k') | base/test/mock_time_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // A helper class used to mock out calls to the static method base::Time::Now.
6 //
7 // Example usage:
8 //
9 // typedef base::Time(TimeProvider)();
10 // class StopWatch {
11 // public:
12 // StopWatch(TimeProvider* time_provider);
13 // void Start();
14 // base::TimeDelta Stop();
15 // private:
16 // TimeProvider* time_provider_;
17 // ...
18 // }
19 //
20 // Normally, you would instantiate a StopWatch with the real Now function:
21 //
22 // StopWatch watch(&base::Time::Now);
23 //
24 // But when testing, you want to instantiate it with
25 // MockTimeProvider::StaticNow, which calls an internally mocked out member.
26 // This allows you to set expectations on the Now method. For example:
27 //
28 // TEST_F(StopWatchTest, BasicTest) {
29 // InSequence s;
30 // StrictMock<MockTimeProvider> mock_time;
31 // EXPECT_CALL(mock_time, Now())
32 // .WillOnce(Return(Time::FromDoubleT(4)));
33 // EXPECT_CALL(mock_time, Now())
34 // .WillOnce(Return(Time::FromDoubleT(10)));
35 //
36 // StopWatch sw(&MockTimeProvider::StaticNow);
37 // sw.Start(); // First call to Now.
38 // TimeDelta elapsed = sw.stop(); // Second call to Now.
39 // ASSERT_EQ(elapsed, TimeDelta::FromSeconds(6));
40 // }
41
42 #include "base/time.h"
43 #include "testing/gmock/include/gmock/gmock.h"
44
45 #ifndef BASE_TEST_MOCK_TIME_PROVIDER_H_
46 #define BASE_TEST_MOCK_TIME_PROVIDER_H_
47
48 namespace base {
49
50 class MockTimeProvider {
51 public:
52 MockTimeProvider();
53 ~MockTimeProvider();
54
55 MOCK_METHOD0(Now, Time());
56
57 static Time StaticNow();
58
59 private:
60 static MockTimeProvider* instance_;
61 DISALLOW_COPY_AND_ASSIGN(MockTimeProvider);
62 };
63
64 } // namespace base
65
66 #endif // BASE_TEST_MOCK_TIME_PROVIDER_H_
OLDNEW
« no previous file with comments | « base/base.gyp ('k') | base/test/mock_time_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698