]> granicus.if.org Git - php/commitdiff
Added tests for new functions
authorYasuo Ohgaki <yohgaki@php.net>
Fri, 18 Oct 2002 07:52:09 +0000 (07:52 +0000)
committerYasuo Ohgaki <yohgaki@php.net>
Fri, 18 Oct 2002 07:52:09 +0000 (07:52 +0000)
13 files changed:
ext/pgsql/tests/17result.phpt
ext/pgsql/tests/18pg_escape_bytea.phpt [new file with mode: 0644]
ext/pgsql/tests/19pg_ping.phpt [new file with mode: 0644]
ext/pgsql/tests/20pg_get_pid.phpt [new file with mode: 0644]
ext/pgsql/tests/21pg_get_notify.phpt [new file with mode: 0644]
ext/pgsql/tests/README [new file with mode: 0644]
ext/pgsql/tests/createdb.inc
ext/pgsql/tests/large_object.inc
ext/pgsql/tests/pg_escape_bytea.inc [new file with mode: 0644]
ext/pgsql/tests/pg_get_notify.inc [new file with mode: 0644]
ext/pgsql/tests/pg_get_pid.inc [new file with mode: 0644]
ext/pgsql/tests/pg_ping.inc [new file with mode: 0644]
ext/pgsql/tests/result.inc

index 33acb3a6820087ebad0470636bbf30c3b17a526b..e8c3f390de5c1f516960c5b08c21d87cc3351a9b 100644 (file)
@@ -37,4 +37,13 @@ array(3) {
   [2]=>
   NULL
 }
+array(3) {
+  ["num"]=>
+  string(1) "2"
+  ["str"]=>
+  string(3) "ABC"
+  ["bin"]=>
+  NULL
+}
+bool(true)
 Ok
diff --git a/ext/pgsql/tests/18pg_escape_bytea.phpt b/ext/pgsql/tests/18pg_escape_bytea.phpt
new file mode 100644 (file)
index 0000000..08832c4
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+PostgreSQL pg_escape_bytea() functions
+--SKIPIF--
+<?php include("skipif.inc"); ?>
+--FILE--
+<?php
+include("pg_escape_bytea.inc");
+?>
+--EXPECT--
+OK
diff --git a/ext/pgsql/tests/19pg_ping.phpt b/ext/pgsql/tests/19pg_ping.phpt
new file mode 100644 (file)
index 0000000..eba678b
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+PostgreSQL pg_ping() functions
+--SKIPIF--
+<?php include("skipif.inc"); ?>
+--FILE--
+<?php
+include("pg_ping.inc");
+?>
+--EXPECT--
+bool(true)
diff --git a/ext/pgsql/tests/20pg_get_pid.phpt b/ext/pgsql/tests/20pg_get_pid.phpt
new file mode 100644 (file)
index 0000000..9572751
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+PostgreSQL pg_get_pid() functions
+--SKIPIF--
+<?php include("skipif.inc"); ?>
+--FILE--
+<?php
+include("pg_get_pid.inc");
+?>
+--EXPECT--
+OK
diff --git a/ext/pgsql/tests/21pg_get_notify.phpt b/ext/pgsql/tests/21pg_get_notify.phpt
new file mode 100644 (file)
index 0000000..0ff3a74
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+PostgreSQL pg_get_notify() functions
+--SKIPIF--
+<?php include("skipif.inc"); ?>
+--FILE--
+<?php
+include("pg_get_notify.inc");
+?>
+--EXPECT--
+OK
diff --git a/ext/pgsql/tests/README b/ext/pgsql/tests/README
new file mode 100644 (file)
index 0000000..2291512
--- /dev/null
@@ -0,0 +1,14 @@
+Test scripts assume: 
+ - PostgreSQL server is installed locally
+ - there is a PostgreSQL account for the users running test script 
+ - there is database named "test"
+
+For instance, if you login name is 'testuser', you should
+have PostgreSQL user account named 'testuser' and have 'test'
+database.
+
+If you have account and database, type "createdb test" from
+command prompt to create database to execute test scripts.
+
+If you find problems in PostgreSQL module, please mail to
+yohgaki@php.net or php-dev@lists.php.net.
index 28a04b702d5925f4895261d31d3d1105c2f832c4..b11883800ff11b70a19e5453edd7572c06f4e728 100644 (file)
@@ -6,7 +6,7 @@ include('config.inc');
 $db = pg_connect($conn_str);
 if (!@pg_num_rows(@pg_query($db, "SELECT * FROM ".$table_name))) 
 {
-       @pg_query($db,$table_def);
+       @pg_query($db,$table_def); // Create table here
        for ($i=0; $i < $num_test_record; $i++) {
                pg_query($db,"INSERT INTO ".$table_name." VALUES ($i, 'ABC');");
        }
index 5b8d1f8b72467e4849a19e9994d123e2dfdd4ebf..f21912b5b6c7929212684025f89a6e0e0e99c394 100644 (file)
@@ -3,6 +3,8 @@
 include('config.inc');
 
 $db = pg_connect($conn_str);
+
+// create/write/close LO
 pg_exec ($db, "begin");
 $oid = pg_lo_create ($db);
 if (!$oid) echo ("pg_lo_create() error\n");
@@ -12,6 +14,7 @@ pg_lo_write ($handle, "large object data\n");
 pg_lo_close ($handle);
 pg_exec ($db, "commit");
 
+// open/read/tell/seek/close LO
 pg_exec ($db, "begin");
 $handle = pg_lo_open ($db, $oid, "w");
 pg_lo_read($handle, 100);
@@ -20,6 +23,7 @@ pg_lo_seek($handle, 2);
 pg_lo_close($handle);
 pg_exec ($db, "commit");
 
+// open/read_all/close LO
 pg_exec ($db, "begin");
 $handle = pg_lo_open ($db, $oid, "w");
 pg_lo_read_all($handle);
@@ -27,6 +31,7 @@ if (pg_last_error()) echo "pg_lo_read_all() error\n".pg_last_error();
 pg_lo_close($handle);
 pg_exec ($db, "commit");
 
+// unlink LO
 pg_exec ($db, "begin");
 pg_lo_unlink($db, $oid) or print("pg_lo_unlink() error\n");
 pg_exec ($db, "commit");
@@ -44,6 +49,19 @@ $oid = pg_lo_create ($db) or print("pg_lo_create() error\n");
 pg_lo_unlink($db, (string)$oid) or print("pg_lo_unlink() error\n");
 pg_exec ($db, "commit");
 
+// import/export LO
+pg_query($db, 'begin');
+$oid = pg_lo_import($db, 'php.gif');
+pg_query($db, 'commit');
+pg_query($db, 'begin');
+@unlink('php.gif.exported');
+pg_lo_export($oid, 'php.gif.exported', $db);
+if (!file_exists('php.gif.exported')) {
+       echo "Export failed\n";
+}
+@unlink('php.gif.exported');
+pg_query($db, 'commit');
+
 echo "OK";
 
 ?>
\ No newline at end of file
diff --git a/ext/pgsql/tests/pg_escape_bytea.inc b/ext/pgsql/tests/pg_escape_bytea.inc
new file mode 100644 (file)
index 0000000..249c2f1
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+// optional functions
+
+include('config.inc');
+
+
+$fp = fopen('php.gif', 'r');
+$image = fread($fp, filesize('php.gif'));
+$esc_image = pg_escape_bytea($image);
+
+$db = pg_connect($conn_str);
+pg_query($db, 'INSERT INTO '.$table_name.' (num, bin) VALUES (9876, \''.$esc_image.'\');');
+$result = pg_query($db, 'SELECT * FROM '.$table_name.' WHERE num = 9876');
+$rows = pg_fetch_all($result);
+$unesc_image = pg_unescape_bytea($rows[0]['bin']);
+
+if ($unesc_image !== $image) {
+       echo "NG";
+}
+else {
+       echo "OK";
+}
+
+
+?>
\ No newline at end of file
diff --git a/ext/pgsql/tests/pg_get_notify.inc b/ext/pgsql/tests/pg_get_notify.inc
new file mode 100644 (file)
index 0000000..dfb4fe3
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+// optional functions
+
+include('config.inc');
+
+
+$db = pg_connect($conn_str);
+pg_query($db, 'LISTEN test_msg');
+pg_query($db, 'NOTIFY test_msg');
+
+$msg = pg_get_notify($db);
+
+isset($msg['message'],$msg['pid']) ? print 'OK' : print 'NG';
+
+
+?>
\ No newline at end of file
diff --git a/ext/pgsql/tests/pg_get_pid.inc b/ext/pgsql/tests/pg_get_pid.inc
new file mode 100644 (file)
index 0000000..5aa8e7e
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+// optional functions
+
+include('config.inc');
+
+
+$db = pg_connect($conn_str);
+$pid = pg_get_pid($db);
+
+is_integer($pid) ? print 'OK' : print 'NG';
+
+
+?>
\ No newline at end of file
diff --git a/ext/pgsql/tests/pg_ping.inc b/ext/pgsql/tests/pg_ping.inc
new file mode 100644 (file)
index 0000000..2d9be9f
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+// optional functions
+
+include('config.inc');
+
+$db = pg_connect($conn_str);
+var_dump(pg_ping($db));
+
+
+?>
\ No newline at end of file
index 6982a84493e86ef5a546dcfcbae8956594a92bb5..fb38938b8959a4c211f13724d7f83a1e5f6bb495 100644 (file)
@@ -15,6 +15,9 @@ $rec = pg_fetch_array($result, 1);
 var_dump($rec);
 $rec = pg_fetch_row($result, 1);
 var_dump($rec);
+$rec = pg_fetch_assoc($result);
+var_dump($rec);
+var_dump(pg_result_seek($result, 0));
 
 echo "Ok\n";