Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: components/sync/test/directory_backing_store_corruption_testing.cc

Issue 2424533002: Modify sync unit test to use standard sql::test:: helper. (Closed)
Patch Set: BUILD.gn merge Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/sync/test/directory_backing_store_corruption_testing.h"
6
7 #include <string>
8
9 #include "base/files/file_util.h"
10 #include "base/files/scoped_file.h"
11
12 namespace syncer {
13 namespace syncable {
14 namespace corruption_testing {
15
16 // This value needs to be large enough to force the underlying DB to be read
17 // from disk before writing, but small enough so that tests don't take too long
18 // and timeout. The value depend on the underlying DB page size as well as the
19 // DB's cache_size PRAGMA. If test fails, you either increase
20 // kNumEntriesRequiredForCorruption, or increase the size of each entry.
21 const int kNumEntriesRequiredForCorruption = 2000;
22
23 bool CorruptDatabase(const base::FilePath& backing_file_path) {
24 // Corrupt the DB by write a bunch of zeros at the beginning.
25 //
26 // Because the file may already open for writing, it's important that we open
27 // it in a sharing-compatible way for platforms that have the concept of
28 // shared/exclusive file access (e.g. Windows).
29 base::ScopedFILE db_file(base::OpenFile(backing_file_path, "wb"));
30 if (!db_file.get())
31 return false;
32 const std::string zeros(4096, '\0');
33 const int num_written = fwrite(zeros.data(), zeros.size(), 1, db_file.get());
34 return num_written == 1U;
35 }
36
37 } // namespace corruption_testing
38 } // namespace syncable
39 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/test/directory_backing_store_corruption_testing.h ('k') | sql/test/test_helpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698