uw              Mon Jul 23 12:13:15 2007 UTC

  Added files:                 
    /php-src/ext/mysqli/tests   mysqli_set_local_infile_default.phpt 
                                
mysqli_set_local_infile_handler_bad_character.phpt 
                                
mysqli_set_local_infile_handler_buffer_overflow.phpt 
                                mysqli_set_local_infile_handler_closefile.phpt 
                                mysqli_set_local_infile_handler_close_link.phpt 
                                mysqli_set_local_infile_handler_kill_link.phpt 
                                
mysqli_set_local_infile_handler_negative_len.phpt 
                                
mysqli_set_local_infile_handler_nested_call.phpt 
                                mysqli_set_local_infile_handler_new_query.phpt 
                                mysqli_set_local_infile_handler_nofileop.phpt 
                                mysqli_set_local_infile_handler.phpt 
                                
mysqli_set_local_infile_handler_replace_buffer.phpt 
                                mysqli_set_local_infile_handler_short_len.phpt 
                                mysqli_set_local_infile_handler_unregister.phpt 
  Log:
  Tests that deal with mysqli_set_local_infile_handler() and 
mysqli_set_local_infile_default()
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_set_local_infile_default.phpt?view=markup&rev=1.1
Index: php-src/ext/mysqli/tests/mysqli_set_local_infile_default.phpt
+++ php-src/ext/mysqli/tests/mysqli_set_local_infile_default.phpt
--TEST--
mysqli_set_local_infile_default()
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');

if (!function_exists('mysqli_set_local_infile_handler'))
        die("skip - function not available.");

require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
        die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
        require_once('connect.inc');
        require_once('local_infile_tools.inc');

        $link = $tmp = null;
        if (!is_null($tmp = @mysqli_set_local_infile_default()))
                printf("[001] Expecting NULL got %s/%s\n", gettype($tmp), $tmp);

        if (!is_null($tmp = @mysqli_set_local_infile_default($link)))
                printf("[002] Expecting NULL got %s/%s\n", gettype($tmp), $tmp);

        include("table.inc");

        if (!is_null($tmp = @mysqli_set_local_infile_default($link, 'foo')))
                printf("[003] Expecting NULL got %s/%s\n", gettype($tmp), $tmp);


        function callback_simple($fp, &$buffer, $buflen, &$error) {
                static $invocation = 0;

                printf("Callback: %d\n", $invocation);

                $invocation++;
                if (!is_resource($fp))
                        printf("[012] First argument passed to callback is not 
a resource but %s/%s\n",
                                $fp, gettype($fp));

                if (!$buffer = fread($fp, $buflen)) {
                        if ($invocation == 1) {
                                printf("[013] Cannot read from stream\n");
                                $error = 'Cannot read from stream';
                        } else {
                                return strlen($buffer);
                        }
                }

                $lines = explode("\n", $buffer);
                if (count($lines) != 4 && strlen($buffer) > 0) {
                        printf("[014] Test is too simple to handle a buffer of 
size %d that cannot hold all lines\n", $buflen);
                        $error = 'Parser too simple';
                }

                $buffer = '';
                foreach ($lines as $k => $line) {
                        if ('' === trim($line))
                                continue;

                        $columns = explode(';', $line);
                        if (empty($columns)) {
                                printf("[015] Cannot parse columns\n");
                                $error = 'Cannot parse columns';
                        }

                        // increase id column value
                        $columns[0] += 1;
                        $buffer .= implode(';', $columns);
                        $buffer .= "\n";
                }

                return strlen($buffer);
        }

        $file = create_standard_csv(4);
        $expected = array(
                array('id' => 98,   'label' => 'x'),
                array('id' => 99,   'label' => 'y'),
                array('id' => 100,  'label' => 'z'),
        );
        try_handler(10, $link, $file, 'callback_simple', $expected);

        $expected = array(
                array('id' => 97,   'label' => 'x'),
                array('id' => 98,   'label' => 'y'),
                array('id' => 99,   'label' => 'z'),
        );
        try_handler(20, $link, $file, 'default', $expected);

        $expected = array(
                array('id' => 98,   'label' => 'x'),
                array('id' => 99,   'label' => 'y'),
                array('id' => 100,  'label' => 'z'),
        );
        try_handler(30, $link, $file, 'callback_simple', $expected);

        mysqli_close($link);

        if (!is_null($tmp = @mysqli_set_local_infile_default($link)))
                printf("[300] Expecting NULL/NULL got %s/%s\n", $tmp, 
gettype($tmp));

        print "done!";
?>
--EXPECTF--
Callback set to 'callback_simple'
Callback: 0
Callback: 1
Callback set to 'default'
Callback set to 'callback_simple'
Callback: 2
Callback: 3
done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_bad_character.phpt?view=markup&rev=1.1
Index: 
php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_bad_character.phpt
+++ php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_bad_character.phpt
--TEST--
mysqli_set_local_infile_handler() - random ASCII character including \0
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');
require_once('connect.inc');

if (!function_exists('mysqli_set_local_infile_handler'))
    die("skip - function not available.");

if (!$TEST_EXPERIMENTAL)
    die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
        require_once('connect.inc');
        require_once('local_infile_tools.inc');
        require_once('table.inc');

        function callback_bad_character($fp, &$buffer, $buflen, &$error) {
                static $invocation = 0;

                printf("Callback: %d\n", $invocation++);

                $num_chars = (ini_get('unicode.semantics')) ? (floor($buflen / 
2) - 10) : ($buflen - 5);
                $part1 = floor($num_chars / 2);
                $part2 = $num_chars - $part1;

                $buffer = '';
                for ($i = 0; $i < $part1; $i++)
                        $buffer .= chr(mt_rand(0, 255));

                $buffer .= ';"';

                for ($i = 0; $i < $part2; $i++)
                        $buffer .= chr(mt_rand(0, 255));

                $buffer .= '";';
                if ($invocation > 10)
                        return 0;

                return strlen($buffer);
        }

        $file = create_standard_csv(5);
        /* we feed the handler with random data, therefore we cannot specify 
and expected rows */
        try_handler(20, $link, $file, 'callback_bad_character');

        mysqli_close($link);
        print "done!";
?>
--EXPECTF--
Callback set to 'callback_bad_character'
Callback: 0
Callback: 1
Callback: 2
Callback: 3
Callback: 4
Callback: 5
Callback: 6
Callback: 7
Callback: 8
Callback: 9
Callback: 10
done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_buffer_overflow.phpt?view=markup&rev=1.1
Index: 
php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_buffer_overflow.phpt
+++ 
php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_buffer_overflow.phpt
--TEST--
mysqli_set_local_infile_handler() - buffer overflow
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');

if (!function_exists('mysqli_set_local_infile_handler'))
        die("skip - function not available.");

include_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
        die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
        require_once('connect.inc');
        require_once('local_infile_tools.inc');
        require_once('table.inc');

        function callback_buffer_overflow($fp, &$buffer, $buflen, &$error) {
                static $invocation = 0;

                printf("Callback: %d\n", $invocation);
                $buffer = fread($fp, $buflen);

                $buffer = str_repeat(';', $buflen * 2);
                return strlen($buffer);
        }

        $file = create_standard_csv(5);
        $expected = array();
        try_handler(20, $link, $file, 'callback_buffer_overflow', $expected);

        mysqli_close($link);
        print "done!";
?>
--EXPECTF--
Callback set to 'callback_buffer_overflow'
Callback: 0

Warning: mysqli_query(): Too much data returned in %s on line %d
[022] LOAD DATA failed, [%d] Too much data returned
done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_closefile.phpt?view=markup&rev=1.1
Index: php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_closefile.phpt
+++ php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_closefile.phpt
--TEST--
mysqli_set_local_infile_handler() - do not use the file pointer
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');

if (!function_exists('mysqli_set_local_infile_handler'))
        die("skip - function not available.");

require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
        die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
        include "connect.inc";
        include("table.inc");
        require_once('local_infile_tools.inc');

        function callback_closefile($fp, &$buffer, $buflen, &$error) {
                static $invocation = 0;

                printf("Callback: %d\n", $invocation++);
                flush();
                if (is_resource($fp))
                        fclose($fp);
                $buffer = "1;'a';\n";
                if ($invocation > 10)
                        return 0;

                return strlen($buffer);
        }

        $file = create_standard_csv(1);
        $expected = array(array('id' => 1, 'label' => 'a'));
        try_handler(20, $link, $file, 'callback_closefile', $expected);

        mysqli_close($link);
        print "done!";
?>
--EXPECTF--
Callback set to 'callback_closefile'
Callback: 0
Callback: 1
Callback: 2
Callback: 3
Callback: 4
Callback: 5
Callback: 6
Callback: 7
Callback: 8
Callback: 9
Callback: 10
done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_close_link.phpt?view=markup&rev=1.1
Index: php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_close_link.phpt
+++ php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_close_link.phpt
--TEST--
mysqli_set_local_infile_handler() - close database link
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');

if (!function_exists('mysqli_set_local_infile_handler'))
        die("skip - function not available.");

require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
        die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
        include "connect.inc";
        include("table.inc");
        require_once('local_infile_tools.inc');

        function callback_close_link($fp, &$buffer, $buflen, &$error) {
                global $link;
                static $invocation = 0;

                printf("Callback: %d\n", $invocation++);
                flush();
                if (is_object($link))
                        mysqli_close($link);

                $buffer = "1;'a';\n";
                if ($invocation > 10)
                        return 0;

                return strlen($buffer);
        }

        $file = create_standard_csv(1);
        $expected = array(array('id' => 1, 'label' => 'a'));
        try_handler(20, $link, $file, 'callback_close_link', $expected);
        mysqli_close($link);
        print "done!";
?>
--EXPECTF--
Callback set to 'callback_close_link'
Callback: 0
done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_kill_link.phpt?view=markup&rev=1.1
Index: php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_kill_link.phpt
+++ php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_kill_link.phpt
--TEST--
mysqli_set_local_infile_handler() - kill database link
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');

if (!function_exists('mysqli_set_local_infile_handler'))
        die("skip - function not available.");

require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
        die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
        include "connect.inc";
        include("table.inc");
        require_once('local_infile_tools.inc');

        function callback_kill_link($fp, &$buffer, $buflen, &$error) {
                global $link;
                static $invocation = 0;

                printf("Callback: %d\n", $invocation++);
                flush();
                if (is_object($link))
                        mysqli_kill($link, mysqli_thread_id($link));

                $buffer = "1;'a';\n";
                if ($invocation > 10)
                        return 0;

                mysqli_set_local_infile_default($link);
                return strlen($buffer);
        }

        $file = create_standard_csv(1);
        $expected = array(array('id' => 1, 'label' => 'a'));
        try_handler(20, $link, $file, 'callback_kill_link', $expected);

        mysqli_close($link);
        print "done!";
?>
--EXPECTF--
Callback set to 'callback_kill_link'
Callback: 0
[022] LOAD DATA failed, [2000] Can't execute load data local init callback 
function
done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_negative_len.phpt?view=markup&rev=1.1
Index: 
php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_negative_len.phpt
+++ php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_negative_len.phpt
--TEST--
mysqli_set_local_infile_handler() - negative return value/buflen to indicate an 
error
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');

if (!function_exists('mysqli_set_local_infile_handler'))
        die("skip - function not available.");

require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
        die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
        require_once('connect.inc');
        require_once('local_infile_tools.inc');
        require_once('table.inc');

        function callback_negative_len($fp, &$buffer, $buflen, &$error) {
                static $invocation = 0;

                printf("Callback: %d\n", $invocation);
                $buffer = fread($fp, $buflen);

                $error = "negative length means error";
                return -1;
        }

        $file = create_standard_csv(1);
        $expected = array();
        try_handler(20, $link, $file, 'callback_negative_len', $expected);

        mysqli_close($link);
        print "done!";
?>
--EXPECTF--
Callback set to 'callback_negative_len'
Callback: 0

Warning: mysqli_query(): negative length means error in %s on line %d
[022] LOAD DATA failed, [2000] negative length means error
done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_nested_call.phpt?view=markup&rev=1.1
Index: php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_nested_call.phpt
+++ php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_nested_call.phpt
--TEST--
mysqli_set_local_infile_handler() - nested calls
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');

if (!function_exists('mysqli_set_local_infile_handler'))
        die("skip - function not available.");

require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
        die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
        require_once('connect.inc');
        require_once('local_infile_tools.inc');
        require_once('table.inc');

        function callback_simple($fp, &$buffer, $buflen, &$error) {
                static $invocation = 0;

                printf("Callback - callback_simple(): %d\n", $invocation);

                $invocation++;
                if (!is_resource($fp))
                        printf("[012] First argument passed to callback is not 
a resource but %s/%s\n",
                                $fp, gettype($fp));

                if (!$buffer = fread($fp, $buflen)) {
                        if ($invocation == 1) {
                                printf("[013] Cannot read from stream\n");
                                $error = 'Cannot read from stream';
                        } else {
                                return strlen($buffer);
                        }
                }

                $lines = explode("\n", $buffer);
                if (count($lines) != 4 && strlen($buffer) > 0) {
                        printf("[014] Test is too simple to handle a buffer of 
size %d that cannot hold all lines\n", $buflen);
                        $error = 'Parser too simple';
                }

                $buffer = '';
                foreach ($lines as $k => $line) {
                        if ('' === trim($line))
                                continue;

                        $columns = explode(';', $line);
                        if (empty($columns)) {
                                printf("[015] Cannot parse columns\n");
                                $error = 'Cannot parse columns';
                        }

                        // increase id column value
                        $columns[0] += 1;
                        $buffer .= implode(';', $columns);
                        $buffer .= "\n";
                }

                /* report the wrong length */
                return strlen($buffer);
        }

        function callback_report_short_len($fp, &$buffer, $buflen, &$error) {
                static $invocation = 0;

                printf("Callback - report_short_len(): %d\n", $invocation++);
                return callback_simple($fp, $buffer, $buflen, $error);
        }

        $file = create_standard_csv(1);
        $expected = array(
                array('id' => 98,   'label' => 'x'),
                array('id' => 99,   'label' => 'y'),
                array('id' => 100,  'label' => 'z'),
        );
        try_handler(20, $link, $file, 'callback_report_short_len', $expected);

        mysqli_close($link);
        print "done!";
?>
--EXPECTF--
Callback set to 'callback_report_short_len'
Callback - report_short_len(): 0
Callback - callback_simple(): 0
Callback - report_short_len(): 1
Callback - callback_simple(): 1
done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_new_query.phpt?view=markup&rev=1.1
Index: php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_new_query.phpt
+++ php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_new_query.phpt
--TEST--
mysqli_set_local_infile_handler() - run new query on db link
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');

if (!function_exists('mysqli_set_local_infile_handler'))
        die("skip - function not available.");

require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
        die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
        require_once('connect.inc');
        require_once('local_infile_tools.inc');
        require_once('table.inc');

        function callback_new_query($fp, &$buffer, $buflen, &$error) {
                global $link;
                static $invocation = 0;

                printf("Callback: %d\n", $invocation++);
                flush();
                if (is_object($link)) {
                        if (!$res = mysqli_query($link, "SELECT id, label FROM 
test")) {
                                printf("[Callback 001 - %03d] Cannot run query, 
[%d] %s\n",
                                        $invocation, mysqli_errno($link), 
mysqli_error($link));
                        }
                        if ($res)
                                mysqli_free_result($res);
                        }
                        $buffer = "1;'a';\n";
                        if ($invocation > 10)
                                return 0;

                        mysqli_set_local_infile_default($link);
                        return strlen($buffer);
        }

        $file = create_standard_csv(1);
        $expected = array(array('id' => 1, 'label' => 'a'));
        try_handler(20, $link, $file, 'callback_new_query', $expected);

        mysqli_close($link);
        print "done!";
?>
--EXPECTF--
Callback set to 'callback_new_query'
Callback: 0
[Callback 001 - 001] Cannot run query, [2014] Commands out of sync; you can't 
run this command now
[022] LOAD DATA failed, [2000] Can't execute load data local init callback 
function
done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_nofileop.phpt?view=markup&rev=1.1
Index: php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_nofileop.phpt
+++ php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_nofileop.phpt
--TEST--
mysqli_set_local_infile_handler() - do not use the file pointer
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');

if (!function_exists('mysqli_set_local_infile_handler'))
        die("skip - function not available.");

require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
        die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
        require_once('connect.inc');
        require_once('local_infile_tools.inc');
        require_once('table.inc');

        function callback_nofileop($fp, &$buffer, $buflen, &$error) {
                static $invocation = 0;

                printf("Callback: %d\n", $invocation++);
                flush();

                $buffer = "1;'a';\n";
                if ($invocation > 10)
                        return 0;

                return strlen($buffer);
        }

        $file = create_standard_csv(1);
        $expected = array(array('id' => 1, 'label' => 'a'));
        try_handler(20, $link, $file, 'callback_nofileop', $expected);

        mysqli_close($link);
        print "done!";
?>
--EXPECTF--
Callback set to 'callback_nofileop'
Callback: 0
Callback: 1
Callback: 2
Callback: 3
Callback: 4
Callback: 5
Callback: 6
Callback: 7
Callback: 8
Callback: 9
Callback: 10
done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_set_local_infile_handler.phpt?view=markup&rev=1.1
Index: php-src/ext/mysqli/tests/mysqli_set_local_infile_handler.phpt
+++ php-src/ext/mysqli/tests/mysqli_set_local_infile_handler.phpt
--TEST--
mysqli_set_local_infile_handler()
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');
require_once('connect.inc');

if (!function_exists('mysqli_set_local_infile_handler'))
        die("skip - function not available.");

require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
        die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
        require_once('connect.inc');
        require_once('local_infile_tools.inc');
        require_once('table.inc');

        function callback_simple($fp, &$buffer, $buflen, &$error) {
                static $invocation = 0;

                printf("Callback: %d\n", $invocation);

                $invocation++;
                if (!is_resource($fp))
                        printf("[012] First argument passed to callback is not 
a resource but %s/%s\n",
                                $fp, gettype($fp));

                if (!$buffer = fread($fp, $buflen)) {
                        if ($invocation == 1) {
                                printf("[013] Cannot read from stream\n");
                                        $error = 'Cannot read from stream';
                        } else {
                                return strlen($buffer);
                        }
                }

                $lines = explode("\n", $buffer);
                if (count($lines) != 4 && strlen($buffer) > 0) {
                        printf("[014] Test is too simple to handle a buffer of 
size %d that cannot hold all lines\n", $buflen);
                        $error = 'Parser too simple';
                }

                $buffer = '';
                foreach ($lines as $k => $line) {
                        if ('' === trim($line))
                                continue;

                        $columns = explode(';', $line);
                        if (empty($columns)) {
                                printf("[015] Cannot parse columns\n");
                                $error = 'Cannot parse columns';
                        }

                        // increase id column value
                        $columns[0] += 1;
                        $buffer .= implode(';', $columns);
                        $buffer .= "\n";
                }

                return strlen($buffer);
        }

        function callback_fclose($fp, &$buffer, $buflen, &$error) {
                static $invocation = 0;

                printf("Callback: %d\n", $invocation++);

                fclose($fp);
                return strlen($buffer);
        }

        function callback_closefile($fp, &$buffer, $buflen, &$error) {
                static $invocation = 0;

                printf("Callback: %d\n", $invocation++);
                flush();
                if (is_resource($fp))
                        fclose($fp);
                $buffer = "1;'a';\n";
                if ($invocation > 10)
                        return 0;

                return strlen($buffer);
        }

        function callback_invalid_args($fp, &$buffer, $buflen) {
                static $invocation = 0;

                printf("Callback: %d\n", $invocation++);
                $buffer = fread($fp, $buflen);

                return strlen($buffer);
        }

        function callback_error($fp, &$buffer, $buflen, &$error) {
                static $invocation = 0;

                printf("Callback: %d\n", $invocation++);
                $buffer = fread($fp, $buflen);
                $error = 'How to access this error?';

                return -1;
        }

        if (!is_null($tmp = @mysqli_set_local_infile_handler()))
                printf("[001] Expecting NULL/NULL got %s/%s\n", $tmp, 
gettype($tmp));

        $handle = null;
        if (!is_null($tmp = @mysqli_set_local_infile_handler($handle)))
                printf("[002] Expecting NULL/NULL got %s/%s\n", $tmp, 
gettype($tmp));

        $handle = @new mysqli();
        if (!is_null($tmp = @mysqli_set_local_infile_handler($handle, 
'callback_simple')))
                printf("[003] Expecting NULL/NULL got %s/%s\n", $tmp, 
gettype($tmp));

        if (false !== ($tmp = @mysqli_set_local_infile_handler($link, 
'unknown')))
                printf("[004] Expecting false/boolean got %s/%s\n", $tmp, 
gettype($tmp));

        $file = create_standard_csv(5);

        $expected = array(
                array('id' => 98,   'label' => 'x'),
                array('id' => 99,   'label' => 'y'),
                array('id' => 100,  'label' => 'z'),
        );
        try_handler(10, $link, $file, 'callback_simple', $expected);

        $expected = array();
        try_handler(20, $link, $file, 'callback_fclose', $expected);

        $expected = array();
        try_handler(30, $link, $file, 'callback_invalid_args', $expected);

        $expected = array();
        try_handler(40, $link, $file, 'callback_error', $expected);


        mysqli_close($link);

        if (!is_null($tmp = @mysqli_set_local_infile_handler($link, 
'callback_simple')))
                printf("[300] Expecting NULL/NULL got %s/%s\n", $tmp, 
gettype($tmp));

        print "done!";
?>
--EXPECTF--
Callback set to 'callback_simple'
Callback: 0
Callback: 1
Callback set to 'callback_fclose'
Callback: 0
Callback set to 'callback_invalid_args'
Should bail!
Callback set to 'callback_error'
Callback: 0

Warning: mysqli_query(): How to access this error? in %s on line %d
[042] LOAD DATA failed, [2000] How to access this error?
done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_replace_buffer.phpt?view=markup&rev=1.1
Index: 
php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_replace_buffer.phpt
+++ php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_replace_buffer.phpt
--TEST--
mysqli_set_local_infile_handler() - replace buffer pointer
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');

if (!function_exists('mysqli_set_local_infile_handler'))
        die("skip - function not available.");

require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
        die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
        require_once('connect.inc');
        require_once('local_infile_tools.inc');
        require_once('table.inc');

        function callback_replace_buffer($fp, &$buffer, $buflen, &$error) {
                static $invocation = 0;

                printf("Callback: %d\n", $invocation++);
                flush();

                $buffer = fread($fp, $buflen);

                $ret = "1;'a';\n";
                $buffer = $ret;

                $num_chars = (ini_get('unicode.semantics')) ? floor($buflen / 
2) : $buflen;
                assert(strlen($buffer) < $num_chars);

                if ($invocation > 10)
                        return 0;

                return strlen($buffer);
        }

        $file = create_standard_csv(1);
        $expected = array(array('id' => 1, 'label' => 'a'));
        if (!try_handler(20, $link, $file, 'callback_replace_buffer', 
$expected))
                printf("[008] Failure\n");

        mysqli_close($link);
        print "done!";
?>
--EXPECTF--
Callback set to 'callback_replace_buffer'
Callback: 0
Callback: 1
Callback: 2
Callback: 3
Callback: 4
Callback: 5
Callback: 6
Callback: 7
Callback: 8
Callback: 9
Callback: 10
done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_short_len.phpt?view=markup&rev=1.1
Index: php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_short_len.phpt
+++ php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_short_len.phpt
--TEST--
mysqli_set_local_infile_handler() - report shorter buffer
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');

if (!function_exists('mysqli_set_local_infile_handler'))
        die("skip - function not available.");

require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
        die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
        require_once('connect.inc');
        require_once('local_infile_tools.inc');
        require_once('table.inc');

        function callback_short_len($fp, &$buffer, $buflen, &$error) {
                static $invocation = 0;

                printf("Callback: %d\n", $invocation);

                $invocation++;
                if (!is_resource($fp))
                        printf("[012] First argument passed to callback is not 
a resource but %s/%s\n",
                                $fp, gettype($fp));

                if (!$buffer = fread($fp, $buflen)) {
                        if ($invocation == 1) {
                                printf("[013] Cannot read from stream\n");
                                $error = 'Cannot read from stream';
                        } else {
                                return strlen($buffer);
                        }
                }

                $lines = explode("\n", $buffer);
                if (count($lines) != 4 && strlen($buffer) > 0) {
                        printf("[014] Test is too simple to handle a buffer of 
size %d that cannot hold all lines\n", $buflen);
                        $error = 'Parser too simple';
                }

                $buffer = '';
                foreach ($lines as $k => $line) {
                        if ('' === trim($line))
                                        continue;

                        $columns = explode(';', $line);
                        if (empty($columns)) {
                                printf("[015] Cannot parse columns\n");
                                $error = 'Cannot parse columns';
                        }

                        // increase id column value
                        $columns[0] += 1;
                        $buffer .= implode(';', $columns);
                        $buffer .= "\n";
                }

                /* report the wrong length */
                return strlen($buffer) - 1;
        }

        $file = create_standard_csv(1);
        $expected = array(
                array('id' => 98,   'label' => 'x'),
                array('id' => 99,   'label' => 'y'),
                array('id' => 100,  'label' => 'z'),
        );
        try_handler(20, $link, $file, 'callback_short_len', $expected);

        mysqli_close($link);
        print "done!";
?>
--EXPECTF--
Callback set to 'callback_short_len'
Callback: 0

Warning: mysqli_query(): Mismatch between the return value of the callback and 
the content length of the buffer. in %s on line %d
[022] LOAD DATA failed, [2000] Mismatch between the return value of the 
callback and the content length of the buffer.
[024/0] [0] ''
done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_unregister.phpt?view=markup&rev=1.1
Index: php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_unregister.phpt
+++ php-src/ext/mysqli/tests/mysqli_set_local_infile_handler_unregister.phpt
--TEST--
mysqli_set_local_infile_handler() - do not use the file pointer
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');

if (!function_exists('mysqli_set_local_infile_handler'))
        die("skip - function not available.");

require_once('connect.inc');
if (!$TEST_EXPERIMENTAL)
        die("skip - experimental (= unsupported) feature");
?>
--FILE--
<?php
        require_once('connect.inc');
        require_once('local_infile_tools.inc');
        require_once('table.inc');

        function callback_unregister($fp, &$buffer, $buflen, &$error) {
                global $link;
                static $invocation = 0;

                printf("Callback: %d\n", $invocation++);
                flush();
                if (is_resource($fp))
                                fclose($fp);
                $buffer = "1;'a';\n";
                if ($invocation > 10)
                        return 0;

                mysqli_set_local_infile_default($link);
                return strlen($buffer);
        }

        $file = create_standard_csv(1);
        $expected = array(array('id' => 1, 'label' => 'a'));
        try_handler(20, $link, $file, 'callback_unregister', $expected);

        mysqli_close($link);
        print "done!";
?>
--EXPECTF--
Callback set to 'callback_unregister'
Callback: 0
[022] LOAD DATA failed, [2000] Can't execute load data local init callback 
function
done!
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to