#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "sql/recovery.h"
#include <stddef.h>
#include <cstdint>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/callback_forward.h"
#include "base/functional/callback_helpers.h"
#include "base/path_service.h"
#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/bind.h"
#include "base/test/gtest_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/buildflag.h"
#include "sql/database.h"
#include "sql/meta_table.h"
#include "sql/sql_features.h"
#include "sql/sqlite_result_code.h"
#include "sql/sqlite_result_code_values.h"
#include "sql/statement.h"
#include "sql/test/scoped_error_expecter.h"
#include "sql/test/test_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/sqlite/sqlite3.h"
namespace sql {
namespace {
ExecuteWithResult;
ExecuteWithResults;
constexpr char kRecoveryResultHistogramName[] = …;
constexpr char kRecoveryResultCodeHistogramName[] = …;
std::string GetSchema(Database* db) { … }
class SqlRecoveryTest : public testing::Test,
public testing::WithParamInterface<bool> { … };
#if BUILDFLAG(IS_FUCHSIA)
INSTANTIATE_TEST_SUITE_P(All, SqlRecoveryTest, testing::Values(false));
#else
INSTANTIATE_TEST_SUITE_P(…);
#endif
TEST_P(SqlRecoveryTest, ShouldAttemptRecovery) { … }
TEST_P(SqlRecoveryTest, RecoverCorruptIndex) { … }
TEST_P(SqlRecoveryTest, RecoverCorruptTable) { … }
TEST_P(SqlRecoveryTest, Meta) { … }
TEST_P(SqlRecoveryTest, AutoRecoverTable) { … }
TEST_P(SqlRecoveryTest, AutoRecoverTableWithDefault) { … }
TEST_P(SqlRecoveryTest, AutoRecoverTableWithRowid) { … }
void TestRecoverDatabase(Database& db,
const base::FilePath& db_path,
bool with_meta,
base::OnceClosure run_recovery) { … }
TEST_P(SqlRecoveryTest, RecoverDatabase) { … }
TEST_P(SqlRecoveryTest, RecoverDatabaseMeta) { … }
TEST_P(SqlRecoveryTest, RecoverIfPossible) { … }
TEST_P(SqlRecoveryTest, RecoverIfPossibleMeta) { … }
TEST_P(SqlRecoveryTest, RecoverIfPossibleWithoutErrorCallback) { … }
TEST_P(SqlRecoveryTest, RecoverIfPossibleWithErrorCallback) { … }
TEST_P(SqlRecoveryTest, RecoverIfPossibleWithClosedDatabase) { … }
TEST_P(SqlRecoveryTest, RecoverIfPossibleWithPerDatabaseUma) { … }
TEST_P(SqlRecoveryTest, RecoverDatabaseWithView) { … }
TEST_P(SqlRecoveryTest, RecoverDatabaseDelete) { … }
TEST_P(SqlRecoveryTest, BeginRecoverDatabase) { … }
TEST_P(SqlRecoveryTest, AttachFailure) { … }
void TestPageSize(const base::FilePath& db_prefix,
int initial_page_size,
const std::string& expected_initial_page_size,
int final_page_size,
const std::string& expected_final_page_size) { … }
TEST_P(SqlRecoveryTest, PageSize) { … }
TEST_P(SqlRecoveryTest, CannotRecoverClosedDb) { … }
TEST_P(SqlRecoveryTest, CannotRecoverDbWithErrorCallback) { … }
TEST_P(SqlRecoveryTest, CannotRecoverNullDb) { … }
TEST_P(SqlRecoveryTest, CannotRecoverInMemoryDb) { … }
TEST_P(SqlRecoveryTest, PRE_RecoverFormerlyWalDbAfterCrash) { … }
TEST_P(SqlRecoveryTest, RecoverFormerlyWalDbAfterCrash) { … }
}
}