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" |
(...skipping 1528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1539 ASSERT_GT(db().GetAppropriateMmapSize(), kMmapAlot); | 1539 ASSERT_GT(db().GetAppropriateMmapSize(), kMmapAlot); |
1540 ASSERT_TRUE(!db().DoesTableExist("meta")); | 1540 ASSERT_TRUE(!db().DoesTableExist("meta")); |
1541 | 1541 |
1542 // When the meta table is first created, it sets up to map everything. | 1542 // When the meta table is first created, it sets up to map everything. |
1543 MetaTable().Init(&db(), 1, 1); | 1543 MetaTable().Init(&db(), 1, 1); |
1544 ASSERT_TRUE(db().DoesTableExist("meta")); | 1544 ASSERT_TRUE(db().DoesTableExist("meta")); |
1545 ASSERT_GT(db().GetAppropriateMmapSize(), kMmapAlot); | 1545 ASSERT_GT(db().GetAppropriateMmapSize(), kMmapAlot); |
1546 ASSERT_TRUE(MetaTable::GetMmapStatus(&db(), &mmap_status)); | 1546 ASSERT_TRUE(MetaTable::GetMmapStatus(&db(), &mmap_status)); |
1547 ASSERT_EQ(MetaTable::kMmapSuccess, mmap_status); | 1547 ASSERT_EQ(MetaTable::kMmapSuccess, mmap_status); |
1548 | 1548 |
| 1549 // Preload with partial progress of one page. Should map everything. |
| 1550 ASSERT_TRUE(db().Execute("REPLACE INTO meta VALUES ('mmap_status', 1)")); |
| 1551 ASSERT_GT(db().GetAppropriateMmapSize(), kMmapAlot); |
| 1552 ASSERT_TRUE(MetaTable::GetMmapStatus(&db(), &mmap_status)); |
| 1553 ASSERT_EQ(MetaTable::kMmapSuccess, mmap_status); |
| 1554 |
1549 // Failure status maps nothing. | 1555 // Failure status maps nothing. |
1550 ASSERT_TRUE(db().Execute("REPLACE INTO meta VALUES ('mmap_status', -2)")); | 1556 ASSERT_TRUE(db().Execute("REPLACE INTO meta VALUES ('mmap_status', -2)")); |
1551 ASSERT_EQ(0UL, db().GetAppropriateMmapSize()); | 1557 ASSERT_EQ(0UL, db().GetAppropriateMmapSize()); |
1552 | 1558 |
1553 // Re-initializing the meta table does not re-create the key if the table | 1559 // Re-initializing the meta table does not re-create the key if the table |
1554 // already exists. | 1560 // already exists. |
1555 ASSERT_TRUE(db().Execute("DELETE FROM meta WHERE key = 'mmap_status'")); | 1561 ASSERT_TRUE(db().Execute("DELETE FROM meta WHERE key = 'mmap_status'")); |
1556 MetaTable().Init(&db(), 1, 1); | 1562 MetaTable().Init(&db(), 1, 1); |
1557 ASSERT_EQ(MetaTable::kMmapSuccess, mmap_status); | 1563 ASSERT_EQ(MetaTable::kMmapSuccess, mmap_status); |
1558 ASSERT_TRUE(MetaTable::GetMmapStatus(&db(), &mmap_status)); | 1564 ASSERT_TRUE(MetaTable::GetMmapStatus(&db(), &mmap_status)); |
(...skipping 27 matching lines...) Expand all Loading... |
1586 ASSERT_FALSE(db().DoesViewExist("MmapStatus")); | 1592 ASSERT_FALSE(db().DoesViewExist("MmapStatus")); |
1587 | 1593 |
1588 // Using alt status, everything should be mapped, with state in the view. | 1594 // Using alt status, everything should be mapped, with state in the view. |
1589 db().set_mmap_alt_status(); | 1595 db().set_mmap_alt_status(); |
1590 ASSERT_GT(db().GetAppropriateMmapSize(), kMmapAlot); | 1596 ASSERT_GT(db().GetAppropriateMmapSize(), kMmapAlot); |
1591 ASSERT_FALSE(db().DoesTableExist("meta")); | 1597 ASSERT_FALSE(db().DoesTableExist("meta")); |
1592 ASSERT_TRUE(db().DoesViewExist("MmapStatus")); | 1598 ASSERT_TRUE(db().DoesViewExist("MmapStatus")); |
1593 EXPECT_EQ(base::IntToString(MetaTable::kMmapSuccess), | 1599 EXPECT_EQ(base::IntToString(MetaTable::kMmapSuccess), |
1594 ExecuteWithResult(&db(), "SELECT * FROM MmapStatus")); | 1600 ExecuteWithResult(&db(), "SELECT * FROM MmapStatus")); |
1595 | 1601 |
1596 // Also maps everything when kMmapSuccess is in the view. | 1602 // Also maps everything when kMmapSuccess is already in the view. |
1597 ASSERT_GT(db().GetAppropriateMmapSize(), kMmapAlot); | 1603 ASSERT_GT(db().GetAppropriateMmapSize(), kMmapAlot); |
1598 | 1604 |
| 1605 // Preload with partial progress of one page. Should map everything. |
| 1606 ASSERT_TRUE(db().Execute("DROP VIEW MmapStatus")); |
| 1607 ASSERT_TRUE(db().Execute("CREATE VIEW MmapStatus (value) AS SELECT 1")); |
| 1608 ASSERT_GT(db().GetAppropriateMmapSize(), kMmapAlot); |
| 1609 EXPECT_EQ(base::IntToString(MetaTable::kMmapSuccess), |
| 1610 ExecuteWithResult(&db(), "SELECT * FROM MmapStatus")); |
| 1611 |
1599 // Failure status leads to nothing being mapped. | 1612 // Failure status leads to nothing being mapped. |
1600 ASSERT_TRUE(db().Execute("DROP VIEW MmapStatus")); | 1613 ASSERT_TRUE(db().Execute("DROP VIEW MmapStatus")); |
1601 ASSERT_TRUE(db().Execute("CREATE VIEW MmapStatus AS SELECT -2")); | 1614 ASSERT_TRUE(db().Execute("CREATE VIEW MmapStatus (value) AS SELECT -2")); |
1602 ASSERT_EQ(0UL, db().GetAppropriateMmapSize()); | 1615 ASSERT_EQ(0UL, db().GetAppropriateMmapSize()); |
1603 EXPECT_EQ(base::IntToString(MetaTable::kMmapFailure), | 1616 EXPECT_EQ(base::IntToString(MetaTable::kMmapFailure), |
1604 ExecuteWithResult(&db(), "SELECT * FROM MmapStatus")); | 1617 ExecuteWithResult(&db(), "SELECT * FROM MmapStatus")); |
1605 } | 1618 } |
1606 | 1619 |
1607 // To prevent invalid SQL from accidentally shipping to production, prepared | 1620 // To prevent invalid SQL from accidentally shipping to production, prepared |
1608 // statements which fail to compile with SQLITE_ERROR call DLOG(FATAL). This | 1621 // statements which fail to compile with SQLITE_ERROR call DLOG(FATAL). This |
1609 // case cannot be suppressed with an error callback. | 1622 // case cannot be suppressed with an error callback. |
1610 TEST_F(SQLConnectionTest, CompileError) { | 1623 TEST_F(SQLConnectionTest, CompileError) { |
1611 // DEATH tests not supported on Android or iOS. | 1624 // DEATH tests not supported on Android or iOS. |
1612 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 1625 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
1613 if (DLOG_IS_ON(FATAL)) { | 1626 if (DLOG_IS_ON(FATAL)) { |
1614 db().set_error_callback(base::Bind(&IgnoreErrorCallback)); | 1627 db().set_error_callback(base::Bind(&IgnoreErrorCallback)); |
1615 ASSERT_DEATH({ | 1628 ASSERT_DEATH({ |
1616 db().GetUniqueStatement("SELECT x"); | 1629 db().GetUniqueStatement("SELECT x"); |
1617 }, "SQL compile error no such column: x"); | 1630 }, "SQL compile error no such column: x"); |
1618 } | 1631 } |
1619 #endif | 1632 #endif |
1620 } | 1633 } |
1621 | 1634 |
1622 } // namespace sql | 1635 } // namespace sql |
OLD | NEW |