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 "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 "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 2064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2075 new DirectoryBackingStore(GetUsername(), GetDatabasePath())); | 2075 new DirectoryBackingStore(GetUsername(), GetDatabasePath())); |
2076 EXPECT_TRUE(dbs->BeginLoad()); | 2076 EXPECT_TRUE(dbs->BeginLoad()); |
2077 } | 2077 } |
2078 std::string bad_data("BAD DATA"); | 2078 std::string bad_data("BAD DATA"); |
2079 EXPECT_TRUE(file_util::WriteFile(GetDatabasePath(), bad_data.data(), | 2079 EXPECT_TRUE(file_util::WriteFile(GetDatabasePath(), bad_data.data(), |
2080 bad_data.size())); | 2080 bad_data.size())); |
2081 { | 2081 { |
2082 scoped_ptr<DirectoryBackingStore> dbs( | 2082 scoped_ptr<DirectoryBackingStore> dbs( |
2083 new DirectoryBackingStore(GetUsername(), GetDatabasePath())); | 2083 new DirectoryBackingStore(GetUsername(), GetDatabasePath())); |
2084 | 2084 |
2085 // In release mode, we expect the sync database to nuke itself and start | 2085 EXPECT_FALSE(dbs->BeginLoad()); |
2086 // over if it detects invalid/corrupted data. | |
2087 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | |
2088 EXPECT_TRUE(dbs->BeginLoad()); | |
2089 #elif defined(NDEBUG) && defined(DCHECK_ALWAYS_ON) | |
2090 EXPECT_DEATH(dbs->BeginLoad(), "stmt_"); | |
2091 #else | |
2092 EXPECT_DEATH(dbs->BeginLoad(), "sqlite error"); | |
2093 #endif | |
2094 } | 2086 } |
2095 } | 2087 } |
2096 | 2088 |
2097 TEST_F(DirectoryBackingStoreTest, DeleteEntries) { | 2089 TEST_F(DirectoryBackingStoreTest, DeleteEntries) { |
2098 SetUpCurrentDatabaseAndCheckVersion(); | 2090 SetUpCurrentDatabaseAndCheckVersion(); |
2099 scoped_ptr<DirectoryBackingStore> dbs( | 2091 scoped_ptr<DirectoryBackingStore> dbs( |
2100 new DirectoryBackingStore(GetUsername(), GetDatabasePath())); | 2092 new DirectoryBackingStore(GetUsername(), GetDatabasePath())); |
2101 dbs->BeginLoad(); | 2093 dbs->BeginLoad(); |
2102 MetahandlesIndex index; | 2094 MetahandlesIndex index; |
2103 STLElementDeleter<MetahandlesIndex> index_deleter(&index); | 2095 STLElementDeleter<MetahandlesIndex> index_deleter(&index); |
(...skipping 29 matching lines...) Expand all Loading... |
2133 | 2125 |
2134 STLDeleteElements(&index); | 2126 STLDeleteElements(&index); |
2135 dbs->LoadEntries(&index); | 2127 dbs->LoadEntries(&index); |
2136 EXPECT_EQ(0U, index.size()); | 2128 EXPECT_EQ(0U, index.size()); |
2137 | 2129 |
2138 dbs->EndLoad(); | 2130 dbs->EndLoad(); |
2139 dbs->EndSave(); | 2131 dbs->EndSave(); |
2140 } | 2132 } |
2141 | 2133 |
2142 } // namespace syncable | 2134 } // namespace syncable |
OLD | NEW |