OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 handy class that takes care of setting up and destroying a | |
6 // syncable::Directory instance for unit tests that require one. | |
7 // | |
8 // The expected usage is to make this a component of your test fixture: | |
9 // | |
10 // class AwesomenessTest : public testing::Test { | |
11 // public: | |
12 // virtual void SetUp() { | |
13 // metadb_.SetUp(); | |
14 // } | |
15 // virtual void TearDown() { | |
16 // metadb_.TearDown(); | |
17 // } | |
18 // protected: | |
19 // TestDirectorySetterUpper metadb_; | |
20 // }; | |
21 // | |
22 // Then, in your tests, get at the directory like so: | |
23 // | |
24 // TEST_F(AwesomenessTest, IsMaximal) { | |
25 // ... now use metadb_.directory() to get at syncable::Entry objects ... | |
26 // } | |
27 // | |
28 | |
29 #ifndef CHROME_BROWSER_SYNC_TEST_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_ | |
30 #define CHROME_BROWSER_SYNC_TEST_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_ | |
31 #pragma once | |
32 | |
33 #include <string> | |
34 | |
35 #include "base/basictypes.h" | |
36 #include "base/compiler_specific.h" | |
37 #include "base/memory/scoped_ptr.h" | |
38 #include "base/scoped_temp_dir.h" | |
39 #include "chrome/browser/sync/internal_api/includes/test_unrecoverable_error_han
dler.h" | |
40 #include "chrome/browser/sync/syncable/syncable.h" | |
41 #include "chrome/browser/sync/test/fake_encryptor.h" | |
42 #include "chrome/browser/sync/test/null_directory_change_delegate.h" | |
43 #include "testing/gmock/include/gmock/gmock.h" | |
44 | |
45 namespace browser_sync { | |
46 | |
47 class TestDirectorySetterUpper { | |
48 public: | |
49 TestDirectorySetterUpper(); | |
50 virtual ~TestDirectorySetterUpper(); | |
51 | |
52 // Create a Directory instance open it. | |
53 virtual void SetUp(); | |
54 | |
55 // Undo everything done by SetUp(): close the directory and delete the | |
56 // backing files. Before closing the directory, this will run the directory | |
57 // invariant checks and perform the SaveChanges action on the directory. | |
58 virtual void TearDown(); | |
59 | |
60 syncable::Directory* directory() { return directory_.get(); } | |
61 | |
62 protected: | |
63 syncable::NullDirectoryChangeDelegate delegate_; | |
64 TestUnrecoverableErrorHandler handler_; | |
65 | |
66 private: | |
67 void RunInvariantCheck(); | |
68 | |
69 ScopedTempDir temp_dir_; | |
70 FakeEncryptor encryptor_; | |
71 scoped_ptr<syncable::Directory> directory_; | |
72 std::string name_; | |
73 | |
74 DISALLOW_COPY_AND_ASSIGN(TestDirectorySetterUpper); | |
75 }; | |
76 | |
77 } // namespace browser_sync | |
78 | |
79 #endif // CHROME_BROWSER_SYNC_TEST_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_ | |
OLD | NEW |