1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-07 02:42:49 +03:00

C preprocessor defines fix

This commit is contained in:
Oleksandr Byelkin
2020-06-04 16:49:21 +02:00
parent ce011210d1
commit 895dcb61e3
24 changed files with 179 additions and 150 deletions

View File

@@ -223,11 +223,11 @@ static int test_change_user(MYSQL *mysql)
/* Prepare environment */
sprintf(buff, "drop database if exists %s", db);
rc= mysql_query(mysql, buff);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
sprintf(buff, "create database %s", db);
rc= mysql_query(mysql, buff);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
sprintf(buff,
"grant select on %s.* to %s@'%%' identified by '%s'",
@@ -235,14 +235,14 @@ static int test_change_user(MYSQL *mysql)
user_pw,
pw);
rc= mysql_query(mysql, buff);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
sprintf(buff,
"grant select on %s.* to %s@'%%'",
db,
user_no_pw);
rc= mysql_query(mysql, buff);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
/* Try some combinations */
@@ -288,13 +288,13 @@ static int test_change_user(MYSQL *mysql)
FAIL_UNLESS(rc, "Error expected");
rc= mysql_change_user(mysql, user_pw, pw, db);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_change_user(mysql, user_pw, pw, NULL);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_change_user(mysql, user_pw, pw, "");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_change_user(mysql, user_no_pw, pw, db);
FAIL_UNLESS(rc, "Error expected");
@@ -306,16 +306,16 @@ static int test_change_user(MYSQL *mysql)
FAIL_UNLESS(rc, "Error expected");
rc= mysql_change_user(mysql, user_no_pw, "", NULL);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_change_user(mysql, user_no_pw, "", "");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_change_user(mysql, user_no_pw, "", db);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_change_user(mysql, user_no_pw, NULL, db);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_change_user(mysql, "", pw, db);
FAIL_UNLESS(rc, "Error expected");
@@ -345,15 +345,15 @@ static int test_change_user(MYSQL *mysql)
sprintf(buff, "drop database %s", db);
rc= mysql_query(mysql, buff);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
sprintf(buff, "drop user %s@'%%'", user_pw);
rc= mysql_query(mysql, buff);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
sprintf(buff, "drop user %s@'%%'", user_no_pw);
rc= mysql_query(mysql, buff);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
return OK;
}
@@ -661,7 +661,7 @@ int test_connection_timeout(MYSQL *unused __attribute__((unused)))
elapsed= time(NULL) - start;
diag("elapsed: %lu", (unsigned long)elapsed);
mysql_close(mysql);
FAIL_IF((unsigned int)elapsed > 2 * timeout, "timeout ignored")
FAIL_IF((unsigned int)elapsed > 2 * timeout, "timeout ignored");
return OK;
}
@@ -681,7 +681,7 @@ int test_connection_timeout2(MYSQL *unused __attribute__((unused)))
elapsed= time(NULL) - start;
diag("elapsed: %lu", (unsigned long)elapsed);
mysql_close(mysql);
FAIL_IF((unsigned int)elapsed > 2 * timeout, "timeout ignored")
FAIL_IF((unsigned int)elapsed > 2 * timeout, "timeout ignored");
return OK;
}
@@ -706,7 +706,7 @@ int test_connection_timeout3(MYSQL *unused __attribute__((unused)))
}
elapsed= time(NULL) - start;
diag("elapsed: %lu", (unsigned long)elapsed);
FAIL_IF((unsigned int)elapsed > timeout + 1, "timeout ignored")
FAIL_IF((unsigned int)elapsed > timeout + 1, "timeout ignored");
mysql_close(mysql);
mysql= mysql_init(NULL);

View File

@@ -1123,7 +1123,7 @@ static int test_bug11909(MYSQL *mysql)
check_stmt_rc(rc, stmt2);
rc= mysql_stmt_fetch(stmt2);
FAIL_UNLESS(rc == 0, "rc != 0")
FAIL_UNLESS(rc == 0, "rc != 0");
FAIL_UNLESS(empno == 10, "empno != 10");
FAIL_UNLESS(strcmp(firstname, "CHRISTINE""") == 0, "firstname != 'Christine'");

View File

@@ -64,57 +64,71 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define MAX_TEST_QUERY_LENGTH 300 /* MAX QUERY BUFFER LENGTH */
/* prevent warnings on Win64 by using STMT_LEN instead of strlen */
#define STMT_LEN(A) (unsigned long)strlen((A))
#define STMT_LEN(A) ((unsigned long)strlen((A)))
#define SKIP_TRAVIS()\
if (getenv("TRAVIS"))\
{\
diag("Skip test on Travis CI");\
return SKIP;\
}
do {\
if (getenv("TRAVIS"))\
{\
diag("Skip test on Travis CI");\
return SKIP;\
}\
}while(0)
#define SKIP_MYSQL(mysql)\
if (!mariadb_connection(mysql))\
{\
diag("Skip test for non MariaDB server");\
return OK;\
}
do {\
if (!mariadb_connection(mysql))\
{\
diag("Skip test for non MariaDB server");\
return OK;\
}\
} while(0)
#define check_mysql_rc(rc, mysql) \
if (rc)\
{\
diag("Error (%d): %s (%d) in %s line %d", rc, mysql_error(mysql), \
mysql_errno(mysql), __FILE__, __LINE__);\
return(FAIL);\
}
do {\
if (rc)\
{\
diag("Error (%d): %s (%d) in %s line %d", rc, mysql_error(mysql), \
mysql_errno(mysql), __FILE__, __LINE__);\
return(FAIL);\
}\
} while(0)
#define check_stmt_rc(rc, stmt) \
if (rc)\
{\
diag("Error: %s (%s: %d)", mysql_stmt_error(stmt), __FILE__, __LINE__);\
return(FAIL);\
}
do {\
if (rc)\
{\
diag("Error: %s (%s: %d)", mysql_stmt_error(stmt), __FILE__, __LINE__);\
return(FAIL);\
}\
} while(0)
#define FAIL_IF(expr, reason)\
if (expr)\
{\
diag("Error: %s (%s: %d)", (reason) ? reason : "", __FILE__, __LINE__);\
return FAIL;\
}
do {\
if (expr)\
{\
diag("Error: %s (%s: %d)", (reason) ? reason : "", __FILE__, __LINE__);\
return FAIL;\
}\
} while(0)
#define FAIL_UNLESS(expr, reason)\
if (!(expr))\
{\
diag("Error: %s (%s: %d)", reason, __FILE__, __LINE__);\
return FAIL;\
}
do {\
if (!(expr))\
{\
diag("Error: %s (%s: %d)", reason, __FILE__, __LINE__);\
return FAIL;\
}\
} while(0)
#define SKIP_CONNECTION_HANDLER \
if (hostname && strstr(hostname, "://"))\
do {\
if (hostname && strstr(hostname, "://"))\
{\
diag("Test skipped (connection handler)");\
return SKIP;\
}
}\
} while(0)
/* connection options */
#define TEST_CONNECTION_DEFAULT 1 /* default connection */

View File

@@ -678,7 +678,7 @@ static int test_prepare_ext(MYSQL *mysql)
char query[MAX_TEST_QUERY_LENGTH];
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prepare_ext");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
sql= (char *)"CREATE TABLE test_prepare_ext"
"("
@@ -716,7 +716,7 @@ static int test_prepare_ext(MYSQL *mysql)
" c32 set('monday', 'tuesday', 'wednesday'))";
rc= mysql_query(mysql, sql);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
/* insert by prepare - all integers */
strcpy(query, "INSERT INTO test_prepare_ext(c1, c2, c3, c4, c5, c6) VALUES(?, ?, ?, ?, ?, ?)");
@@ -785,7 +785,7 @@ static int test_prepare_ext(MYSQL *mysql)
mysql_stmt_close(stmt);
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prepare_ext");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
return OK;
}
@@ -1203,7 +1203,7 @@ static int test_long_data(MYSQL *mysql)
stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));
rc= mysql_stmt_prepare(stmt, SL(query));
check_stmt_rc(rc, stmt)
check_stmt_rc(rc, stmt);
FAIL_IF(mysql_stmt_param_count(stmt) != 3, "Paramcount != 3");
@@ -1296,7 +1296,7 @@ static int test_long_data_str(MYSQL *mysql)
stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));
rc= mysql_stmt_prepare(stmt, SL(query));
check_stmt_rc(rc, stmt)
check_stmt_rc(rc, stmt);
FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Paramcount != 2");
@@ -1395,7 +1395,7 @@ static int test_long_data_str1(MYSQL *mysql)
stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));
rc= mysql_stmt_prepare(stmt, SL(query));
check_stmt_rc(rc, stmt)
check_stmt_rc(rc, stmt);
FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Paramcount != 2");
@@ -1465,7 +1465,7 @@ static int test_long_data_str1(MYSQL *mysql)
stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));
rc= mysql_stmt_prepare(stmt, SL(query));
check_stmt_rc(rc, stmt)
check_stmt_rc(rc, stmt);
FAIL_IF(mysql_stmt_param_count(stmt) != 0, "Paramcount != 0");
@@ -1560,7 +1560,7 @@ static int test_long_data_bin(MYSQL *mysql)
stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));
rc= mysql_stmt_prepare(stmt, SL(query));
check_stmt_rc(rc, stmt)
check_stmt_rc(rc, stmt);
FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Paramcount != 2");
@@ -1653,7 +1653,7 @@ static int test_simple_delete(MYSQL *mysql)
stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));
rc= mysql_stmt_prepare(stmt, SL(query));
check_stmt_rc(rc, stmt)
check_stmt_rc(rc, stmt);
FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Paramcount != 2");

View File

@@ -1064,10 +1064,10 @@ static int test_bug1946(MYSQL *mysql)
rc= mysql_query(mysql, "DROP TABLE IF EXISTS prepare_command");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "CREATE TABLE prepare_command(ID INT)");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));
@@ -1106,9 +1106,9 @@ static int test_bug20152(MYSQL *mysql)
tm.second = 42;
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "CREATE TABLE t1 (f1 DATE)");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
stmt= mysql_stmt_init(mysql);
rc= mysql_stmt_prepare(stmt, SL(query));
@@ -1120,7 +1120,7 @@ static int test_bug20152(MYSQL *mysql)
rc= mysql_stmt_close(stmt);
check_stmt_rc(rc, stmt);
rc= mysql_query(mysql, "DROP TABLE t1");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
FAIL_UNLESS(tm.hour == 14 && tm.minute == 9 && tm.second == 42, "time != 14:09:42");
return OK;
}
@@ -1142,10 +1142,10 @@ static int test_bug2247(MYSQL *mysql)
/* create table and insert few rows */
rc= mysql_query(mysql, drop);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, create);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));
@@ -1160,7 +1160,7 @@ static int test_bug2247(MYSQL *mysql)
FAIL_UNLESS(exp_count == 1, "exp_count != 1");
rc= mysql_query(mysql, SELECT);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
/*
mysql_store_result overwrites mysql->affected_rows. Check that
mysql_stmt_affected_rows() returns the same value, whereas
@@ -1173,7 +1173,7 @@ static int test_bug2247(MYSQL *mysql)
FAIL_UNLESS(exp_count == mysql_stmt_affected_rows(stmt), "affected_rows != exp_count");
rc= mysql_query(mysql, update);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
FAIL_UNLESS(mysql_affected_rows(mysql) == NUM_ROWS, "affected_rows != NUM_ROWS");
FAIL_UNLESS(exp_count == mysql_stmt_affected_rows(stmt), "affected_rows != exp_count");
@@ -1192,13 +1192,13 @@ static int test_bug2247(MYSQL *mysql)
FAIL_UNLESS(exp_count == NUM_ROWS, "exp_count != NUM_ROWS");
rc= mysql_query(mysql, insert);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
FAIL_UNLESS(mysql_affected_rows(mysql) == 1, "affected_rows != 1");
FAIL_UNLESS(exp_count == mysql_stmt_affected_rows(stmt), "affected_rows != exp_count");
mysql_stmt_close(stmt);
rc= mysql_query(mysql, drop);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
return OK;
}
@@ -1215,10 +1215,10 @@ static int test_bug2248(MYSQL *mysql)
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bug2248");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "CREATE TABLE test_bug2248 (id int)");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));
@@ -1256,7 +1256,7 @@ static int test_bug2248(MYSQL *mysql)
mysql_stmt_close(stmt);
rc= mysql_query(mysql, "DROP TABLE test_bug2248");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
return OK;
}
@@ -2658,7 +2658,7 @@ static int test_bug5194(MYSQL *mysql)
MAX_PARAM_COUNT * CHARS_PER_PARAM + 1);
param_str= (char*) malloc(COLUMN_COUNT * CHARS_PER_PARAM);
FAIL_IF(my_bind == 0 || query == 0 || param_str == 0, "Not enough memory")
FAIL_IF(my_bind == 0 || query == 0 || param_str == 0, "Not enough memory");
stmt= mysql_stmt_init(mysql);

View File

@@ -541,16 +541,16 @@ static int test_bug19671(MYSQL *mysql)
mysql_query(mysql, "set sql_mode=''");
rc= mysql_query(mysql, "drop table if exists t1");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "drop view if exists v1");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "create table t1(f1 int)");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "create view v1 as select va.* from t1 va");
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
result= mysql_list_fields(mysql, "v1", NULL);
FAIL_IF(!result, "Invalid result set");
@@ -568,8 +568,8 @@ static int test_bug19671(MYSQL *mysql)
}
mysql_free_result(result);
check_mysql_rc(mysql_query(mysql, "drop view v1"), mysql)
check_mysql_rc(mysql_query(mysql, "drop table t1"), mysql)
check_mysql_rc(mysql_query(mysql, "drop view v1"), mysql);
check_mysql_rc(mysql_query(mysql, "drop table t1"), mysql);
return OK;
}
@@ -604,17 +604,17 @@ static int test_bug21726(MYSQL *mysql)
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, update_query);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
insert_id= mysql_insert_id(mysql);
FAIL_UNLESS(insert_id == 2, "insert_id != 2");
rc= mysql_query(mysql, update_query);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
insert_id= mysql_insert_id(mysql);
FAIL_UNLESS(insert_id == 3, "insert_id != 3");
rc= mysql_query(mysql, select_query);
check_mysql_rc(rc, mysql)
check_mysql_rc(rc, mysql);
insert_id= mysql_insert_id(mysql);
FAIL_UNLESS(insert_id == 3, "insert_id != 3");
result= mysql_store_result(mysql);