diff options
author | Łukasz Paczos <lukas.paczos@gmail.com> | 2019-03-13 14:15:16 +0100 |
---|---|---|
committer | Łukasz Paczos <lukas.paczos@gmail.com> | 2019-03-13 14:35:29 +0100 |
commit | 835804277fc75cedfbee0c04a7e54c415119a5c3 (patch) | |
tree | f6bd9be12bcb600ba808b1e7000940628090e576 | |
parent | 10a9249d125072267cddbbea1c0456798fbbc003 (diff) | |
download | qtlocation-mapboxgl-upstream/lp-verify-database-path-change-unit-test.tar.gz |
[core] database path change unit testupstream/lp-verify-database-path-change-unit-test
-rw-r--r-- | platform/default/include/mbgl/storage/offline_database.hpp | 2 | ||||
-rw-r--r-- | platform/default/src/mbgl/storage/offline_database.cpp | 30 | ||||
-rw-r--r-- | test/storage/offline_database.test.cpp | 8 |
3 files changed, 25 insertions, 15 deletions
diff --git a/platform/default/include/mbgl/storage/offline_database.hpp b/platform/default/include/mbgl/storage/offline_database.hpp index aad2778f73..6414affbbe 100644 --- a/platform/default/include/mbgl/storage/offline_database.hpp +++ b/platform/default/include/mbgl/storage/offline_database.hpp @@ -45,6 +45,8 @@ public: void changePath(const std::string&); + void cleanup(); + optional<Response> get(const Resource&); // Return value is (inserted, stored size) diff --git a/platform/default/src/mbgl/storage/offline_database.cpp b/platform/default/src/mbgl/storage/offline_database.cpp index 6111e91e7e..1e53e96d6d 100644 --- a/platform/default/src/mbgl/storage/offline_database.cpp +++ b/platform/default/src/mbgl/storage/offline_database.cpp @@ -27,16 +27,7 @@ OfflineDatabase::OfflineDatabase(std::string path_, uint64_t maximumCacheSize_) } OfflineDatabase::~OfflineDatabase() { - // Deleting these SQLite objects may result in exceptions, but we're in a destructor, so we - // can't throw anything. - try { - statements.clear(); - db.reset(); - } catch (const util::IOException& ex) { - handleError(ex, "close database"); - } catch (const mapbox::sqlite::Exception& ex) { - handleError(ex, "close database"); - } + cleanup(); } void OfflineDatabase::initialize() { @@ -78,15 +69,24 @@ void OfflineDatabase::initialize() { } } -void OfflineDatabase::changePath(const std::string& path_) { +void OfflineDatabase::changePath(const std::string&) { Log::Info(Event::Database, "Changing the database path."); - - statements.clear(); - db.reset(); - path = path_; + cleanup(); initialize(); } +void OfflineDatabase::cleanup() { + // Deleting these SQLite objects may result in exceptions + try { + statements.clear(); + db.reset(); + } catch (const util::IOException& ex) { + handleError(ex, "close database"); + } catch (const mapbox::sqlite::Exception& ex) { + handleError(ex, "close database"); + } +} + void OfflineDatabase::handleError(const mapbox::sqlite::Exception& ex, const char* action) { if (ex.code == mapbox::sqlite::ResultCode::NotADB || ex.code == mapbox::sqlite::ResultCode::Corrupt || diff --git a/test/storage/offline_database.test.cpp b/test/storage/offline_database.test.cpp index d6405fd452..744803a4b2 100644 --- a/test/storage/offline_database.test.cpp +++ b/test/storage/offline_database.test.cpp @@ -1352,3 +1352,11 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(MergeDatabaseWithDiskFull)) { } #endif // __QT__ +TEST(OfflineDatabse, ChangePath) { + std::string newPath("test/fixtures/offline_database/test.db"); + OfflineDatabase db(":memory:"); + db.changePath(newPath); + mapbox::sqlite::Database::open(newPath, mapbox::sqlite::ReadOnly); + util::deleteFile(newPath); +} + |