]> granicus.if.org Git - php/commitdiff
Added some tests for dba extension
authorMarcus Boerger <helly@php.net>
Fri, 25 Oct 2002 09:42:29 +0000 (09:42 +0000)
committerMarcus Boerger <helly@php.net>
Fri, 25 Oct 2002 09:42:29 +0000 (09:42 +0000)
ext/dba/tests/001.phpt [new file with mode: 0644]
ext/dba/tests/002.phpt [new file with mode: 0644]
ext/dba/tests/003.phpt [new file with mode: 0644]
ext/dba/tests/004.phpt [new file with mode: 0644]
ext/dba/tests/005.phpt [new file with mode: 0644]
ext/dba/tests/006.phpt [new file with mode: 0644]
ext/dba/tests/skipif.inc [new file with mode: 0644]
ext/dba/tests/test.inc [new file with mode: 0644]

diff --git a/ext/dba/tests/001.phpt b/ext/dba/tests/001.phpt
new file mode 100644 (file)
index 0000000..909f782
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+DBA File Creation Test
+--SKIPIF--
+<?php 
+       require_once('skipif.inc');
+?>
+--FILE--
+<?php
+       require_once('test.inc');
+       if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) {
+       echo "database file created with $handler.\n";
+       } else {
+       echo "$db_file does not exist\n";
+    }
+       dba_close($db_file);
+?>
+--EXPECTF--
+database file created with %s.
\ No newline at end of file
diff --git a/ext/dba/tests/002.phpt b/ext/dba/tests/002.phpt
new file mode 100644 (file)
index 0000000..d2fd7d0
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+DBA Insert/Fetch Test
+--SKIPIF--
+<?php 
+       require_once('skipif.inc');
+?>
+--FILE--
+<?php
+       require_once('test.inc');
+       if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) {
+               dba_insert("key1", "This is a test insert", $db_file);
+               echo dba_fetch("key1", $db_file);
+               dba_close($db_file);
+       } else {
+               echo "Error creating database\n";
+       }
+?>
+--EXPECT--
+This is a test insert
diff --git a/ext/dba/tests/003.phpt b/ext/dba/tests/003.phpt
new file mode 100644 (file)
index 0000000..64225a8
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+DBA Insert/Replace/Fetch Test
+--SKIPIF--
+<?php 
+       require_once('skipif.inc');
+?>
+--FILE--
+<?php
+       require_once('test.inc');
+       if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) {
+               dba_insert("key1", "This is a test insert", $db_file);
+               dba_replace("key1", "This is the replacement text", $db_file);
+               $a = dba_fetch("key1", $db_file);
+               dba_close($db_file);
+               echo $a;
+       } else {
+               echo "Error creating database\n";
+       }
+?>
+--EXPECT--
+This is the replacement text
diff --git a/ext/dba/tests/004.phpt b/ext/dba/tests/004.phpt
new file mode 100644 (file)
index 0000000..9259a78
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+DBA Multiple Insert/Fetch Test
+--SKIPIF--
+<?php 
+       require_once('skipif.inc');
+?>
+--FILE--
+<?php
+       require_once('test.inc');
+       if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) {
+               dba_insert("key1", "Content String 1", $db_file);
+               dba_insert("key2", "Content String 2", $db_file);
+               dba_insert("key3", "Third Content String", $db_file);
+               dba_insert("key4", "Another Content String", $db_file);
+               dba_insert("key5", "The last content string", $db_file);
+               $a = dba_fetch("key4", $db_file);
+               $b = dba_fetch("key2", $db_file);
+               dba_close($db_file);
+               echo "$a $b";
+       } else {
+               echo "Error creating database\n";
+       }
+?>
+--EXPECT--
+Another Content String Content String 2
diff --git a/ext/dba/tests/005.phpt b/ext/dba/tests/005.phpt
new file mode 100644 (file)
index 0000000..98b1d9e
--- /dev/null
@@ -0,0 +1,32 @@
+--TEST--
+DBA FirstKey/NextKey Loop Test With 5 Items
+--SKIPIF--
+<?php 
+       require_once('skipif.inc');
+?>
+--FILE--
+<?php
+       require_once('test.inc');
+       if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) {
+               dba_insert("key1", "Content String 1", $db_file);
+               dba_insert("key2", "Content String 2", $db_file);
+               dba_insert("key3", "Third Content String", $db_file);
+               dba_insert("key4", "Another Content String", $db_file);
+               dba_insert("key5", "The last content string", $db_file);
+               $a = dba_firstkey($db_file);
+               $i=0;
+               while($a) {
+                       $a = dba_nextkey($db_file);
+                       $i++;
+               }
+               echo $i;
+               for ($i=1; $i<6; $i++) {
+                       echo dba_exists("key$i", $db_file) ? "Y" : "N";
+               }
+               dba_close($db_file);
+       } else {
+               echo "Error creating database\n";
+       }
+?>
+--EXPECT--
+5YYYYY
diff --git a/ext/dba/tests/006.phpt b/ext/dba/tests/006.phpt
new file mode 100644 (file)
index 0000000..5d9882a
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--
+DBA FirstKey/NextKey with 2 deletes
+--SKIPIF--
+<?php 
+       require_once('skipif.inc');
+?>
+--FILE--
+<?php
+       require_once('test.inc');
+       if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) {
+               dba_insert("key1", "Content String 1", $db_file);
+               dba_insert("key2", "Content String 2", $db_file);
+               dba_insert("key3", "Third Content String", $db_file);
+               dba_insert("key4", "Another Content String", $db_file);
+               dba_insert("key5", "The last content string", $db_file);
+               dba_delete("key3", $db_file);
+               dba_delete("key1", $db_file);
+               $a = dba_firstkey($db_file);
+               $i=0;
+               while($a) {
+                       $a = dba_nextkey($db_file);
+                       $i++;
+               }
+               echo $i;
+               for ($i=1; $i<6; $i++) {
+                       echo dba_exists("key$i", $db_file) ? "Y" : "N";
+               }
+               dba_close($db_file);
+       } else {
+               echo "Error creating database\n";
+       }
+?>
+--EXPECT--
+3NYNYY
\ No newline at end of file
diff --git a/ext/dba/tests/skipif.inc b/ext/dba/tests/skipif.inc
new file mode 100644 (file)
index 0000000..9a35e1e
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+       if (!extension_loaded('dba')) die('skip dba extension not available');
+       if (!function_exists('dba_handlers')) die ('skip dba_handlers() not available');
+       if (!sizeof(dba_handlers())) die('skip no handlers installed');
+?>
diff --git a/ext/dba/tests/test.inc b/ext/dba/tests/test.inc
new file mode 100644 (file)
index 0000000..30bc0c3
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+       $db_file = dirname(__FILE__).'/test.dbm'; 
+       $handler = dba_handlers(); 
+       $handler = $handler[0];
+?>