ssufficool                               Tue, 29 Jun 2010 06:04:17 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=300844

Log:
Add tests for recent fixes

Changed paths:
    A   php/php-src/trunk/ext/pdo_dblib/tests/
    A   php/php-src/trunk/ext/pdo_dblib/tests/bug_38955.phpt
    A   php/php-src/trunk/ext/pdo_dblib/tests/bug_45876.phpt
    A   php/php-src/trunk/ext/pdo_dblib/tests/bug_47588.phpt
    A   php/php-src/trunk/ext/pdo_dblib/tests/bug_50755.phpt
    A   php/php-src/trunk/ext/pdo_dblib/tests/common.phpt
    A   php/php-src/trunk/ext/pdo_dblib/tests/config.inc
    A   php/php-src/trunk/ext/pdo_dblib/tests/pdo_dblib.phpt

Added: php/php-src/trunk/ext/pdo_dblib/tests/bug_38955.phpt
===================================================================
--- php/php-src/trunk/ext/pdo_dblib/tests/bug_38955.phpt	                        (rev 0)
+++ php/php-src/trunk/ext/pdo_dblib/tests/bug_38955.phpt	2010-06-29 06:04:17 UTC (rev 300844)
@@ -0,0 +1,62 @@
+--TEST--
+ PDO_DBLIB driver does not support transactions
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_dblib')) die('skip not loaded');
+require dirname(__FILE__) . '/config.inc';
+require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+PDOTest::skip();
+?>
+--FILE--
+<?php
+require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
+$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
+
+/*We see these rows */
+$db->query("CREATE table php_test(val int)");
+$db->beginTransaction();
+$db->query("INSERT INTO php_test(val) values(1)");
+$db->query("INSERT INTO php_test(val) values(2)");
+$db->query("INSERT INTO php_test(val) values(3)");
+$db->query("INSERT INTO php_test(val) values(4)");
+$db->commit();
+
+/*We don't see these rows */
+$db->beginTransaction();
+$db->query("INSERT INTO php_test(val) values(5)");
+$db->query("INSERT INTO php_test(val) values(6)");
+$db->query("INSERT INTO php_test(val) values(7)");
+$db->query("INSERT INTO php_test(val) values(8)");
+$db->rollback();
+
+$rs = $db->query("SELECT * FROM php_test");
+$rows = $rs->fetchAll(PDO::FETCH_ASSOC);
+var_dump($rows);
+
+$db->query("DROP table php_test");
+?>
+--EXPECT--
+array(4) {
+  [0]=>
+  array(1) {
+    ["val"]=>
+    string(1) "1"
+  }
+  [1]=>
+  array(1) {
+    ["val"]=>
+    string(1) "2"
+  }
+  [2]=>
+  array(1) {
+    ["val"]=>
+    string(1) "3"
+  }
+  [3]=>
+  array(1) {
+    ["val"]=>
+    string(1) "4"
+  }
+}

Added: php/php-src/trunk/ext/pdo_dblib/tests/bug_45876.phpt
===================================================================
--- php/php-src/trunk/ext/pdo_dblib/tests/bug_45876.phpt	                        (rev 0)
+++ php/php-src/trunk/ext/pdo_dblib/tests/bug_45876.phpt	2010-06-29 06:04:17 UTC (rev 300844)
@@ -0,0 +1,40 @@
+--TEST--
+PDO_DBLIB: Does not support get column meta
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_dblib')) die('skip not loaded');
+require dirname(__FILE__) . '/config.inc';
+require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+PDOTest::skip();
+?>
+--FILE--
+<?php
+require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
+$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
+
+$stmt = $db->prepare("select ic1.* from information_schema.columns ic1");
+$stmt->execute();
+var_dump($stmt->getColumnMeta(0));
+$stmt = null;
+?>
+--EXPECT--
+array(8) {
+  ["max_length"]=>
+  int(255)
+  ["precision"]=>
+  int(0)
+  ["scale"]=>
+  int(0)
+  ["column_source"]=>
+  string(13) "table_catalog"
+  ["native_type"]=>
+  string(4) "char"
+  ["name"]=>
+  string(13) "table_catalog"
+  ["len"]=>
+  int(255)
+  ["pdo_type"]=>
+  int(2)
+}

Added: php/php-src/trunk/ext/pdo_dblib/tests/bug_47588.phpt
===================================================================
--- php/php-src/trunk/ext/pdo_dblib/tests/bug_47588.phpt	                        (rev 0)
+++ php/php-src/trunk/ext/pdo_dblib/tests/bug_47588.phpt	2010-06-29 06:04:17 UTC (rev 300844)
@@ -0,0 +1,50 @@
+--TEST--
+PDO_DBLIB: Quoted field names
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_dblib')) die('skip not loaded');
+require dirname(__FILE__) . '/config.inc';
+require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+PDOTest::skip();
+?>
+--FILE--
+<?php
+require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
+$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
+
+$db->query('CREATE TABLE "Test Table" ("My Field" int, "Another Field" varchar(32) not null default \'test_string\')');
+$db->query('INSERT INTO "Test Table" ("My Field") values(1)');
+$db->query('INSERT INTO "Test Table" ("My Field") values(2)');
+$db->query('INSERT INTO "Test Table" ("My Field") values(3)');
+$rs = $db->query('SELECT * FROM "Test Table"');
+var_dump($rs->fetchAll(PDO::FETCH_ASSOC));
+$db->query('DROP TABLE "Test Table"');
+echo "Done.\n";
+?>
+--EXPECT--
+array(3) {
+  [0]=>
+  array(2) {
+    ["my field"]=>
+    string(1) "1"
+    ["another field"]=>
+    string(11) "test_string"
+  }
+  [1]=>
+  array(2) {
+    ["my field"]=>
+    string(1) "2"
+    ["another field"]=>
+    string(11) "test_string"
+  }
+  [2]=>
+  array(2) {
+    ["my field"]=>
+    string(1) "3"
+    ["another field"]=>
+    string(11) "test_string"
+  }
+}
+Done.

Added: php/php-src/trunk/ext/pdo_dblib/tests/bug_50755.phpt
===================================================================
--- php/php-src/trunk/ext/pdo_dblib/tests/bug_50755.phpt	                        (rev 0)
+++ php/php-src/trunk/ext/pdo_dblib/tests/bug_50755.phpt	2010-06-29 06:04:17 UTC (rev 300844)
@@ -0,0 +1,34 @@
+--TEST--
+PDO_DBLIB: Out of memory on large recordsets
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_dblib')) die('skip not loaded');
+require dirname(__FILE__) . '/config.inc';
+require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+PDOTest::skip();
+?>
+--FILE--
+<?php
+require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
+$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
+
+/* This should be sufficient to overflow any buffers */
+$stmt = $db->prepare("select *
+from information_schema.columns ic1
+cross join information_schema.columns ic2
+cross join information_schema.columns ic3");
+
+$x = $stmt->execute();
+$n = 0;
+while (($r = $stmt->fetch())) {
+	$n++;
+}
+$stmt = null;
+
+echo "OK\n";
+
+?>
+--EXPECT--
+OK

Added: php/php-src/trunk/ext/pdo_dblib/tests/common.phpt
===================================================================
--- php/php-src/trunk/ext/pdo_dblib/tests/common.phpt	                        (rev 0)
+++ php/php-src/trunk/ext/pdo_dblib/tests/common.phpt	2010-06-29 06:04:17 UTC (rev 300844)
@@ -0,0 +1,29 @@
+--TEST--
+DBLIB
+--SKIPIF--
+<?php # vim:ft=php
+if (!extension_loaded('pdo_dblib')) print 'skip';
+?>
+--REDIRECTTEST--
+# magic auto-configuration
+# Also update config.inc if you make changes here...
+
+$config = array(
+	'TESTS' => 'ext/pdo/tests'
+);
+
+if (false !== getenv('PDO_DBLIB_TEST_DSN'))
+	$config['ENV']['PDOTEST_DSN'] = getenv('PDO_DBLIB_TEST_DSN');
+else
+	$config['ENV']['PDOTEST_DSN'] = 'dblib:host=localhost dbname=test';
+
+if (false !== getenv('PDO_DBLIB_TEST_USER'))
+	$config['ENV']['PDOTEST_USER'] = getenv('PDO_DBLIB_TEST_USER');
+
+if (false !== getenv('PDO_DBLIB_TEST_PASS'))
+	$config['ENV']['PDOTEST_PASS'] = getenv('PDO_DBLIB_TEST_PASS');
+
+if (false !== getenv('PDO_DBLIB_TEST_ATTR'))
+	$config['ENV']['PDOTEST_ATTR'] = getenv('PDO_DBLIB_TEST_ATTR');
+
+return $config;

Added: php/php-src/trunk/ext/pdo_dblib/tests/config.inc
===================================================================
--- php/php-src/trunk/ext/pdo_dblib/tests/config.inc	                        (rev 0)
+++ php/php-src/trunk/ext/pdo_dblib/tests/config.inc	2010-06-29 06:04:17 UTC (rev 300844)
@@ -0,0 +1,20 @@
+<?php
+
+if (false !== getenv('PDO_DBLIB_TEST_DSN'))
+	$config['ENV']['PDOTEST_DSN'] = getenv('PDO_DBLIB_TEST_DSN');
+else
+	$config['ENV']['PDOTEST_DSN'] = 'dblib:host=localhost dbname=test';
+
+if (false !== getenv('PDO_DBLIB_TEST_USER'))
+	$config['ENV']['PDOTEST_USER'] = getenv('PDO_DBLIB_TEST_USER');
+
+if (false !== getenv('PDO_DBLIB_TEST_PASS'))
+	$config['ENV']['PDOTEST_PASS'] = getenv('PDO_DBLIB_TEST_PASS');
+
+if (false !== getenv('PDO_DBLIB_TEST_ATTR'))
+	$config['ENV']['PDOTEST_ATTR'] = getenv('PDO_DBLIB_TEST_ATTR');
+
+foreach ($config['ENV'] as $k => $v) {
+	putenv("$k=$v");
+}
+?>

Added: php/php-src/trunk/ext/pdo_dblib/tests/pdo_dblib.phpt
===================================================================
--- php/php-src/trunk/ext/pdo_dblib/tests/pdo_dblib.phpt	                        (rev 0)
+++ php/php-src/trunk/ext/pdo_dblib/tests/pdo_dblib.phpt	2010-06-29 06:04:17 UTC (rev 300844)
@@ -0,0 +1,91 @@
+--TEST--
+PDO_DBLIB: Core tests
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_dblib')) die('skip not loaded');
+require dirname(__FILE__) . '/config.inc';
+require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+PDOTest::skip();
+?>
+--FILE--
+<?php
+require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
+$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
+$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
+
+test_transaction();
+test_quotedident();
+test_prepare();
+
+function test_quotedident() {
+	global $db;
+	$db->query('CREATE TABLE "Test Table" ("My Field" int, "Another Field" varchar(32) not null default \'test_string\')');
+	$db->query('INSERT INTO "Test Table" ("My Field") values(1)');
+	$db->query('INSERT INTO "Test Table" ("My Field") values(2)');
+	$db->query('INSERT INTO "Test Table" ("My Field") values(3)');
+	$rs = $db->query('SELECT * FROM "Test Table"');
+	var_dump($rs->fetchAll(PDO::FETCH_ASSOC));
+	$db->query('DROP TABLE "Test Table"');
+}
+
+function test_transaction() {
+	global $db;
+	echo "Transactions\n";
+
+	/*We see these rows */
+	$db->query("CREATE table php_test(val int)");
+	$db->beginTransaction();
+	$db->query("INSERT INTO php_test(val) values(1)");
+	$db->query("INSERT INTO php_test(val) values(2)");
+	$db->query("INSERT INTO php_test(val) values(3)");
+	$db->query("INSERT INTO php_test(val) values(4)");
+	$db->commit();
+
+	/*We don't see these rows */
+	$db->beginTransaction();
+	$db->query("INSERT INTO php_test(val) values(5)");
+	$db->query("INSERT INTO php_test(val) values(6)");
+	$db->query("INSERT INTO php_test(val) values(7)");
+	$db->query("INSERT INTO php_test(val) values(8)");
+	$db->rollback();
+
+	$rs = $db->query("SELECT * FROM php_test");
+	$rows = $rs->fetchAll(PDO::FETCH_ASSOC);
+	var_dump($rows);
+
+	$db->query("DROP table php_test");
+
+}
+
+$db = null;
+
+function test_prepare() {
+	global $db;
+	echo "Prepare:\n";
+	$stmt = $db->prepare("select ic1.*
+	from information_schema.columns ic1
+	cross join information_schema.columns ic2
+	cross join information_schema.columns ic3");
+
+	echo "Execute:\n";
+	$x = $stmt->execute();
+
+	echo "Fetch\n";
+	$n = 0;
+	$mem = 0;
+	while (($r = $stmt->fetch())) {
+		if ($n ==0)
+			$mem = memory_get_usage();
+		if ($n % 1000 == 0) {
+			echo($mem - memory_get_usage());
+		}
+		$n++;
+
+	}
+	$stmt = null;
+}
+
+echo "All done\n";
+?>
+--EXPECT--
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to