bool TestExtVariable::test_floatval() { VS(f_floatval("12.3"), 12.3); return Count(true); }
bool TestExtProcess::test_pcntl_getpriority() { VS(f_pcntl_getpriority(), 0); return Count(true); }
bool TestExtProcess::test_escapeshellcmd() { VS(f_escapeshellcmd("perl \""), "perl \\\""); return Count(true); }
bool TestExtNetwork::test_gethostbynamel() { VS(f_gethostbynamel("localhost"), CREATE_VECTOR1("127.0.0.1")); return Count(true); }
bool TestExtNetwork::test_getprotobynumber() { VS(f_getprotobynumber(6), "tcp"); return Count(true); }
bool TestExtNetwork::test_socket_get_status() { VS(f_socket_get_status(Object()), false); return Count(true); }
bool TestExtNetwork::test_gethostbyaddr() { VS(f_gethostbyaddr("127.0.0.1"), "localhost.localdomain"); return Count(true); }
NLDO1200("8038_l24", 0x0DC, 0x0DD, LDO_1200), NLDO("8038_l26", "8038_l26_pc", 0x0E0, 0x0E1, LDO_150), NLDO1200("8038_l27", 0x0E2, 0x0E3, LDO_1200), /* name pc_name ctrl test2 clk sleep hpm_min */ SMPS("8038_s1", "8038_s1_pc", 0x1E0, 0x1E5, 0x009, 0x1E2, SMPS_1500), SMPS("8038_s2", "8038_s2_pc", 0x1D8, 0x1DD, 0x00A, 0x1DA, SMPS_1500), SMPS("8038_s3", "8038_s3_pc", 0x1D0, 0x1D5, 0x00B, 0x1D2, SMPS_1500), SMPS("8038_s4", "8038_s4_pc", 0x1E8, 0x1ED, 0x00C, 0x1EA, SMPS_1500), /* name ctrl fts_cnfg1 pfm pwr_cnfg hpm_min */ FTSMPS("8038_s5", 0x025, 0x02E, 0x026, 0x032, SMPS_2000), FTSMPS("8038_s6", 0x036, 0x03F, 0x037, 0x043, SMPS_2000), /* name pc_name ctrl test */ VS("8038_lvs1", "8038_lvs1_pc", 0x060, 0x061), VS("8038_lvs2", "8038_lvs2_pc", 0x062, 0x063), }; #define MAX_NAME_COMPARISON_LEN 32 static int __devinit match_regulator( struct pm8xxx_regulator_core_platform_data *core_data, const char *name) { int found = 0; int i; for (i = 0; i < ARRAY_SIZE(regulator_data); i++) { if (regulator_data[i].rdesc.name && strncmp(regulator_data[i].rdesc.name, name, MAX_NAME_COMPARISON_LEN) == 0) {
bool TestExtJson::test_json_decode() { Array arr = CREATE_MAP1("fbid", 101501853510151001LL); VS(f_json_decode(f_json_encode(arr), true), arr); VS(f_json_decode("{\"0\":{\"00\":0}}", true), CREATE_MAP1("0", CREATE_MAP1("00", 0))); VS(f_json_decode("{\"a\":1,\"b\":2.3,\"3\":\"test\"}", true), CREATE_MAP3("a", 1, "b", 2.3, 3, "test")); VS(f_json_decode("[\"a\",1,true,false,null]", true), CREATE_VECTOR5("a", 1, true, false, uninit_null())); Object obj = f_json_decode("{\"a\":1,\"b\":2.3,\"3\":\"test\"}"); Object obj2(SystemLib::AllocStdClassObject()); obj2->o_set("a", 1); obj2->o_set("b", 2.3); obj2->o_set("3", "test"); VS(obj.toArray(), obj2.toArray()); obj = f_json_decode("[\"a\",1,true,false,null]"); VS(obj.toArray(), CREATE_VECTOR5("a", 1, true, false, uninit_null())); VS(f_json_decode("{z:1}", true), uninit_null()); VS(f_json_decode("{z:1}", true, k_JSON_FB_LOOSE), CREATE_MAP1("z", 1)); VS(f_json_decode("{z:\"z\"}", true), uninit_null()); VS(f_json_decode("{z:\"z\"}", true, k_JSON_FB_LOOSE), CREATE_MAP1("z", "z")); VS(f_json_decode("{'x':1}", true), uninit_null()); VS(f_json_decode("{'x':1}", true, k_JSON_FB_LOOSE), CREATE_MAP1("x", 1)); VS(f_json_decode("{y:1,}", true), uninit_null()); VS(f_json_decode("{y:1,}", true, k_JSON_FB_LOOSE), CREATE_MAP1("y", 1)); VS(f_json_decode("{,}", true), uninit_null()); VS(f_json_decode("{,}", true, k_JSON_FB_LOOSE), uninit_null()); VS(f_json_decode("[1,2,3,]", true), uninit_null()); VS(f_json_decode("[1,2,3,]", true, k_JSON_FB_LOOSE), CREATE_VECTOR3(1,2,3)); VS(f_json_decode("[,]", true), uninit_null()); VS(f_json_decode("[,]", true, k_JSON_FB_LOOSE), uninit_null()); VS(f_json_decode("[]", true), Array::Create()); VS(f_json_decode("[]", true, k_JSON_FB_LOOSE), Array::Create()); VS(f_json_decode("{}", true), Array::Create()); VS(f_json_decode("{}", true, k_JSON_FB_LOOSE), Array::Create()); VS(f_json_decode("[{\"a\":\"apple\"},{\"b\":\"banana\"}]", true), CREATE_VECTOR2(CREATE_MAP1("a", "apple"), CREATE_MAP1("b", "banana"))); Variant a = "[{\"a\":[{\"n\":\"1st\"}]},{\"b\":[{\"n\":\"2nd\"}]}]"; VS(f_json_decode(a, true), CREATE_VECTOR2 (CREATE_MAP1("a", CREATE_VECTOR1(CREATE_MAP1("n", "1st"))), CREATE_MAP1("b", CREATE_VECTOR1(CREATE_MAP1("n", "2nd"))))); return Count(true); }
bool TestExtFb::test_fb_utf8_strlen() { VS(f_fb_utf8_strlen(""), 0); VS(f_fb_utf8_strlen("a"), 1); VS(f_fb_utf8_strlen("ab"), 2); // Valid UTF-8 sequence returns code point count. VS(f_fb_utf8_strlen("\ub098\ub294"), 2); VS(f_fb_utf8_strlen(INVALID_UTF_8_STRING), 2); for (int i = 0; i < 2; i++) { // Test utf8ize() handling of invalid UTF-8 sequences and how // fb_utf8_strlen() counts them. // RuntimeOption::Utf8izeReplace set to non-zero value replaces invalid // bytes, including '\0' with a special UTF-8 code point: "\uFFFD". // RuntimeOption::Utf8izeReplace set to zero deletes the invalid // byte then continues parsing. RuntimeOption::Utf8izeReplace = (i == 0); { Variant s = String("abc\0def", 7, AttachLiteral); VS(s.toString().size(), 7); VS(f_fb_utf8_strlen(s), 7); f_fb_utf8ize(ref(s)); // Modifies s int ret = s.toString().size(); if (RuntimeOption::Utf8izeReplace) { VS(ret, 9); // '\0' converted to "\uFFFD" } else { VS(ret, 6); // '\0' deleted from s } ret = f_fb_utf8_strlen(s); if (RuntimeOption::Utf8izeReplace) { VS(ret, 7); // '\0' and "\uFFFD" are both one code point, so no change } else { VS(ret, 6); // '\0' deleted, so one fewer code point } } } return Count(true); }
bool TestExtFb::test_fb_utf8_substr() { // Falsey inputs VS(f_fb_utf8_substr("", 0, 0), false); VS(f_fb_utf8_substr("", 0, 1), false); VS(f_fb_utf8_substr("hon\xE7k", 0, INT_MAX), "hon\uFFFDk"); VS(f_fb_utf8_substr("hon\xE7k", 0, 3), "hon"); // Never hits invalid byte VS(f_fb_utf8_substr("hon\xE7k", -4, INT_MAX), "on\uFFFDk"); // Common cases VS(f_fb_utf8_substr("X", 0, 1), "X"); VS(f_fb_utf8_substr("Hello", 0, INT_MAX), "Hello"); VS(f_fb_utf8_substr("Hello", 1, 2), "el"); VS(f_fb_utf8_substr("Pr\u00DC\u00DDx", 2, 2), "\u00DC\u00DD"); // Negative start VS(f_fb_utf8_substr("abcdef", -1, INT_MAX), "f"); VS(f_fb_utf8_substr("abcdef", -2, INT_MAX), "ef"); VS(f_fb_utf8_substr("abcdef", -3, 1), "d"); VS(f_fb_utf8_substr("", -1, 1), false); VS(f_fb_utf8_substr("X", -1, 1), "X"); VS(f_fb_utf8_substr("XY", -1, 1), "Y"); VS(f_fb_utf8_substr("Pr\u00DC\u00DDx", -3, 2), "\u00DC\u00DD"); // Negative lengths VS(f_fb_utf8_substr("abcdef", 0, -1), "abcde"); VS(f_fb_utf8_substr("abcdef", 2, -1), "cde"); VS(f_fb_utf8_substr("abcdef", 4, -4), false); // nothing to return VS(f_fb_utf8_substr("abcdef", -3, -1), "de"); // Invalid sequence VS(f_fb_utf8_substr(INVALID_UTF_8_STRING, 0), "\uFFFD\x28"); return Count(true); }
// fb_utf8_strlen_deprecated() returns byte count on invalid input. bool TestExtFb::test_fb_utf8_strlen_deprecated() { // Invalid UTF-8 sequence fails. VS(f_fb_utf8_strlen_deprecated(INVALID_UTF_8_STRING), 3); return Count(true); }
bool TestExtFb::test_fb_utf8ize() { for (int i = 0; i < 2; i++) { RuntimeOption::Utf8izeReplace = (i == 0); { Variant s = "hon\xE7k"; VERIFY(f_fb_utf8ize(ref(s))); if (RuntimeOption::Utf8izeReplace) { VS(s, "hon\uFFFDk"); } else { VS(s, "honk"); } } { Variant s = "test\xE0\xB0\xB1\xE0"; VERIFY(f_fb_utf8ize(ref(s))); if (RuntimeOption::Utf8izeReplace) { VS(s, "test\xE0\xB0\xB1\uFFFD"); } else { VS(s, "test\xE0\xB0\xB1"); } } { Variant s = "test\xE0\xB0\xB1\xE0\xE0"; VERIFY(f_fb_utf8ize(ref(s))); if (RuntimeOption::Utf8izeReplace) { VS(s, "test\xE0\xB0\xB1\uFFFD\uFFFD"); } else { VS(s, "test\xE0\xB0\xB1"); } } { Variant s = "\xfc"; VERIFY(f_fb_utf8ize(ref(s))); if (RuntimeOption::Utf8izeReplace) { VS(s, "\uFFFD"); } else { VS(s, ""); } } { Variant s = "\xfc\xfc"; VERIFY(f_fb_utf8ize(ref(s))); if (RuntimeOption::Utf8izeReplace) { VS(s, "\uFFFD\uFFFD"); } else { VS(s, ""); } } { // We intentionally consider null bytes invalid sequences. Variant s = String("abc\0def", 7, AttachLiteral); VERIFY(f_fb_utf8ize(ref(s))); if (RuntimeOption::Utf8izeReplace) { VS(s, "abc\uFFFD""def"); } else { VS(s, "abcdef"); } } { // ICU treats this as as two code points. // The old implementation treated this as three code points. Variant s = INVALID_UTF_8_STRING; VERIFY(f_fb_utf8ize(ref(s))); if (RuntimeOption::Utf8izeReplace) { VS(s, "\uFFFD""\x28"); } else { VS(s, "\x28"); } } } return Count(true); }
bool TestExtVariable::test_strval() { VS(f_strval(123), "123"); return Count(true); }
bool TestExtNetwork::test_ip2long() { VS(f_ip2long("127.0.0.1"), 2130706433); return Count(true); }
bool TestExtClass::test_get_declared_classes() { Array classes = f_get_declared_classes(); VS(f_in_array("test", classes, true), true); return Count(true); }
bool TestExtNetwork::test_long2ip() { VS(f_long2ip(2130706433), "127.0.0.1"); return Count(true); }
bool TestExtClass::test_get_declared_interfaces() { Array classes = f_get_declared_interfaces(); VS(f_in_array("itestable", classes, true), true); return Count(true); }
bool TestExtNetwork::test_headers_list() { f_header("Location: http://www.facebook.com"); VS(f_headers_list(), Array()); return Count(true); }
bool TestExtClass::test_get_class_methods() { Array methods = f_get_class_methods("TEst"); VS(methods[0], "foo"); return Count(true); }
bool TestExtNetwork::test_gethostbyname() { VS(f_gethostbyname("localhost"), "127.0.0.1"); return Count(true); }
bool TestExtClass::test_get_class_vars() { Array properties = f_get_class_vars("TEst"); VS(properties, CREATE_MAP1("foo", uninit_null())); return Count(true); }
bool TestExtNetwork::test_getprotobyname() { VS(f_getprotobyname("tcp"), 6); return Count(true); }
bool TestExtClass::test_get_class_constants() { Array constants = f_get_class_constants("test"); VS(constants, CREATE_MAP1("const_foo", "f")); return Count(true); }
bool TestExtNetwork::test_getservbyname() { VS(f_getservbyname("http", "tcp"), 80); return Count(true); }
/* * cmp - chr-substring compare * * Backrefs need this. It should preferably be efficient. * Note that it does not need to report anything except equal/unequal. * Note also that the length is exact, and the comparison should not * stop at embedded NULs! */ static int /* 0 for equal, nonzero for unequal */ cmp(const chr *x, const chr *y, /* strings to compare */ size_t len) /* exact length of comparison */ { return memcmp(VS(x), VS(y), len * sizeof(chr)); }
bool TestExtProcess::test_escapeshellarg() { VS(f_escapeshellarg("\""), "'\"'"); return Count(true); }
bool TestExtNetwork::test_getservbyport() { VS(f_getservbyport(80, "tcp"), "http"); return Count(true); }
bool TestExtString::test_addcslashes() { VS(f_addcslashes("ABCDEFGH\n", "A..D\n"), "\\A\\B\\C\\DEFGH\\n"); VS(f_addcslashes(String("\x00\x0D\n", 3, AttachLiteral), null_string), "\\000\\r\\n"); return Count(true); }
bool TestExtVariable::test_doubleval() { VS(f_doubleval("12.3"), 12.3); return Count(true); }