| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 // csync::UserShare instance for unit tests that require one. | 6 // syncer::UserShare 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 { |
| 11 // public: | 11 // public: |
| 12 // virtual void SetUp() { | 12 // virtual void SetUp() { |
| 13 // test_user_share_.SetUp(); | 13 // test_user_share_.SetUp(); |
| 14 // } | 14 // } |
| 15 // virtual void TearDown() { | 15 // virtual void TearDown() { |
| 16 // test_user_share_.TearDown(); | 16 // test_user_share_.TearDown(); |
| 17 // } | 17 // } |
| 18 // protected: | 18 // protected: |
| 19 // TestUserShare test_user_share_; | 19 // TestUserShare test_user_share_; |
| 20 // }; | 20 // }; |
| 21 // | 21 // |
| 22 // Then, in your tests: | 22 // Then, in your tests: |
| 23 // | 23 // |
| 24 // TEST_F(AwesomenessTest, IsMaximal) { | 24 // TEST_F(AwesomenessTest, IsMaximal) { |
| 25 // csync::ReadTransaction trans(test_user_share_.user_share()); | 25 // syncer::ReadTransaction trans(test_user_share_.user_share()); |
| 26 // ... | 26 // ... |
| 27 // } | 27 // } |
| 28 // | 28 // |
| 29 | 29 |
| 30 #ifndef SYNC_INTERNAL_API_PUBLIC_TEST_TEST_USER_SHARE_H_ | 30 #ifndef SYNC_INTERNAL_API_PUBLIC_TEST_TEST_USER_SHARE_H_ |
| 31 #define SYNC_INTERNAL_API_PUBLIC_TEST_TEST_USER_SHARE_H_ | 31 #define SYNC_INTERNAL_API_PUBLIC_TEST_TEST_USER_SHARE_H_ |
| 32 #pragma once | 32 #pragma once |
| 33 | 33 |
| 34 #include "base/basictypes.h" | 34 #include "base/basictypes.h" |
| 35 #include "sync/internal_api/public/user_share.h" | 35 #include "sync/internal_api/public/user_share.h" |
| 36 | 36 |
| 37 namespace csync { | 37 namespace syncer { |
| 38 | 38 |
| 39 class TestDirectorySetterUpper; | 39 class TestDirectorySetterUpper; |
| 40 | 40 |
| 41 class TestUserShare { | 41 class TestUserShare { |
| 42 public: | 42 public: |
| 43 TestUserShare(); | 43 TestUserShare(); |
| 44 ~TestUserShare(); | 44 ~TestUserShare(); |
| 45 | 45 |
| 46 // Sets up the UserShare instance. Clears any existing database | 46 // Sets up the UserShare instance. Clears any existing database |
| 47 // backing files that might exist on disk. | 47 // backing files that might exist on disk. |
| 48 void SetUp(); | 48 void SetUp(); |
| 49 | 49 |
| 50 // Undo everything done by SetUp(): closes the UserShare and deletes | 50 // Undo everything done by SetUp(): closes the UserShare and deletes |
| 51 // the backing files. Before closing the directory, this will run | 51 // the backing files. Before closing the directory, this will run |
| 52 // the directory invariant checks and perform the SaveChanges action | 52 // the directory invariant checks and perform the SaveChanges action |
| 53 // on the user share's directory. | 53 // on the user share's directory. |
| 54 void TearDown(); | 54 void TearDown(); |
| 55 | 55 |
| 56 // Non-NULL iff called between a call to SetUp() and TearDown(). | 56 // Non-NULL iff called between a call to SetUp() and TearDown(). |
| 57 csync::UserShare* user_share(); | 57 syncer::UserShare* user_share(); |
| 58 | 58 |
| 59 private: | 59 private: |
| 60 scoped_ptr<TestDirectorySetterUpper> dir_maker_; | 60 scoped_ptr<TestDirectorySetterUpper> dir_maker_; |
| 61 scoped_ptr<csync::UserShare> user_share_; | 61 scoped_ptr<syncer::UserShare> user_share_; |
| 62 | 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(TestUserShare); | 63 DISALLOW_COPY_AND_ASSIGN(TestUserShare); |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 } // namespace csync | 66 } // namespace syncer |
| 67 | 67 |
| 68 #endif // SYNC_INTERNAL_API_PUBLIC_TEST_TEST_USER_SHARE_H_ | 68 #endif // SYNC_INTERNAL_API_PUBLIC_TEST_TEST_USER_SHARE_H_ |
| OLD | NEW |