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 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 // Renamed a column in Version 70 | 872 // Renamed a column in Version 70 |
873 ASSERT_FALSE(connection.DoesColumnExist("metas", "singleton_tag")); | 873 ASSERT_FALSE(connection.DoesColumnExist("metas", "singleton_tag")); |
874 ASSERT_TRUE(connection.DoesColumnExist("metas", "unique_server_tag")); | 874 ASSERT_TRUE(connection.DoesColumnExist("metas", "unique_server_tag")); |
875 ASSERT_TRUE(connection.DoesColumnExist("metas", "unique_client_tag")); | 875 ASSERT_TRUE(connection.DoesColumnExist("metas", "unique_client_tag")); |
876 | 876 |
877 // Removed extended attributes in Version 72. | 877 // Removed extended attributes in Version 72. |
878 ASSERT_FALSE(connection.DoesTableExist("extended_attributes")); | 878 ASSERT_FALSE(connection.DoesTableExist("extended_attributes")); |
879 } | 879 } |
880 | 880 |
881 MetahandlesIndex index; | 881 MetahandlesIndex index; |
| 882 STLElementDeleter<MetahandlesIndex> index_deleter(&index); |
882 dbs->LoadEntries(&index); | 883 dbs->LoadEntries(&index); |
883 dbs->EndLoad(); | 884 dbs->EndLoad(); |
884 | 885 |
885 MetahandlesIndex::iterator it = index.begin(); | 886 MetahandlesIndex::iterator it = index.begin(); |
886 ASSERT_TRUE(it != index.end()); | 887 ASSERT_TRUE(it != index.end()); |
887 ASSERT_EQ(1, (*it)->ref(META_HANDLE)); | 888 ASSERT_EQ(1, (*it)->ref(META_HANDLE)); |
888 EXPECT_TRUE((*it)->ref(ID).IsRoot()); | 889 EXPECT_TRUE((*it)->ref(ID).IsRoot()); |
889 | 890 |
890 ASSERT_TRUE(++it != index.end()) << "Upgrade destroyed database contents."; | 891 ASSERT_TRUE(++it != index.end()) << "Upgrade destroyed database contents."; |
891 ASSERT_EQ(2, (*it)->ref(META_HANDLE)); | 892 ASSERT_EQ(2, (*it)->ref(META_HANDLE)); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 EXPECT_FALSE((*it)->ref(SERVER_SPECIFICS). | 998 EXPECT_FALSE((*it)->ref(SERVER_SPECIFICS). |
998 GetExtension(sync_pb::bookmark).has_favicon()); | 999 GetExtension(sync_pb::bookmark).has_favicon()); |
999 | 1000 |
1000 ASSERT_TRUE(++it != index.end()); | 1001 ASSERT_TRUE(++it != index.end()); |
1001 ASSERT_EQ(13, (*it)->ref(META_HANDLE)); | 1002 ASSERT_EQ(13, (*it)->ref(META_HANDLE)); |
1002 | 1003 |
1003 ASSERT_TRUE(++it != index.end()); | 1004 ASSERT_TRUE(++it != index.end()); |
1004 ASSERT_EQ(14, (*it)->ref(META_HANDLE)); | 1005 ASSERT_EQ(14, (*it)->ref(META_HANDLE)); |
1005 | 1006 |
1006 ASSERT_TRUE(++it == index.end()); | 1007 ASSERT_TRUE(++it == index.end()); |
1007 | |
1008 STLDeleteElements(&index); | |
1009 } | 1008 } |
1010 | 1009 |
1011 INSTANTIATE_TEST_CASE_P(DirectoryBackingStore, MigrationTest, | 1010 INSTANTIATE_TEST_CASE_P(DirectoryBackingStore, MigrationTest, |
1012 testing::Range(67, kCurrentDBVersion)); | 1011 testing::Range(67, kCurrentDBVersion)); |
1013 | 1012 |
1014 TEST_F(DirectoryBackingStoreTest, ModelTypeIds) { | 1013 TEST_F(DirectoryBackingStoreTest, ModelTypeIds) { |
1015 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 1014 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
1016 std::string model_id = | 1015 std::string model_id = |
1017 DirectoryBackingStore::ModelTypeEnumToModelId(ModelTypeFromInt(i)); | 1016 DirectoryBackingStore::ModelTypeEnumToModelId(ModelTypeFromInt(i)); |
1018 EXPECT_EQ(i, | 1017 EXPECT_EQ(i, |
(...skipping 22 matching lines...) Expand all Loading... |
1041 EXPECT_DEATH(dbs->BeginLoad(), "sqlite error"); | 1040 EXPECT_DEATH(dbs->BeginLoad(), "sqlite error"); |
1042 #endif | 1041 #endif |
1043 } | 1042 } |
1044 } | 1043 } |
1045 | 1044 |
1046 TEST_F(DirectoryBackingStoreTest, DeleteEntries) { | 1045 TEST_F(DirectoryBackingStoreTest, DeleteEntries) { |
1047 SetUpCurrentDatabaseAndCheckVersion(); | 1046 SetUpCurrentDatabaseAndCheckVersion(); |
1048 scoped_ptr<DirectoryBackingStore> dbs( | 1047 scoped_ptr<DirectoryBackingStore> dbs( |
1049 new DirectoryBackingStore(GetUsername(), GetDatabasePath())); | 1048 new DirectoryBackingStore(GetUsername(), GetDatabasePath())); |
1050 dbs->BeginLoad(); | 1049 dbs->BeginLoad(); |
1051 | |
1052 MetahandlesIndex index; | 1050 MetahandlesIndex index; |
| 1051 STLElementDeleter<MetahandlesIndex> index_deleter(&index); |
1053 dbs->LoadEntries(&index); | 1052 dbs->LoadEntries(&index); |
1054 size_t initial_size = index.size(); | 1053 size_t initial_size = index.size(); |
1055 ASSERT_LT(0U, initial_size) << "Test requires entries to delete."; | 1054 ASSERT_LT(0U, initial_size) << "Test requires entries to delete."; |
1056 int64 first_to_die = (*index.begin())->ref(META_HANDLE); | 1055 int64 first_to_die = (*index.begin())->ref(META_HANDLE); |
1057 MetahandleSet to_delete; | 1056 MetahandleSet to_delete; |
1058 to_delete.insert(first_to_die); | 1057 to_delete.insert(first_to_die); |
1059 EXPECT_TRUE(dbs->DeleteEntries(to_delete)); | 1058 EXPECT_TRUE(dbs->DeleteEntries(to_delete)); |
1060 | 1059 |
1061 index.clear(); | 1060 STLDeleteElements(&index); |
1062 dbs->LoadEntries(&index); | 1061 dbs->LoadEntries(&index); |
1063 | 1062 |
1064 EXPECT_EQ(initial_size - 1, index.size()); | 1063 EXPECT_EQ(initial_size - 1, index.size()); |
1065 bool delete_failed = false; | 1064 bool delete_failed = false; |
1066 for (MetahandlesIndex::iterator it = index.begin(); it != index.end(); | 1065 for (MetahandlesIndex::iterator it = index.begin(); it != index.end(); |
1067 ++it) { | 1066 ++it) { |
1068 if ((*it)->ref(META_HANDLE) == first_to_die) { | 1067 if ((*it)->ref(META_HANDLE) == first_to_die) { |
1069 delete_failed = true; | 1068 delete_failed = true; |
1070 break; | 1069 break; |
1071 } | 1070 } |
1072 } | 1071 } |
1073 EXPECT_FALSE(delete_failed); | 1072 EXPECT_FALSE(delete_failed); |
1074 | 1073 |
1075 to_delete.clear(); | 1074 to_delete.clear(); |
1076 for (MetahandlesIndex::iterator it = index.begin(); it != index.end(); | 1075 for (MetahandlesIndex::iterator it = index.begin(); it != index.end(); |
1077 ++it) { | 1076 ++it) { |
1078 to_delete.insert((*it)->ref(META_HANDLE)); | 1077 to_delete.insert((*it)->ref(META_HANDLE)); |
1079 } | 1078 } |
1080 | 1079 |
1081 EXPECT_TRUE(dbs->DeleteEntries(to_delete)); | 1080 EXPECT_TRUE(dbs->DeleteEntries(to_delete)); |
1082 | 1081 |
1083 index.clear(); | 1082 STLDeleteElements(&index); |
1084 dbs->LoadEntries(&index); | 1083 dbs->LoadEntries(&index); |
1085 EXPECT_EQ(0U, index.size()); | 1084 EXPECT_EQ(0U, index.size()); |
1086 | 1085 |
1087 dbs->EndLoad(); | 1086 dbs->EndLoad(); |
1088 dbs->EndSave(); | 1087 dbs->EndSave(); |
1089 } | 1088 } |
1090 | 1089 |
1091 } // namespace syncable | 1090 } // namespace syncable |
OLD | NEW |