[tests] Added a test for getting resources from the database

This test would have flagged the Qt regression.
This commit is contained in:
Thiago Marcos P. Santos
2018-02-22 11:33:03 +01:00
committed by Bruno de Oliveira Abinader
parent ba019b0256
commit 869799a716
3 changed files with 37 additions and 1 deletions

4
.gitignore vendored
View File

@@ -17,6 +17,8 @@ xcuserdata
/test/fixtures/api/2.png
/test/fixtures/offline_database/offline.db
/test/fixtures/offline_database/offline.db-*
/test/fixtures/offline_database/satellite.db
/test/fixtures/offline_database/satellite.db-*
/test/fixtures/offline_database/invalid.db
/test/fixtures/offline_database/invalid.db-*
/test/fixtures/offline_database/migrated.db
@@ -38,4 +40,4 @@ test/fixtures/storage/assets.zip
# Generated list files from code generation
/scripts/generate-cmake-files.list
/scripts/generate-shaders.list
/scripts/generate-style-code.list
/scripts/generate-style-code.list

Binary file not shown.

View File

@@ -38,6 +38,10 @@ void writeFile(const char* name, const std::string& data) {
mbgl::util::write_file(name, data);
}
void copyFile(const char* orig, const char* dest) {
mbgl::util::write_file(dest, mbgl::util::read_file(orig));
}
} // namespace
TEST(OfflineDatabase, TEST_REQUIRES_WRITE(Create)) {
@@ -143,6 +147,36 @@ TEST(OfflineDatabase, PutResource) {
EXPECT_EQ("second", *updateGetResult->data);
}
TEST(OfflineDatabase, TEST_REQUIRES_WRITE(GetResourceFromOfflineRegion)) {
using namespace mbgl;
createDir("test/fixtures/offline_database");
deleteFile("test/fixtures/offline_database/satellite.db");
copyFile("test/fixtures/offline_database/satellite_test.db", "test/fixtures/offline_database/satellite.db");
OfflineDatabase db("test/fixtures/offline_database/satellite.db", mapbox::sqlite::ReadOnly);
Resource resource = Resource::style("mapbox://styles/mapbox/satellite-v9");
ASSERT_TRUE(db.get(resource));
}
TEST(OfflineDatabase, PutAndGetResource) {
using namespace mbgl;
OfflineDatabase db(":memory:");
Response response1;
response1.data = std::make_shared<std::string>("foobar");
Resource resource = Resource::style("mapbox://example.com/style");
db.put(resource, response1);
auto response2 = db.get(resource);
ASSERT_EQ(*response1.data, *(*response2).data);
}
TEST(OfflineDatabase, PutTile) {
using namespace mbgl;