bool TestExtNetwork::test_pfsockopen() {
  Variant f = f_pfsockopen("facebook.com", 80);
  VERIFY(!same(f, false));
  f_fputs(f, "GET / HTTP/1.0\n\n");
  VERIFY(!f_fread(f, 15).toString().empty());
  return Count(true);
}
bool TestExtFile::test_popen() {
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_fputs(f, "testing popen");
  f_fclose(f);

  f = f_popen("cat test/test_ext_file.tmp", "r");
  VS(f_fread(f, 20), "testing popen");
  return Count(true);
}
bool TestExtFile::test_fgetss() {
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_fputs(f, "<html><head>testing</head><body> fgetss</body></html>\n");
  f_fclose(f);

  f = f_fopen("test/test_ext_file.tmp", "r");
  VS(f_fgetss(f), "testing fgetss\n");
  return Count(true);
}
bool TestExtFile::test_fstat() {
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_fputs(f, "testing fstat");
  f_fclose(f);

  f = f_fopen("test/test_ext_file.tmp", "r");
  VS(f_fstat(f)["size"], 13);
  return Count(true);
}
bool TestExtFile::test_fscanf() {
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_fputs(f, "testing fscanf");
  f_fclose(f);

  f = f_fopen("test/test_ext_file.tmp", "r");
  VS(f_fscanf(2, f, "%s %s"), CREATE_VECTOR2("testing", "fscanf"));
  return Count(true);
}
bool TestExtFile::test_fputs() {
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_fputs(f, "testing fputs");
  f_fclose(f);

  f = f_fopen("test/test_ext_file.tmp", "r");
  VF(f, "testing fputs");
  return Count(true);
}
bool TestExtFile::test_chown() {
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_fputs(f, "testing\nchown\n");
  f_fclose(f);
  VERIFY(f_chmod("test/test_ext_file.txt", 0777));
  //VERIFY(f_chown("test/test_ext_file.tmp", "hzhao"));
  f_unlink("test/test_ext_file.tmp");
  return Count(true);
}
bool TestExtFile::test_file() {
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_fputs(f, "testing\nfile\n");
  f_fclose(f);

  Variant items = f_file("test/test_ext_file.tmp");
  VS(items, CREATE_VECTOR2("testing\n", "file\n"));
  return Count(true);
}
bool TestExtFile::test_ftell() {
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_fputs(f, "testing ftell");
  f_fclose(f);

  f = f_fopen("test/test_ext_file.tmp", "r");
  f_fseek(f, -5, k_SEEK_END);
  VS(f_ftell(f), 8);
  return Count(true);
}
bool TestExtFile::test_fread() {
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_fputs(f, "testing fread");
  f_fclose(f);

  f = f_fopen("test/test_ext_file.tmp", "r");
  VS(f_fread(f, 7), "testing");
  VS(f_fread(f, 100), " fread");
  return Count(true);
}
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);
}
bool TestExtFile::test_feof() {
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_fputs(f, "testing feof");
  f_fclose(f);

  f = f_fopen("test/test_ext_file.tmp", "r");
  VERIFY(!f_feof(f));
  VS(f_fread(f, 20), "testing feof");
  VERIFY(f_feof(f));
  return Count(true);
}
bool TestExtFile::test_file_get_contents() {
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_fputs(f, "testing file_get_contents");
  f_fclose(f);

  VS(f_file_get_contents("test/test_ext_file.tmp"),
     "testing file_get_contents");

  VS(f_unserialize(f_file_get_contents("compress.zlib://test/test_zlib_file")),
     CREATE_VECTOR1("rblock:216105"));
  return Count(true);
}
bool TestExtFile::test_fgetc() {
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_fputs(f, "testing fgetc");
  f_fclose(f);

  f = f_fopen("test/test_ext_file.tmp", "r");
  VS(f_fgetc(f), "t");
  VS(f_fgetc(f), "e");
  VS(f_fgetc(f), "s");
  VS(f_fgetc(f), "t");
  return Count(true);
}
bool TestExtFile::test_ftruncate() {
  Variant f = f_fopen("test/ext/test_ext_file.tmp", "w");
  f_fputs(f, "testing ftruncate");
  f_fclose(f);

  f = f_fopen("test/ext/test_ext_file.tmp", "r+");
  f_ftruncate(f, 7);
  f_fclose(f);

  f = f_fopen("test/ext/test_ext_file.tmp", "r");
  VS(f_fread(f, 20), "testing");
  return Count(true);
}
bool TestExtFile::test_fseek() {
  Variant f = f_fopen("test/ext/test_ext_file.tmp", "w");
  f_fputs(f, "testing fseek");
  f_fclose(f);

  f = f_fopen("test/ext/test_ext_file.tmp", "r");
  f_fseek(f, -5, k_SEEK_END);
  VS(f_fread(f, 7), "fseek");

  f_fseek(f, 7);
  VS(f_fread(f, 7), " fseek");
  return Count(true);
}
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);
}
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 TestExtFile::test_tmpfile() {
  Variant f = f_tmpfile();
  f_fputs(f, "testing tmpfile");
  f_fclose(f);
  return Count(true);
}