| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/scoped_file.h" | 10 #include "base/files/scoped_file.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/metrics/statistics_recorder.h" | 14 #include "base/metrics/statistics_recorder.h" |
| 15 #include "base/test/histogram_tester.h" | 15 #include "base/test/histogram_tester.h" |
| 16 #include "base/trace_event/process_memory_dump.h" | 16 #include "base/trace_event/process_memory_dump.h" |
| 17 #include "sql/connection.h" | 17 #include "sql/connection.h" |
| 18 #include "sql/connection_memory_dump_provider.h" | 18 #include "sql/connection_memory_dump_provider.h" |
| 19 #include "sql/correct_sql_test_base.h" | 19 #include "sql/correct_sql_test_base.h" |
| 20 #include "sql/meta_table.h" | 20 #include "sql/meta_table.h" |
| 21 #include "sql/statement.h" | 21 #include "sql/statement.h" |
| 22 #include "sql/test/error_callback_support.h" | 22 #include "sql/test/error_callback_support.h" |
| 23 #include "sql/test/scoped_error_ignorer.h" | 23 #include "sql/test/scoped_error_ignorer.h" |
| 24 #include "sql/test/test_helpers.h" | 24 #include "sql/test/test_helpers.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "third_party/sqlite/sqlite3.h" | 26 #include "third_party/sqlite/sqlite3.h" |
| 27 | 27 |
| 28 #if defined(OS_IOS) && defined(USE_SYSTEM_SQLITE) |
| 29 #include "base/ios/ios_util.h" |
| 30 #endif |
| 31 |
| 28 namespace sql { | 32 namespace sql { |
| 29 namespace test { | 33 namespace test { |
| 30 | 34 |
| 31 // Replaces the database time source with an object that steps forward 1ms on | 35 // Replaces the database time source with an object that steps forward 1ms on |
| 32 // each check, and which can be jumped forward an arbitrary amount of time | 36 // each check, and which can be jumped forward an arbitrary amount of time |
| 33 // programmatically. | 37 // programmatically. |
| 34 class ScopedMockTimeSource { | 38 class ScopedMockTimeSource { |
| 35 public: | 39 public: |
| 36 ScopedMockTimeSource(Connection& db) | 40 ScopedMockTimeSource(Connection& db) |
| 37 : db_(db), | 41 : db_(db), |
| (...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1428 sql::Connection::Delete(db_path()); | 1432 sql::Connection::Delete(db_path()); |
| 1429 db().set_mmap_disabled(); | 1433 db().set_mmap_disabled(); |
| 1430 ASSERT_TRUE(db().Open(db_path())); | 1434 ASSERT_TRUE(db().Open(db_path())); |
| 1431 { | 1435 { |
| 1432 sql::Statement s(db().GetUniqueStatement("PRAGMA mmap_size")); | 1436 sql::Statement s(db().GetUniqueStatement("PRAGMA mmap_size")); |
| 1433 ASSERT_TRUE(s.Step()); | 1437 ASSERT_TRUE(s.Step()); |
| 1434 EXPECT_LE(s.ColumnInt(0), 0); | 1438 EXPECT_LE(s.ColumnInt(0), 0); |
| 1435 } | 1439 } |
| 1436 } | 1440 } |
| 1437 | 1441 |
| 1438 // Test specific operation of the GetAppropriateMmapSize() helper. | |
| 1439 #if defined(OS_IOS) | |
| 1440 TEST_F(SQLConnectionTest, GetAppropriateMmapSize) { | 1442 TEST_F(SQLConnectionTest, GetAppropriateMmapSize) { |
| 1441 ASSERT_EQ(0UL, db().GetAppropriateMmapSize()); | 1443 #if defined(OS_IOS) && defined(USE_SYSTEM_SQLITE) |
| 1442 } | 1444 // Mmap is not supported on iOS9. |
| 1443 #else | 1445 if (!base::ios::IsRunningOnIOS10OrLater()) { |
| 1444 TEST_F(SQLConnectionTest, GetAppropriateMmapSize) { | 1446 ASSERT_EQ(0UL, db().GetAppropriateMmapSize()); |
| 1447 return; |
| 1448 } |
| 1449 #endif |
| 1450 |
| 1445 const size_t kMmapAlot = 25 * 1024 * 1024; | 1451 const size_t kMmapAlot = 25 * 1024 * 1024; |
| 1446 int64_t mmap_status = MetaTable::kMmapFailure; | 1452 int64_t mmap_status = MetaTable::kMmapFailure; |
| 1447 | 1453 |
| 1448 // If there is no meta table (as for a fresh database), assume that everything | 1454 // If there is no meta table (as for a fresh database), assume that everything |
| 1449 // should be mapped, and the status of the meta table is not affected. | 1455 // should be mapped, and the status of the meta table is not affected. |
| 1450 ASSERT_TRUE(!db().DoesTableExist("meta")); | 1456 ASSERT_TRUE(!db().DoesTableExist("meta")); |
| 1451 ASSERT_GT(db().GetAppropriateMmapSize(), kMmapAlot); | 1457 ASSERT_GT(db().GetAppropriateMmapSize(), kMmapAlot); |
| 1452 ASSERT_TRUE(!db().DoesTableExist("meta")); | 1458 ASSERT_TRUE(!db().DoesTableExist("meta")); |
| 1453 | 1459 |
| 1454 // When the meta table is first created, it sets up to map everything. | 1460 // When the meta table is first created, it sets up to map everything. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1470 ASSERT_TRUE(MetaTable::GetMmapStatus(&db(), &mmap_status)); | 1476 ASSERT_TRUE(MetaTable::GetMmapStatus(&db(), &mmap_status)); |
| 1471 ASSERT_EQ(0, mmap_status); | 1477 ASSERT_EQ(0, mmap_status); |
| 1472 | 1478 |
| 1473 // With no key, map everything and create the key. | 1479 // With no key, map everything and create the key. |
| 1474 // TODO(shess): This really should be "maps everything after validating it", | 1480 // TODO(shess): This really should be "maps everything after validating it", |
| 1475 // but that is more complicated to structure. | 1481 // but that is more complicated to structure. |
| 1476 ASSERT_GT(db().GetAppropriateMmapSize(), kMmapAlot); | 1482 ASSERT_GT(db().GetAppropriateMmapSize(), kMmapAlot); |
| 1477 ASSERT_TRUE(MetaTable::GetMmapStatus(&db(), &mmap_status)); | 1483 ASSERT_TRUE(MetaTable::GetMmapStatus(&db(), &mmap_status)); |
| 1478 ASSERT_EQ(MetaTable::kMmapSuccess, mmap_status); | 1484 ASSERT_EQ(MetaTable::kMmapSuccess, mmap_status); |
| 1479 } | 1485 } |
| 1480 #endif | |
| 1481 | 1486 |
| 1482 // To prevent invalid SQL from accidentally shipping to production, prepared | 1487 // To prevent invalid SQL from accidentally shipping to production, prepared |
| 1483 // statements which fail to compile with SQLITE_ERROR call DLOG(FATAL). This | 1488 // statements which fail to compile with SQLITE_ERROR call DLOG(FATAL). This |
| 1484 // case cannot be suppressed with an error callback. | 1489 // case cannot be suppressed with an error callback. |
| 1485 TEST_F(SQLConnectionTest, CompileError) { | 1490 TEST_F(SQLConnectionTest, CompileError) { |
| 1486 // DEATH tests not supported on Android or iOS. | 1491 // DEATH tests not supported on Android or iOS. |
| 1487 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 1492 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 1488 if (DLOG_IS_ON(FATAL)) { | 1493 if (DLOG_IS_ON(FATAL)) { |
| 1489 db().set_error_callback(base::Bind(&IgnoreErrorCallback)); | 1494 db().set_error_callback(base::Bind(&IgnoreErrorCallback)); |
| 1490 ASSERT_DEATH({ | 1495 ASSERT_DEATH({ |
| 1491 db().GetUniqueStatement("SELECT x"); | 1496 db().GetUniqueStatement("SELECT x"); |
| 1492 }, "SQL compile error no such column: x"); | 1497 }, "SQL compile error no such column: x"); |
| 1493 } | 1498 } |
| 1494 #endif | 1499 #endif |
| 1495 } | 1500 } |
| 1496 | 1501 |
| 1497 } // namespace sql | 1502 } // namespace sql |
| OLD | NEW |