]> granicus.if.org Git - php/commitdiff
Improve basic code coverage
authorChristopher Jones <sixd@php.net>
Mon, 1 Mar 2010 20:33:18 +0000 (20:33 +0000)
committerChristopher Jones <sixd@php.net>
Mon, 1 Mar 2010 20:33:18 +0000 (20:33 +0000)
ext/dba/tests/clean.inc [new file with mode: 0644]
ext/dba/tests/dba010.phpt [new file with mode: 0644]
ext/dba/tests/dba_optimize.phpt [new file with mode: 0644]
ext/dba/tests/dba_split.phpt [new file with mode: 0644]
ext/dba/tests/dba_sync.phpt [new file with mode: 0644]

diff --git a/ext/dba/tests/clean.inc b/ext/dba/tests/clean.inc
new file mode 100644 (file)
index 0000000..7c53e7e
--- /dev/null
@@ -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 (file)
index 0000000..183562d
--- /dev/null
@@ -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 (file)
index 0000000..2fd8504
--- /dev/null
@@ -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 (file)
index 0000000..ca4769c
--- /dev/null
@@ -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 (file)
index 0000000..e09896a
--- /dev/null
@@ -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===