OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/syncable/syncable.h" | 5 #include "chrome/browser/sync/syncable/syncable.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 | 10 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 98 } |
99 protected: | 99 protected: |
100 ScopedTempDir temp_dir_; | 100 ScopedTempDir temp_dir_; |
101 FilePath db_path_; | 101 FilePath db_path_; |
102 }; | 102 }; |
103 | 103 |
104 TEST_F(SyncableGeneralTest, General) { | 104 TEST_F(SyncableGeneralTest, General) { |
105 Directory dir; | 105 Directory dir; |
106 dir.Open(db_path_, "SimpleTest"); | 106 dir.Open(db_path_, "SimpleTest"); |
107 | 107 |
| 108 int64 root_metahandle; |
| 109 { |
| 110 ReadTransaction rtrans(&dir, __FILE__, __LINE__); |
| 111 Entry e(&rtrans, GET_BY_ID, rtrans.root_id()); |
| 112 ASSERT_TRUE(e.good()); |
| 113 root_metahandle = e.Get(META_HANDLE); |
| 114 } |
| 115 |
108 int64 written_metahandle; | 116 int64 written_metahandle; |
109 const Id id = TestIdFactory::FromNumber(99); | 117 const Id id = TestIdFactory::FromNumber(99); |
110 std::string name = "Jeff"; | 118 std::string name = "Jeff"; |
111 // Test simple read operations on an empty DB. | 119 // Test simple read operations on an empty DB. |
112 { | 120 { |
113 ReadTransaction rtrans(&dir, __FILE__, __LINE__); | 121 ReadTransaction rtrans(&dir, __FILE__, __LINE__); |
114 Entry e(&rtrans, GET_BY_ID, id); | 122 Entry e(&rtrans, GET_BY_ID, id); |
115 ASSERT_FALSE(e.good()); // Hasn't been written yet. | 123 ASSERT_FALSE(e.good()); // Hasn't been written yet. |
116 | 124 |
117 Directory::ChildHandles child_handles; | 125 Directory::ChildHandles child_handles; |
118 dir.GetChildHandles(&rtrans, rtrans.root_id(), &child_handles); | 126 dir.GetChildHandlesById(&rtrans, rtrans.root_id(), &child_handles); |
| 127 EXPECT_TRUE(child_handles.empty()); |
| 128 |
| 129 dir.GetChildHandlesByHandle(&rtrans, root_metahandle, &child_handles); |
119 EXPECT_TRUE(child_handles.empty()); | 130 EXPECT_TRUE(child_handles.empty()); |
120 } | 131 } |
121 | 132 |
122 // Test creating a new meta entry. | 133 // Test creating a new meta entry. |
123 { | 134 { |
124 WriteTransaction wtrans(&dir, UNITTEST, __FILE__, __LINE__); | 135 WriteTransaction wtrans(&dir, UNITTEST, __FILE__, __LINE__); |
125 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), name); | 136 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), name); |
126 ASSERT_TRUE(me.good()); | 137 ASSERT_TRUE(me.good()); |
127 me.Put(ID, id); | 138 me.Put(ID, id); |
128 me.Put(BASE_VERSION, 1); | 139 me.Put(BASE_VERSION, 1); |
129 written_metahandle = me.Get(META_HANDLE); | 140 written_metahandle = me.Get(META_HANDLE); |
130 } | 141 } |
131 | 142 |
132 // Test GetChildHandles after something is now in the DB. | 143 // Test GetChildHandles* after something is now in the DB. |
133 // Also check that GET_BY_ID works. | 144 // Also check that GET_BY_ID works. |
134 { | 145 { |
135 ReadTransaction rtrans(&dir, __FILE__, __LINE__); | 146 ReadTransaction rtrans(&dir, __FILE__, __LINE__); |
136 Entry e(&rtrans, GET_BY_ID, id); | 147 Entry e(&rtrans, GET_BY_ID, id); |
137 ASSERT_TRUE(e.good()); | 148 ASSERT_TRUE(e.good()); |
138 | 149 |
139 Directory::ChildHandles child_handles; | 150 Directory::ChildHandles child_handles; |
140 dir.GetChildHandles(&rtrans, rtrans.root_id(), &child_handles); | 151 dir.GetChildHandlesById(&rtrans, rtrans.root_id(), &child_handles); |
141 EXPECT_EQ(1u, child_handles.size()); | 152 EXPECT_EQ(1u, child_handles.size()); |
142 | 153 |
143 for (Directory::ChildHandles::iterator i = child_handles.begin(); | 154 for (Directory::ChildHandles::iterator i = child_handles.begin(); |
| 155 i != child_handles.end(); ++i) { |
| 156 EXPECT_EQ(*i, written_metahandle); |
| 157 } |
| 158 |
| 159 dir.GetChildHandlesByHandle(&rtrans, root_metahandle, &child_handles); |
| 160 EXPECT_EQ(1u, child_handles.size()); |
| 161 |
| 162 for (Directory::ChildHandles::iterator i = child_handles.begin(); |
144 i != child_handles.end(); ++i) { | 163 i != child_handles.end(); ++i) { |
145 EXPECT_EQ(*i, written_metahandle); | 164 EXPECT_EQ(*i, written_metahandle); |
146 } | 165 } |
147 } | 166 } |
148 | 167 |
149 // Test writing data to an entity. Also check that GET_BY_HANDLE works. | 168 // Test writing data to an entity. Also check that GET_BY_HANDLE works. |
150 static const char s[] = "Hello World."; | 169 static const char s[] = "Hello World."; |
151 { | 170 { |
152 WriteTransaction trans(&dir, UNITTEST, __FILE__, __LINE__); | 171 WriteTransaction trans(&dir, UNITTEST, __FILE__, __LINE__); |
153 MutableEntry e(&trans, GET_BY_HANDLE, written_metahandle); | 172 MutableEntry e(&trans, GET_BY_HANDLE, written_metahandle); |
(...skipping 1627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1781 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) { | 1800 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) { |
1782 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 1801 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
1783 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 1802 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
1784 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); | 1803 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); |
1785 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); | 1804 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); |
1786 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); | 1805 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); |
1787 } | 1806 } |
1788 | 1807 |
1789 } // namespace | 1808 } // namespace |
1790 } // namespace syncable | 1809 } // namespace syncable |
OLD | NEW |