diff options
author | Ondřej Surý <ondrej@sury.org> | 2010-10-21 08:52:46 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2010-10-21 08:52:46 +0200 |
commit | 01fcdff3849c3691d9aaeaab735846ab6d8895ca (patch) | |
tree | 6460876d356113fa7053df36f2aa00baa7db24a9 /ext/dba/tests | |
parent | 855a09f4eded707941180c9d90acd17c25e29447 (diff) | |
download | php-01fcdff3849c3691d9aaeaab735846ab6d8895ca.tar.gz |
Imported Upstream version 5.3.3upstream/5.3.3
Diffstat (limited to 'ext/dba/tests')
51 files changed, 1621 insertions, 43 deletions
diff --git a/ext/dba/tests/bug36436.phpt b/ext/dba/tests/bug36436.phpt index 4e8daa860..19254df3c 100755 --- a/ext/dba/tests/bug36436.phpt +++ b/ext/dba/tests/bug36436.phpt @@ -3,13 +3,13 @@ Bug #36436 (DBA problem with Berkeley DB4) --SKIPIF-- <?php $handler = 'db4'; - require_once dirname(__FILE__) .'/skipif.inc'; + require_once(dirname(__FILE__) .'/skipif.inc'); ?> --FILE-- <?php $handler = 'db4'; -require_once dirname(__FILE__) .'/test.inc'; +require_once(dirname(__FILE__) .'/test.inc'); $db = dba_popen($db_filename, 'c', 'db4'); @@ -22,10 +22,13 @@ var_dump(dba_firstkey($db)); var_dump(dba_nextkey($db)); dba_close($db); -unlink($db_filename); ?> ===DONE=== +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); +?> --EXPECTF-- resource(%d) of type (dba persistent) string(3) "XYZ" diff --git a/ext/dba/tests/bug38698.phpt b/ext/dba/tests/bug38698.phpt new file mode 100755 index 000000000..56dde8526 --- /dev/null +++ b/ext/dba/tests/bug38698.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #38698 (Bug #38698 for some keys cdbmake creates corrupted db and cdb can't read valid db) +--SKIPIF-- +<?php + $handler = 'cdb_make'; + require_once(dirname(__FILE__) .'/skipif.inc'); +?> +--FILE-- +<?php + +$db_file = dirname(__FILE__) .'/129php.cdb'; + +if (($db_make=dba_open($db_file, "n", 'cdb_make'))!==FALSE) { + dba_insert(pack('i',129), "Booo!", $db_make); + dba_close($db_make); + // write md5 checksum of generated database file + var_dump(md5_file($db_file)); + @unlink($db_file); +} else { + echo "Error creating database\n"; +} +?> +===DONE=== +--EXPECT-- +string(32) "1f34b74bde3744265acfc21e0f30af95" +===DONE=== diff --git a/ext/dba/tests/bug48240.phpt b/ext/dba/tests/bug48240.phpt index 27f8d95e6..5a72073f3 100644 --- a/ext/dba/tests/bug48240.phpt +++ b/ext/dba/tests/bug48240.phpt @@ -3,23 +3,26 @@ Bug #48240 (DBA Segmentation fault dba_nextkey) --SKIPIF-- <?php $handler = 'db4'; - require_once dirname(__FILE__) .'/skipif.inc'; + require_once(dirname(__FILE__) .'/skipif.inc'); ?> --FILE-- <?php $handler = 'db4'; -require_once dirname(__FILE__) .'/test.inc'; +require_once(dirname(__FILE__) .'/test.inc'); $db = dba_open($db_filename, 'c', 'db4'); var_dump(dba_nextkey($db)); dba_close($db); -unlink($db_filename); ?> ===DONE=== +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); +?> --EXPECT-- bool(false) ===DONE=== diff --git a/ext/dba/tests/bug49125.phpt b/ext/dba/tests/bug49125.phpt index 3724b89c9..e06495a10 100644 --- a/ext/dba/tests/bug49125.phpt +++ b/ext/dba/tests/bug49125.phpt @@ -3,7 +3,7 @@ Bug #49125 (Error in dba_exists C code) --SKIPIF-- <?php $handler = 'db4'; - require_once dirname(__FILE__) .'/skipif.inc'; + require_once(dirname(__FILE__) .'/skipif.inc'); ?> --FILE-- <?php @@ -11,7 +11,7 @@ Bug #49125 (Error in dba_exists C code) error_reporting(E_ALL); $handler = 'db4'; -require_once dirname(__FILE__) .'/test.inc'; +require_once(dirname(__FILE__) .'/test.inc'); $db = dba_popen($db_filename, 'c', 'db4'); @@ -21,7 +21,10 @@ var_dump(dba_exists('foo', $db)); dba_close($db); -unlink($db_filename); - +?> +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); +?> --EXPECT-- bool(true) diff --git a/ext/dba/tests/clean.inc b/ext/dba/tests/clean.inc new file mode 100644 index 000000000..7c53e7e61 --- /dev/null +++ b/ext/dba/tests/clean.inc @@ -0,0 +1,5 @@ +<?php + $db_filename = dirname(__FILE__) .'/test0.dbm'; // see test.inc + @unlink($db_filename); + @unlink($db_filename.'.lck'); +?> diff --git a/ext/dba/tests/dba001.phpt b/ext/dba/tests/dba001.phpt index 00aec6969..b63829abb 100644 --- a/ext/dba/tests/dba001.phpt +++ b/ext/dba/tests/dba001.phpt @@ -2,12 +2,12 @@ DBA File Creation Test --SKIPIF-- <?php - require_once dirname(__FILE__) .'/skipif.inc'; + require_once(dirname(__FILE__) .'/skipif.inc'); die("info $HND handler used"); ?> --FILE-- <?php - require_once dirname(__FILE__) .'/test.inc'; + require_once(dirname(__FILE__) .'/test.inc'); echo "database handler: $handler\n"; if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { echo "database file created\n"; @@ -16,6 +16,10 @@ DBA File Creation Test echo "$db_file does not exist\n"; } ?> +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); +?> --EXPECTF-- database handler: %s database file created diff --git a/ext/dba/tests/dba002.phpt b/ext/dba/tests/dba002.phpt index 974b09fab..e60e73360 100644 --- a/ext/dba/tests/dba002.phpt +++ b/ext/dba/tests/dba002.phpt @@ -2,12 +2,12 @@ DBA Insert/Fetch Test --SKIPIF-- <?php - require_once dirname(__FILE__) .'/skipif.inc'; + require_once(dirname(__FILE__) .'/skipif.inc'); die("info $HND handler used"); ?> --FILE-- <?php - require_once dirname(__FILE__) .'/test.inc'; + require_once(dirname(__FILE__) .'/test.inc'); echo "database handler: $handler\n"; if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { dba_insert("key1", "This is a test insert", $db_file); @@ -17,6 +17,10 @@ DBA Insert/Fetch Test echo "Error creating database\n"; } ?> +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); +?> --EXPECTF-- database handler: %s This is a test insert diff --git a/ext/dba/tests/dba003.phpt b/ext/dba/tests/dba003.phpt index 832c7a0dc..a027b5356 100644 --- a/ext/dba/tests/dba003.phpt +++ b/ext/dba/tests/dba003.phpt @@ -2,12 +2,12 @@ DBA Insert/Replace/Fetch Test --SKIPIF-- <?php - require_once dirname(__FILE__) .'/skipif.inc'; + require_once(dirname(__FILE__) .'/skipif.inc'); die("info $HND handler used"); ?> --FILE-- <?php - require_once dirname(__FILE__) .'/test.inc'; + require_once(dirname(__FILE__) .'/test.inc'); echo "database handler: $handler\n"; if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { dba_insert("key1", "This is a test insert", $db_file); @@ -19,6 +19,10 @@ DBA Insert/Replace/Fetch Test echo "Error creating database\n"; } ?> +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); +?> --EXPECTF-- database handler: %s This is the replacement text diff --git a/ext/dba/tests/dba004.phpt b/ext/dba/tests/dba004.phpt index 42da1c64b..6e7180cf6 100644 --- a/ext/dba/tests/dba004.phpt +++ b/ext/dba/tests/dba004.phpt @@ -2,12 +2,12 @@ DBA Multiple Insert/Fetch Test --SKIPIF-- <?php - require_once dirname(__FILE__) .'/skipif.inc'; + require_once(dirname(__FILE__) .'/skipif.inc'); die("info $HND handler used"); ?> --FILE-- <?php - require_once dirname(__FILE__) .'/test.inc'; + require_once(dirname(__FILE__) .'/test.inc'); echo "database handler: $handler\n"; if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { dba_insert("key1", "Content String 1", $db_file); @@ -23,6 +23,10 @@ DBA Multiple Insert/Fetch Test echo "Error creating database\n"; } ?> +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); +?> --EXPECTF-- database handler: %s Another Content String Content String 2 diff --git a/ext/dba/tests/dba005.phpt b/ext/dba/tests/dba005.phpt index 3e7e58086..68ad60022 100644 --- a/ext/dba/tests/dba005.phpt +++ b/ext/dba/tests/dba005.phpt @@ -2,12 +2,12 @@ DBA FirstKey/NextKey Loop Test With 5 Items --SKIPIF-- <?php - require_once dirname(__FILE__) .'/skipif.inc'; + require_once(dirname(__FILE__) .'/skipif.inc'); die("info $HND handler used"); ?> --FILE-- <?php - require_once dirname(__FILE__) .'/test.inc'; + require_once(dirname(__FILE__) .'/test.inc'); echo "database handler: $handler\n"; if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { dba_insert("key1", "Content String 1", $db_file); @@ -30,6 +30,10 @@ DBA FirstKey/NextKey Loop Test With 5 Items echo "Error creating database\n"; } ?> +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); +?> --EXPECTF-- database handler: %s 5YYYYY diff --git a/ext/dba/tests/dba006.phpt b/ext/dba/tests/dba006.phpt index f6177b0b9..a3fc738fa 100644 --- a/ext/dba/tests/dba006.phpt +++ b/ext/dba/tests/dba006.phpt @@ -2,12 +2,12 @@ DBA FirstKey/NextKey with 2 deletes --SKIPIF-- <?php - require_once dirname(__FILE__) .'/skipif.inc'; + require_once(dirname(__FILE__) .'/skipif.inc'); die("info $HND handler used"); ?> --FILE-- <?php - require_once dirname(__FILE__) .'/test.inc'; + require_once(dirname(__FILE__) .'/test.inc'); echo "database handler: $handler\n"; if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { dba_insert("key1", "Content String 1", $db_file); @@ -32,6 +32,10 @@ DBA FirstKey/NextKey with 2 deletes echo "Error creating database\n"; } ?> +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); +?> --EXPECTF-- database handler: %s 3NYNYY diff --git a/ext/dba/tests/dba007.phpt b/ext/dba/tests/dba007.phpt index 0f30932fc..2519fdc59 100644 --- a/ext/dba/tests/dba007.phpt +++ b/ext/dba/tests/dba007.phpt @@ -2,16 +2,16 @@ DBA Multiple File Creation Test --SKIPIF-- <?php - require_once dirname(__FILE__) .'/skipif.inc'; + require_once(dirname(__FILE__) .'/skipif.inc'); if (!function_exists('dba_list')) die('skip dba_list() not available'); die("info $HND handler used"); ?> --FILE-- <?php - require_once dirname(__FILE__) .'/test.inc'; + require_once(dirname(__FILE__) .'/test.inc'); echo "database handler: $handler\n"; - $db_file1 = dirname(__FILE__).'/test1.dbm'; - $db_file2 = dirname(__FILE__).'/test2.dbm'; + $db_file1 = $db_filename1 = dirname(__FILE__).'/test1.dbm'; + $db_file2 = $db_filename2 = dirname(__FILE__).'/test2.dbm'; if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { echo "database file created\n"; } else { @@ -29,6 +29,13 @@ DBA Multiple File Creation Test } var_dump(dba_list()); dba_close($db_file); + + @unlink($db_filename1); + @unlink($db_filename2); +?> +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); ?> --EXPECTF-- database handler: %s diff --git a/ext/dba/tests/dba008.phpt b/ext/dba/tests/dba008.phpt index 8fde8ff3f..f7015d921 100644 --- a/ext/dba/tests/dba008.phpt +++ b/ext/dba/tests/dba008.phpt @@ -2,12 +2,13 @@ DBA magic_quotes_runtime Test --SKIPIF-- <?php - require_once dirname(__FILE__) .'/skipif.inc'; + die('skip, magic_quotes removed'); + require_once(dirname(__FILE__) .'/skipif.inc'); die("info $HND handler used"); ?> --FILE-- <?php - require_once dirname(__FILE__) .'/test.inc'; + require_once(dirname(__FILE__) .'/test.inc'); echo "database handler: $handler\n"; if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { ini_set('magic_quotes_runtime', 0); @@ -24,6 +25,10 @@ DBA magic_quotes_runtime Test echo "Error creating database\n"; } ?> +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); +?> --EXPECTF-- database handler: %s string(1) """ diff --git a/ext/dba/tests/dba009.phpt b/ext/dba/tests/dba009.phpt index b4d8308e8..698657b2a 100755 --- a/ext/dba/tests/dba009.phpt +++ b/ext/dba/tests/dba009.phpt @@ -2,12 +2,12 @@ DBA dba_popen Test --SKIPIF-- <?php - require_once dirname(__FILE__) .'/skipif.inc'; + require_once(dirname(__FILE__) .'/skipif.inc'); print("info $HND handler used"); ?> --FILE-- <?php - require_once dirname(__FILE__) .'/test.inc'; + require_once(dirname(__FILE__) .'/test.inc'); echo "database handler: $handler\n"; if (($db=dba_popen($db_file, "n", $handler))!==FALSE) { echo "Opened\n"; @@ -24,6 +24,10 @@ DBA dba_popen Test echo dba_fetch("a", $db)."\n"; } ?> +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); +?> --EXPECTF-- database handler: %s Opened diff --git a/ext/dba/tests/dba010.phpt b/ext/dba/tests/dba010.phpt new file mode 100644 index 000000000..c818373f1 --- /dev/null +++ b/ext/dba/tests/dba010.phpt @@ -0,0 +1,44 @@ +--TEST-- +DBA with array keys +--SKIPIF-- +<?php + require_once(dirname(__FILE__) .'/skipif.inc'); + die("info $HND handler used"); +?> +--FILE-- +<?php +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; +if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { + dba_insert(array("", "name0") , "Content String 1", $db_file); + dba_insert(array("key1", "name1") , "Content String 1", $db_file); + dba_insert(array("key2","name2"), "Content String 2", $db_file); + dba_insert("[key3]name3", "Third Content String", $db_file); + dba_insert(array("key4","name4"), "Another Content String", $db_file); + dba_insert(array("key5","name5"), "The last content string", $db_file); + $a = dba_firstkey($db_file); + $i=0; + while($a) { + $a = dba_nextkey($db_file); + $i++; + } + echo $i; + echo dba_exists(array("","name0"), $db_file) ? "Y" : "N"; + for ($i=1; $i<5; $i++) { + echo dba_exists("[key$i]name$i", $db_file) ? "Y" : "N"; + } + echo dba_exists(array("key5","name5"), $db_file) ? "Y" : "N"; + echo "\n"; + dba_close($db_file); +} else { + echo "Error creating database\n"; +} + +?> +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: %s +6YYYYYY diff --git a/ext/dba/tests/dba011.phpt b/ext/dba/tests/dba011.phpt new file mode 100644 index 000000000..71164be3c --- /dev/null +++ b/ext/dba/tests/dba011.phpt @@ -0,0 +1,38 @@ +--TEST-- +DBA argument tests +--SKIPIF-- +<?php +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; +var_dump(dba_open($db_file)); +var_dump(dba_open($db_file, 'n')); +var_dump(dba_open($db_file, 'n', 'bogus')); +var_dump(dba_open($db_file, 'q', $handler)); +var_dump(dba_open($db_file, 'nq', $handler)); +var_dump(dba_open($db_file, 'n', $handler, 2, 3, 4, 5, 6, 7, 8)); +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: flatfile + +Warning: Wrong parameter count for dba_open() in %sdba011.php on line %d +NULL +resource(%d) of type (dba) + +Warning: dba_open(%stest0.dbm,n): No such handler: bogus in %sdba011.php on line %d +bool(false) + +Warning: dba_open(%stest0.dbm,q): Illegal DBA mode in %sdba011.php on line %d +bool(false) + +Warning: dba_open(%stest0.dbm,nq): Illegal DBA mode in %sdba011.php on line %d +bool(false) +resource(%d) of type (dba) diff --git a/ext/dba/tests/dba012.phpt b/ext/dba/tests/dba012.phpt new file mode 100644 index 000000000..821c4e2ab --- /dev/null +++ b/ext/dba/tests/dba012.phpt @@ -0,0 +1,42 @@ +--TEST-- +DBA dba.default_handler tests +--SKIPIF-- +<?php +$handler = "flatfile"; +require_once(dirname(__FILE__) .'/skipif.inc'); +?> +--INI-- +dba.default_handler=flatfile +--FILE-- +<?php +$handler = "flatfile"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; + +echo "Test 1\n"; + +ini_set('dba.default_handler', 'does_not_exist'); + +var_dump(dba_open($db_filename, 'c')); + +echo "Test 2\n"; + +ini_set('dba.default_handler', ''); + +var_dump(dba_open($db_filename, 'n')); + +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: flatfile +Test 1 + +Warning: ini_set(): No such handler: does_not_exist in %sdba012.php on line %d +resource(%d) of type (dba) +Test 2 + +Warning: dba_open(%stest0.dbm,n): No default handler selected in %sdba012.php on line %d +bool(false) diff --git a/ext/dba/tests/dba013.phpt b/ext/dba/tests/dba013.phpt new file mode 100644 index 000000000..bf95642e9 --- /dev/null +++ b/ext/dba/tests/dba013.phpt @@ -0,0 +1,27 @@ +--TEST-- +DBA with array key with empty array +--SKIPIF-- +<?php +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; + +if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { + dba_insert(array(), "Content String 1", $db_file); +} else { + echo "Error creating database\n"; +} + +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: %s + +Catchable fatal error: dba_insert(): Key does not have exactly two elements: (key, name) in %sdba013.php on line %d diff --git a/ext/dba/tests/dba014.phpt b/ext/dba/tests/dba014.phpt new file mode 100644 index 000000000..7e52be7c3 --- /dev/null +++ b/ext/dba/tests/dba014.phpt @@ -0,0 +1,27 @@ +--TEST-- +DBA with array key with array containing too many elements +--SKIPIF-- +<?php +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; + +if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { + dba_insert(array("a", "b", "c"), "Content String 2", $db_file); +} else { + echo "Error creating database\n"; +} + +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: %s + +Catchable fatal error: dba_insert(): Key does not have exactly two elements: (key, name) in %sdba014.php on line %d diff --git a/ext/dba/tests/dba015.phpt b/ext/dba/tests/dba015.phpt new file mode 100644 index 000000000..9f560c5b2 --- /dev/null +++ b/ext/dba/tests/dba015.phpt @@ -0,0 +1,76 @@ +--TEST-- +DBA with persistent connections +--SKIPIF-- +<?php +$handler = "flatfile"; +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php + +$handler = "flatfile"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; + +echo "Test 1\n"; +$db_file1 = dba_popen($db_filename, 'n', 'flatfile'); +dba_insert("key1", "This is a test insert 1", $db_file1); +echo dba_fetch("key1", $db_file1), "\n"; + + +echo "Test 2\n"; +$db_file2 = dba_popen($db_filename, 'n', 'flatfile'); +if ($db_file1 === $db_file2) { + echo "resources are the same\n"; +} else { + echo "resources are different\n"; +} + + +echo "Test 3 - fetch both rows from second resource\n"; +dba_insert("key2", "This is a test insert 2", $db_file2); +echo dba_fetch("key1", $db_file2), "\n"; +echo dba_fetch("key2", $db_file2), "\n"; + + +echo "Test 4 - fetch both rows from first resource\n"; +echo dba_fetch("key1", $db_file1), "\n"; +echo dba_fetch("key2", $db_file1), "\n"; + +echo "Test 5 - close 2nd resource\n"; +dba_close($db_file2); +var_dump($db_file1); +var_dump($db_file2); + +echo "Test 6 - query after closing 2nd resource\n"; +echo dba_fetch("key1", $db_file1), "\n"; +echo dba_fetch("key2", $db_file1), "\n"; + +?> +===DONE=== +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); +?> +--XFAIL-- +Test 6 crashes in flatfile_findkey with dba pointer of NULL, bug http://bugs.php.net/bug.php?id=51278 +--EXPECTF-- +database handler: flatfile +Test 1 +This is a test insert 1 +Test 2 +resources are different +Test 3 - fetch both rows from second resource +This is a test insert 1 +This is a test insert 2 +Test 4 - fetch both rows from first resource +This is a test insert 1 +This is a test insert 2 +Test 5 - close 2nd resource +resource(%d) of type (dba persistent) +resource(%d) of type (Unknown) +Test 6 - query after closing 2nd resource +This is a test insert 1 +This is a test insert 2 +===DONE=== diff --git a/ext/dba/tests/dba016.phpt b/ext/dba/tests/dba016.phpt new file mode 100644 index 000000000..29726ac11 --- /dev/null +++ b/ext/dba/tests/dba016.phpt @@ -0,0 +1,23 @@ +--TEST-- +DBA lock modifier error message test +--SKIPIF-- +<?php +$handler = "flatfile"; +require_once(dirname(__FILE__) .'/skipif.inc'); +?> +--FILE-- +<?php + +$handler = "flatfile"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; + +$db_file1 = dba_popen($db_filename, 'n-t', 'flatfile'); + +?> +===DONE=== +--EXPECTF-- +database handler: flatfile + +Warning: dba_popen(%stest0.dbm,n-t): You cannot combine modifiers - (no lock) and t (test lock) in %sdba016.php on line %d +===DONE=== diff --git a/ext/dba/tests/dba_cdb.phpt b/ext/dba/tests/dba_cdb.phpt index 0b7559648..b9ef68f2b 100644 --- a/ext/dba/tests/dba_cdb.phpt +++ b/ext/dba/tests/dba_cdb.phpt @@ -3,16 +3,20 @@ DBA CDB handler test --SKIPIF-- <?php $handler = 'cdb'; - require_once dirname(__FILE__) .'/skipif.inc'; + require_once(dirname(__FILE__) .'/skipif.inc'); die('info CDB does not support replace or delete'); ?> --FILE-- <?php $handler = 'cdb'; - require_once dirname(__FILE__) .'/test.inc'; - require_once dirname(__FILE__) .'/dba_handler.inc'; + require_once(dirname(__FILE__) .'/test.inc'); + require_once(dirname(__FILE__) .'/dba_handler.inc'); ?> ===DONE=== +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); +?> --EXPECT-- database handler: cdb 5YYYYY diff --git a/ext/dba/tests/dba_cdb_001.phpt b/ext/dba/tests/dba_cdb_001.phpt new file mode 100644 index 000000000..437275438 --- /dev/null +++ b/ext/dba/tests/dba_cdb_001.phpt @@ -0,0 +1,89 @@ +--TEST-- +DBA CDB handler test +--SKIPIF-- +<?php +$handler = 'cdb'; +require_once(dirname(__FILE__) .'/skipif.inc'); +die('info CDB does not support replace or delete'); +?> +--FILE-- +<?php + +$handler = 'cdb'; +require_once(dirname(__FILE__) .'/test.inc'); + +echo "Test 0\n"; + +if (($db_file = dba_open($db_filename, 'n', $handler))!==FALSE) { + var_dump(dba_insert("key1", "Content String 1", $db_file)); + var_dump(dba_replace("key1", "New Content String", $db_file)); + var_dump(dba_fetch("key1", $db_file)); + var_dump(dba_firstkey($db_file)); + var_dump(dba_delete("key1", $db_file)); + var_dump(dba_optimize($db_file)); + var_dump(dba_sync($db_file)); + dba_close($db_file); +} +else { + echo "Failed to open DB\n"; +} + +unlink($db_filename); + +echo "Test 1\n"; + +if (($db_file = dba_open($db_filename, 'c', $handler))!==FALSE) { + dba_insert("key1", "Content String 1", $db_file); + dba_close($db_file); +} +else { + echo "Failed to open DB\n"; +} + +echo "Test 2\n"; + +if (($db_file = dba_open($db_filename, 'r', $handler))!==FALSE) { + dba_insert("key1", "Content String 1", $db_file); + dba_close($db_file); +} +else { + echo "Failed to open DB\n"; +} + +echo "Test 3\n"; + +if (($db_file = dba_open($db_filename, 'w', $handler))!==FALSE) { + echo dba_fetch("key1", $db_file), "\n"; + dba_close($db_file); +} +else { + echo "Failed to open DB\n"; +} + +?> +===DONE=== +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +Test 0 +bool(true) +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) +bool(true) +Test 1 + +Warning: dba_open(%stest0.dbm,c): Driver initialization failed for handler: cdb: Update operations are not supported in %sdba_cdb_001.php on line %d +Failed to open DB +Test 2 + +Warning: dba_insert(): You cannot perform a modification to a database without proper access in %sdba_cdb_001.php on line %d +Test 3 + +Warning: dba_open(%stest0.dbm,w): Driver initialization failed for handler: cdb: Update operations are not supported in %sdba_cdb_001.php on line %d +Failed to open DB +===DONE=== diff --git a/ext/dba/tests/dba_cdb_make.phpt b/ext/dba/tests/dba_cdb_make.phpt index 6691d0a28..c1d0a0188 100644 --- a/ext/dba/tests/dba_cdb_make.phpt +++ b/ext/dba/tests/dba_cdb_make.phpt @@ -5,13 +5,13 @@ magic_quotes_runtime=1 --SKIPIF-- <?php $handler = 'cdb_make'; - require_once dirname(__FILE__) .'/skipif.inc'; + require_once(dirname(__FILE__) .'/skipif.inc'); die('info CDB_MAKE does not support reading'); ?> --FILE-- <?php $handler = 'cdb_make'; - require_once dirname(__FILE__) .'/test.inc'; + require_once(dirname(__FILE__) .'/test.inc'); echo "database handler: $handler\n"; // print md5 checksum of test.cdb which is generated by cdb_make program var_dump(md5_file(dirname(__FILE__).'/test.cdb')); @@ -32,6 +32,10 @@ magic_quotes_runtime=1 echo "Error creating database\n"; } ?> +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); +?> --EXPECT-- Warning: Directive 'magic_quotes_runtime' is deprecated in PHP 5.3 and greater in Unknown on line 0 database handler: cdb_make diff --git a/ext/dba/tests/dba_db4.phpt b/ext/dba/tests/dba_db4_000.phpt index 2c2a7a694..bbbc52c9f 100644 --- a/ext/dba/tests/dba_db4.phpt +++ b/ext/dba/tests/dba_db4_000.phpt @@ -2,16 +2,20 @@ DBA DB4 handler test --SKIPIF-- <?php - $handler = 'db4'; - require_once dirname(__FILE__) .'/skipif.inc'; +$handler = 'db4'; +require_once(dirname(__FILE__) .'/skipif.inc'); ?> --FILE-- <?php - $handler = 'db4'; - require_once dirname(__FILE__) .'/test.inc'; - require_once dirname(__FILE__) .'/dba_handler.inc'; +$handler = 'db4'; +require_once(dirname(__FILE__) .'/test.inc'); +require_once(dirname(__FILE__) .'/dba_handler.inc'); ?> ===DONE=== +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> --EXPECT-- database handler: db4 3NYNYY diff --git a/ext/dba/tests/dba_db4_001.phpt b/ext/dba/tests/dba_db4_001.phpt new file mode 100644 index 000000000..ecc8389cb --- /dev/null +++ b/ext/dba/tests/dba_db4_001.phpt @@ -0,0 +1,32 @@ +--TEST-- +DBA DB4 New File Creation open("c") & Insert Test +--SKIPIF-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php + +$handler = "db4"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; +if (($db_file = dba_open($db_filename, "c", $handler)) !== FALSE) { + echo "database file created\n"; + dba_insert("key1", "This is a test insert", $db_file); + echo dba_fetch("key1", $db_file), "\n"; + dba_close($db_file); +} else { + echo "Error creating $db_filename\n"; +} + +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: db4 +database file created +This is a test insert diff --git a/ext/dba/tests/dba_db4_002.phpt b/ext/dba/tests/dba_db4_002.phpt new file mode 100644 index 000000000..18ac0ec46 --- /dev/null +++ b/ext/dba/tests/dba_db4_002.phpt @@ -0,0 +1,32 @@ +--TEST-- +DBA DB4 New File Creation open("n") & Insert Test +--SKIPIF-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php + +$handler = "db4"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; +if (($db_file = dba_open($db_filename, "n", $handler)) !== FALSE) { + echo "database file created\n"; + dba_insert("key1", "This is a test insert", $db_file); + echo dba_fetch("key1", $db_file), "\n"; + dba_close($db_file); +} else { + echo "Error creating $db_filename\n"; +} + +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: db4 +database file created +This is a test insert diff --git a/ext/dba/tests/dba_db4_003.phpt b/ext/dba/tests/dba_db4_003.phpt new file mode 100644 index 000000000..7e8568c08 --- /dev/null +++ b/ext/dba/tests/dba_db4_003.phpt @@ -0,0 +1,46 @@ +--TEST-- +DBA DB4 File Creation open("c") with existing file +--SKIPIF-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php + +$handler = "db4"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; + +var_dump(file_put_contents($db_filename, "Dummy contents")); + +if (($db_file = dba_open($db_filename, "c", $handler)) !== FALSE) { + if (file_exists($db_filename)) { + echo "database file created\n"; + dba_close($db_file); + } else { + echo "File did not get created\n"; + } +} else { + echo "Error creating $db_filename\n"; +} + +// Check the file still exists +$s = file_get_contents($db_filename); +echo "$s\n"; + +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: db4 +int(14) + +Notice: dba_open(): %stest0.dbm: unexpected file type or format in %sdba_db4_003.php on line %d + +Warning: dba_open(%stest0.dbm,c): Driver initialization failed for handler: db4: Invalid argument in %sdba_db4_003.php on line %d +Error creating %stest0.dbm +Dummy contents diff --git a/ext/dba/tests/dba_db4_004.phpt b/ext/dba/tests/dba_db4_004.phpt new file mode 100644 index 000000000..ca876f82d --- /dev/null +++ b/ext/dba/tests/dba_db4_004.phpt @@ -0,0 +1,40 @@ +--TEST-- +DBA DB4 Truncate Existing File open("n") +--SKIPIF-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php + +$handler = "db4"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; + +var_dump(file_put_contents($db_filename, "Dummy contents")); + +if (($db_file = dba_open($db_filename, "n", $handler)) !== FALSE) { + if (file_exists($db_filename)) { + echo "database file created\n"; + dba_insert("key1", "This is a test insert", $db_file); + echo dba_fetch("key1", $db_file), "\n"; + dba_close($db_file); + } else { + echo "File did not get created\n"; + } +} else { + echo "Error creating $db_filename\n"; +} + +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: db4 +int(14) +database file created +This is a test insert diff --git a/ext/dba/tests/dba_db4_005.phpt b/ext/dba/tests/dba_db4_005.phpt new file mode 100644 index 000000000..54bb475e9 --- /dev/null +++ b/ext/dba/tests/dba_db4_005.phpt @@ -0,0 +1,32 @@ +--TEST-- +DBA DB4 New File Creation popen("c") & Insert Test +--SKIPIF-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php + +$handler = "db4"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; +if (($db_file = dba_popen($db_filename, "c", $handler)) !== FALSE) { + echo "database file created\n"; + dba_insert("key1", "This is a test insert", $db_file); + echo dba_fetch("key1", $db_file), "\n"; + dba_close($db_file); +} else { + echo "Error creating $db_filename\n"; +} + +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: db4 +database file created +This is a test insert diff --git a/ext/dba/tests/dba_db4_006.phpt b/ext/dba/tests/dba_db4_006.phpt new file mode 100644 index 000000000..7d95385fe --- /dev/null +++ b/ext/dba/tests/dba_db4_006.phpt @@ -0,0 +1,32 @@ +--TEST-- +DBA DB4 New File Creation popen("n") & Insert Test +--SKIPIF-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php + +$handler = "db4"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; +if (($db_file = dba_popen($db_filename, "n", $handler)) !== FALSE) { + echo "database file created\n"; + dba_insert("key1", "This is a test insert", $db_file); + echo dba_fetch("key1", $db_file), "\n"; + dba_close($db_file); +} else { + echo "Error creating $db_filename\n"; +} + +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: db4 +database file created +This is a test insert diff --git a/ext/dba/tests/dba_db4_007.phpt b/ext/dba/tests/dba_db4_007.phpt new file mode 100644 index 000000000..bd95e0bec --- /dev/null +++ b/ext/dba/tests/dba_db4_007.phpt @@ -0,0 +1,41 @@ +--TEST-- +DBA DB4 File Creation popen("c") with existing invalid file +--SKIPIF-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php + +$handler = "db4"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; + +var_dump(file_put_contents($db_filename, "Dummy contents")); + +if (($db_file = dba_popen($db_filename, "c", $handler)) !== FALSE) { + if (file_exists($db_filename)) { + echo "database file created\n"; + dba_close($db_file); + } else { + echo "File did not get created\n"; + } +} else { + echo "Error creating $db_filename\n"; +} + +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: db4 +int(14) + +Notice: dba_popen(): %stest0.dbm: unexpected file type or format in %sdba_db4_007.php on line %d + +Warning: dba_popen(%stest0.dbm,c): Driver initialization failed for handler: db4: Invalid argument in %sdba_db4_007.php on line %d +Error creating %stest0.dbm diff --git a/ext/dba/tests/dba_db4_008.phpt b/ext/dba/tests/dba_db4_008.phpt new file mode 100644 index 000000000..80f62eab5 --- /dev/null +++ b/ext/dba/tests/dba_db4_008.phpt @@ -0,0 +1,40 @@ +--TEST-- +DBA DB4 Truncate Existing File popen("n") +--SKIPIF-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php + +$handler = "db4"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; + +var_dump(file_put_contents($db_filename, "Dummy contents")); + +if (($db_file = dba_popen($db_filename, "n", $handler)) !== FALSE) { + if (file_exists($db_filename)) { + echo "database file created\n"; + dba_insert("key1", "This is a test insert", $db_file); + echo dba_fetch("key1", $db_file), "\n"; + dba_close($db_file); + } else { + echo "File did not get created\n"; + } +} else { + echo "Error creating $db_filename\n"; +} + +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: db4 +int(14) +database file created +This is a test insert diff --git a/ext/dba/tests/dba_db4_009.phpt b/ext/dba/tests/dba_db4_009.phpt new file mode 100644 index 000000000..5a870c90e --- /dev/null +++ b/ext/dba/tests/dba_db4_009.phpt @@ -0,0 +1,53 @@ +--TEST-- +DBA DB4 Multiple File Creation Test +--SKIPIF-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; +$db_file1 = $db_filename1 = dirname(__FILE__).'/test1.dbm'; +$db_file2 = $db_filename2 = dirname(__FILE__).'/test2.dbm'; +if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { + echo "database file created\n"; +} else { + echo "$db_file does not exist\n"; +} +if (($db_file1=dba_open($db_file1, "n", $handler))!==FALSE) { + echo "database file created\n"; +} else { + echo "$db_file does not exist\n"; +} +if (($db_file2=dba_open($db_file2, "n", $handler))!==FALSE) { + echo "database file created\n"; +} else { + echo "$db_file does not exist\n"; +} +var_dump(dba_list()); +dba_close($db_file); + +@unlink($db_filename1); +@unlink($db_filename2); +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: db4 +database file created +database file created +database file created +array(3) { + [%d]=> + string(%d) "%stest0.dbm" + [%d]=> + string(%d) "%stest1.dbm" + [%d]=> + string(%d) "%stest2.dbm" +} diff --git a/ext/dba/tests/dba_db4_010.phpt b/ext/dba/tests/dba_db4_010.phpt new file mode 100644 index 000000000..fb31f0583 --- /dev/null +++ b/ext/dba/tests/dba_db4_010.phpt @@ -0,0 +1,38 @@ +--TEST-- +DBA DB4 magic_quotes_runtime Test +--SKIPIF-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; +if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) { + ini_set('magic_quotes_runtime', 0); + dba_insert("key1", '"', $db_file); + var_dump(dba_fetch("key1", $db_file)); + ini_set('magic_quotes_runtime', 1); + var_dump(dba_fetch("key1", $db_file)); + dba_replace("key1", '\"', $db_file); + var_dump(dba_fetch("key1", $db_file)); + ini_set('magic_quotes_runtime', 0); + var_dump(dba_fetch("key1", $db_file)); + dba_close($db_file); +} else { + echo "Error creating database\n"; +} +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: db4 +string(1) """ +string(2) "\"" +string(2) "\"" +string(1) """ diff --git a/ext/dba/tests/dba_db4_011.phpt b/ext/dba/tests/dba_db4_011.phpt new file mode 100644 index 000000000..ce9be2770 --- /dev/null +++ b/ext/dba/tests/dba_db4_011.phpt @@ -0,0 +1,36 @@ +--TEST-- +DBA DB4 with repeated key +--SKIPIF-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; +if (($db_file=dba_open($db_filename, "c", $handler))!==FALSE) { + var_dump(dba_insert("key1", "Content String 1", $db_file)); + var_dump(dba_insert("key2", "Content String 2", $db_file)); + var_dump(dba_insert("key2", "Same key", $db_file)); + echo dba_fetch("key1", $db_file), "\n"; + echo dba_fetch("key2", $db_file), "\n"; + dba_close($db_file); +} else { + echo "Error creating database\n"; +} + +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: db4 +bool(true) +bool(true) +bool(false) +Content String 1 +Content String 2 diff --git a/ext/dba/tests/dba_db4_012.phpt b/ext/dba/tests/dba_db4_012.phpt new file mode 100644 index 000000000..2caa43c84 --- /dev/null +++ b/ext/dba/tests/dba_db4_012.phpt @@ -0,0 +1,31 @@ +--TEST-- +DBA DB4 New File Creation open("rl") +--SKIPIF-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php + +$handler = "db4"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; +if (($db_file = dba_open($db_filename, "rl", $handler)) !== FALSE) { + echo "database file created\n"; + dba_close($db_file); +} else { + echo "Error creating $db_filename\n"; +} + +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: db4 + +Warning: dba_open(%stest0.dbm,rl): Driver initialization failed for handler: db4: No such file or directory in %sdba_db4_012.php on line %d +Error creating %stest0.dbm diff --git a/ext/dba/tests/dba_db4_013.phpt b/ext/dba/tests/dba_db4_013.phpt new file mode 100644 index 000000000..ba2d171dc --- /dev/null +++ b/ext/dba/tests/dba_db4_013.phpt @@ -0,0 +1,40 @@ +--TEST-- +DBA DB4 File open("rl") & Insert Test +--SKIPIF-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php + +$handler = "db4"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; + +if (($db_file = dba_popen($db_filename, "c", $handler)) !== FALSE) { + echo "database file created\n"; + dba_close($db_file); +} + +if (($db_file = dba_popen($db_filename, "rl", $handler)) !== FALSE) { + echo "database file opened\n"; + dba_insert("key1", "This is a test insert", $db_file); + echo dba_fetch("key1", $db_file), "\n"; + dba_close($db_file); +} else { + echo "Error creating $db_filename\n"; +} + +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: db4 +database file created +database file opened + +Warning: dba_insert(): You cannot perform a modification to a database without proper access in %sdba_db4_013.php on line %d diff --git a/ext/dba/tests/dba_db4_014.phpt b/ext/dba/tests/dba_db4_014.phpt new file mode 100644 index 000000000..6fb22f87b --- /dev/null +++ b/ext/dba/tests/dba_db4_014.phpt @@ -0,0 +1,32 @@ +--TEST-- +DBA DB4 File open("wl") & Insert Test +--SKIPIF-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php + +$handler = "db4"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; + +if (($db_file = dba_open($db_filename, "wl", $handler)) !== FALSE) { + echo "database file opened\n"; + dba_close($db_file); +} else { + echo "Error creating $db_filename\n"; +} + +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: db4 + +Warning: dba_open(%stest0.dbm,wl): Driver initialization failed for handler: db4: No such file or directory in %sdba_db4_014.php on line %d +Error creating %stest0.dbm diff --git a/ext/dba/tests/dba_db4_015.phpt b/ext/dba/tests/dba_db4_015.phpt new file mode 100644 index 000000000..a1535675b --- /dev/null +++ b/ext/dba/tests/dba_db4_015.phpt @@ -0,0 +1,39 @@ +--TEST-- +DBA DB4 File open("wl") & Insert Test +--SKIPIF-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php + +$handler = "db4"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; + +if (($db_file = dba_popen($db_filename, "c", $handler)) !== FALSE) { + echo "database file created\n"; + dba_close($db_file); +} + +if (($db_file = dba_popen($db_filename, "wl", $handler)) !== FALSE) { + echo "database file opened\n"; + dba_insert("key1", "This is a test insert", $db_file); + echo dba_fetch("key1", $db_file), "\n"; + dba_close($db_file); +} else { + echo "Error creating $db_filename\n"; +} + +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: db4 +database file created +database file opened +This is a test insert diff --git a/ext/dba/tests/dba_db4_016.phpt b/ext/dba/tests/dba_db4_016.phpt new file mode 100644 index 000000000..b79cc71f8 --- /dev/null +++ b/ext/dba/tests/dba_db4_016.phpt @@ -0,0 +1,59 @@ +--TEST-- +DBA DB4 File Creation popen("c") with existing valid file +--SKIPIF-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php + +$handler = "db4"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; + +if (($db_file = dba_popen($db_filename, "c", $handler)) !== FALSE) { + if (file_exists($db_filename)) { + echo "database file created\n"; + var_dump(dba_insert("key1", "This is a test insert", $db_file)); + echo dba_fetch("key1", $db_file), "\n"; + dba_close($db_file); + } else { + echo "File did not get created\n"; + } +} else { + echo "Error creating $db_filename\n"; +} + +// Now test reopening it +if (($db_file = dba_popen($db_filename, "c", $handler)) !== FALSE) { + if (file_exists($db_filename)) { + echo "database file created\n"; + var_dump(dba_insert("key1", "second open test", $db_file)); + var_dump(dba_insert("key2", "second open test row 2", $db_file)); + echo dba_fetch("key1", $db_file), "\n"; + echo dba_fetch("key2", $db_file), "\n"; + dba_close($db_file); + } else { + echo "File did not get created\n"; + } +} else { + echo "Error creating $db_filename\n"; +} + +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: db4 +database file created +bool(true) +This is a test insert +database file created +bool(false) +bool(true) +This is a test insert +second open test row 2 diff --git a/ext/dba/tests/dba_db4_017.phpt b/ext/dba/tests/dba_db4_017.phpt new file mode 100644 index 000000000..12bf3df86 --- /dev/null +++ b/ext/dba/tests/dba_db4_017.phpt @@ -0,0 +1,37 @@ +--TEST-- +DBA DB4 file creation dba_open("cd") +--SKIPIF-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/skipif.inc'); +?> +--FILE-- +<?php + +$handler = "db4"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; + +if (($db_file = dba_open($db_filename, "cd", $handler)) !== FALSE) { + if (file_exists($db_filename)) { + echo "database file created\n"; + var_dump(dba_insert("key1", "This is a test insert", $db_file)); + echo dba_fetch("key1", $db_file), "\n"; + dba_close($db_file); + } else { + echo "File did not get created\n"; + } +} else { + echo "Error creating $db_filename\n"; +} + +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: db4 +database file created +bool(true) +This is a test insert diff --git a/ext/dba/tests/dba_db4_018.phpt b/ext/dba/tests/dba_db4_018.phpt new file mode 100644 index 000000000..ecd1980e4 --- /dev/null +++ b/ext/dba/tests/dba_db4_018.phpt @@ -0,0 +1,76 @@ +--TEST-- +DBA DB4 with persistent connections +--SKIPIF-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php + +$handler = "db4"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; + +echo "Test 1\n"; +$db_file1 = dba_popen($db_filename, 'n', 'flatfile'); +dba_insert("key1", "This is a test insert 1", $db_file1); +echo dba_fetch("key1", $db_file1), "\n"; + + +echo "Test 2\n"; +$db_file2 = dba_popen($db_filename, 'n', 'flatfile'); +if ($db_file1 === $db_file2) { + echo "resources are the same\n"; +} else { + echo "resources are different\n"; +} + + +echo "Test 3 - fetch both rows from second resource\n"; +dba_insert("key2", "This is a test insert 2", $db_file2); +echo dba_fetch("key1", $db_file2), "\n"; +echo dba_fetch("key2", $db_file2), "\n"; + + +echo "Test 4 - fetch both rows from first resource\n"; +echo dba_fetch("key1", $db_file1), "\n"; +echo dba_fetch("key2", $db_file1), "\n"; + +echo "Test 5 - close 2nd resource\n"; +dba_close($db_file2); +var_dump($db_file1); +var_dump($db_file2); + +echo "Test 6 - query after closing 2nd resource\n"; +echo dba_fetch("key1", $db_file1), "\n"; +echo dba_fetch("key2", $db_file1), "\n"; + +?> +===DONE=== +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); +?> +--XFAIL-- +Test 6 crashes with dba pointer of NULL, bug http://bugs.php.net/bug.php?id=51278 +--EXPECTF-- +database handler: db4 +Test 1 +This is a test insert 1 +Test 2 +resources are different +Test 3 - fetch both rows from second resource +This is a test insert 1 +This is a test insert 2 +Test 4 - fetch both rows from first resource +This is a test insert 1 +This is a test insert 2 +Test 5 - close 2nd resource +resource(%d) of type (dba persistent) +resource(%d) of type (Unknown) +Test 6 - query after closing 2nd resource +This is a test insert 1 +This is a test insert 2 +===DONE=== diff --git a/ext/dba/tests/dba_db4_handlers.phpt b/ext/dba/tests/dba_db4_handlers.phpt new file mode 100644 index 000000000..d238f431a --- /dev/null +++ b/ext/dba/tests/dba_db4_handlers.phpt @@ -0,0 +1,50 @@ +--TEST-- +DBA DB4 Handler Test +--SKIPIF-- +<?php +$handler="db4"; +require(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php +$handler="db4"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; + +function check($h) +{ + if (!$h) { + return; + } + + foreach ($h as $key) { + if ($key === "db4") { + echo "Success: db4 enabled\n"; + } + } +} + +echo "Test 1\n"; + +check(dba_handlers()); + +echo "Test 2 - full info\n"; +$h = dba_handlers(1); +foreach ($h as $key => $val) { + if ($key === "db4") { + echo "$val\n"; + } +} + +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTREGEX-- +database handler: db4 +Test 1 +Success: db4 enabled +Test 2 - full info +.*Berkeley DB (4|5).* diff --git a/ext/dba/tests/dba_db4_optimize.phpt b/ext/dba/tests/dba_db4_optimize.phpt new file mode 100644 index 000000000..de27dd8df --- /dev/null +++ b/ext/dba/tests/dba_db4_optimize.phpt @@ -0,0 +1,38 @@ +--TEST-- +DBA DB4 Optimize Test +--SKIPIF-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; +if (($db_file=dba_open($db_filename, "n", $handler))!==FALSE) { + dba_insert("key1", "Content String 1", $db_file); + dba_insert("key2", "Content String 2", $db_file); + for ($i=1; $i<3; $i++) { + echo dba_exists("key$i", $db_file) ? "Y" : "N"; + } + echo "\n"; + var_dump(dba_optimize($db_file)); + dba_close($db_file); +} else { + echo "Error creating database\n"; +} + +?> +===DONE=== +<?php exit(0); ?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: db4 +YY +bool(true) +===DONE=== diff --git a/ext/dba/tests/dba_db4_sync.phpt b/ext/dba/tests/dba_db4_sync.phpt new file mode 100644 index 000000000..8c4e248bc --- /dev/null +++ b/ext/dba/tests/dba_db4_sync.phpt @@ -0,0 +1,38 @@ +--TEST-- +DBA DB4 Sync Test +--SKIPIF-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php +$handler = "db4"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; +if (($db_file=dba_open($db_filename, "n", $handler))!==FALSE) { + dba_insert("key1", "Content String 1", $db_file); + dba_insert("key2", "Content String 2", $db_file); + for ($i=1; $i<3; $i++) { + echo dba_exists("key$i", $db_file) ? "Y" : "N"; + } + echo "\n"; + var_dump(dba_sync($db_file)); + dba_close($db_file); +} else { + echo "Error creating database\n"; +} + +?> +===DONE=== +<?php exit(0); ?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: db4 +YY +bool(true) +===DONE=== diff --git a/ext/dba/tests/dba_flatfile.phpt b/ext/dba/tests/dba_flatfile.phpt index a85472bbe..8e1ca6a93 100644 --- a/ext/dba/tests/dba_flatfile.phpt +++ b/ext/dba/tests/dba_flatfile.phpt @@ -3,15 +3,19 @@ DBA FlatFile handler test --SKIPIF-- <?php $handler = 'flatfile'; - require_once dirname(__FILE__) .'/skipif.inc'; + require_once(dirname(__FILE__) .'/skipif.inc'); ?> --FILE-- <?php $handler = 'flatfile'; - require_once dirname(__FILE__) .'/test.inc'; - require_once dirname(__FILE__) .'/dba_handler.inc'; + require_once(dirname(__FILE__) .'/test.inc'); + require_once(dirname(__FILE__) .'/dba_handler.inc'); ?> ===DONE=== +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); +?> --EXPECT-- database handler: flatfile 3NYNYY diff --git a/ext/dba/tests/dba_handlers.phpt b/ext/dba/tests/dba_handlers.phpt new file mode 100644 index 000000000..9f66a79f2 --- /dev/null +++ b/ext/dba/tests/dba_handlers.phpt @@ -0,0 +1,69 @@ +--TEST-- +DBA Handler Test +--SKIPIF-- +<?php +$handler="flatfile"; +require(dirname(__FILE__) .'/skipif.inc'); +die("info $HND handler used"); +?> +--FILE-- +<?php +$handler="flatfile"; +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; + +function check($h) +{ + if (!$h) { + return; + } + + foreach ($h as $key) { + if ($key === "flatfile") { + echo "Success: flatfile enabled\n"; + } + } +} + +echo "Test 1\n"; + +check(dba_handlers()); + +echo "Test 2\n"; + +check(dba_handlers(null)); + +echo "Test 3\n"; + +check(dba_handlers(1, 2)); + +echo "Test 4\n"; + +check(dba_handlers(0)); + +echo "Test 5 - full info\n"; +$h = dba_handlers(1); +foreach ($h as $key => $val) { + if ($key === "flatfile") { + echo "Success: flatfile enabled\n"; + } +} + +?> +--CLEAN-- +<?php +require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: flatfile +Test 1 +Success: flatfile enabled +Test 2 +Success: flatfile enabled +Test 3 + +Warning: dba_handlers() expects at most 1 parameter, 2 given in %sdba_handlers.php on line %d +Test 4 +Success: flatfile enabled +Test 5 - full info +Success: flatfile enabled diff --git a/ext/dba/tests/dba_optimize.phpt b/ext/dba/tests/dba_optimize.phpt new file mode 100644 index 000000000..794d7e8f7 --- /dev/null +++ b/ext/dba/tests/dba_optimize.phpt @@ -0,0 +1,51 @@ +--TEST-- +DBA Optimize Test +--SKIPIF-- +<?php + require_once dirname(__FILE__) .'/skipif.inc'; + die("info $HND handler used"); +?> +--FILE-- +<?php +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; +if (($db_file=dba_open($db_filename, "n", $handler))!==FALSE) { + dba_insert("key1", "Content String 1", $db_file); + dba_insert("key2", "Content String 2", $db_file); + $a = dba_firstkey($db_file); + $i=0; + while($a) { + $a = dba_nextkey($db_file); + $i++; + } + echo $i; + for ($i=1; $i<3; $i++) { + echo dba_exists("key$i", $db_file) ? "Y" : "N"; + } + echo "\n"; + var_dump(dba_optimize()); + var_dump(dba_optimize("")); + var_dump(dba_optimize($db_file)); + dba_close($db_file); +} else { + echo "Error creating database\n"; +} + +?> +===DONE=== +<?php exit(0); ?> +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: flatfile +2YY + +Warning: dba_optimize() expects exactly 1 parameter, 0 given in %sdba_optimize.php on line %d +NULL + +Warning: dba_optimize() expects parameter 1 to be resource, string given in %sdba_optimize.php on line %d +NULL +bool(true) +===DONE=== diff --git a/ext/dba/tests/dba_split.phpt b/ext/dba/tests/dba_split.phpt new file mode 100644 index 000000000..0989f09fe --- /dev/null +++ b/ext/dba/tests/dba_split.phpt @@ -0,0 +1,83 @@ +--TEST-- +DBA Split Test +--SKIPIF-- +<?php + require_once dirname(__FILE__) .'/skipif.inc'; + die("info $HND handler used"); +?> +--FILE-- +<?php +var_dump(dba_key_split("key1", "name")); +var_dump(dba_key_split(1)); +var_dump(dba_key_split(null)); +var_dump(dba_key_split("")); +var_dump(dba_key_split("name1")); +var_dump(dba_key_split("[key1")); +var_dump(dba_key_split("[key1]")); +var_dump(dba_key_split("key1]")); +var_dump(dba_key_split("[key1]name1")); +var_dump(dba_key_split("[key1]name1[key2]name2")); +var_dump(dba_key_split("[key1]name1")); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +Warning: Wrong parameter count for dba_key_split() in %sdba_split.php on line %d +NULL +array(2) { + [0]=> + string(0) "" + [1]=> + string(1) "1" +} +bool(false) +array(2) { + [0]=> + string(0) "" + [1]=> + string(0) "" +} +array(2) { + [0]=> + string(0) "" + [1]=> + string(5) "name1" +} +array(2) { + [0]=> + string(0) "" + [1]=> + string(5) "[key1" +} +array(2) { + [0]=> + string(4) "key1" + [1]=> + string(0) "" +} +array(2) { + [0]=> + string(0) "" + [1]=> + string(5) "key1]" +} +array(2) { + [0]=> + string(4) "key1" + [1]=> + string(5) "name1" +} +array(2) { + [0]=> + string(4) "key1" + [1]=> + string(16) "name1[key2]name2" +} +array(2) { + [0]=> + string(4) "key1" + [1]=> + string(5) "name1" +} +===DONE=== diff --git a/ext/dba/tests/dba_sync.phpt b/ext/dba/tests/dba_sync.phpt new file mode 100644 index 000000000..e0906eeee --- /dev/null +++ b/ext/dba/tests/dba_sync.phpt @@ -0,0 +1,51 @@ +--TEST-- +DBA Sync Test +--SKIPIF-- +<?php + require_once dirname(__FILE__) .'/skipif.inc'; + die("info $HND handler used"); +?> +--FILE-- +<?php +require_once(dirname(__FILE__) .'/test.inc'); +echo "database handler: $handler\n"; +if (($db_file=dba_open($db_filename, "n", $handler))!==FALSE) { + dba_insert("key1", "Content String 1", $db_file); + dba_insert("key2", "Content String 2", $db_file); + $a = dba_firstkey($db_file); + $i=0; + while($a) { + $a = dba_nextkey($db_file); + $i++; + } + echo $i; + for ($i=1; $i<3; $i++) { + echo dba_exists("key$i", $db_file) ? "Y" : "N"; + } + echo "\n"; + var_dump(dba_sync()); + var_dump(dba_sync("")); + var_dump(dba_sync($db_file)); + dba_close($db_file); +} else { + echo "Error creating database\n"; +} + +?> +===DONE=== +<?php exit(0); ?> +--CLEAN-- +<?php + require(dirname(__FILE__) .'/clean.inc'); +?> +--EXPECTF-- +database handler: flatfile +2YY + +Warning: dba_sync() expects exactly 1 parameter, 0 given in %sdba_sync.php on line %d +NULL + +Warning: dba_sync() expects parameter 1 to be resource, string given in %sdba_sync.php on line %d +NULL +bool(true) +===DONE=== |