Replacing MYSQL_TEST_COMPRESS env var with more generic MYSQL_TEST_CONNECT_FLAGS to be able to test all connection flags. Fixing some test.

This commit is contained in:
Ulf Wendel 2009-09-25 10:54:16 +00:00
parent eea0660def
commit a5e4c6f795
4 changed files with 29 additions and 29 deletions

View File

@ -16,7 +16,7 @@
$engine = getenv("MYSQL_TEST_ENGINE") ? getenv("MYSQL_TEST_ENGINE") : "MyISAM";
$socket = getenv("MYSQL_TEST_SOCKET") ? getenv("MYSQL_TEST_SOCKET") : null;
$skip_on_connect_failure = getenv("MYSQL_TEST_SKIP_CONNECT_FAILURE") ? getenv("MYSQL_TEST_SKIP_CONNECT_FAILURE") : true;
$test_compress = getenv("MYSQL_TEST_COMPRESS") ? (boolean)getenv("MYSQL_TEST_COMPRESS") : false;
$connect_flags = getenv("MYSQL_TEST_CONNECT_FLAGS") ? (int)getenv("MYSQL_TEST_CONNECT_FLAGS") : 0;
/* Development setting: test experimal features and/or feature requests that never worked before? */
$TEST_EXPERIMENTAL = (in_array(getenv("MYSQL_TEST_EXPERIMENTAL"), array(0, 1))) ?
@ -51,6 +51,7 @@
/* unknown */
$MYSQLND_VERSION = -1;
}
}
if (!function_exists('sys_get_temp_dir')) {
@ -76,17 +77,17 @@
/**
* Whenever possible, please use this wrapper to make testing ot MYSQLI_CLIENT_COMPRESS (and potentially SSL) possible
*
* @param compress mixed: -1 => use global default, false -> no compression, true -> compression
* @param enable_env_flags Enable setting of connection flags through env(MYSQL_TEST_CONNECT_FLAGS)?
*/
function my_mysqli_connect($host, $user, $passwd, $db, $port, $socket, $compress = -1) {
global $test_compress;
function my_mysqli_connect($host, $user, $passwd, $db, $port, $socket, $enable_env_flags = true) {
global $connect_flags;
if (-1 == $compress)
$compress = $test_compress;
$flags = ($enable_env_flags) ? $connect_flags : false;
if ($compress) {
if ($flags !== false) {
$link = mysqli_init();
mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, 0 & MYSQLI_CLIENT_COMPRESS);
if (!mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, $flags))
$link = false;
} else {
$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket);
}
@ -97,27 +98,26 @@
/**
* Whenever possible, please use this wrapper to make testing ot MYSQLI_CLIENT_COMPRESS (and potentially SSL) possible
*
* @param compress mixed: -1 => use global default, false -> no compression, true -> compression
* @param enable_env_flags Enable setting of connection flags through env(MYSQL_TEST_CONNECT_FLAGS)
*/
function my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, $flags = 0, $compress = -1) {
global $test_compress;
function my_mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, $flags = 0, $enable_env_flags = true) {
global $connect_flags;
if (-1 == $compress)
$compress = $test_compress;
if ($enable_env_flags)
$flags & $connect_flags;
return mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, $flags & MYSQLI_CLIENT_COMPRESS);
return mysqli_real_connect($link, $host, $user, $passwd, $db, $port, $socket, $flags);
}
class my_mysqli extends mysqli {
public function __construct($host, $user, $passwd, $db, $port, $socket, $compress = -1) {
global $test_compress;
public function __construct($host, $user, $passwd, $db, $port, $socket, $enable_env_flags = true) {
global $connect_flags;
if (-1 == $compress)
$compress = $test_compress;
$flags = ($enable_env_flags) ? $connect_flags : false;
if ($compress) {
if ($flags !== false) {
parent::init();
$this->real_connect($host, $user, $passwd, $db, $port, $socket, 0 & MYSQLI_CLIENT_COMPRESS);
$this->real_connect($host, $user, $passwd, $db, $port, $socket, $flags);
} else {
parent::__construct($host, $user, $passwd, $db, $port, $socket);
}

View File

@ -29,7 +29,7 @@ require_once('skipifconnectfailure.inc');
$link = @my_mysqli_connect($host, $user . 'unknown_really', $passwd . 'non_empty', $db, $port, $socket);
if (false !== $link)
printf("[004] Connect to the server should fail using host=%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s, expecting boolean/false, got %s/%s\n",
$host, $user . 'unknown_really', $db, $port, $socket, gettype($link), $link);
$host, $user . 'unknown_really', $db, $port, $socket, gettype($link), var_export($link, true));
if (0 === ($tmp = mysqli_connect_errno()))
printf("[005] Expecting integer/any non-zero, got %s/%s\n", gettype($tmp), $tmp);

View File

@ -28,12 +28,12 @@ new mysqli()
var_dump(mysqli_connect_errno());
print "3) bail\n";
if (false !== ($link = my_mysqli_connect($myhost))) {
if (false !== ($link = mysqli_connect($myhost))) {
printf("[003] Expecting boolean/false, got %s/%s\n", gettype($link), $link);
}
print "4) be quiet\n";
if (false !== ($link = @my_mysqli_connect($myhost))) {
if (false !== ($link = @mysqli_connect($myhost))) {
printf("[004] Expecting boolean/false, got %s/%s\n", gettype($link), $link);
}
var_dump(mysqli_connect_error());
@ -50,7 +50,7 @@ Warning: mysqli::mysqli(): (HY000/200%d): %s
int(200%d)
3) bail
Warning: my_mysqli_connect(): (HY000/200%d): %s
Warning: mysqli_connect(): (HY000/200%d): %s
4) be quiet
%s(%d) "%s"
int(200%d)

View File

@ -44,15 +44,15 @@ mysqli.max_links=1
bool(true)
int(1)
Warning: mysqli_connect(): Too many open links (1) in %s on line %d
Warning: mysqli_%sonnect(): Too many open links (1) in %s on line %d
Warning: mysqli_connect(): Too many open links (1) in %s on line %d
Warning: mysqli_%sonnect(): Too many open links (1) in %s on line %d
Warning: mysqli_connect(): Too many open links (1) in %s on line %d
Warning: mysqli_%sonnect(): Too many open links (1) in %s on line %d
Warning: mysqli_connect(): Too many open links (1) in %s on line %d
Warning: mysqli_%sonnect(): Too many open links (1) in %s on line %d
Warning: mysqli_connect(): Too many open links (1) in %s on line %d
Warning: mysqli_%sonnect(): Too many open links (1) in %s on line %d
Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in %s on line %d