Modify a stream test to run parts of it outside Windows (#1158)

This commit is contained in:
Jenny Tam 2020-07-15 17:04:42 -07:00 committed by GitHub
parent 92f796c07a
commit 61f87aacf6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,7 +1,7 @@
--TEST--
reading different encodings in strings and streams.
--SKIPIF--
<?php require('skipif_unix.inc'); ?>
<?php require('skipif.inc'); ?>
--FILE--
<?php
@ -18,7 +18,7 @@ function setup_test($conn, $field_type)
function start_test()
{
require_once('MsCommon.inc');
sqlsrv_configure('WarningsReturnAsErrors', 0);
$conn = connect();
if (!$conn) {
@ -108,31 +108,34 @@ function start_test()
echo "retrieving char encoded varchar(max)\n";
$stmt = sqlsrv_query($conn, $params['selectQuery']);
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
$result = sqlsrv_fetch($stmt);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
$db_stream = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR));
if ($db_stream === false) {
die(print_r(sqlsrv_errors(), true));
}
$file_stream = fopen($params['testImageURL'], "rb");
while (($file_line = fread($file_stream, 80)) &&
($db_line = fread($db_stream, 80))) {
if ($file_line != $db_line) {
// continue testing even if the data not identical
echo("Characters not identical!!\n");
break;
// TODO: need to investigate whether the following works outside Windows
if (isWindows()) {
$stmt = sqlsrv_query($conn, $params['selectQuery']);
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
}
sqlsrv_free_stmt($stmt);
$result = sqlsrv_fetch($stmt);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
$db_stream = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR));
if ($db_stream === false) {
die(print_r(sqlsrv_errors(), true));
}
$file_stream = fopen($params['testImageURL'], "rb");
while (($file_line = fread($file_stream, 80)) &&
($db_line = fread($db_stream, 80))) {
if ($file_line != $db_line) {
// continue testing even if the data not identical
echo("Characters not identical!!\n");
break;
}
}
sqlsrv_free_stmt($stmt);
}
$params = setup_test($conn, "nvarchar(max)");
@ -164,28 +167,35 @@ function start_test()
echo "retrieving char encoded nvarchar(max)\n";
$stmt = sqlsrv_query($conn, $params['selectQuery']);
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
if (isWindows()) {
$stmt = sqlsrv_query($conn, $params['selectQuery']);
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
$result = sqlsrv_fetch($stmt);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
$result = sqlsrv_fetch($stmt);
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
$db_stream = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR));
if ($db_stream === false) {
die(print_r(sqlsrv_errors(), true));
}
$db_stream = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR));
if ($db_stream === false) {
die(print_r(sqlsrv_errors(), true));
}
while ($db_line = fread($db_stream, 80)) {
echo "$db_line\n";
$questionMarks = str_repeat('?', 20);
while ($db_line = fread($db_stream, 80)) {
$pos = strpos($db_line, $questionMarks);
if ($pos === false) {
echo "Unable to find a bunch of question marks together\n";
echo "$db_line\n";
}
}
sqlsrv_free_stmt($stmt);
}
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
echo "Test successful.\n";
}
@ -331,20 +341,4 @@ retrieving binary encoded varchar(max)
retrieving char encoded varchar(max)
retrieving binary encoded nvarchar(max)
retrieving char encoded nvarchar(max)
???xC???????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????„???????????????????????????????????
?????¶˙???????????????????????????????????xC?????????????????????????????????
????????????????????????????????,???????????????????????????????????????????????
????????????I???????????????????e???????????????????????????????????????????????
???????????D????????????????????????????????-?@??????????????A??????????????????
???????????T?<3F>?????????????????%?z??????????????????????????????????????????????
?????????????Z??Ű??????????????????????????????a????????????????????????????????
???????? ????????????????????????????????????u?????????????????????????????????
?g???????????????????????? ??????????????????¦??????¨?????Ë???????????Ľ?????????
????????????????????????????????????????????????????????????????????????????????
????????????????????????????????U???????????????????????????????????????????????
???????????Ô?????????????????????????G??????????????????????????????????????????
???????????????????????????????????????????????????????????????????????????????
??????????a?????????????????????????????????????L???????????????<???????????????
??????????p??????R????????????P????????????????????????????µ?
Test successful.