| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium 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 // A handy class that takes care of setting up and destroying a | 5 // A handy class that takes care of setting up and destroying a |
| 6 // syncable::Directory instance for unit tests that require one. | 6 // syncable::Directory instance for unit tests that require one. |
| 7 // | 7 // |
| 8 // The expected usage is to make this a component of your test fixture: | 8 // The expected usage is to make this a component of your test fixture: |
| 9 // | 9 // |
| 10 // class AwesomenessTest : public testing::Test { | 10 // class AwesomenessTest : public testing::Test { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 namespace syncable { | 37 namespace syncable { |
| 38 class DirectoryManager; | 38 class DirectoryManager; |
| 39 class ScopedDirLookup; | 39 class ScopedDirLookup; |
| 40 } // namespace syncable | 40 } // namespace syncable |
| 41 | 41 |
| 42 namespace browser_sync { | 42 namespace browser_sync { |
| 43 | 43 |
| 44 class TestDirectorySetterUpper { | 44 class TestDirectorySetterUpper { |
| 45 public: | 45 public: |
| 46 TestDirectorySetterUpper(); | 46 TestDirectorySetterUpper(); |
| 47 virtual ~TestDirectorySetterUpper(); | 47 ~TestDirectorySetterUpper(); |
| 48 | 48 |
| 49 // Create a DirectoryManager instance and use it to open the directory. | 49 // Create a DirectoryManager instance and use it to open the directory. |
| 50 // Clears any existing database backing files that might exist on disk. | 50 // Clears any existing database backing files that might exist on disk. |
| 51 virtual void SetUp(); | 51 void SetUp(); |
| 52 | 52 |
| 53 // Undo everything done by SetUp(): close the directory and delete the | 53 // Undo everything done by SetUp(): close the directory and delete the |
| 54 // backing files. Before closing the directory, this will run the directory | 54 // backing files. Before closing the directory, this will run the directory |
| 55 // invariant checks and perform the SaveChanges action on the directory. | 55 // invariant checks and perform the SaveChanges action on the directory. |
| 56 virtual void TearDown(); | 56 void TearDown(); |
| 57 | 57 |
| 58 syncable::DirectoryManager* manager() const { return manager_.get(); } | 58 syncable::DirectoryManager* manager() const { return manager_.get(); } |
| 59 const PathString& name() const { return name_; } | 59 const PathString& name() const { return name_; } |
| 60 | 60 |
| 61 protected: | |
| 62 virtual void Init(); | |
| 63 | |
| 64 private: | 61 private: |
| 65 void RunInvariantCheck(const syncable::ScopedDirLookup& dir); | 62 void RunInvariantCheck(const syncable::ScopedDirLookup& dir); |
| 66 | 63 |
| 67 scoped_ptr<syncable::DirectoryManager> manager_; | 64 scoped_ptr<syncable::DirectoryManager> manager_; |
| 68 const PathString name_; | 65 const PathString name_; |
| 69 PathString file_path_; | 66 PathString file_path_; |
| 70 }; | 67 }; |
| 71 | 68 |
| 72 // A variant of the above where SetUp does not actually open the directory. | |
| 73 // You must manually invoke Open(). This is useful if you are writing a test | |
| 74 // that depends on the DirectoryManager::OPENED event. | |
| 75 class ManuallyOpenedTestDirectorySetterUpper : public TestDirectorySetterUpper { | |
| 76 public: | |
| 77 ManuallyOpenedTestDirectorySetterUpper() : was_opened_(false) {} | |
| 78 virtual void SetUp(); | |
| 79 virtual void TearDown(); | |
| 80 void Open(); | |
| 81 private: | |
| 82 bool was_opened_; | |
| 83 }; | |
| 84 | |
| 85 } // namespace browser_sync | 69 } // namespace browser_sync |
| 86 | 70 |
| 87 #endif // CHROME_TEST_SYNC_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_ | 71 #endif // CHROME_TEST_SYNC_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_ |
| OLD | NEW |