OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "app/sql/connection.h" | 9 #include "app/sql/connection.h" |
10 #include "app/sql/statement.h" | 10 #include "app/sql/statement.h" |
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 // In release mode, we expect the sync database to nuke itself and start | 1036 // In release mode, we expect the sync database to nuke itself and start |
1037 // over if it detects invalid/corrupted data. | 1037 // over if it detects invalid/corrupted data. |
1038 #if defined(NDEBUG) | 1038 #if defined(NDEBUG) |
1039 EXPECT_TRUE(dbs->BeginLoad()); | 1039 EXPECT_TRUE(dbs->BeginLoad()); |
1040 #else | 1040 #else |
1041 EXPECT_DEATH(dbs->BeginLoad(), "sqlite error"); | 1041 EXPECT_DEATH(dbs->BeginLoad(), "sqlite error"); |
1042 #endif | 1042 #endif |
1043 } | 1043 } |
1044 } | 1044 } |
1045 | 1045 |
| 1046 TEST_F(DirectoryBackingStoreTest, DeleteEntries) { |
| 1047 SetUpCurrentDatabaseAndCheckVersion(); |
| 1048 scoped_ptr<DirectoryBackingStore> dbs( |
| 1049 new DirectoryBackingStore(GetUsername(), GetDatabasePath())); |
| 1050 dbs->BeginLoad(); |
| 1051 |
| 1052 MetahandlesIndex index; |
| 1053 dbs->LoadEntries(&index); |
| 1054 size_t initial_size = index.size(); |
| 1055 ASSERT_LT(0U, initial_size) << "Test requires entries to delete."; |
| 1056 int64 first_to_die = (*index.begin())->ref(META_HANDLE); |
| 1057 MetahandleSet to_delete; |
| 1058 to_delete.insert(first_to_die); |
| 1059 EXPECT_TRUE(dbs->DeleteEntries(to_delete)); |
| 1060 |
| 1061 index.clear(); |
| 1062 dbs->LoadEntries(&index); |
| 1063 |
| 1064 EXPECT_EQ(initial_size - 1, index.size()); |
| 1065 bool delete_failed = false; |
| 1066 for (MetahandlesIndex::iterator it = index.begin(); it != index.end(); |
| 1067 ++it) { |
| 1068 if ((*it)->ref(META_HANDLE) == first_to_die) { |
| 1069 delete_failed = true; |
| 1070 break; |
| 1071 } |
| 1072 } |
| 1073 EXPECT_FALSE(delete_failed); |
| 1074 |
| 1075 to_delete.clear(); |
| 1076 for (MetahandlesIndex::iterator it = index.begin(); it != index.end(); |
| 1077 ++it) { |
| 1078 to_delete.insert((*it)->ref(META_HANDLE)); |
| 1079 } |
| 1080 |
| 1081 EXPECT_TRUE(dbs->DeleteEntries(to_delete)); |
| 1082 |
| 1083 index.clear(); |
| 1084 dbs->LoadEntries(&index); |
| 1085 EXPECT_EQ(0U, index.size()); |
| 1086 |
| 1087 dbs->EndLoad(); |
| 1088 dbs->EndSave(); |
| 1089 } |
| 1090 |
1046 } // namespace syncable | 1091 } // namespace syncable |
OLD | NEW |