8 #include "hep_concurrency/simultaneous_function_spawner.h" 27 cout <<
"start test_with_new_database\n";
30 std::cout <<
"end test_with_new_database\n";
36 cout <<
"start test_with_matching_table\n";
39 std::cout <<
"end test_with_matching_table\n";
42 template <
class... ARGS>
47 cout <<
"start test_with_colliding_table\n";
51 assert(
"Failed throw for mismatched table" ==
nullptr);
56 assert(
"Threw wrong exception for mismatched table" ==
nullptr);
58 cout <<
"end test_with_colliding_table\n";
64 auto n =
static_cast<int*
>(
p);
66 assert(
strcmp(cnames[0],
"count(*)") == 0);
67 *
n = stoi(results[0]);
74 cout <<
"start test_filling_table\n";
76 constexpr
int nrows{903};
79 for (
int i = 0; i <
nrows; ++i) {
80 nt.insert(i, 1.5 * i);
84 nmatches <<
select(
"count(*)").from(c,
"zz");
87 cout <<
"end test_filling_table\n";
93 cout <<
"start test_parallel_filling_table\n";
95 constexpr
int nrows_per_thread{100};
96 constexpr
unsigned nthreads{10};
97 string const tablename{
"zz"};
104 std::vector<std::function<void()>> tasks;
105 for (
unsigned i{}; i < nthreads; ++i) {
106 tasks.emplace_back([i, &nt] {
107 for (
unsigned j{}; j < nrows_per_thread; ++j) {
108 auto const j1 = j + i * 100;
109 nt.insert(j1, 1.5 * j1);
113 hep::concurrency::simultaneous_function_spawner sfs{tasks};
116 nmatches <<
select(
"count(*)").from(c, tablename);
117 assert(
unique_value(nmatches) == nrows_per_thread * nthreads);
118 cout <<
"end test_parallel_filling_table\n";
124 cout <<
"start test_column_constraint\n";
130 cout <<
"end test_column_constraint\n";
141 for (std::size_t i = 0; i < 103; ++i) {
142 table.insert(i, 0.5 * i, i * i);
146 cnt <<
select(
"count(*)").from(*c,
"tab1");
152 const char*
fname{
"no_such_file.db"};
162 test_with_colliding_table<int, double>(*
c, {{
"y",
"txt"}});
163 test_with_colliding_table<int, double>(*
c, {{
"x",
"text"}});
164 test_with_colliding_table<int, int>(*
c, {{
"x",
"txt"}});
165 test_with_colliding_table<int, double, int>(*
c, {{
"x",
"txt",
"z"}});
166 test_with_colliding_table<int>(*
c, {{
"x"}});
177 std::cout <<
"Unknown exception caught\n";
void test_with_new_database(Connection &c)
bool hasTableWithSchema(sqlite3 *db, std::string const &tablename, std::string expectedSchema)
T unique_value(query_result< T > const &r)
void test_with_matching_table(Connection &c)
void test_column_constraint(Connection &c)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
auto make_connection(std::string const &file_name, PolicyArgs &&...) -> Connection *
void test_file_create(ConnectionFactory &cf)
void test_parallel_filling_table(Connection &c)
std::string create_table_ddl(std::string const &tablename, Cols const &...cols)
int count_rows(void *p, int nrows, char **results, char **cnames)
auto select(T const &...t)
auto array(Array const &a)
Returns a manipulator which will print the specified array.
int strcmp(const String &s1, const String &s2)
void test_filling_table(Connection &c)
unsigned nrows(sqlite3 *db, std::string const &tablename)
static std::vector< std::string > const names
void test_with_colliding_table(Connection &c, array< string, sizeof...(ARGS)> const &names)
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)