OLD | NEW |
(Empty) | |
| 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 |
| 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 // ScopedDirLookup dir(metadb_.manager(), metadb_.name()); |
| 26 // ... now use |dir| to get at syncable::Entry objects ... |
| 27 // } |
| 28 // |
| 29 |
| 30 #ifndef CHROME_TEST_SYNC_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_ |
| 31 #define CHROME_TEST_SYNC_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_ |
| 32 |
| 33 #include "base/scoped_ptr.h" |
| 34 #include "chrome/browser/sync/syncable/syncable.h" |
| 35 #include "chrome/browser/sync/util/sync_types.h" |
| 36 |
| 37 namespace syncable { |
| 38 class DirectoryManager; |
| 39 class ScopedDirLookup; |
| 40 } // namespace syncable |
| 41 |
| 42 namespace browser_sync { |
| 43 |
| 44 class TestDirectorySetterUpper { |
| 45 public: |
| 46 TestDirectorySetterUpper(); |
| 47 ~TestDirectorySetterUpper(); |
| 48 |
| 49 // Create a DirectoryManager instance and use it to open the directory. |
| 50 // Clears any existing database backing files that might exist on disk. |
| 51 void SetUp(); |
| 52 |
| 53 // Undo everything done by SetUp(): close the directory and delete |
| 54 // the backing files. Before closing the directory, this will run the |
| 55 // directory invariant checks and perform the SaveChanges action on |
| 56 // the directory. |
| 57 void TearDown(); |
| 58 |
| 59 syncable::DirectoryManager* manager() const { return manager_.get(); } |
| 60 const PathString& name() const { return name_; } |
| 61 |
| 62 private: |
| 63 void RunInvariantCheck(const syncable::ScopedDirLookup& dir); |
| 64 |
| 65 scoped_ptr<syncable::DirectoryManager> manager_; |
| 66 const PathString name_; |
| 67 PathString file_path_; |
| 68 }; |
| 69 |
| 70 } // namespace browser_sync |
| 71 |
| 72 #endif // CHROME_TEST_SYNC_ENGINE_TEST_DIRECTORY_SETTER_UPPER_H_ |
OLD | NEW |