2
0
mirror of https://github.com/boostorg/mysql.git synced 2026-02-02 09:02:09 +00:00

Completed integ tests for fetch_many

This commit is contained in:
ruben
2019-12-07 21:41:14 +00:00
parent 0dcd46233f
commit d9f9bbbbe6
2 changed files with 55 additions and 14 deletions

View File

@@ -2,6 +2,7 @@
#define TEST_TEST_COMMON_HPP_
#include "mysql/value.hpp"
#include "mysql/row.hpp"
#include <vector>
namespace mysql
@@ -15,6 +16,27 @@ std::vector<value> makevalues(Types&&... args)
return std::vector<value>{mysql::value(std::forward<Types>(args))...};
}
template <typename... Types>
row makerow(Types&&... args)
{
// note: metadata dangles, just for testing
return row(makevalues(std::forward<Types>(args)...), {}, {});
}
template <typename... Types>
std::vector<row> makerows(std::size_t row_size, Types&&... args)
{
auto values = makevalues(std::forward<Types>(args)...);
assert(values.size() % row_size == 0);
std::vector<row> res;
for (std::size_t i = 0; i < values.size(); i += row_size)
{
std::vector<value> row_values (values.begin() + i, values.begin() + i + row_size);
res.push_back(row(std::move(row_values), {})); // metadata dangles, just for testing
}
return res;
}
}
}

View File

@@ -49,15 +49,34 @@ struct QueryTest : public mysql::test::IntegTest
EXPECT_EQ(result.info(), info);
}
void validate_2fields_meta(
const std::vector<field_metadata>& fields,
const std::string& table
) const
{
validate_meta(fields, {
meta_validator(table, "id", field_type::int_),
meta_validator(table, "field_varchar", field_type::varchar, collation::utf8_general_ci)
});
}
void validate_2fields_meta(
const resultset_type& result,
const std::string& table
) const
{
validate_meta(result.fields(), {
meta_validator(table, "id", field_type::int_),
meta_validator(table, "field_varchar", field_type::varchar, collation::utf8_general_ci)
});
validate_2fields_meta(result.fields(), table);
}
void validate_2fields_meta(
const std::vector<owning_row>& rows,
const std::string& table
) const
{
for (const auto& row: rows)
{
validate_2fields_meta(row.metadata(), table);
}
}
};
@@ -329,15 +348,15 @@ TEST_F(QueryTest, FetchMany_MoreRowsThanCount)
auto rows = result.fetch_many(2, errc);
ASSERT_EQ(errc, error_code());
EXPECT_FALSE(result.complete());
EXPECT_EQ(rows.size(), 2);
// TODO: check values & metadata
validate_2fields_meta(rows, "three_rows_table");
EXPECT_EQ(rows, (makerows(2, 1, "f0", 2, "f1")));
// Fetch another two (completes the resultset)
rows = result.fetch_many(2, errc);
ASSERT_EQ(errc, error_code());
EXPECT_TRUE(result.complete());
EXPECT_EQ(rows.size(), 1);
// TODO: check values & metadata
validate_2fields_meta(rows, "three_rows_table");
EXPECT_EQ(rows, (makerows(2, 3, "f2")));
}
TEST_F(QueryTest, FetchMany_LessRowsThanCount)
@@ -348,8 +367,8 @@ TEST_F(QueryTest, FetchMany_LessRowsThanCount)
auto rows = result.fetch_many(3, errc);
ASSERT_EQ(errc, error_code());
EXPECT_TRUE(result.complete());
EXPECT_EQ(rows.size(), 2);
// TODO: check values & metadata
validate_2fields_meta(rows, "two_rows_table");
EXPECT_EQ(rows, (makerows(2, 1, "f0", 2, "f1")));
}
TEST_F(QueryTest, FetchMany_SameRowsAsCount)
@@ -360,8 +379,8 @@ TEST_F(QueryTest, FetchMany_SameRowsAsCount)
auto rows = result.fetch_many(2, errc);
ASSERT_EQ(errc, error_code());
EXPECT_FALSE(result.complete());
EXPECT_EQ(rows.size(), 2);
// TODO: check values & metadata
validate_2fields_meta(rows, "two_rows_table");
EXPECT_EQ(rows, (makerows(2, 1, "f0", 2, "f1")));
// Fetch again, exhausts the resultset
rows = result.fetch_many(2, errc);
@@ -378,8 +397,8 @@ TEST_F(QueryTest, FetchMany_CountEqualsOne)
auto rows = result.fetch_many(1, errc);
ASSERT_EQ(errc, error_code());
EXPECT_FALSE(result.complete());
EXPECT_EQ(rows.size(), 1);
// TODO: check values & metadata
validate_2fields_meta(rows, "one_row_table");
EXPECT_EQ(rows, (makerows(2, 1, "f0")));
}
// Query for INT types