| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "sync/test/engine/test_directory_setter_upper.h" | 5 #include "sync/test/engine/test_directory_setter_upper.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "sync/syncable/directory.h" | 11 #include "sync/syncable/directory.h" |
| 12 #include "sync/syncable/in_memory_directory_backing_store.h" | 12 #include "sync/syncable/in_memory_directory_backing_store.h" |
| 13 #include "sync/syncable/mutable_entry.h" | 13 #include "sync/syncable/mutable_entry.h" |
| 14 #include "sync/syncable/syncable_read_transaction.h" | 14 #include "sync/syncable/syncable_read_transaction.h" |
| 15 #include "sync/syncable/syncable_write_transaction.h" | 15 #include "sync/syncable/syncable_write_transaction.h" |
| 16 #include "sync/test/test_transaction_observer.h" | 16 #include "sync/test/test_transaction_observer.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 namespace syncer { | 19 namespace syncer { |
| 20 | 20 |
| 21 TestDirectorySetterUpper::TestDirectorySetterUpper() : name_("Test") {} | 21 TestDirectorySetterUpper::TestDirectorySetterUpper() : name_("Test") {} |
| 22 | 22 |
| 23 TestDirectorySetterUpper::~TestDirectorySetterUpper() {} | 23 TestDirectorySetterUpper::~TestDirectorySetterUpper() {} |
| 24 | 24 |
| 25 void TestDirectorySetterUpper::SetUp() { | 25 void TestDirectorySetterUpper::SetUp() { |
| 26 test_transaction_observer_.reset(new syncable::TestTransactionObserver()); | 26 test_transaction_observer_.reset(new syncable::TestTransactionObserver()); |
| 27 WeakHandle<syncable::TransactionObserver> transaction_observer = | 27 WeakHandle<syncable::TransactionObserver> transaction_observer = |
| 28 MakeWeakHandle(test_transaction_observer_->AsWeakPtr()); | 28 MakeWeakHandle(test_transaction_observer_->AsWeakPtr()); |
| 29 | 29 |
| 30 directory_.reset(new syncable::Directory( | 30 directory_.reset( |
| 31 new syncable::InMemoryDirectoryBackingStore(name_), | 31 new syncable::Directory( |
| 32 &handler_, | 32 new syncable::InMemoryDirectoryBackingStore(name_), |
| 33 NULL, | 33 &handler_, |
| 34 &encryption_handler_, | 34 NULL, |
| 35 encryption_handler_.cryptographer())); | 35 &encryption_handler_, |
| 36 encryption_handler_.cryptographer())); |
| 36 ASSERT_EQ(syncable::OPENED, directory_->Open( | 37 ASSERT_EQ(syncable::OPENED, directory_->Open( |
| 37 name_, &delegate_, transaction_observer)); | 38 name_, &delegate_, transaction_observer)); |
| 38 } | 39 } |
| 39 | 40 |
| 41 void TestDirectorySetterUpper::SetUpWith( |
| 42 syncer::syncable::DirectoryBackingStore* directory_store) { |
| 43 CHECK(directory_store); |
| 44 test_transaction_observer_.reset(new syncable::TestTransactionObserver()); |
| 45 WeakHandle<syncable::TransactionObserver> transaction_observer = |
| 46 MakeWeakHandle(test_transaction_observer_->AsWeakPtr()); |
| 47 |
| 48 directory_.reset( |
| 49 new syncable::Directory(directory_store, |
| 50 &handler_, |
| 51 NULL, |
| 52 &encryption_handler_, |
| 53 encryption_handler_.cryptographer())); |
| 54 ASSERT_EQ(syncable::OPENED, directory_->Open( |
| 55 name_, &delegate_, transaction_observer)); |
| 56 } |
| 57 |
| 40 void TestDirectorySetterUpper::TearDown() { | 58 void TestDirectorySetterUpper::TearDown() { |
| 41 if (!directory()->good()) | 59 if (!directory()->good()) |
| 42 return; | 60 return; |
| 43 | 61 |
| 44 RunInvariantCheck(); | 62 RunInvariantCheck(); |
| 45 directory()->SaveChanges(); | 63 directory()->SaveChanges(); |
| 46 RunInvariantCheck(); | 64 RunInvariantCheck(); |
| 47 directory()->SaveChanges(); | 65 directory()->SaveChanges(); |
| 48 | 66 |
| 49 directory_.reset(); | 67 directory_.reset(); |
| 50 } | 68 } |
| 51 | 69 |
| 52 void TestDirectorySetterUpper::RunInvariantCheck() { | 70 void TestDirectorySetterUpper::RunInvariantCheck() { |
| 53 // Check invariants for all items. | 71 // Check invariants for all items. |
| 54 syncable::ReadTransaction trans(FROM_HERE, directory()); | 72 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 55 | 73 |
| 56 // The TestUnrecoverableErrorHandler that this directory was constructed with | 74 // The TestUnrecoverableErrorHandler that this directory was constructed with |
| 57 // will handle error reporting, so we can safely ignore the return value. | 75 // will handle error reporting, so we can safely ignore the return value. |
| 58 directory()->FullyCheckTreeInvariants(&trans); | 76 directory()->FullyCheckTreeInvariants(&trans); |
| 59 } | 77 } |
| 60 | 78 |
| 61 } // namespace syncer | 79 } // namespace syncer |
| OLD | NEW |