Added new tests for testing gb18030 (#1166)

This commit is contained in:
Jenny Tam 2020-07-24 18:31:39 -07:00 committed by GitHub
parent e1e0108b1f
commit e9090a4c2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 258 additions and 18 deletions

View file

@ -5,7 +5,14 @@ This file must be saved in ANSI encoding and the required locale must be present
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif_unix_ansitests.inc'); ?>
<?php
require('skipif_unix_ansitests.inc');
$loc = setlocale(LC_ALL, 'fr_FR@euro');
$loc1 = setlocale(LC_ALL, 'fr_FR.ISO8859-15');
if (empty($loc) && empty($loc1)) {
die("skip required French locale not available");
}
?>
--FILE--
<?php

View file

@ -0,0 +1,53 @@
--TEST--
Test Chinese locale in Linux
--DESCRIPTION--
This test will invoke another php scirpt that is saved as GB2312(Simplified Chinese) ANSI format,
namely pdo_test_gb18030.php.
To run this test, create a temporary database first with the correct collation
CREATE DATABASE [GB18030test]
COLLATE Chinese_PRC_CI_AS
Next, set the correct locale and convert the php script, like this:
export LC_ALL=zh_CN.gb18030
iconv -c -f GB2312 -t GB18030 pdo_test_gb18030.php > test_gb18030.php
Drop the temporary database when the test is finished.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php
require('skipif_unix_ansitests.inc');
$loc = setlocale(LC_ALL, 'zh_CN.gb18030');
if (empty($loc)) {
die("skip required gb18030 locale not available");
}
--FILE--
<?php
function runTest($conn, $tempDB)
{
$query = "CREATE DATABASE $tempDB COLLATE Chinese_PRC_CI_AS";
$conn->exec($query);
shell_exec("export LC_ALL=zh_CN.gb18030");
shell_exec("iconv -c -f GB2312 -t GB18030 pdo_test_gb18030.php > test_gb18030.php");
print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/test_gb18030.php $tempDB"));
}
try {
$tempDB = 'GB18030test' . rand(1, 100);
require_once('MsSetup.inc');
$conn = new PDO("sqlsrv:server = $server;database=master;driver=$driver", $uid, $pwd);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
runTest($conn, $tempDB);
} catch (PDOException $e) {
echo $e->getMessage() . PHP_EOL;
} finally {
$query = "DROP DATABASE $tempDB";
$conn->exec($query);
unset($conn);
}
?>
--EXPECT--
Done

View file

@ -0,0 +1,63 @@
<?php
/*
This ansi test is invoked by pdo_ansi_locale_zh.phpt
*/
function insertText($conn, $text, $hexValue)
{
$hex = bin2hex($text);
if ($hex !== $hexValue) {
"Expected $hexValue but got $hex" . PHP_EOL;
}
$tsql = "INSERT INTO test1 VALUES (?)";
$stmt = $conn->prepare($tsql);
$stmt->execute(array($text));
}
require_once('MsSetup.inc');
$tempDB = ($_SERVER['argv'][1]);
setlocale(LC_ALL, 'zh_CN.gb18030');
try {
$conn = new PDO("sqlsrv:server = $server;database=$tempDB;driver=$driver", $uid, $pwd);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_SYSTEM);
$tsql = "CREATE TABLE test1([id] int identity, [name] [varchar](50) NULL)";
$stmt = $conn->query($tsql);
// Next, insert the strings
$inputs = array('中文', '你好', '未找到信息', '获取更多');
$hexValues = array('d6d0cec4', 'c4e3bac3', 'ceb4d5d2b5bdd0c5cfa2', 'bbf1c8a1b8fcb6e0');
for ($i = 0; $i < 4; $i++) {
insertText($conn, $inputs[$i], $hexValues[$i]);
}
// Next, fetch the strings
$tsql = "SELECT * FROM test1";
$stmt = $conn->query($tsql);
$i = 0;
while ($result = $stmt->fetch(PDO::FETCH_NUM)) {
$name = $result[1];
if ($name !== $inputs[$i]) {
echo "Expected $inputs[$i] but got $name" . PHP_EOL;
}
$i++;
}
} catch (PDOException $e) {
echo $e->getMessage() . PHP_EOL;
} finally {
$tsql = "DROP TABLE test1";
$conn->exec($tsql);
unset($stmt);
unset($conn);
}
echo "Done";
?>

View file

@ -12,11 +12,4 @@ require_once('MsSetup.inc');
if ($localeDisabled) {
die("skip not set up to test ansi locale");
}
$loc = setlocale(LC_ALL, 'fr_FR@euro');
$loc1 = setlocale(LC_ALL, 'fr_FR.ISO8859-15');
if (empty($loc) && empty($loc1)) {
die("skip required French locale not available");
}
?>
?>

View file

@ -12,11 +12,4 @@ require_once('MsSetup.inc');
if ($localeDisabled) {
die("skip not set up to test ansi locale");
}
$loc = setlocale(LC_ALL, 'fr_FR@euro');
$loc1 = setlocale(LC_ALL, 'fr_FR.ISO8859-15');
if (empty($loc) && empty($loc1)) {
die("skip required French locale not available");
}
?>
?>

View file

@ -5,7 +5,16 @@ This file must be saved in ANSI encoding and the required locale must be present
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif_unix_ansitests.inc'); ?>
<?php
require('skipif_unix_ansitests.inc');
$loc = setlocale(LC_ALL, 'fr_FR@euro');
$loc1 = setlocale(LC_ALL, 'fr_FR.ISO8859-15');
if (empty($loc) && empty($loc1)) {
die("skip required French locale not available");
}
?>
--FILE--
<?php

View file

@ -0,0 +1,55 @@
--TEST--
Test Chinese locale in Linux
--DESCRIPTION--
This test will invoke another php scirpt that is saved as GB2312(Simplified Chinese) ANSI format,
namely sqlsrv_test_gb18030.php.
To run this test, create a temporary database first with the correct collation
CREATE DATABASE [GB18030test]
COLLATE Chinese_PRC_CI_AS
Next, set the correct locale and convert the php script, like this:
export LC_ALL=zh_CN.gb18030
iconv -c -f GB2312 -t GB18030 sqlsrv_test_gb18030.php > test_gb18030.php
Drop the temporary database when the test is finished.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php
require('skipif_unix_ansitests.inc');
$loc = setlocale(LC_ALL, 'zh_CN.gb18030');
if (empty($loc)) {
die("skip required gb18030 locale not available");
}
--FILE--
<?php
function runTest()
{
require_once('MsSetup.inc');
$options = array("Database"=>"master", "UID"=>$userName, "PWD"=>$userPassword);
$conn = sqlsrv_connect($server, $options);
if( $conn === false ) {
die(print_r(sqlsrv_errors(), true));
}
$tempDB = 'GB18030test' . rand(1, 100);
$query = "CREATE DATABASE $tempDB COLLATE Chinese_PRC_CI_AS";
$stmt = sqlsrv_query($conn, $query);
if ($stmt === false) {
echo "Failed to create the database $tempDB\n";
}
shell_exec("export LC_ALL=zh_CN.gb18030");
shell_exec("iconv -c -f GB2312 -t GB18030 sqlsrv_test_gb18030.php > test_gb18030.php");
print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/test_gb18030.php $tempDB"));
$query = "DROP DATABASE $tempDB";
sqlsrv_query($conn, $query);
sqlsrv_close($conn);
}
runTest();
?>
--EXPECT--
Done

View file

@ -0,0 +1,67 @@
<?php
/*
This ansi test is invoked by sqlsrv_ansi_locale_zh.phpt
*/
function insertText($conn, $text, $hexValue)
{
$hex = bin2hex($text);
if ($hex !== $hexValue) {
"Expected $hexValue but got $hex" . PHP_EOL;
}
$tsql = "INSERT INTO test1 VALUES (?)";
$params = array($text);
$stmt = sqlsrv_query($conn, $tsql, $params);
if ($stmt === false) {
var_dump(sqlsrv_errors());
}
}
require_once('MsSetup.inc');
$tempDB = ($_SERVER['argv'][1]);
setlocale(LC_ALL, 'zh_CN.gb18030');
$options = array("Database"=>$tempDB, "UID"=>$userName, "PWD"=>$userPassword);
$conn = sqlsrv_connect($server, $options);
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
}
$tsql = "CREATE TABLE test1([id] int identity, [name] [varchar](50) NULL)";
$stmt = sqlsrv_query($conn, $tsql);
// Next, insert the strings
$inputs = array('中文', '你好', '未找到信息', '获取更多');
$hexValues = array('d6d0cec4', 'c4e3bac3', 'ceb4d5d2b5bdd0c5cfa2', 'bbf1c8a1b8fcb6e0');
for ($i = 0; $i < 4; $i++) {
insertText($conn, $inputs[$i], $hexValues[$i]);
}
// Next, fetch the strings
$tsql = "SELECT * FROM test1";
$stmt = sqlsrv_query($conn, $tsql);
if ($stmt === false) {
var_dump(sqlsrv_errors());
}
$i = 0;
while (sqlsrv_fetch($stmt)) {
$name = sqlsrv_get_field($stmt, 1);
if ($name !== $inputs[$i]) {
echo "Expected $inputs[$i] but got $name" . PHP_EOL;
}
$i++;
}
$tsql = "DROP TABLE test1";
sqlsrv_query($conn, $tsql);
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
echo "Done";
?>