|
|
@@ -1,12 +1,12 @@ |
|
|
|
#include <memory> |
|
|
|
#include <type_traits> |
|
|
|
#include <gtest/gtest.h> |
|
|
|
#include <mariadb.h> |
|
|
|
#include <cppmariadb.h> |
|
|
|
|
|
|
|
#include "mock.h" |
|
|
|
|
|
|
|
using namespace ::testing; |
|
|
|
using namespace ::mariadb; |
|
|
|
using namespace ::cppmariadb; |
|
|
|
|
|
|
|
/**********************************************************************************************************/ |
|
|
|
TEST(MariaDbTests, MariaDB_connect) |
|
|
@@ -103,7 +103,7 @@ TEST(MariaDbTests, Connection_execute_queryFailed) |
|
|
|
.Times(1); |
|
|
|
|
|
|
|
connection con(reinterpret_cast<MYSQL*>(0x6818)); |
|
|
|
EXPECT_THROW(con.execute("SELECT * FROM blubb"), ::mariadb::exception); |
|
|
|
EXPECT_THROW(con.execute("SELECT * FROM blubb"), ::cppmariadb::exception); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(MariaDbTests, Connection_execute_storeResultFailed_fieldCountGreaterZero) |
|
|
@@ -123,7 +123,7 @@ TEST(MariaDbTests, Connection_execute_storeResultFailed_fieldCountGreaterZero) |
|
|
|
.Times(1); |
|
|
|
|
|
|
|
connection con(reinterpret_cast<MYSQL*>(0x6818)); |
|
|
|
EXPECT_THROW(con.execute("SELECT * FROM blubb"), ::mariadb::exception); |
|
|
|
EXPECT_THROW(con.execute("SELECT * FROM blubb"), ::cppmariadb::exception); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(MariaDbTests, Connection_execute_storeResultFailed_fieldCountIsZero) |
|
|
@@ -183,7 +183,7 @@ TEST(MariaDbTests, Connection_executeStored_queryFailed) |
|
|
|
.Times(1); |
|
|
|
|
|
|
|
connection con(reinterpret_cast<MYSQL*>(0x6818)); |
|
|
|
EXPECT_THROW(con.execute_stored("SELECT * FROM blubb"), ::mariadb::exception); |
|
|
|
EXPECT_THROW(con.execute_stored("SELECT * FROM blubb"), ::cppmariadb::exception); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(MariaDbTests, Connection_executeStored_storeResultFailed_fieldCountGreaterZero) |
|
|
@@ -203,7 +203,7 @@ TEST(MariaDbTests, Connection_executeStored_storeResultFailed_fieldCountGreaterZ |
|
|
|
.Times(1); |
|
|
|
|
|
|
|
connection con(reinterpret_cast<MYSQL*>(0x6818)); |
|
|
|
EXPECT_THROW(con.execute_stored("SELECT * FROM blubb"), ::mariadb::exception); |
|
|
|
EXPECT_THROW(con.execute_stored("SELECT * FROM blubb"), ::cppmariadb::exception); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(MariaDbTests, Connection_executeStored_storeResultFailed_fieldCountIsZero) |
|
|
@@ -264,7 +264,7 @@ TEST(MariaDbTests, Connection_executeUsed_queryFailed) |
|
|
|
.Times(1); |
|
|
|
|
|
|
|
connection con(reinterpret_cast<MYSQL*>(0x6818)); |
|
|
|
EXPECT_THROW(con.execute_used("SELECT * FROM blubb"), ::mariadb::exception); |
|
|
|
EXPECT_THROW(con.execute_used("SELECT * FROM blubb"), ::cppmariadb::exception); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(MariaDbTests, Connection_executeused_useResultFailed_fieldCountGreaterZero) |
|
|
@@ -284,7 +284,7 @@ TEST(MariaDbTests, Connection_executeused_useResultFailed_fieldCountGreaterZero) |
|
|
|
.Times(1); |
|
|
|
|
|
|
|
connection con(reinterpret_cast<MYSQL*>(0x6818)); |
|
|
|
EXPECT_THROW(con.execute_used("SELECT * FROM blubb"), ::mariadb::exception); |
|
|
|
EXPECT_THROW(con.execute_used("SELECT * FROM blubb"), ::cppmariadb::exception); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(MariaDbTests, Connection_executeUsed_useResultFailed_fieldCountIsZero) |
|
|
@@ -345,7 +345,7 @@ TEST(MariaDbTests, Statement_set_invalidIndex) |
|
|
|
{ |
|
|
|
StrictMock<MariaDbMock> mock; |
|
|
|
statement s("SELECT * FROM ?table?"); |
|
|
|
EXPECT_THROW(s.set(4, "test"), ::mariadb::exception); |
|
|
|
EXPECT_THROW(s.set(4, "test"), ::cppmariadb::exception); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(MariaDbTests, Statement_set_validName) |
|
|
@@ -359,7 +359,7 @@ TEST(MariaDbTests, Statement_set_invalidName) |
|
|
|
{ |
|
|
|
StrictMock<MariaDbMock> mock; |
|
|
|
statement s("SELECT * FROM ?table?"); |
|
|
|
EXPECT_THROW(s.set("foo", "test"), ::mariadb::exception); |
|
|
|
EXPECT_THROW(s.set("foo", "test"), ::cppmariadb::exception); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(MariaDbTests, Statement_query) |
|
|
@@ -661,7 +661,7 @@ TEST(MariaDbTests, Row_at_invalidIndex) |
|
|
|
|
|
|
|
result_stored result(reinterpret_cast<MYSQL_RES*>(0x51651)); |
|
|
|
row row(result, const_cast<MYSQL_ROW>(&RowData[0])); |
|
|
|
EXPECT_THROW(row.at(3), ::mariadb::exception); |
|
|
|
EXPECT_THROW(row.at(3), ::cppmariadb::exception); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(MariaDbTests, Row_at_validIndex) |
|
|
@@ -706,7 +706,7 @@ TEST(MariaDbTests, Row_at_invalidName) |
|
|
|
|
|
|
|
result_stored result(reinterpret_cast<MYSQL_RES*>(0x51651)); |
|
|
|
row row(result, const_cast<MYSQL_ROW>(&RowData[0])); |
|
|
|
EXPECT_THROW(row.at("blubb"), ::mariadb::exception); |
|
|
|
EXPECT_THROW(row.at("blubb"), ::cppmariadb::exception); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(MariaDbTests, Row_at_validName) |
|
|
@@ -831,19 +831,19 @@ TEST(MariaDbTests, Row_const_reverse_iterator) |
|
|
|
/**********************************************************************************************************/ |
|
|
|
TEST(MariaDbTests, Field_index) |
|
|
|
{ |
|
|
|
mariadb::result_stored result (reinterpret_cast<MYSQL_RES*>(0x51651)); |
|
|
|
mariadb::row row (result, const_cast<MYSQL_ROW>(&RowData[0])); |
|
|
|
mariadb::field field (row, 1, RowData[1], RowLengths[1]); |
|
|
|
cppmariadb::result_stored result (reinterpret_cast<MYSQL_RES*>(0x51651)); |
|
|
|
cppmariadb::row row (result, const_cast<MYSQL_ROW>(&RowData[0])); |
|
|
|
cppmariadb::field field (row, 1, RowData[1], RowLengths[1]); |
|
|
|
EXPECT_EQ(1, field.index()); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(MariaDbTests, Field_isNull) |
|
|
|
{ |
|
|
|
mariadb::result_stored result (reinterpret_cast<MYSQL_RES*>(0x51651)); |
|
|
|
mariadb::row row (result, const_cast<MYSQL_ROW>(&RowData[0])); |
|
|
|
mariadb::field field0 (row, 1, nullptr, 0); |
|
|
|
mariadb::field field1 (row, 1, "", 0); |
|
|
|
mariadb::field field2 (row, 1, "asd", 3); |
|
|
|
cppmariadb::result_stored result (reinterpret_cast<MYSQL_RES*>(0x51651)); |
|
|
|
cppmariadb::row row (result, const_cast<MYSQL_ROW>(&RowData[0])); |
|
|
|
cppmariadb::field field0 (row, 1, nullptr, 0); |
|
|
|
cppmariadb::field field1 (row, 1, "", 0); |
|
|
|
cppmariadb::field field2 (row, 1, "asd", 3); |
|
|
|
|
|
|
|
EXPECT_TRUE (field0.is_null()); |
|
|
|
EXPECT_FALSE(field1.is_null()); |
|
|
@@ -852,11 +852,11 @@ TEST(MariaDbTests, Field_isNull) |
|
|
|
|
|
|
|
TEST(MariaDbTests, Field_isEmpty) |
|
|
|
{ |
|
|
|
mariadb::result_stored result (reinterpret_cast<MYSQL_RES*>(0x51651)); |
|
|
|
mariadb::row row (result, const_cast<MYSQL_ROW>(&RowData[0])); |
|
|
|
mariadb::field field0 (row, 1, nullptr, 0); |
|
|
|
mariadb::field field1 (row, 1, "", 0); |
|
|
|
mariadb::field field2 (row, 1, "asd", 3); |
|
|
|
cppmariadb::result_stored result (reinterpret_cast<MYSQL_RES*>(0x51651)); |
|
|
|
cppmariadb::row row (result, const_cast<MYSQL_ROW>(&RowData[0])); |
|
|
|
cppmariadb::field field0 (row, 1, nullptr, 0); |
|
|
|
cppmariadb::field field1 (row, 1, "", 0); |
|
|
|
cppmariadb::field field2 (row, 1, "asd", 3); |
|
|
|
|
|
|
|
EXPECT_TRUE (field0.is_empty()); |
|
|
|
EXPECT_TRUE (field1.is_empty()); |
|
|
@@ -867,9 +867,9 @@ TEST(MariaDbTests, Field_data) |
|
|
|
{ |
|
|
|
static const char* data = "test"; |
|
|
|
|
|
|
|
mariadb::result_stored result (reinterpret_cast<MYSQL_RES*>(0x51651)); |
|
|
|
mariadb::row row (result, const_cast<MYSQL_ROW>(&RowData[0])); |
|
|
|
mariadb::field field (row, 1, data, 4); |
|
|
|
cppmariadb::result_stored result (reinterpret_cast<MYSQL_RES*>(0x51651)); |
|
|
|
cppmariadb::row row (result, const_cast<MYSQL_ROW>(&RowData[0])); |
|
|
|
cppmariadb::field field (row, 1, data, 4); |
|
|
|
|
|
|
|
EXPECT_EQ(data, field.data()); |
|
|
|
} |
|
|
@@ -878,20 +878,20 @@ TEST(MariaDbTests, Field_size) |
|
|
|
{ |
|
|
|
static const char* data = "test"; |
|
|
|
|
|
|
|
mariadb::result_stored result (reinterpret_cast<MYSQL_RES*>(0x51651)); |
|
|
|
mariadb::row row (result, const_cast<MYSQL_ROW>(&RowData[0])); |
|
|
|
mariadb::field field (row, 1, data, 4); |
|
|
|
cppmariadb::result_stored result (reinterpret_cast<MYSQL_RES*>(0x51651)); |
|
|
|
cppmariadb::row row (result, const_cast<MYSQL_ROW>(&RowData[0])); |
|
|
|
cppmariadb::field field (row, 1, data, 4); |
|
|
|
|
|
|
|
EXPECT_EQ(4, field.size()); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(MariaDbTests, Field_implicit_bool_cast) |
|
|
|
{ |
|
|
|
mariadb::result_stored result (reinterpret_cast<MYSQL_RES*>(0x51651)); |
|
|
|
mariadb::row row (result, const_cast<MYSQL_ROW>(&RowData[0])); |
|
|
|
mariadb::field field0 (row, 1, nullptr, 0); |
|
|
|
mariadb::field field1 (row, 1, "", 0); |
|
|
|
mariadb::field field2 (row, 1, "asd", 3); |
|
|
|
cppmariadb::result_stored result (reinterpret_cast<MYSQL_RES*>(0x51651)); |
|
|
|
cppmariadb::row row (result, const_cast<MYSQL_ROW>(&RowData[0])); |
|
|
|
cppmariadb::field field0 (row, 1, nullptr, 0); |
|
|
|
cppmariadb::field field1 (row, 1, "", 0); |
|
|
|
cppmariadb::field field2 (row, 1, "asd", 3); |
|
|
|
|
|
|
|
EXPECT_FALSE(static_cast<bool>(field0)); |
|
|
|
EXPECT_FALSE(static_cast<bool>(field1)); |
|
|
@@ -900,10 +900,10 @@ TEST(MariaDbTests, Field_implicit_bool_cast) |
|
|
|
|
|
|
|
TEST(MariaDbTests, Field_get) |
|
|
|
{ |
|
|
|
mariadb::result_stored result (reinterpret_cast<MYSQL_RES*>(0x51651)); |
|
|
|
mariadb::row row (result, const_cast<MYSQL_ROW>(&RowData[0])); |
|
|
|
mariadb::field field0 (row, 1, "123", 3); |
|
|
|
mariadb::field field1 (row, 1, "asd", 3); |
|
|
|
cppmariadb::result_stored result (reinterpret_cast<MYSQL_RES*>(0x51651)); |
|
|
|
cppmariadb::row row (result, const_cast<MYSQL_ROW>(&RowData[0])); |
|
|
|
cppmariadb::field field0 (row, 1, "123", 3); |
|
|
|
cppmariadb::field field1 (row, 1, "asd", 3); |
|
|
|
|
|
|
|
EXPECT_EQ(123, field0.get<int>()); |
|
|
|
EXPECT_EQ(std::string("asd"), field1.get<std::string>()); |