split tests

This commit is contained in:
Remi Collet
2024-01-25 15:15:13 +01:00
parent 838b674c99
commit 17af22056b
4 changed files with 65 additions and 16 deletions

View File

@@ -60,6 +60,7 @@ more than adequate.
<file name="dio_raw_stream_007.phpt" role="test" />
<file name="dio_stat.phpt" role="test" />
<file name="dio_stat_win.phpt" role="test" />
<file name="dio_truncate.phpt" role="test" />
<file name="dio_write.phpt" role="test" />
<file name="gh12.phpt" role="test" />
</dir> <!-- //tests -->

View File

@@ -121,7 +121,6 @@ PHP_FUNCTION(dio_open)
/* }}} */
#ifndef PHP_WIN32
/* {{{ proto resource dio_fdopen(int fd)
Returns a resource for the specified file descriptor. */
PHP_FUNCTION(dio_fdopen)
@@ -252,7 +251,6 @@ PHP_FUNCTION(dio_write)
/* }}} */
#ifndef PHP_WIN32
/* {{{ proto bool dio_truncate(resource fd, int offset)
Truncate file descriptor fd to offset bytes */
PHP_FUNCTION(dio_truncate)
@@ -343,7 +341,6 @@ PHP_FUNCTION(dio_seek)
/* }}} */
#ifndef PHP_WIN32
/* {{{ proto mixed dio_fcntl(resource fd, int cmd[, mixed arg])
Perform a c library fcntl on fd */
PHP_FUNCTION(dio_fcntl)
@@ -451,7 +448,6 @@ PHP_FUNCTION(dio_fcntl)
#endif
#ifndef PHP_WIN32
/* {{{ proto mixed dio_tcsetattr(resource fd, array args )
Perform a c library tcsetattr on fd */
PHP_FUNCTION(dio_tcsetattr)

58
tests/dio_truncate.phpt Normal file
View File

@@ -0,0 +1,58 @@
--TEST--
Test dio_write, dio_read, dio_truncate, dio_seek
--SKIPIF--
<?php
if (!extension_loaded("dio")) die("skip extension missing");
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') print "skip Linux only";
?>
--FILE--
<?php
$filename = __DIR__ . "/write.txt";
echo "+ open\n";
var_dump($f = dio_open($filename, O_CREAT | O_RDWR, 0644));
if ($f) {
$s = dio_stat($f);
printf("Size=%d Mode=%o\n", $s['size'], $s['mode']);
echo "+ write\n";
var_dump(dio_write($f, "foobar"));
$s = dio_stat($f);
printf("Size=%d Mode=%o\n", $s['size'], $s['mode']);
echo "+ truncate\n";
var_dump(dio_truncate($f, 3));
$s = dio_stat($f);
printf("Size=%d Mode=%o\n", $s['size'], $s['mode']);
echo "+ seek\n";
var_dump(dio_seek($f, 0));
echo "+ read\n";
var_dump(dio_read($f));
echo "+ close\n";
dio_close($f);
}
?>
Done
--CLEAN--
<?php
@unlink(__DIR__ . "/write.txt");
?>
--EXPECTF--
+ open
resource(%d) of type (Direct I/O File Descriptor)
Size=0 Mode=100644
+ write
int(6)
Size=6 Mode=100644
+ truncate
bool(true)
Size=3 Mode=100644
+ seek
int(0)
+ read
string(3) "foo"
+ close
Done

View File

@@ -12,23 +12,19 @@ if (!extension_loaded("dio")) die("skip extension missing");
var_dump($f = dio_open($filename, O_CREAT | O_RDWR, 0644));
if ($f) {
$s = dio_stat($f);
printf("Size=%d Mode=%o\n", $s['size'], $s['mode']);
printf("Size=%d\n", $s['size']);
echo "+ write\n";
var_dump(dio_write($f, "foobar"));
$s = dio_stat($f);
printf("Size=%d Mode=%o\n", $s['size'], $s['mode']);
echo "+ truncate\n";
var_dump(dio_truncate($f, 3));
$s = dio_stat($f);
printf("Size=%d Mode=%o\n", $s['size'], $s['mode']);
printf("Size=%d\n", $s['size']);
echo "+ seek\n";
var_dump(dio_seek($f, 0));
echo "+ read\n";
var_dump(dio_read($f, 1));
var_dump(dio_read($f, 2));
var_dump(dio_read($f));
var_dump(dio_read($f));
@@ -44,18 +40,16 @@ Done
--EXPECTF--
+ open
resource(%d) of type (Direct I/O File Descriptor)
Size=0 Mode=100644
Size=0
+ write
int(6)
Size=6 Mode=100644
+ truncate
bool(true)
Size=3 Mode=100644
Size=6
+ seek
int(0)
+ read
string(1) "f"
string(2) "oo"
string(3) "bar"
NULL
+ close
Done