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.
5 #include "sync/test/engine/test_directory_setter_upper.h"
7 #include "base/compiler_specific.h"
8 #include "base/files/file_util.h"
9 #include "base/location.h"
10 #include "base/strings/string_util.h"
11 #include "sync/syncable/directory.h"
12 #include "sync/syncable/in_memory_directory_backing_store.h"
13 #include "sync/syncable/mutable_entry.h"
14 #include "sync/syncable/syncable_read_transaction.h"
15 #include "sync/syncable/syncable_write_transaction.h"
16 #include "sync/test/test_transaction_observer.h"
17 #include "testing/gtest/include/gtest/gtest.h"
21 TestDirectorySetterUpper::TestDirectorySetterUpper() : name_("Test") {}
23 TestDirectorySetterUpper::~TestDirectorySetterUpper() {}
25 void TestDirectorySetterUpper::SetUp() {
26 test_transaction_observer_
.reset(new syncable::TestTransactionObserver());
27 WeakHandle
<syncable::TransactionObserver
> transaction_observer
=
28 MakeWeakHandle(test_transaction_observer_
->AsWeakPtr());
31 new syncable::Directory(
32 new syncable::InMemoryDirectoryBackingStore(name_
),
36 encryption_handler_
.cryptographer()));
37 ASSERT_EQ(syncable::OPENED
, directory_
->Open(
38 name_
, &delegate_
, transaction_observer
));
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());
49 new syncable::Directory(directory_store
,
53 encryption_handler_
.cryptographer()));
54 ASSERT_EQ(syncable::OPENED
, directory_
->Open(
55 name_
, &delegate_
, transaction_observer
));
58 void TestDirectorySetterUpper::TearDown() {
59 if (!directory()->good())
63 directory()->SaveChanges();
65 directory()->SaveChanges();
70 void TestDirectorySetterUpper::RunInvariantCheck() {
71 // Check invariants for all items.
72 syncable::ReadTransaction
trans(FROM_HERE
, directory());
74 // The TestUnrecoverableErrorHandler that this directory was constructed with
75 // will handle error reporting, so we can safely ignore the return value.
76 directory()->FullyCheckTreeInvariants(&trans
);