Ejemplo n.º 1
0
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);
}
Ejemplo n.º 2
0
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);
}
Ejemplo n.º 3
0
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);
}
Ejemplo n.º 4
0
bool TestExtFile::test_fputs() {
  Variant f = f_fopen("test/ext/test_ext_file.tmp", "w");
  f_fputs(f, "testing fputs");
  f_fclose(f);

  f = f_fopen("test/ext/test_ext_file.tmp", "r");
  VF(f, "testing fputs");
  return Count(true);
}
Ejemplo n.º 5
0
bool TestExtFile::test_fwrite() {
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_fwrite(f, "testing fwrite", 7);
  f_fclose(f);

  f = f_fopen("test/test_ext_file.tmp", "r");
  VF(f, "testing");
  return Count(true);
}
Ejemplo n.º 6
0
bool TestExtFile::test_vfprintf() {
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_vfprintf(f, "%s %s", CREATE_VECTOR2("testing", "vfprintf"));
  f_fclose(f);

  f = f_fopen("test/test_ext_file.tmp", "r");
  VF(f, "testing vfprintf");
  return Count(true);
}
Ejemplo n.º 7
0
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);
}
Ejemplo n.º 8
0
bool TestExtFile::test_fputcsv() {
  Array fields = CREATE_VECTOR2("apple", "\"banana\"");
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_fputcsv(f, fields);
  f_fclose(f);

  f = f_fopen("test/test_ext_file.tmp", "r");
  VF(f, "apple,\"\"\"banana\"\"\"\n");
  return Count(true);
}
Ejemplo n.º 9
0
bool TestExtFile::test_fflush() {
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_fputs(f, "testing fflush");
  f_fflush(f);
  f_fclose(f);

  f = f_fopen("test/test_ext_file.tmp", "r");
  VS(f_fread(f, 20), "testing fflush");
  return Count(true);
}
Ejemplo n.º 10
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.º 11
0
bool TestExtFile::test_fread() {
  Variant f = f_fopen("test/ext/test_ext_file.tmp", "w");
  f_fputs(f, "testing fread");
  f_fclose(f);

  f = f_fopen("test/ext/test_ext_file.tmp", "r");
  VS(f_fread(f, 7), "testing");
  VS(f_fread(f, 100), " fread");
  return Count(true);
}
Ejemplo n.º 12
0
bool TestExtFile::test_fgetcsv() {
  Array fields = CREATE_VECTOR2("a", "b");
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_fputcsv(f, fields);
  f_fclose(f);

  f = f_fopen("test/test_ext_file.tmp", "r");
  Array read = f_fgetcsv(f);
  VS(read, fields);
  return Count(true);
}
Ejemplo n.º 13
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.º 14
0
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);
}
Ejemplo n.º 15
0
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);
}
Ejemplo n.º 16
0
bool TestExtFile::test_read_write() {
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_fwrite(f, "testing read/write");
  f_fclose(f);

  f = f_fopen("test/test_ext_file.tmp", "r+");
  f_fseek(f, 8);
  f_fwrite(f, "succeeds");
  f_fseek(f, 8);
  VS(f_fread(f, 8), "succeeds");
  return Count(true);
}
Ejemplo n.º 17
0
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);
}
Ejemplo n.º 18
0
Object f_hphp_splfileobject___construct(CObjRef obj, CStrRef filename, CStrRef open_mode, bool use_include_path, CVarRef context) {
  Variant f = f_fopen(filename, open_mode, use_include_path,
                      context.isNull() ? null_object : context.toObject());
  c_SplFileObject *c_splfo = obj.getTyped<c_SplFileObject>();
  c_splfo->m_rsrc = NEWOBJ(SplFileObject)(f);
  return c_splfo;
}
Ejemplo n.º 19
0
bool f_error_log(const String& message, int message_type /* = 0 */,
                 const String& destination /* = null_string */,
                 const String& extra_headers /* = null_string */) {
  // error_log() should not invoke the user error handler,
  // so we use Logger::Error() instead of raise_warning() or raise_error()
  switch (message_type) {
  case 0:
  {
    std::string line(message.data(),
                     // Truncate to 512k
                     message.size() > (1<<19) ? (1<<19) : message.size());
    Logger::Error(line);
    return true;
  }
  case 3:
  {
    Variant outfile = f_fopen(destination, "a"); // open for append only
    if (outfile.isNull()) {
      Logger::Error("can't open error_log file!\n");
      return false;
    }
    f_fwrite(outfile.toResource(), message);
    f_fclose(outfile.toResource());
    return true;
  }
  case 2: // not used per PHP
  default:
    Logger::Error("error_log does not support message_type %d!", message_type);
    break;
  }
  return false;
}
Ejemplo n.º 20
0
bool TestExtFile::test_fpassthru() {
  Variant f = f_fopen("test/test_ext_file.txt", "r");
  f_ob_start();
  VS(f_fpassthru(f), 17);
  VS(f_ob_get_clean(), "Testing Ext File\n");
  f_ob_end_clean();
  return Count(true);
}
Ejemplo n.º 21
0
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);
}
Ejemplo n.º 22
0
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);
}
Ejemplo n.º 23
0
bool TestExtFile::test_pclose() {
  Variant f = f_fopen("test/ext/test_ext_file.tmp", "w");
  f_fputs(f, "testing pclose");
  f_fclose(f);

  f = f_popen("cat test/ext/test_ext_file.tmp", "r");
  VS(f_fread(f, 20), "testing pclose");
  f_pclose(f);
  return Count(true);
}
Ejemplo n.º 24
0
bool TestExtZlib::test_gzencode() {
  Variant zipped = f_gzencode("testing gzencode");
  Variant f = f_fopen("test/test_ext_zlib.tmp", "w");
  f_fwrite(f, zipped);
  f_fclose(f);

  f_ob_start();
  f_readgzfile("test/test_ext_zlib.tmp");
  VS(f_ob_get_clean(), "testing gzencode");
  f_ob_end_clean();
  return Count(true);
}
Ejemplo n.º 25
0
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);
}
Ejemplo n.º 26
0
bool TestExtBzip2::test_bzerrno() {
  Variant f = f_fopen("test/test_ext_bzip2.tmp", "w");
  f_fwrite(f, "this is a test");
  f_fclose(f);
  f = f_bzopen("test/test_ext_bzip2.tmp", "r");
  f_bzread(f);
  int ret = f_bzerrno(f);
  f_bzclose(f);
  f_unlink("test/test_ext_bzip2.tmp");
  VS(ret, -5);
  return Count(true);
}
Ejemplo n.º 27
0
bool TestExtBzip2::test_bzerrstr() {
  Variant f = f_fopen("test/test_ext_bzip2.tmp", "w");
  f_fwrite(f, "this is a test");
  f_fclose(f);
  f = f_bzopen("test/test_ext_bzip2.tmp", "r");
  f_bzread(f);
  String ret = f_bzerrstr(f);
  f_bzclose(f);
  f_unlink("test/test_ext_bzip2.tmp");
  VS(ret, "DATA_ERROR_MAGIC");
  return Count(true);
}
Ejemplo n.º 28
0
bool TestExtBzip2::test_bzerror() {
  Variant f = f_fopen("test/test_ext_bzip2.tmp", "w");
  f_fwrite(f, "this is a test");
  f_fclose(f);
  f = f_bzopen("test/test_ext_bzip2.tmp", "r");
  f_bzread(f);
  Variant ret = f_bzerror(f);
  f_bzclose(f);
  f_unlink("test/test_ext_bzip2.tmp");
  VS(ret, CREATE_MAP2("errno", -5, "errstr", "DATA_ERROR_MAGIC"));
  return Count(true);
}
Ejemplo n.º 29
0
bool f_hash_update_file(CObjRef init_context, CStrRef filename,
                        CObjRef stream_context /* = null */) {
  Variant f = f_fopen(filename, "rb");
  if (same(f, false)) {
    return false;
  }

  HashContext *hash = init_context.getTyped<HashContext>();
  for (Variant chunk = f_fread(f, 1024); !is_empty_string(chunk);
       chunk = f_fread(f, 1024)) {
    String schunk = chunk.toString();
    hash->ops->hash_update(hash->context, (unsigned char *)schunk.data(),
                           schunk.size());
  }
  return true;
}
Ejemplo n.º 30
0
bool TestExtStream::test_stream_get_line() {
  {
    Variant f = f_fopen("test/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);
}