Ejemplo n.º 1
0
bool TestExtFile::test_fgets() {
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_fputs(f, "testing\nfgets\n\n");
  f_fclose(f);

  f = f_fopen("test/test_ext_file.tmp", "r");
  VS(f_fgets(f), "testing\n");
  VS(f_fgets(f), "fgets\n");
  VS(f_fgets(f), "\n");
  return Count(true);
}
Ejemplo n.º 2
0
bool TestExtStream::test_stream_copy_to_stream() {
  Variant src = f_fopen("test/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);
}
Ejemplo n.º 3
0
bool TestExtStream::test_stream_get_meta_data() {
  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["timed_out"], true);
  VS(meta["blocked"], false);

  return Count(true);
}
Ejemplo n.º 4
0
bool TestExtNetwork::test_fsockopen() {
  {
    Variant f = f_fsockopen("facebook.com", 80);
    VERIFY(!same(f, false));
    f_fputs(f, "GET / HTTP/1.0\n\n");
    VERIFY(!f_fread(f, 15).toString().empty());
  }
  {
    Variant f = f_fsockopen("ssl://www.facebook.com", 443);
    VERIFY(!same(f, false));
    f_fwrite(f,
             "GET / HTTP/1.1\r\n"
             "Host: www.facebook.com\r\n"
             "Connection: Close\r\n"
             "\r\n");
    StringBuffer response;
    while (!same(f_feof(f), true)) {
      Variant line = f_fgets(f, 128);
      response.append(line.toString());
    }
    VERIFY(!response.detach().empty());
  }
  return Count(true);
}