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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 TEST_F(SyncableGeneralTest, General) { | 110 TEST_F(SyncableGeneralTest, General) { |
111 Directory dir(new InMemoryDirectoryBackingStore("SimpleTest"), | 111 Directory dir(new InMemoryDirectoryBackingStore("SimpleTest"), |
112 &handler_, | 112 &handler_, |
113 NULL, | 113 NULL, |
114 NULL, | 114 NULL, |
115 NULL); | 115 NULL); |
116 | 116 |
117 ASSERT_EQ(OPENED, dir.Open( | 117 ASSERT_EQ(OPENED, dir.Open( |
118 "SimpleTest", &delegate_, NullTransactionObserver())); | 118 "SimpleTest", &delegate_, NullTransactionObserver())); |
119 | 119 |
120 int64 root_metahandle; | |
121 { | |
122 ReadTransaction rtrans(FROM_HERE, &dir); | |
123 Entry e(&rtrans, GET_BY_ID, rtrans.root_id()); | |
124 ASSERT_TRUE(e.good()); | |
125 root_metahandle = e.GetMetahandle(); | |
126 } | |
127 | |
128 int64 written_metahandle; | 120 int64 written_metahandle; |
129 const Id id = TestIdFactory::FromNumber(99); | 121 const Id id = TestIdFactory::FromNumber(99); |
130 std::string name = "Jeff"; | 122 std::string name = "Jeff"; |
131 // Test simple read operations on an empty DB. | 123 // Test simple read operations on an empty DB. |
132 { | 124 { |
133 ReadTransaction rtrans(FROM_HERE, &dir); | 125 ReadTransaction rtrans(FROM_HERE, &dir); |
134 Entry e(&rtrans, GET_BY_ID, id); | 126 Entry e(&rtrans, GET_BY_ID, id); |
135 ASSERT_FALSE(e.good()); // Hasn't been written yet. | 127 ASSERT_FALSE(e.good()); // Hasn't been written yet. |
136 | 128 |
137 Directory::Metahandles child_handles; | 129 Directory::Metahandles child_handles; |
138 dir.GetChildHandlesById(&rtrans, rtrans.root_id(), &child_handles); | 130 dir.GetChildHandlesById(&rtrans, rtrans.root_id(), &child_handles); |
139 EXPECT_TRUE(child_handles.empty()); | 131 EXPECT_TRUE(child_handles.empty()); |
140 | |
141 dir.GetChildHandlesByHandle(&rtrans, root_metahandle, &child_handles); | |
142 EXPECT_TRUE(child_handles.empty()); | |
143 } | 132 } |
144 | 133 |
145 // Test creating a new meta entry. | 134 // Test creating a new meta entry. |
146 { | 135 { |
147 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); | 136 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); |
148 MutableEntry me(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), name); | 137 MutableEntry me(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), name); |
149 ASSERT_TRUE(me.good()); | 138 ASSERT_TRUE(me.good()); |
150 me.PutId(id); | 139 me.PutId(id); |
151 me.PutBaseVersion(1); | 140 me.PutBaseVersion(1); |
152 written_metahandle = me.GetMetahandle(); | 141 written_metahandle = me.GetMetahandle(); |
153 } | 142 } |
154 | 143 |
155 // Test GetChildHandles* after something is now in the DB. | 144 // Test GetChildHandles* after something is now in the DB. |
156 // Also check that GET_BY_ID works. | 145 // Also check that GET_BY_ID works. |
157 { | 146 { |
158 ReadTransaction rtrans(FROM_HERE, &dir); | 147 ReadTransaction rtrans(FROM_HERE, &dir); |
159 Entry e(&rtrans, GET_BY_ID, id); | 148 Entry e(&rtrans, GET_BY_ID, id); |
160 ASSERT_TRUE(e.good()); | 149 ASSERT_TRUE(e.good()); |
161 | 150 |
162 Directory::Metahandles child_handles; | 151 Directory::Metahandles child_handles; |
163 dir.GetChildHandlesById(&rtrans, rtrans.root_id(), &child_handles); | 152 dir.GetChildHandlesById(&rtrans, rtrans.root_id(), &child_handles); |
164 EXPECT_EQ(1u, child_handles.size()); | 153 EXPECT_EQ(1u, child_handles.size()); |
165 | 154 |
166 for (Directory::Metahandles::iterator i = child_handles.begin(); | 155 for (Directory::Metahandles::iterator i = child_handles.begin(); |
167 i != child_handles.end(); ++i) { | 156 i != child_handles.end(); ++i) { |
168 EXPECT_EQ(*i, written_metahandle); | 157 EXPECT_EQ(*i, written_metahandle); |
169 } | 158 } |
170 | |
171 dir.GetChildHandlesByHandle(&rtrans, root_metahandle, &child_handles); | |
172 EXPECT_EQ(1u, child_handles.size()); | |
173 | |
174 for (Directory::Metahandles::iterator i = child_handles.begin(); | |
175 i != child_handles.end(); ++i) { | |
176 EXPECT_EQ(*i, written_metahandle); | |
177 } | |
178 } | 159 } |
179 | 160 |
180 // Test writing data to an entity. Also check that GET_BY_HANDLE works. | 161 // Test writing data to an entity. Also check that GET_BY_HANDLE works. |
181 static const char s[] = "Hello World."; | 162 static const char s[] = "Hello World."; |
182 { | 163 { |
183 WriteTransaction trans(FROM_HERE, UNITTEST, &dir); | 164 WriteTransaction trans(FROM_HERE, UNITTEST, &dir); |
184 MutableEntry e(&trans, GET_BY_HANDLE, written_metahandle); | 165 MutableEntry e(&trans, GET_BY_HANDLE, written_metahandle); |
185 ASSERT_TRUE(e.good()); | 166 ASSERT_TRUE(e.good()); |
186 PutDataAsBookmarkFavicon(&trans, &e, s, sizeof(s)); | 167 PutDataAsBookmarkFavicon(&trans, &e, s, sizeof(s)); |
187 } | 168 } |
(...skipping 2106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2294 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 2275 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
2295 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); | 2276 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); |
2296 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); | 2277 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); |
2297 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); | 2278 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); |
2298 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); | 2279 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); |
2299 } | 2280 } |
2300 | 2281 |
2301 } // namespace | 2282 } // namespace |
2302 } // namespace syncable | 2283 } // namespace syncable |
2303 } // namespace syncer | 2284 } // namespace syncer |
OLD | NEW |