Port TestExtIconv to php

Esse commit está contido em:
Jordan DeLong
2013-06-14 22:45:13 -07:00
commit de Sara Golemon
commit 740998c959
5 arquivos alterados com 115 adições e 187 exclusões
-1
Ver Arquivo
@@ -36,7 +36,6 @@
#include "hphp/facebook/extensions/urlextraction/test_ext_urlextraction.h"
#include "hphp/test/ext/test_ext_curl.h"
#include "hphp/test/ext/test_ext_file.h"
#include "hphp/test/ext/test_ext_iconv.h"
#include "hphp/test/ext/test_ext_icu.h"
#include "hphp/test/ext/test_ext_icu_ucnv.h"
#include "hphp/test/ext/test_ext_icu_ucsdet.h"
-141
Ver Arquivo
@@ -1,141 +0,0 @@
/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#include "hphp/test/ext/test_ext_iconv.h"
#include "hphp/runtime/ext/ext_iconv.h"
///////////////////////////////////////////////////////////////////////////////
bool TestExtIconv::RunTests(const std::string &which) {
bool ret = true;
RUN_TEST(test_iconv_mime_encode);
RUN_TEST(test_iconv_mime_decode);
RUN_TEST(test_iconv_mime_decode_headers);
RUN_TEST(test_iconv_get_encoding);
RUN_TEST(test_iconv_set_encoding);
RUN_TEST(test_iconv);
RUN_TEST(test_iconv_strlen);
RUN_TEST(test_iconv_strpos);
RUN_TEST(test_iconv_strrpos);
RUN_TEST(test_iconv_substr);
RUN_TEST(test_ob_iconv_handler);
return ret;
}
///////////////////////////////////////////////////////////////////////////////
static const StaticString s_scheme("scheme");
bool TestExtIconv::test_iconv_mime_encode() {
Array preferences = CREATE_MAP4("input-charset", "ISO-8859-1",
"output-charset", "UTF-8",
"line-length", 76,
"line-break-chars", "\n");
preferences.set(s_scheme, "Q");
VS(f_iconv_mime_encode("Subject", "Pr\xDC""fung Pr\xDC""fung", preferences),
"Subject: =?UTF-8?Q?Pr=C3=9Cfung=20Pr=C3=9Cfung?=");
preferences.set(s_scheme, "B");
VS(f_iconv_mime_encode("Subject", "Pr\xDC""fung Pr\xDC""fung", preferences),
"Subject: =?UTF-8?B?UHLDnGZ1bmcgUHLDnGZ1bmc=?=");
return Count(true);
}
bool TestExtIconv::test_iconv_mime_decode() {
VS(f_iconv_mime_decode("=?windows-1256?Q?My_Persona?= =?windows-1256?Q?l_Profile_?= =?windows-1256?Q?was_Disabl?= =?windows-1256?Q?ed=FE?="), false);
VS(f_iconv_mime_decode("Subject: =?UTF-8?B?UHLDnGZ1bmcgUHLDnGZ1bmc=?=",
0, "ISO-8859-1"),
"Subject: Pr\xDC""fung Pr\xDC""fung");
VS(f_iconv_mime_decode(
"Subject: =?utf-8?Q?JS_typeahead_should_normalize_Polish_=C5=82_=3C-=3E_"
"l_?=\n =?utf-8?Q?=28S=C5=82awek_Biel=29?=",
0,
"UTF-8"),
"Subject: JS typeahead should normalize Polish \u0142 <-> l (S\u0142awek "
"Biel)");
return Count(true);
}
bool TestExtIconv::test_iconv_mime_decode_headers() {
VS(f_iconv_mime_decode_headers
("Subject: =?UTF-8?B?UHLDnGZ1bmcgUHLDnGZ1bmc=?=\n"
"Subject: =?UTF-8?B?UHLDnGZ1bmcgUHLDnGZ1bmc=?=\n",
0, "ISO-8859-1"),
CREATE_MAP1("Subject", CREATE_VECTOR2("Pr\xDC""fung Pr\xDC""fung",
"Pr\xDC""fung Pr\xDC""fung")));
return Count(true);
}
bool TestExtIconv::test_iconv_get_encoding() {
VS(f_iconv_get_encoding(),
CREATE_MAP3("input_encoding", "ISO-8859-1",
"output_encoding", "ISO-8859-1",
"internal_encoding", "ISO-8859-1"));
return Count(true);
}
bool TestExtIconv::test_iconv_set_encoding() {
VS(f_iconv_set_encoding("output_encoding", "UTF-8"), true);
VS(f_iconv_get_encoding(),
CREATE_MAP3("input_encoding", "ISO-8859-1",
"output_encoding", "UTF-8",
"internal_encoding", "ISO-8859-1"));
return Count(true);
}
bool TestExtIconv::test_iconv() {
VS(f_iconv("UTF-8", "BIG5", "\xE2\x82\xAC"), "\xa3\xe1");
VS(f_iconv("ISO-8859-1", "UTF-8", "Pr\xDC""fung"), "Pr\xC3\x9C""fung");
return Count(true);
}
bool TestExtIconv::test_iconv_strlen() {
VS(f_iconv_strlen("Pr\xDC""fung", "ISO-8859-1"), 7);
VS(f_iconv_strlen("Pr\xC3\x9C""fung", "UTF-8"), 7);
return Count(true);
}
bool TestExtIconv::test_iconv_strpos() {
VS(f_iconv_strpos("Pr\xC3\x9C\xC3\x9D""fung", "\xC3\x9D", 0, "UTF-8"), 3);
return Count(true);
}
bool TestExtIconv::test_iconv_strrpos() {
VS(f_iconv_strrpos("Pr\xC3\x9C""abc\xC3\x9C""fung", "\xC3\x9C", "UTF-8"), 6);
return Count(true);
}
bool TestExtIconv::test_iconv_substr() {
VS(f_iconv_substr("Pr\xC3\x9C\xC3\x9D""fung", 2, 2, "UTF-8"),
"\xC3\x9C\xC3\x9D");
return Count(true);
}
bool TestExtIconv::test_ob_iconv_handler() {
// TODO: test this in TestServer
return Count(true);
}
-45
Ver Arquivo
@@ -1,45 +0,0 @@
/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#ifndef incl_HPHP_TEST_EXT_ICONV_H_
#define incl_HPHP_TEST_EXT_ICONV_H_
// >>>>>> Generated by idl.php. Do NOT modify. <<<<<<
#include "hphp/test/ext/test_cpp_ext.h"
///////////////////////////////////////////////////////////////////////////////
class TestExtIconv : public TestCppExt {
public:
virtual bool RunTests(const std::string &which);
bool test_iconv_mime_encode();
bool test_iconv_mime_decode();
bool test_iconv_mime_decode_headers();
bool test_iconv_get_encoding();
bool test_iconv_set_encoding();
bool test_iconv();
bool test_iconv_strlen();
bool test_iconv_strpos();
bool test_iconv_strrpos();
bool test_iconv_substr();
bool test_ob_iconv_handler();
};
///////////////////////////////////////////////////////////////////////////////
#endif // incl_HPHP_TEST_EXT_ICONV_H_
+99
Ver Arquivo
@@ -0,0 +1,99 @@
<?php
function VS($x, $y) {
var_dump($x === $y);
if ($x !== $y) { echo "Failed: $y\n"; echo "Got: $x\n";
var_dump(debug_backtrace()); }
}
function VERIFY($x) { VS($x, true); }
//////////////////////////////////////////////////////////////////////
function test_iconv_mime_encode() {
$preferences = array("input-charset" => "ISO-8859-1",
"output-charset" => "UTF-8",
"line-length" => 76,
"line-break-chars" => "\n");
$preferences['scheme'] = "Q";
VS(iconv_mime_encode("Subject", "Pr\xDC"."fung Pr\xDC"."fung", $preferences),
"Subject: =?UTF-8?Q?Pr=C3=9Cfung=20Pr=C3=9Cfung?=");
$preferences['scheme'] = "B";
VS(iconv_mime_encode("Subject", "Pr\xDC"."fung Pr\xDC"."fung", $preferences),
"Subject: =?UTF-8?B?UHLDnGZ1bmcgUHLDnGZ1bmc=?=");
}
function test_iconv_mime_decode() {
VS(iconv_mime_decode("=?windows-1256?Q?My_Persona?= =?windows-1256?Q?l_Profile_?= =?windows-1256?Q?was_Disabl?= =?windows-1256?Q?ed=FE?="), false);
VS(iconv_mime_decode("Subject: =?UTF-8?B?UHLDnGZ1bmcgUHLDnGZ1bmc=?=",
0, "ISO-8859-1"),
"Subject: Pr\xDC"."fung Pr\xDC"."fung");
VS(iconv_mime_decode(
"Subject: =?utf-8?Q?JS_typeahead_should_normalize_Polish_=C5=82_=3C-=3E_".
"l_?=\n =?utf-8?Q?=28S=C5=82awek_Biel=29?=",
0,
"UTF-8"),
"Subject: JS typeahead should normalize Polish \xC5\x82 <-> l (S\xC5\x82awek ".
"Biel)");
}
function test_iconv_mime_decode_headers() {
VS(iconv_mime_decode_headers
("Subject: =?UTF-8?B?UHLDnGZ1bmcgUHLDnGZ1bmc=?=\n".
"Subject: =?UTF-8?B?UHLDnGZ1bmcgUHLDnGZ1bmc=?=\n",
0, "ISO-8859-1"),
array("Subject" => array("Pr\xDC"."fung Pr\xDC"."fung",
"Pr\xDC"."fung Pr\xDC"."fung")));
}
function test_iconv_get_encoding() {
VS(iconv_get_encoding(),
array("input_encoding" => "ISO-8859-1",
"output_encoding" => "ISO-8859-1",
"internal_encoding" => "ISO-8859-1"));
}
function test_iconv_set_encoding() {
VS(iconv_set_encoding("output_encoding", "UTF-8"), true);
VS(iconv_get_encoding(),
array("input_encoding" => "ISO-8859-1",
"output_encoding" => "UTF-8",
"internal_encoding" => "ISO-8859-1"));
}
function test_iconv() {
VS(iconv("UTF-8", "BIG5", "\xE2\x82\xAC"), "\xa3\xe1");
VS(iconv("ISO-8859-1", "UTF-8", "Pr\xDC"."fung"), "Pr\xC3\x9C"."fung");
}
function test_iconv_strlen() {
VS(iconv_strlen("Pr\xDC"."fung", "ISO-8859-1"), 7);
VS(iconv_strlen("Pr\xC3\x9C"."fung", "UTF-8"), 7);
}
function test_iconv_strpos() {
VS(iconv_strpos("Pr\xC3\x9C\xC3\x9D"."fung", "\xC3\x9D", 0, "UTF-8"), 3);
}
function test_iconv_strrpos() {
VS(iconv_strrpos("Pr\xC3\x9C"."abc\xC3\x9C"."fung", "\xC3\x9C", "UTF-8"), 6);
}
function test_iconv_substr() {
VS(iconv_substr("Pr\xC3\x9C\xC3\x9D"."fung", 2, 2, "UTF-8"),
"\xC3\x9C\xC3\x9D");
}
test_iconv_mime_encode();
test_iconv_mime_decode();
test_iconv_mime_decode_headers();
test_iconv_get_encoding();
test_iconv_set_encoding();
test_iconv();
test_iconv_strlen();
test_iconv_strpos();
test_iconv_strrpos();
test_iconv_substr();
@@ -0,0 +1,16 @@
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)