diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2017-01-05 12:09:30 -0400 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2017-01-23 19:06:53 +0200 |
commit | 88b7fc3929acbe119b3dbfa2a9f6dbd04b338ebe (patch) | |
tree | a2e8c9e41630346f8030810a2e34ee602bd9cc9e /test/storage | |
parent | eb772258cfa1af3a530ce9ff750c86aff20f96cf (diff) | |
download | qtlocation-mapboxgl-88b7fc3929acbe119b3dbfa2a9f6dbd04b338ebe.tar.gz |
[Qt] Implement mapbox::sqlite::{Database,Statement} using QtSql
Diffstat (limited to 'test/storage')
-rw-r--r-- | test/storage/offline_database.test.cpp | 19 | ||||
-rw-r--r-- | test/storage/sqlite.test.cpp | 27 |
2 files changed, 27 insertions, 19 deletions
diff --git a/test/storage/offline_database.test.cpp b/test/storage/offline_database.test.cpp index 5e8da106da..2e25835d80 100644 --- a/test/storage/offline_database.test.cpp +++ b/test/storage/offline_database.test.cpp @@ -80,25 +80,6 @@ private: } // namespace -TEST(OfflineDatabase, Statement) { - using namespace mbgl; - - mapbox::sqlite::Database db(":memory:", mapbox::sqlite::ReadWrite | mapbox::sqlite::Create); - db.exec("CREATE TABLE test (id INTEGER)"); - mapbox::sqlite::Statement stmt1 = db.prepare("INSERT INTO test (id) VALUES (?1)"); - stmt1.bind(1, 0); - stmt1.run(); - ASSERT_EQ(stmt1.lastInsertRowId(), 1); - ASSERT_EQ(stmt1.changes(), 1); - - mapbox::sqlite::Statement stmt2 = db.prepare("INSERT INTO test (id) VALUES (?1)"); - stmt2.bind(1, 0); - stmt2.run(); - ASSERT_EQ(stmt1.lastInsertRowId(), 1); - ASSERT_EQ(stmt2.lastInsertRowId(), 2); - ASSERT_EQ(stmt2.changes(), 1); -} - TEST(OfflineDatabase, TEST_REQUIRES_WRITE(Create)) { using namespace mbgl; diff --git a/test/storage/sqlite.test.cpp b/test/storage/sqlite.test.cpp new file mode 100644 index 0000000000..dbd7a09868 --- /dev/null +++ b/test/storage/sqlite.test.cpp @@ -0,0 +1,27 @@ +#include <mbgl/test/util.hpp> + +#include <gtest/gtest.h> +#include <sqlite3.hpp> + +TEST(SQLite, Statement) { + using namespace mbgl; + + mapbox::sqlite::Database db(":memory:", mapbox::sqlite::Create | mapbox::sqlite::ReadWrite); + db.exec("CREATE TABLE test (id INTEGER);"); + + mapbox::sqlite::Statement stmt1 = db.prepare("INSERT INTO test (id) VALUES (?1);"); + ASSERT_EQ(stmt1.lastInsertRowId(), 0); + ASSERT_EQ(stmt1.changes(), 0u); + stmt1.bind(1, 10); + stmt1.run(); + ASSERT_EQ(stmt1.lastInsertRowId(), 1); + ASSERT_EQ(stmt1.changes(), 1u); + + mapbox::sqlite::Statement stmt2 = db.prepare("INSERT INTO test (id) VALUES (?1);"); + ASSERT_EQ(stmt2.lastInsertRowId(), 0); + ASSERT_EQ(stmt2.changes(), 0u); + stmt2.bind(1, 20); + stmt2.run(); + ASSERT_EQ(stmt2.lastInsertRowId(), 2); + ASSERT_EQ(stmt2.changes(), 1u); +} |