bool TestExtFile::VerifyFile(CVarRef f, CStrRef contents) {
  f_ob_start();
  f_fpassthru(f);
  VS(f_ob_get_clean(), contents);
  f_ob_end_clean();
  return true;
}
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);
}
Esempio n. 3
0
bool TestExtMailparse::test_mailparse_stream_encode() {
    {
        String text = "hello, this is some text=hello.";
        Variant fp = f_tmpfile();
        f_fwrite(fp, text);
        f_rewind(fp);
        Variant dest = f_tmpfile();
        f_mailparse_stream_encode(fp, dest, "quoted-printable");
        f_rewind(dest);
        Variant data = f_fread(dest, 2048);
        VS(data, "hello, this is some text=3Dhello.");
    }
    {
        String text =
            "To: [email protected]\n"
            "\n"
            "blah blah blah From blah $ \" & £ blah blah blah blah blah\n"
            "From the first of the month, things will be different!\n"
            "blah blah blah From blah\n"
            "Frome is a town in Somerset.";

        f_ob_start();

        Variant fp = f_tmpfile();
        f_fwrite(fp, text);
        f_rewind(fp);

        Variant fpdest = f_tmpfile();
        f_mailparse_stream_encode(fp, fpdest, "quoted-printable");
        f_rewind(fpdest);
        f_fpassthru(fpdest);

        f_fclose(fp);
        f_fclose(fpdest);

        String output = f_ob_get_contents();
        f_ob_end_clean();
        VS(output,
           "To: [email protected]\r\n"
           "\r\n"
           "blah blah blah From blah $ \" & =C2=A3 blah blah blah blah blah\r\n"
           "=46rom the first of the month, things will be different!\r\n"
           "blah blah blah From blah\r\n"
           "Frome is a town in Somerset.");
    }

    return Count(true);
}
bool TestExtMailparse::test_mailparse_msg_extract_part() {
  String text =
    "To: [email protected]\n"
    "Mime-Version: 1.0\n"
    "Content-Type: text/plain\n"
    "Subject: A simple MIME message\n"
    "\n"
    "hello, this is some text hello.\n"
    "blah blah blah.\n";

  Variant fp = f_tmpfile();
  f_fwrite(fp, text);
  f_rewind(fp);

  f_ob_start();

  Variant mime = f_mailparse_msg_create();
  f_mailparse_msg_parse(mime, text);

  echo("Extract to output\n");
  f_mailparse_msg_extract_part_file(mime, fp);

  echo("Extract and return as string\n");
  Variant result = f_mailparse_msg_extract_part_file(mime, fp, uninit_null());
  echo("-->\n");
  echo(result);

  echo("\nExtract to open file\n");
  Variant fpdest = f_tmpfile();
  f_mailparse_msg_extract_part_file(mime, fp, fpdest);
  echo("\nrewinding\n");
  f_rewind(fpdest);
  f_fpassthru(fpdest);

  echo("\nExtract via user function\n");
  f_mailparse_msg_extract_part_file(mime, fp);

  echo("\nExtract whole part to output\n");
  f_mailparse_msg_extract_whole_part_file(mime, fp);

  echo("\nExtract part from string to output\n");
  f_mailparse_msg_extract_part(mime, text);
  f_fclose(fpdest);
  f_fclose(fp);

  String output = f_ob_get_contents();
  f_ob_end_clean();

  VS(output,
     "Extract to output\n"
     "hello, this is some text hello.\n"
     "blah blah blah.\n"
     "Extract and return as string\n"
     "-->\n"
     "hello, this is some text hello.\n"
     "blah blah blah.\n"
     "\n"
     "Extract to open file\n"
     "\n"
     "rewinding\n"
     "hello, this is some text hello.\n"
     "blah blah blah.\n"
     "\n"
     "Extract via user function\n"
     "hello, this is some text hello.\n"
     "blah blah blah.\n"
     "\n"
     "Extract whole part to output\n"
     "To: [email protected]\n"
     "Mime-Version: 1.0\n"
     "Content-Type: text/plain\n"
     "Subject: A simple MIME message\n"
     "\n"
     "hello, this is some text hello.\n"
     "blah blah blah.\n"
     "\n"
     "Extract part from string to output\n"
     "hello, this is some text hello.\n"
     "blah blah blah.\n");

  return Count(true);
}