Beispiel #1
0
bool TestExtOutput::test_ob_list_handlers() {
  f_ob_start();
  f_ob_start("test");
  Array handlers = f_ob_list_handlers();
  f_ob_end_clean();
  f_ob_end_clean();
  VS(handlers, CREATE_VECTOR2(null, "test"));
  return Count(true);
}
Beispiel #2
0
bool TestExtOutput::test_flush() {
  f_ob_start();
  f_ob_start("strtolower");
  g_context->write(""); // we can't really verify what's written to stdout
  f_flush();
  f_ob_end_clean();
  f_ob_end_clean();
  return Count(true);
}
Beispiel #3
0
bool TestExtOutput::test_ob_get_flush() {
  f_ob_start();
  f_ob_start();
  g_context->write("test");
  VS(f_ob_get_flush(), "test");
  VS(f_ob_get_flush(), "");
  f_ob_end_clean();
  VS(f_ob_get_flush(), "test");
  f_ob_end_clean();
  return Count(true);
}
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;
}
Beispiel #5
0
bool TestExtZlib::test_readgzfile() {
  f_ob_start();
  f_readgzfile("test/test_ext_zlib.gz");
  VS(f_ob_get_clean(), "Testing Ext Zlib\n");
  f_ob_end_clean();
  return Count(true);
}
bool TestExtOutput::test_ob_get_length() {
    f_ob_start();
    g_context->out() << "test";
    VS(f_ob_get_length(), 4);
    f_ob_end_clean();
    return Count(true);
}
bool TestExtFile::test_readfile() {
  f_ob_start();
  VS(f_readfile("test/test_ext_file.txt"), 17);
  VS(f_ob_get_clean(), "Testing Ext File\n");
  f_ob_end_clean();
  return Count(true);
}
Beispiel #8
0
Variant f_ob_get_clean() {
  String output = f_ob_get_contents();
  if (!f_ob_end_clean()) {
    return false;
  }
  return output;
}
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);
}
Beispiel #10
0
bool TestExtSoap::verify_response(CStrRef request, CStrRef expected) {
  f_ob_start();
  m_server->t_handle(request);
  String res = f_ob_get_contents();
  f_ob_end_clean();
  VS(res, expected);
  return true;
}
Beispiel #11
0
bool TestExtZlib::test_gzpassthru() {
  Variant f = f_gzopen("test/test_ext_zlib.gz", "r");
  f_ob_start();
  f_gzpassthru(f);
  VS(f_ob_get_clean(), "Testing Ext Zlib\n");
  f_ob_end_clean();
  return Count(true);
}
Beispiel #12
0
bool TestExtOutput::test_ob_get_contents() {
  f_ob_start();
  g_context->write("test");
  VS(f_ob_get_contents(), "test");
  VS(f_ob_get_contents(), "test"); // verifying content stays
  f_ob_end_clean();
  return Count(true);
}
Beispiel #13
0
bool TestExtOutput::test_ob_end_clean() {
  f_ob_start();
  f_ob_start("strtolower");
  g_context->write("TEst");
  f_ob_end_clean();
  VS(f_ob_get_clean(), "");
  return Count(true);
}
Beispiel #14
0
bool TestExtOutput::test_ob_get_level() {
  VS(f_ob_get_level(), 0);
  f_ob_start();
  VS(f_ob_get_level(), 1);
  f_ob_end_clean();
  VS(f_ob_get_level(), 0);
  return Count(true);
}
bool TestExtMailparse::test_mailparse_msg_create() {
  const char *files[] = { "mime", "phpcvs1", "qp", "uue" };

  for (unsigned int i = 0; i < sizeof(files)/sizeof(files[0]); i++) {
    string file = files[i];
    string testname = "test/ext/test_ext_mailparse." + file + ".txt";
    string expname = "test/ext/test_ext_mailparse." + file + ".exp";

    Variant mime = f_mailparse_msg_create();
    PlainFile input;
    input.open(testname, "r");
    while (!input.eof()) {
      String data = input.read(1024);
      if (!data.isNull()) {
        f_mailparse_msg_parse(mime, data);
      }
    }
    input.close();

    Array arr = f_mailparse_msg_get_structure(mime);
    f_ob_start();
    echo("Message: "); echo(file.c_str()); echo("\n");
    for (ArrayIter iter(arr); iter; ++iter) {
      Variant partname = iter.second();
      int depth = f_count(f_explode(".", partname)) - 1;
      String indent = f_str_repeat("  ", depth * 2);

      Variant subpart = f_mailparse_msg_get_part(mime, partname);
      if (subpart.isNull()) {
        f_var_dump(partname); echo("\n");
        f_var_dump(arr);
        break;
      }

      Variant data = f_mailparse_msg_get_part_data(subpart);
      echo("\n"); echo(indent); echo("Part "); echo(partname); echo("\n");
      f_ksort(ref(data));
      for (ArrayIter iter(data); iter; ++iter) {
        String key = iter.first().toString();
        if (key != "headers" && key != "ending-pos-body") {
          echo(indent); echo(key); echo(" => ");
          f_var_dump(iter.second());
        }
      }
    }
    String output = f_ob_get_contents();

    Variant expect = f_file_get_contents(expname.c_str());
    VS(output, expect);
    f_ob_end_clean();
  }

  return Count(true);
}
Beispiel #16
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);
}
bool TestExtMailparse::test_mailparse_rfc822_parse_addresses() {
    static const StaticString
    s_display("display"),
              s_address("address"),
              s_is_group("is_group");
    Array addresses =
        CREATE_VECTOR2("\":sysmail\"@ Some-Group. Some-Org, Muhammed."
                       "(I am the greatest) Ali @(the)Vegas.WBA",
                       "\"strange\":\":sysmail\"@ Some-Group. Some-Org, Muhammed."
                       "(I am the greatest) Ali @(the)Vegas.WBA;");

    f_ob_start();

    for (ArrayIter iter(addresses); iter; ++iter) {
        Variant parsed = f_mailparse_rfc822_parse_addresses(iter.second());
        for (ArrayIter iter2(parsed); iter2; ++iter2) {
            Variant pair = iter2.second();
            echo(pair[s_display]);
            echo("\n");
            echo(pair[s_address]);
            echo("\n");
            if (pair[s_is_group].toBoolean()) {
                Variant sub = f_mailparse_rfc822_parse_addresses
                              (f_substr(pair[s_address], 1, f_strlen(pair[s_address]) - 2));
                for (ArrayIter iter3(sub); iter3; ++iter3) {
                    echo("   ");
                    echo(iter3.second()[s_address]);
                    echo("\n");
                }
            }
        }
        echo("...\n");
    }

    String output = f_ob_get_contents();
    f_ob_end_clean();
    VS(output,
       ":[email protected]\n"
       "\":sysmail\"@Some-Group.Some-Org\n"
       "I am the greatest the\n"
       "[email protected]\n"
       "...\n"
       "strange\n"
       ":\":sysmail\"@Some-Group.Some-Org,[email protected];\n"
       "   \":sysmail\"@Some-Group.Some-Org\n"
       "   [email protected]\n"
       "...\n");

    return Count(true);
}
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);
}
Beispiel #19
0
bool TestExtCurl::test_curl_exec() {
  {
    Variant c = f_curl_init(String(get_request_uri()));
    f_curl_setopt(c.toResource(), k_CURLOPT_RETURNTRANSFER, true);
    Variant res = f_curl_exec(c.toResource());
    VS(res, "OK");
  }
  {
    Variant c = f_curl_init(String(get_request_uri()));
    f_curl_setopt(c.toResource(), k_CURLOPT_WRITEFUNCTION, "curl_write_func");
    f_ob_start();
    f_curl_exec(c.toResource());
    String res = f_ob_get_contents();
    VS(res, "curl_write_func called with OK");
    f_ob_end_clean();
  }
  return Count(true);
}
bool TestExtMailparse::test_mailparse_uudecode_all() {
  static const StaticString s_filename("filename");
  String text =
    "To: [email protected]\n"
    "\n"
    "hello, this is some text hello.\n"
    "blah blah blah.\n"
    "\n"
    "begin 644 test.txt\n"
    "/=&AI<R!I<R!A('1E<W0*\n"
    "`\n"
    "end";

  f_ob_start();

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

  Variant data = f_mailparse_uudecode_all(fp);
  echo("BODY\n");
  f_readfile(data[0][s_filename]);
  echo("UUE\n");
  f_readfile(data[1][s_filename]);

  f_unlink(data[0][s_filename]);
  f_unlink(data[1][s_filename]);

  String output = f_ob_get_contents();
  f_ob_end_clean();
  VS(output,
     "BODY\n"
     "To: [email protected]\n"
     "\n"
     "hello, this is some text hello.\n"
     "blah blah blah.\n"
     "\n"
     "UUE\n"
     "this is a test\n");

  return Count(true);
}
Beispiel #21
0
String f_ob_get_clean() {
  String output = f_ob_get_contents();
  f_ob_end_clean();
  return output;
}
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);
}