9#include <framework/utilities/sqlite.h>
10#include <framework/geometry/B2Vector3.h>
12#include <gtest/gtest.h>
19 class SQLiteTest:
public ::testing::Test {
22 sqlite3* m_connection{
nullptr};
26 int result = sqlite3_open_v2(
":memory:", &m_connection, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
nullptr);
27 ASSERT_EQ(result, SQLITE_OK);
28 std::string sql = R
"DOC(
29 CREATE TABLE test(name TEXT, x FLOAT, y FLOAT, z FLOAT);
30 INSERT INTO test VALUES ('IP', 0, 0, 0);
31 INSERT INTO test VALUES ('X', 1, 0, 0);
32 INSERT INTO test VALUES ('Y', 0, 1, 0);
33 INSERT INTO test VALUES ('Z', 0, 0, 1);
35 result = sqlite3_exec(m_connection, sql.c_str(), nullptr,
nullptr,
nullptr);
36 ASSERT_EQ(result, SQLITE_OK);
40 void TearDown()
override
42 int result = sqlite3_close_v2(m_connection);
43 ASSERT_EQ(result, SQLITE_OK);
48 TEST_F(SQLiteTest, Statement)
51 std::vector<std::tuple<std::string, double>> expected{{
"IP", 0.}, {
"X", 1.}, {
"Y", 0.}, {
"Z", 0.}};
52 for (
auto&& row : stmt) {
53 ASSERT_FALSE(expected.empty());
54 ASSERT_EQ(row, expected.back());
57 ASSERT_TRUE(expected.empty());
61 TEST_F(SQLiteTest, StatementTypeConversion)
64 std::vector<std::tuple<std::string, std::string>> expected{{
"IP",
"0.0"}, {
"X",
"1.0"}, {
"Y",
"0.0"}, {
"Z",
"0.0"}};
65 for (
auto&& row : stmt) {
66 ASSERT_FALSE(expected.empty());
67 ASSERT_EQ(row, expected.back());
70 ASSERT_TRUE(expected.empty());
74 TEST_F(SQLiteTest, StatementTypeConversion2)
77 std::vector<std::tuple<std::string, int>> expected{{
"IP", 0}, {
"X", 1}, {
"Y", 0}, {
"Z", 0}};
78 for (
auto&& row : stmt) {
79 ASSERT_FALSE(expected.empty());
80 ASSERT_EQ(row, expected.back());
83 ASSERT_TRUE(expected.empty());
87 TEST_F(SQLiteTest, SimpleStatement)
90 std::set<std::string> expected{
"IP",
"X",
"Z"};
92 std::set<std::string> actual(stmt.begin(), stmt.end());
93 ASSERT_EQ(expected, actual);
96 actual = std::set<std::string>(stmt.begin(), stmt.end());
97 ASSERT_EQ(expected, actual);
101 TEST_F(SQLiteTest, SimpleStatementParameterConversion)
104 std::set<std::string> expected{
"IP",
"X",
"Z"};
106 std::set<std::string> actual(stmt.begin(), stmt.end());
107 ASSERT_EQ(expected, actual);
110 actual = std::set<std::string>(stmt.begin(), stmt.end());
111 ASSERT_EQ(expected, actual);
115 TEST_F(SQLiteTest, ObjectStatement)
118 auto it = stmt.begin();
119 ASSERT_NE(it, stmt.end());
121 ASSERT_NE(++it, stmt.end());
123 ASSERT_NE(++it, stmt.end());
125 ASSERT_NE(++it, stmt.end());
127 ASSERT_EQ(++it, stmt.end());
131 TEST_F(SQLiteTest, NotEnoughParams)
134 ASSERT_THROW(stmt.execute(), std::runtime_error);
138 TEST_F(SQLiteTest, TooManyParams)
141 ASSERT_THROW(stmt.execute(0,
"foo"), std::runtime_error);
145 TEST_F(SQLiteTest, NotEnoughColumns)
148 ASSERT_THROW(construct(), std::runtime_error);
152 TEST_F(SQLiteTest, TooManyColumns)
155 ASSERT_THROW(construct(), std::runtime_error);
SQLite prepared statement wrapper.
B2Vector3< double > B2Vector3D
typedef for common usage with double
Abstract base class for different kinds of events.