From 33f82236a1e9061aba8050399835e82e0531c82b Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Mon, 21 Jan 2013 17:44:37 +0100 Subject: [PATCH] tests++ --- tests/_skipif.inc | 2 ++ tests/async001.phpt | 48 ++++++++++++++++++++++++++++++++++++ tests/async002.phpt | 60 +++++++++++++++++++++++++++++++++++++++++++++ tests/reset001.phpt | 21 ++++++++++++++++ 4 files changed, 131 insertions(+) create mode 100644 tests/async001.phpt create mode 100644 tests/async002.phpt create mode 100644 tests/reset001.phpt diff --git a/tests/_skipif.inc b/tests/_skipif.inc index 93ac8ae..50fee40 100644 --- a/tests/_skipif.inc +++ b/tests/_skipif.inc @@ -3,3 +3,5 @@ function _ext($ext) { extension_loaded($ext) or die("skip $ext not loaded"); } _ext("pq"); +include "_setup.inc"; +defined("PQ_DSN") or die("skip PG_DSN undefined"); diff --git a/tests/async001.phpt b/tests/async001.phpt new file mode 100644 index 0000000..9fa2eb7 --- /dev/null +++ b/tests/async001.phpt @@ -0,0 +1,48 @@ +--TEST-- +async connect +--SKIPIF-- + +--FILE-- +status); +echo "W"; +$w = array($c->socket); +$r = $e = null; +stream_select($r, $w, $e, null); +while (true) { + $s[] = $c->status; + echo "P"; + switch ($c->poll()) { + case pq\Connection::POLLING_READING: + echo "R"; + $w = $e = null; + $r = array($c->socket); + stream_select($r, $w, $e, NULL); + break; + case pq\Connection::POLLING_WRITING: + echo "W"; + $w = array($c->socket); + $r = $e = null; + stream_select($r, $w, $e, null); + break; + case pq\Connection::POLLING_FAILED: + echo "F"; + break 2; + case pq\Connection::POLLING_OK: + echo "S"; + break 2; + } +} +printf("\n%s\n", implode(",", $s)); +?> +DONE +--EXPECTREGEX-- +Test +(WP(RP)*)+S +3(,\d+),+4 +DONE diff --git a/tests/async002.phpt b/tests/async002.phpt new file mode 100644 index 0000000..3dd80d1 --- /dev/null +++ b/tests/async002.phpt @@ -0,0 +1,60 @@ +--TEST-- +async reset +--SKIPIF-- + +--FILE-- +status); + echo "W"; + $w = array($c->socket); + $r = $e = null; + stream_select($r, $w, $e, null); + while (true) { + $s[] = $c->status; + echo "P"; + switch ($c->poll()) { + case pq\Connection::POLLING_READING: + echo "R"; + $w = $e = null; + $r = array($c->socket); + stream_select($r, $w, $e, NULL); + break; + case pq\Connection::POLLING_WRITING: + echo "W"; + $w = array($c->socket); + $r = $e = null; + stream_select($r, $w, $e, null); + break; + case pq\Connection::POLLING_FAILED: + echo "F"; + break 2; + case pq\Connection::POLLING_OK: + echo "S"; + break 2; + } + } + printf("\n%s\n", implode(",", $s)); +} + +complete($c); + +if ($c->status == pq\Connection::OK) { + $c->reset(); + complete($c); +} +?> +DONE +--EXPECTREGEX-- +Test +(WP(RP)*)+S +3(,\d+),+4 +(WP(RP)*)+S +3(,\d+),+4 +DONE diff --git a/tests/reset001.phpt b/tests/reset001.phpt new file mode 100644 index 0000000..f83e042 --- /dev/null +++ b/tests/reset001.phpt @@ -0,0 +1,21 @@ +--TEST-- +connection reset +--SKIPIF-- + +--FILE-- +reset()); +var_dump($c->reset()); + +?> +DONE +--EXPECT-- +Test +bool(true) +bool(true) +DONE -- 2.30.2