mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
WIP C-based test
This commit is contained in:
@@ -34,3 +34,7 @@ MY_ADD_TEST(mf_iocache)
|
||||
ADD_EXECUTABLE(my_json_writer-t my_json_writer-t.cc dummy_builtins.cc)
|
||||
TARGET_LINK_LIBRARIES(my_json_writer-t sql mytap)
|
||||
MY_ADD_TEST(my_json_writer)
|
||||
|
||||
ADD_EXECUTABLE(mysql_opt_bind-t mysql_opt_bind-t.c dummy_builtins.cc)
|
||||
TARGET_LINK_LIBRARIES(mysql_opt_bind-t sql mytap)
|
||||
MY_ADD_TEST(mysql_opt_bind)
|
||||
|
71
unittest/sql/mysql_opt_bind-t.c
Normal file
71
unittest/sql/mysql_opt_bind-t.c
Normal file
@@ -0,0 +1,71 @@
|
||||
//TODO license headr
|
||||
#include <stdbool.h>
|
||||
#include <tap.h>
|
||||
#include <mysql.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
static const bool ARG_TRUE= true;
|
||||
static const char QUERY[]= "SELECT SUBSTRING_INDEX(USER(), '@', -1)";
|
||||
|
||||
const char *const port_string= getenv("MASTER_MYPORT");
|
||||
const unsigned int port=
|
||||
port_string? (unsigned int)strtoul(port, NULL, 10) : 0;
|
||||
|
||||
//TODO classes allow explicit case handling
|
||||
const char *bind_addresses[][2] = {
|
||||
{ "127.0.0.1", /* Cloudflare DNS */ "1.0.0.1" },
|
||||
{ "localhost", "example.com" },
|
||||
//TODO IPv6
|
||||
};
|
||||
int count= sizeof(bind_addresses) / sizeof(const char *);
|
||||
|
||||
plan(count);
|
||||
for (size_t i= 0; i < count; ++i)
|
||||
{
|
||||
const char *bind_address= bind_addresses[i];
|
||||
MYSQL connection;
|
||||
MYSQL_RES *results;
|
||||
bool success= false;
|
||||
|
||||
// need init thread. mysql_thread_init(); mysql_thread_end();
|
||||
if (!mysql_init(&connection))
|
||||
{
|
||||
diag("failed to initialize connection");
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (mysql_options(&connection, MYSQL_OPT_BIND, bind_address))
|
||||
{
|
||||
diag("MYSQL_OPT_BIND not accepted");
|
||||
goto close;
|
||||
}
|
||||
mysql_options(&connection, MYSQL_OPT_RECONNECT, &ARG_TRUE);
|
||||
|
||||
if (!mysql_real_connect(&connection,
|
||||
NULL, // server address
|
||||
NULL, // user
|
||||
NULL, // password
|
||||
NULL, // database
|
||||
port,
|
||||
NULL, // socket
|
||||
0x0 // flags
|
||||
))
|
||||
{
|
||||
if (/* TODO test fails from invalid addresses */ false)
|
||||
success= true;
|
||||
else
|
||||
diag("failed to connect to the server");
|
||||
goto close;
|
||||
}
|
||||
|
||||
// TODO query
|
||||
|
||||
close:
|
||||
mysql_close(&connection);
|
||||
end:
|
||||
ok(success, bind_address);
|
||||
}
|
||||
test_case();
|
||||
return exit_status();
|
||||
}
|
Reference in New Issue
Block a user