diff options
| author | Christopher Jones <sixd@php.net> | 2010-03-01 20:33:18 +0000 |
|---|---|---|
| committer | Christopher Jones <sixd@php.net> | 2010-03-01 20:33:18 +0000 |
| commit | c0719f1098843034ba1a398307cfca20b8c96d87 (patch) | |
| tree | cb19c13b0358267a9b9b6b8a438c87e80cb97b60 | |
| parent | f789ac323b74c5cce3188c91579732dc6a4fa468 (diff) | |
| download | php-git-c0719f1098843034ba1a398307cfca20b8c96d87.tar.gz | |
Improve basic code coverage
| -rw-r--r-- | ext/dba/tests/clean.inc | 5 | ||||
| -rw-r--r-- | ext/dba/tests/dba010.phpt | 41 | ||||
| -rw-r--r-- | ext/dba/tests/dba_optimize.phpt | 45 | ||||
| -rw-r--r-- | ext/dba/tests/dba_split.phpt | 79 | ||||
| -rw-r--r-- | ext/dba/tests/dba_sync.phpt | 45 |
5 files changed, 215 insertions, 0 deletions
diff --git a/ext/dba/tests/clean.inc b/ext/dba/tests/clean.inc new file mode 100644 index 0000000000..7c53e7e61f --- /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/dba010.phpt b/ext/dba/tests/dba010.phpt new file mode 100644 index 0000000000..183562dc32 --- /dev/null +++ b/ext/dba/tests/dba010.phpt @@ -0,0 +1,41 @@ +--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"; + dba_close($db_file); +} else { + echo "Error creating database\n"; +} + +require_once(dirname(__FILE__) .'/clean.inc'); + +?> +--EXPECTF-- +database handler: flatfile +6YYYYYY
\ No newline at end of file diff --git a/ext/dba/tests/dba_optimize.phpt b/ext/dba/tests/dba_optimize.phpt new file mode 100644 index 0000000000..2fd8504525 --- /dev/null +++ b/ext/dba/tests/dba_optimize.phpt @@ -0,0 +1,45 @@ +--TEST-- +DBA Optimize Test +--SKIPIF-- +--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"; +} + +require_once(dirname(__FILE__) .'/clean.inc'); + +?> +===DONE=== +<?php exit(0); ?> +--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, Unicode 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 0000000000..ca4769c28c --- /dev/null +++ b/ext/dba/tests/dba_split.phpt @@ -0,0 +1,79 @@ +--TEST-- +DBA Split Test +--SKIPIF-- +--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 0000000000..e09896aacc --- /dev/null +++ b/ext/dba/tests/dba_sync.phpt @@ -0,0 +1,45 @@ +--TEST-- +DBA Sync Test +--SKIPIF-- +--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"; +} + +require_once(dirname(__FILE__) .'/clean.inc'); + +?> +===DONE=== +<?php exit(0); ?> +--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, Unicode string given in %sdba_sync.php on line %d +NULL +bool(true) +===DONE=== |
