OLD | NEW |
| (Empty) |
1 // Copyright 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 #include "sync/internal_api/public/test/test_user_share.h" | |
6 | |
7 #include <stddef.h> | |
8 | |
9 #include "base/compiler_specific.h" | |
10 #include "sync/syncable/directory.h" | |
11 #include "sync/syncable/mutable_entry.h" | |
12 #include "sync/syncable/syncable_read_transaction.h" | |
13 #include "sync/syncable/syncable_write_transaction.h" | |
14 #include "sync/test/engine/test_directory_setter_upper.h" | |
15 #include "sync/test/engine/test_id_factory.h" | |
16 #include "sync/test/engine/test_syncable_utils.h" | |
17 #include "testing/gtest/include/gtest/gtest.h" | |
18 | |
19 namespace syncer { | |
20 | |
21 TestUserShare::TestUserShare() : dir_maker_(new TestDirectorySetterUpper()) {} | |
22 | |
23 TestUserShare::~TestUserShare() { | |
24 if (user_share_) | |
25 ADD_FAILURE() << "Should have called TestUserShare::TearDown()"; | |
26 } | |
27 | |
28 void TestUserShare::SetUp() { | |
29 user_share_.reset(new UserShare()); | |
30 dir_maker_->SetUp(); | |
31 | |
32 // The pointer is owned by dir_maker_, we should not be storing it in a | |
33 // unique_ptr. We must be careful to ensure the unique_ptr never deletes it. | |
34 user_share_->directory.reset(dir_maker_->directory()); | |
35 } | |
36 | |
37 void TestUserShare::TearDown() { | |
38 // Ensure the unique_ptr doesn't delete the memory we don't own. | |
39 ignore_result(user_share_->directory.release()); | |
40 | |
41 user_share_.reset(); | |
42 dir_maker_->TearDown(); | |
43 } | |
44 | |
45 bool TestUserShare::Reload() { | |
46 if (!user_share_->directory->SaveChanges()) | |
47 return false; | |
48 | |
49 syncer::syncable::DirectoryBackingStore* saved_store = | |
50 user_share_->directory->store_.release(); | |
51 | |
52 // Ensure the unique_ptr doesn't delete the memory we don't own. | |
53 ignore_result(user_share_->directory.release()); | |
54 user_share_.reset(new UserShare()); | |
55 dir_maker_->SetUpWith(saved_store); | |
56 user_share_->directory.reset(dir_maker_->directory()); | |
57 return true; | |
58 } | |
59 | |
60 UserShare* TestUserShare::user_share() { | |
61 return user_share_.get(); | |
62 } | |
63 | |
64 SyncEncryptionHandler* TestUserShare::encryption_handler() { | |
65 return dir_maker_->encryption_handler(); | |
66 } | |
67 | |
68 syncable::TestTransactionObserver* TestUserShare::transaction_observer() { | |
69 return dir_maker_->transaction_observer(); | |
70 } | |
71 | |
72 /* static */ | |
73 bool TestUserShare::CreateRoot(ModelType model_type, UserShare* user_share) { | |
74 syncer::syncable::Directory* directory = user_share->directory.get(); | |
75 syncable::WriteTransaction wtrans(FROM_HERE, syncable::UNITTEST, directory); | |
76 CreateTypeRoot(&wtrans, directory, model_type); | |
77 return true; | |
78 } | |
79 | |
80 size_t TestUserShare::GetDeleteJournalSize() const { | |
81 syncable::ReadTransaction trans(FROM_HERE, user_share_->directory.get()); | |
82 return user_share_->directory->delete_journal()->GetDeleteJournalSize(&trans); | |
83 } | |
84 | |
85 } // namespace syncer | |
OLD | NEW |