TestExtStream -> php
Esse commit está contido em:
@@ -48,7 +48,6 @@
|
||||
#include "hphp/test/ext/test_ext_session.h"
|
||||
#include "hphp/test/ext/test_ext_soap.h"
|
||||
#include "hphp/test/ext/test_ext_sqlite3.h"
|
||||
#include "hphp/test/ext/test_ext_stream.h"
|
||||
#include "hphp/test/ext/test_ext_string.h"
|
||||
#include "hphp/test/ext/test_ext_variable.h"
|
||||
#include "hphp/test/ext/test_ext_zlib.h"
|
||||
|
||||
@@ -1,465 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| HipHop for PHP |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 3.01 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| http://www.php.net/license/3_01.txt |
|
||||
| If you did not receive a copy of the PHP license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#include "hphp/test/ext/test_ext_stream.h"
|
||||
#include "hphp/runtime/ext/ext_stream.h"
|
||||
#include "hphp/runtime/ext/ext_socket.h"
|
||||
#include "hphp/runtime/ext/ext_file.h"
|
||||
#include "hphp/runtime/ext/ext_options.h"
|
||||
#include "hphp/runtime/ext/ext_array.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TestExtStream::RunTests(const std::string &which) {
|
||||
bool ret = true;
|
||||
|
||||
RUN_TEST(test_stream_context_create);
|
||||
RUN_TEST(test_stream_context_get_default);
|
||||
RUN_TEST(test_stream_context_get_options);
|
||||
RUN_TEST(test_stream_context_set_option);
|
||||
RUN_TEST(test_stream_context_set_param);
|
||||
RUN_TEST(test_stream_copy_to_stream);
|
||||
RUN_TEST(test_stream_encoding);
|
||||
RUN_TEST(test_stream_bucket_append);
|
||||
RUN_TEST(test_stream_bucket_prepend);
|
||||
RUN_TEST(test_stream_bucket_make_writeable);
|
||||
RUN_TEST(test_stream_bucket_new);
|
||||
RUN_TEST(test_stream_filter_register);
|
||||
RUN_TEST(test_stream_filter_remove);
|
||||
RUN_TEST(test_stream_filter_append);
|
||||
RUN_TEST(test_stream_filter_prepend);
|
||||
RUN_TEST(test_stream_get_contents);
|
||||
RUN_TEST(test_stream_get_filters);
|
||||
RUN_TEST(test_stream_get_line);
|
||||
RUN_TEST(test_stream_get_meta_data);
|
||||
RUN_TEST(test_stream_get_transports);
|
||||
RUN_TEST(test_stream_get_wrappers);
|
||||
RUN_TEST(test_stream_register_wrapper);
|
||||
RUN_TEST(test_stream_wrapper_register);
|
||||
RUN_TEST(test_stream_wrapper_restore);
|
||||
RUN_TEST(test_stream_wrapper_unregister);
|
||||
RUN_TEST(test_stream_resolve_include_path);
|
||||
RUN_TEST(test_stream_select);
|
||||
RUN_TEST(test_stream_set_blocking);
|
||||
RUN_TEST(test_stream_set_timeout);
|
||||
RUN_TEST(test_stream_set_write_buffer);
|
||||
RUN_TEST(test_set_file_buffer);
|
||||
RUN_TEST(test_stream_socket_accept);
|
||||
RUN_TEST(test_stream_socket_server);
|
||||
RUN_TEST(test_stream_socket_client);
|
||||
RUN_TEST(test_stream_socket_enable_crypto);
|
||||
RUN_TEST(test_stream_socket_get_name);
|
||||
RUN_TEST(test_stream_socket_pair);
|
||||
RUN_TEST(test_stream_socket_recvfrom);
|
||||
RUN_TEST(test_stream_socket_sendto);
|
||||
RUN_TEST(test_stream_socket_sendto_issue324);
|
||||
RUN_TEST(test_stream_socket_shutdown);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// so we run on different range of ports every time
|
||||
static int get_random_port() {
|
||||
static int base = -1;
|
||||
if (base == -1) {
|
||||
base = 12345 + (int)((time(0) * 100) % 30000);
|
||||
}
|
||||
return ++base;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TestExtStream::test_stream_context_create() {
|
||||
f_stream_context_create();
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_context_get_default() {
|
||||
try {
|
||||
f_stream_context_get_default();
|
||||
} catch (const NotImplementedException& e) {
|
||||
return Count(true);
|
||||
}
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_context_get_options() {
|
||||
try {
|
||||
f_stream_context_get_options(Object());
|
||||
} catch (const NotImplementedException& e) {
|
||||
return Count(true);
|
||||
}
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_context_set_option() {
|
||||
try {
|
||||
f_stream_context_set_option(Object(), "");
|
||||
} catch (const NotImplementedException& e) {
|
||||
return Count(true);
|
||||
}
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_context_set_param() {
|
||||
try {
|
||||
f_stream_context_set_param(Object(), Array());
|
||||
} catch (const NotImplementedException& e) {
|
||||
return Count(true);
|
||||
}
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_copy_to_stream() {
|
||||
Variant src = f_fopen("test/ext/test_ext_file.txt", "r");
|
||||
Variant dest = f_fopen("test/test_ext_file.tmp", "w");
|
||||
f_stream_copy_to_stream(src, dest);
|
||||
f_fclose(dest);
|
||||
|
||||
Variant f = f_fopen("test/test_ext_file.tmp", "r");
|
||||
VS(f_fgets(f), "Testing Ext File\n");
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_encoding() {
|
||||
try {
|
||||
f_stream_encoding(Object());
|
||||
} catch (const NotSupportedException& e) {
|
||||
return Count(true);
|
||||
}
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_bucket_append() {
|
||||
try {
|
||||
f_stream_bucket_append(Object(), Object());
|
||||
} catch (const NotSupportedException& e) {
|
||||
return Count(true);
|
||||
}
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_bucket_prepend() {
|
||||
try {
|
||||
f_stream_bucket_prepend(Object(), Object());
|
||||
} catch (const NotSupportedException& e) {
|
||||
return Count(true);
|
||||
}
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_bucket_make_writeable() {
|
||||
try {
|
||||
f_stream_bucket_make_writeable(Object());
|
||||
} catch (const NotSupportedException& e) {
|
||||
return Count(true);
|
||||
}
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_bucket_new() {
|
||||
try {
|
||||
f_stream_bucket_new(Object(), "");
|
||||
} catch (const NotSupportedException& e) {
|
||||
return Count(true);
|
||||
}
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_filter_register() {
|
||||
try {
|
||||
f_stream_filter_register("", "");
|
||||
} catch (const NotSupportedException& e) {
|
||||
return Count(true);
|
||||
}
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_filter_remove() {
|
||||
try {
|
||||
f_stream_filter_remove(Object());
|
||||
} catch (const NotSupportedException& e) {
|
||||
return Count(true);
|
||||
}
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_filter_append() {
|
||||
try {
|
||||
f_stream_filter_append(Object(), "");
|
||||
} catch (const NotSupportedException& e) {
|
||||
return Count(true);
|
||||
}
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_filter_prepend() {
|
||||
try {
|
||||
f_stream_filter_prepend(Object(), "");
|
||||
} catch (const NotSupportedException& e) {
|
||||
return Count(true);
|
||||
}
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_get_contents() {
|
||||
{
|
||||
Variant f = f_fopen("test/ext/test_ext_file.txt", "r");
|
||||
VS(f_stream_get_contents(f), "Testing Ext File\n");
|
||||
}
|
||||
|
||||
{
|
||||
Variant f = f_tmpfile();
|
||||
|
||||
f_fwrite(f, "fwrite1");
|
||||
f_fseek(f, 0); VS(f_stream_get_contents(f), "fwrite1");
|
||||
|
||||
f_fwrite(f, "fwrite2");
|
||||
f_fseek(f, 0); VS(f_stream_get_contents(f), "fwrite1fwrite2");
|
||||
|
||||
f_fwrite(f, "fwrite3");
|
||||
VS(f_stream_get_contents(f), "");
|
||||
|
||||
f_fclose(f);
|
||||
}
|
||||
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_get_filters() {
|
||||
try {
|
||||
f_stream_get_filters();
|
||||
} catch (const NotSupportedException& e) {
|
||||
return Count(true);
|
||||
}
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_get_line() {
|
||||
{
|
||||
Variant f = f_fopen("test/ext/test_ext_file.txt", "r");
|
||||
VS(f_stream_get_line(f), "Testing Ext File\n");
|
||||
}
|
||||
|
||||
{
|
||||
Variant f = f_tmpfile();
|
||||
f_fwrite(f, "stream_get_line@test");
|
||||
f_fseek(f, 0);
|
||||
VS(f_stream_get_line(f, 300, "@"), "stream_get_line");
|
||||
VS(f_stream_get_line(f, 300, "@"), "test");
|
||||
VS(f_stream_get_line(f, 300, "@"), "");
|
||||
f_fclose(f);
|
||||
}
|
||||
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_get_meta_data() {
|
||||
static const StaticString
|
||||
s_timed_out("timed_out"),
|
||||
s_blocked("blocked");
|
||||
int port = get_random_port();
|
||||
string address = string("127.0.0.1:") + boost::lexical_cast<string>(port);
|
||||
|
||||
Variant server = f_stream_socket_server(address);
|
||||
Variant client = f_stream_socket_client(address);
|
||||
|
||||
f_stream_set_timeout(client, 0, 500 * 1000); // 500ms
|
||||
Variant line = f_fgets(client);
|
||||
Variant meta = f_stream_get_meta_data(client);
|
||||
VS(meta[s_timed_out], true);
|
||||
VS(meta[s_blocked], false);
|
||||
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_get_transports() {
|
||||
VERIFY(f_stream_get_transports().size() > 0);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_get_wrappers() {
|
||||
Array w = f_stream_get_wrappers();
|
||||
VS(f_in_array("file", w), true);
|
||||
VS(f_in_array("http", w), true);
|
||||
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_register_wrapper() {
|
||||
return test_stream_wrapper_register();
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_wrapper_register() {
|
||||
// test_code_run
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_wrapper_restore() {
|
||||
int64_t count = f_count(f_stream_get_wrappers());
|
||||
|
||||
VS(f_stream_wrapper_unregister("http"), true);
|
||||
VS(f_count(f_stream_get_wrappers()), count - 1);
|
||||
|
||||
VS(f_stream_wrapper_restore("http"), true);
|
||||
VS(f_count(f_stream_get_wrappers()), count);
|
||||
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_wrapper_unregister() {
|
||||
return test_stream_wrapper_restore();
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_resolve_include_path() {
|
||||
String old_include_path = f_get_include_path();
|
||||
f_set_include_path(".:test/");
|
||||
String filename = f_getcwd();
|
||||
filename += "/test/ext/test_ext_file.txt";
|
||||
VS(filename, f_stream_resolve_include_path("ext/test_ext_file.txt"));
|
||||
VS(uninit_null(), f_stream_resolve_include_path("some-nonexistant-file.ext"));
|
||||
f_set_include_path(old_include_path);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_select() {
|
||||
Variant f = f_fopen("test/ext/test_ext_file.txt", "r");
|
||||
Variant reads = CREATE_VECTOR1(f);
|
||||
VERIFY(!same(f_stream_select(ref(reads), uninit_null(), uninit_null(), 0, 0), false));
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_set_blocking() {
|
||||
Variant f = f_fopen("test/ext/test_ext_file.txt", "r");
|
||||
VERIFY(f_stream_set_blocking(f, 0));
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_set_timeout() {
|
||||
Variant f = f_fopen("test/ext/test_ext_file.txt", "r");
|
||||
f_stream_set_timeout(f, 0);
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_set_write_buffer() {
|
||||
Variant f = f_fopen("test/test_ext_file.tmp", "w");
|
||||
f_stream_set_write_buffer(f, 1 /* PHP_STREAM_BUFFER_LINE */);
|
||||
f_fputs(f, "testing\nanother line\n");
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_set_file_buffer() {
|
||||
Variant f = f_fopen("test/test_ext_file.tmp", "w");
|
||||
f_set_file_buffer(f, 1 /* PHP_STREAM_BUFFER_LINE */);
|
||||
f_fputs(f, "testing\nanother line\n");
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_socket_accept() {
|
||||
// tested in test_stream_socket_recvfrom
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_socket_server() {
|
||||
// tested in test_stream_socket_recvfrom
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_socket_client() {
|
||||
// tested in test_stream_socket_recvfrom
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_socket_enable_crypto() {
|
||||
try {
|
||||
f_stream_socket_enable_crypto(Object(), true);
|
||||
} catch (const NotSupportedException& e) {
|
||||
return Count(true);
|
||||
}
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_socket_get_name() {
|
||||
Variant client = f_stream_socket_client("facebook.com:80");
|
||||
VERIFY(!f_stream_socket_get_name(client, true).toString().empty());
|
||||
VERIFY(!f_stream_socket_get_name(client, false).toString().empty());
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_socket_pair() {
|
||||
Variant fds = f_stream_socket_pair(k_AF_UNIX, k_SOCK_STREAM, 0);
|
||||
VS(fds.toArray().size(), 2);
|
||||
VERIFY(more(fds[0], 0));
|
||||
VERIFY(more(fds[1], 0));
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_socket_recvfrom() {
|
||||
vector<string> addresses;
|
||||
int port = get_random_port();
|
||||
addresses.push_back("127.0.0.1:" + boost::lexical_cast<string>(port)); // TCP
|
||||
addresses.push_back("unix:///tmp/test_stream.sock"); // UNIX domain
|
||||
unlink("/tmp/test_stream.sock");
|
||||
|
||||
for (unsigned int i = 0; i < addresses.size(); i++) {
|
||||
const string &address = addresses[i];
|
||||
|
||||
Variant server = f_stream_socket_server(address);
|
||||
Variant client = f_stream_socket_client(address);
|
||||
|
||||
Variant s = f_stream_socket_accept(server);
|
||||
String text = "testing";
|
||||
if (i == 1) {
|
||||
VERIFY(f_socket_send(client, text, 7, 0));
|
||||
} else {
|
||||
VERIFY(f_stream_socket_sendto(client, text, 0, address));
|
||||
}
|
||||
|
||||
Variant buffer = f_stream_socket_recvfrom(s, 100);
|
||||
VS(buffer, "testing");
|
||||
}
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_socket_sendto() {
|
||||
// tested in test_stream_socket_recvfrom
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_socket_sendto_issue324() {
|
||||
int port = get_random_port();
|
||||
const string address = "127.0.0.1:" + boost::lexical_cast<string>(port);
|
||||
|
||||
Variant server = f_stream_socket_server(address);
|
||||
Variant client = f_stream_socket_client(address);
|
||||
|
||||
Variant s = f_stream_socket_accept(server);
|
||||
String text = "testing";
|
||||
VERIFY(f_stream_socket_sendto(client, text, 0, null_string));
|
||||
|
||||
Variant buffer = f_stream_socket_recvfrom(s, 100);
|
||||
VS(buffer, "testing");
|
||||
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
bool TestExtStream::test_stream_socket_shutdown() {
|
||||
int port = get_random_port();
|
||||
string address = "127.0.0.1:" + boost::lexical_cast<string>(port);
|
||||
Variant server = f_stream_socket_server(address);
|
||||
VERIFY(f_stream_socket_shutdown(server, 0));
|
||||
return Count(true);
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| HipHop for PHP |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 3.01 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| http://www.php.net/license/3_01.txt |
|
||||
| If you did not receive a copy of the PHP license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#ifndef incl_HPHP_TEST_EXT_STREAM_H_
|
||||
#define incl_HPHP_TEST_EXT_STREAM_H_
|
||||
|
||||
// >>>>>> Generated by idl.php. Do NOT modify. <<<<<<
|
||||
|
||||
#include "hphp/test/ext/test_cpp_ext.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class TestExtStream : public TestCppExt {
|
||||
public:
|
||||
virtual bool RunTests(const std::string &which);
|
||||
|
||||
bool test_stream_context_create();
|
||||
bool test_stream_context_get_default();
|
||||
bool test_stream_context_get_options();
|
||||
bool test_stream_context_set_option();
|
||||
bool test_stream_context_set_param();
|
||||
bool test_stream_copy_to_stream();
|
||||
bool test_stream_encoding();
|
||||
bool test_stream_bucket_append();
|
||||
bool test_stream_bucket_prepend();
|
||||
bool test_stream_bucket_make_writeable();
|
||||
bool test_stream_bucket_new();
|
||||
bool test_stream_filter_register();
|
||||
bool test_stream_filter_remove();
|
||||
bool test_stream_filter_append();
|
||||
bool test_stream_filter_prepend();
|
||||
bool test_stream_get_contents();
|
||||
bool test_stream_get_filters();
|
||||
bool test_stream_get_line();
|
||||
bool test_stream_get_meta_data();
|
||||
bool test_stream_get_transports();
|
||||
bool test_stream_get_wrappers();
|
||||
bool test_stream_register_wrapper();
|
||||
bool test_stream_wrapper_register();
|
||||
bool test_stream_wrapper_restore();
|
||||
bool test_stream_wrapper_unregister();
|
||||
bool test_stream_resolve_include_path();
|
||||
bool test_stream_select();
|
||||
bool test_stream_set_blocking();
|
||||
bool test_stream_set_timeout();
|
||||
bool test_stream_set_write_buffer();
|
||||
bool test_set_file_buffer();
|
||||
bool test_stream_socket_accept();
|
||||
bool test_stream_socket_server();
|
||||
bool test_stream_socket_client();
|
||||
bool test_stream_socket_enable_crypto();
|
||||
bool test_stream_socket_get_name();
|
||||
bool test_stream_socket_pair();
|
||||
bool test_stream_socket_recvfrom();
|
||||
bool test_stream_socket_sendto();
|
||||
bool test_stream_socket_sendto_issue324();
|
||||
bool test_stream_socket_shutdown();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // incl_HPHP_TEST_EXT_STREAM_H_
|
||||
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
function VS($x, $y) {
|
||||
var_dump($x === $y);
|
||||
if ($x !== $y) { echo "Failed: $y\n"; echo "Got: $x\n";
|
||||
var_dump(debug_backtrace()); }
|
||||
}
|
||||
function VERIFY($x) { VS($x != false, true); }
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
// so we run on different range of ports every time
|
||||
function get_random_port() {
|
||||
static $base = -1;
|
||||
if ($base == -1) {
|
||||
$base = 12345 + (int)((int)(microtime(false) * 100) % 30000);
|
||||
}
|
||||
return ++$base;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function test_stream_copy_to_stream() {
|
||||
$src = fopen(__DIR__."/../ext_file/test_ext_file.txt", "r");
|
||||
$dtmp = tempnam('/tmp', 'vmcopystream');
|
||||
$dest = fopen($dtmp, "w");
|
||||
stream_copy_to_stream($src, $dest);
|
||||
fclose($dest);
|
||||
|
||||
$f = fopen($dtmp, "r");
|
||||
VS(fgets($f), "Testing Ext File\n");
|
||||
|
||||
unlink($dtmp);
|
||||
}
|
||||
|
||||
function test_stream_get_contents() {
|
||||
$f = fopen(__DIR__."/../ext_file/test_ext_file.txt", "r");
|
||||
VS(stream_get_contents($f), "Testing Ext File\n");
|
||||
|
||||
$f = tmpfile();
|
||||
|
||||
fwrite($f, "fwrite1");
|
||||
fseek($f, 0); VS(stream_get_contents($f), "fwrite1");
|
||||
|
||||
fwrite($f, "fwrite2");
|
||||
fseek($f, 0); VS(stream_get_contents($f), "fwrite1fwrite2");
|
||||
|
||||
fwrite($f, "fwrite3");
|
||||
VS(stream_get_contents($f), "");
|
||||
|
||||
fclose($f);
|
||||
}
|
||||
|
||||
function test_stream_get_line() {
|
||||
$f = fopen(__DIR__."/../ext_file/test_ext_file.txt", "r");
|
||||
VS(stream_get_line($f), "Testing Ext File\n");
|
||||
|
||||
$f = tmpfile();
|
||||
fwrite($f, "stream_get_line@test");
|
||||
fseek($f, 0);
|
||||
VS(stream_get_line($f, 300, "@"), "stream_get_line");
|
||||
VS(stream_get_line($f, 300, "@"), "test");
|
||||
VS(stream_get_line($f, 300, "@"), "");
|
||||
fclose($f);
|
||||
}
|
||||
|
||||
function test_stream_get_meta_data() {
|
||||
$port = get_random_port();
|
||||
$address = "127.0.0.1:" . $port;
|
||||
|
||||
$server = stream_socket_server($address);
|
||||
$client = stream_socket_client($address);
|
||||
|
||||
stream_set_timeout($client, 0, 500 * 1000); // 500ms
|
||||
$line = fgets($client);
|
||||
$meta = stream_get_meta_data($client);
|
||||
VS($meta['timed_out'], true);
|
||||
VS($meta['blocked'], false);
|
||||
}
|
||||
|
||||
function test_stream_misc() {
|
||||
VERIFY(count(stream_get_transports()) > 0);
|
||||
|
||||
$w = stream_get_wrappers();
|
||||
VS(in_array("file", $w), true);
|
||||
VS(in_array("http", $w), true);
|
||||
}
|
||||
|
||||
function test_stream_wrapper_restore() {
|
||||
$count = count(stream_get_wrappers());
|
||||
|
||||
VS(stream_wrapper_unregister("http"), true);
|
||||
VS(count(stream_get_wrappers()), $count - 1);
|
||||
|
||||
VS(stream_wrapper_restore("http"), true);
|
||||
VS(count(stream_get_wrappers()), $count);
|
||||
}
|
||||
|
||||
function test_stream_select() {
|
||||
$f = fopen(__DIR__."/../ext_file/test_ext_file.txt", "r");
|
||||
$reads = array($f);
|
||||
VERIFY(stream_select($reads, $ignore, $ignore, 0, 0) != false);
|
||||
}
|
||||
|
||||
function test_stream_socket_recvfrom() {
|
||||
$port = get_random_port();
|
||||
$addresses = array(
|
||||
"127.0.0.1:" . $port, // TCP
|
||||
"unix:///tmp/test_stream.sock" // UNIX domain
|
||||
);
|
||||
unlink("/tmp/test_stream.sock");
|
||||
|
||||
$i = 0;
|
||||
foreach ($addresses as $address) {
|
||||
$server = stream_socket_server($address);
|
||||
$client = stream_socket_client($address);
|
||||
|
||||
$s = stream_socket_accept($server);
|
||||
$text = "testing";
|
||||
if ($i++ == 1) {
|
||||
VERIFY(socket_send($client, $text, 7, 0) != false);
|
||||
} else {
|
||||
VERIFY(stream_socket_sendto($client, $text, 0, $address) != false);
|
||||
}
|
||||
|
||||
$buffer = stream_socket_recvfrom($s, 100);
|
||||
VS($buffer, "testing");
|
||||
}
|
||||
}
|
||||
|
||||
function test_stream_socket_sendto_issue324() {
|
||||
$port = get_random_port();
|
||||
$address = "127.0.0.1:" . $port;
|
||||
|
||||
$server = stream_socket_server($address);
|
||||
$client = stream_socket_client($address);
|
||||
|
||||
$s = stream_socket_accept($server);
|
||||
$text = "testing";
|
||||
VERIFY(stream_socket_sendto($client, $text, 0, ''));
|
||||
|
||||
$buffer = stream_socket_recvfrom($s, 100);
|
||||
VS($buffer, "testing");
|
||||
}
|
||||
|
||||
function test_stream_socket_shutdown() {
|
||||
$port = get_random_port();
|
||||
$address = "127.0.0.1:" . $port;
|
||||
$server = stream_socket_server($address);
|
||||
VERIFY(stream_socket_shutdown($server, 0));
|
||||
}
|
||||
|
||||
test_stream_copy_to_stream();
|
||||
test_stream_get_contents();
|
||||
test_stream_get_line();
|
||||
test_stream_get_meta_data();
|
||||
test_stream_misc();
|
||||
test_stream_wrapper_restore();
|
||||
test_stream_select();
|
||||
test_stream_socket_recvfrom();
|
||||
test_stream_socket_sendto_issue324();
|
||||
test_stream_socket_shutdown();
|
||||
@@ -0,0 +1,26 @@
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
Referência em uma Nova Issue
Bloquear um usuário