From 494733bd31e5f14f20e680d40a81e4f001fac11c Mon Sep 17 00:00:00 2001 From: Edwin Smith Date: Mon, 29 Apr 2013 14:25:54 -0400 Subject: [PATCH] Remove Array::operator[](litstr) Refactor the remaining uses of litstr-indexed Array, and get rid of the operator overload. --- hphp/runtime/base/type_array.h | 4 +- hphp/runtime/base/type_variant.h | 5 - hphp/runtime/eval/debugger/cmd/cmd_info.cpp | 105 +++++++++--------- hphp/runtime/eval/debugger/cmd/cmd_list.cpp | 16 ++- .../runtime/eval/debugger/cmd/cmd_machine.cpp | 4 +- .../runtime/eval/debugger/debugger_client.cpp | 38 ++++--- hphp/runtime/ext/ext_imagesprite.cpp | 30 ++--- hphp/runtime/ext/soap/encoding.cpp | 10 +- hphp/test/test_cpp_base.cpp | 18 +-- hphp/test/test_ext_datetime.cpp | 31 ++++-- hphp/test/test_ext_file.cpp | 7 +- hphp/test/test_ext_function.cpp | 3 +- hphp/test/test_ext_imagesprite.cpp | 60 ++++------ hphp/test/test_ext_ipc.cpp | 3 +- hphp/test/test_ext_openssl.cpp | 5 +- hphp/test/test_ext_process.cpp | 23 ++-- hphp/test/test_ext_sqlite3.cpp | 7 +- hphp/test/test_ext_url.cpp | 18 ++- hphp/test/test_logger.cpp | 12 +- 19 files changed, 216 insertions(+), 183 deletions(-) diff --git a/hphp/runtime/base/type_array.h b/hphp/runtime/base/type_array.h index 7806328d8..27ffe54b6 100644 --- a/hphp/runtime/base/type_array.h +++ b/hphp/runtime/base/type_array.h @@ -273,6 +273,7 @@ class Array : protected SmartPtr { const Variant operator[](double key) const; const Variant operator[](CStrRef key) const; const Variant operator[](CVarRef key) const; + const Variant operator[](const char*) const = delete; // use CStrRef Variant &lval(int64_t key) { if (!m_px) ArrayBase::operator=(ArrayData::Create()); @@ -473,9 +474,6 @@ class Array : protected SmartPtr { void setEvalScalar() const; - //litstr overloads - const Variant operator[](litstr key) const; - private: // helpers bool compare(CArrRef v2) const; diff --git a/hphp/runtime/base/type_variant.h b/hphp/runtime/base/type_variant.h index d9ba654d0..00f6091bd 100644 --- a/hphp/runtime/base/type_variant.h +++ b/hphp/runtime/base/type_variant.h @@ -1495,11 +1495,6 @@ inline Variant uninit_null() { return Variant(); } -//litstr overloads -inline const Variant Array::operator[](litstr key) const { - return (*this)[String(key)]; -} - /////////////////////////////////////////////////////////////////////////////// } diff --git a/hphp/runtime/eval/debugger/cmd/cmd_info.cpp b/hphp/runtime/eval/debugger/cmd/cmd_info.cpp index 1679ced77..02dda78e3 100644 --- a/hphp/runtime/eval/debugger/cmd/cmd_info.cpp +++ b/hphp/runtime/eval/debugger/cmd/cmd_info.cpp @@ -23,28 +23,31 @@ namespace HPHP { namespace Eval { /////////////////////////////////////////////////////////////////////////////// -static const StaticString s_params("params"); -static const StaticString s_ref("ref"); -static const StaticString s_name("name"); -static const StaticString s_varg("varg"); -static const StaticString s_type("type"); -static const StaticString s_default("default"); -static const StaticString s_defaultext("defaultext"); -static const StaticString s_msg("msg"); -static const StaticString s_constants("constants"); -static const StaticString s_methods("methods"); -static const StaticString s_access("access"); -static const StaticString s_static("static"); -static const StaticString s_abstract("abstract"); -static const StaticString s_final("final"); -static const StaticString s_doc("doc"); -static const StaticString s_internal("internal"); -static const StaticString s_file("file"); -static const StaticString s_line1("line1"); -static const StaticString s_line2("line2"); -static const StaticString s_properties("properties"); -static const StaticString s_private_properties("private_properties"); -static const StaticString s_defaultText("defaultText"); +static const StaticString + s_params("params"), + s_ref("ref"), + s_name("name"), + s_varg("varg"), + s_type("type"), + s_default("default"), + s_msg("msg"), + s_constants("constants"), + s_methods("methods"), + s_access("access"), + s_static("static"), + s_abstract("abstract"), + s_final("final"), + s_doc("doc"), + s_internal("internal"), + s_file("file"), + s_line1("line1"), + s_line2("line2"), + s_properties("properties"), + s_private_properties("private_properties"), + s_defaultText("defaultText"), + s_parent("parent"), + s_interfaces("interfaces"), + s_interface("interface"); void CmdInfo::sendImpl(DebuggerThriftBuffer &thrift) { DebuggerCommand::sendImpl(thrift); @@ -423,19 +426,19 @@ bool CmdInfo::TryMethod(DebuggerClient *client, StringBuffer &sb, CArrRef info, subsymbol = subsymbol.substr(0, subsymbol.size() - 2); } - String key = FindSubSymbol(info["methods"], subsymbol); + String key = FindSubSymbol(info[s_methods], subsymbol); if (!key.isNull()) { - Array func = info["methods"][key].toArray(); + Array func = info[s_methods][key].toArray(); PrintHeader(client, sb, func); sb.printf("%s %s%s%sfunction %s::%s%s(%s);\n", func[s_access].toString().data(), GetModifier(func, s_static).data(), GetModifier(func, s_final).data(), GetModifier(func, s_abstract).data(), - info["name"].toString().data(), - func["ref"].toBoolean() ? "&" : "", - func["name"].toString().data(), - GetParams(func["params"], func["varg"], true).data()); + info[s_name].toString().data(), + func[s_ref].toBoolean() ? "&" : "", + func[s_name].toString().data(), + GetParams(func[s_params], func[s_varg], true).data()); return true; } return false; @@ -464,16 +467,16 @@ void CmdInfo::PrintInfo(DebuggerClient *client, StringBuffer &sb, CArrRef info, PrintHeader(client, sb, info); StringBuffer parents; - String parent = info["parent"].toString(); + String parent = info[s_parent].toString(); if (!parent.empty()) { parents.append("extends "); parents.append(parent); parents.append(' '); } - if (!info["interfaces"].toArray().empty()) { + if (!info[s_interfaces].toArray().empty()) { parents.append("implements "); bool first = true; - for (ArrayIter iter(info["interfaces"]); iter; ++iter) { + for (ArrayIter iter(info[s_interfaces]); iter; ++iter) { if (first) { first = false; } else { @@ -488,52 +491,52 @@ void CmdInfo::PrintInfo(DebuggerClient *client, StringBuffer &sb, CArrRef info, sb.printf("%s%s%s %s %s{\n", GetModifier(info, s_final).data(), GetModifier(info, s_abstract).data(), - info["interface"].toBoolean() ? "interface" : "class", - info["name"].toString().data(), + info[s_interface].toBoolean() ? "interface" : "class", + info[s_name].toString().data(), parent.data()); - if (!info["constants"].toArray().empty()) { + if (!info[s_constants].toArray().empty()) { sb.printf(" // constants\n"); - for (ArrayIter iter(info["constants"]); iter; ++iter) { + for (ArrayIter iter(info[s_constants]); iter; ++iter) { sb.printf(" const %s = %s;\n", iter.first().toString().data(), DebuggerClient::FormatVariable(iter.second()).data()); } } - if (!info["properties"].toArray().empty() || - !info["private_properties"].toArray().empty()) { + if (!info[s_properties].toArray().empty() || + !info[s_private_properties].toArray().empty()) { sb.printf(" // properties\n"); - for (ArrayIter iter(info["properties"]); iter; ++iter) { + for (ArrayIter iter(info[s_properties]); iter; ++iter) { Array prop = iter.second().toArray(); sb.printf(" %s%s %s$%s;\n", - prop["doc"].toBoolean() ? "[doc] " : "", - prop["access"].toString().data(), + prop[s_doc].toBoolean() ? "[doc] " : "", + prop[s_access].toString().data(), GetModifier(prop, s_static).data(), - prop["name"].toString().data()); + prop[s_name].toString().data()); } - for (ArrayIter iter(info["private_properties"]); iter; ++iter) { + for (ArrayIter iter(info[s_private_properties]); iter; ++iter) { Array prop = iter.second().toArray(); sb.printf(" %sprivate %s$%s;\n", - prop["doc"].toBoolean() ? "[doc] " : "", + prop[s_doc].toBoolean() ? "[doc] " : "", GetModifier(prop, s_static).data(), - prop["name"].toString().data()); + prop[s_name].toString().data()); } } - if (!info["methods"].toArray().empty()) { + if (!info[s_methods].toArray().empty()) { sb.printf(" // methods\n"); - for (ArrayIter iter(info["methods"]); iter; ++iter) { + for (ArrayIter iter(info[s_methods]); iter; ++iter) { Array func = iter.second().toArray(); sb.printf(" %s%s %s%s%sfunction %s%s(%s);\n", - func["doc"].toBoolean() ? "[doc] " : "", - func["access"].toString().data(), + func[s_doc].toBoolean() ? "[doc] " : "", + func[s_access].toString().data(), GetModifier(func, s_static).data(), GetModifier(func, s_final).data(), GetModifier(func, s_abstract).data(), - func["ref"].toBoolean() ? "&" : "", - func["name"].toString().data(), - GetParams(func["params"], func["varg"]).data()); + func[s_ref].toBoolean() ? "&" : "", + func[s_name].toString().data(), + GetParams(func[s_params], func[s_varg]).data()); } } diff --git a/hphp/runtime/eval/debugger/cmd/cmd_list.cpp b/hphp/runtime/eval/debugger/cmd/cmd_list.cpp index 5c53f5772..b37a2cdf8 100644 --- a/hphp/runtime/eval/debugger/cmd/cmd_list.cpp +++ b/hphp/runtime/eval/debugger/cmd/cmd_list.cpp @@ -121,6 +121,12 @@ bool CmdList::listFileRange(DebuggerClient *client, int line, return false; } +static const StaticString + s_methods("methods"), + s_file("file"), + s_line1("line2"), + s_line2("line2"); + bool CmdList::listFunctionOrClass(DebuggerClient *client) { assert(client->argCount() == 1); CmdInfoPtr cmdInfo(new CmdInfo()); @@ -134,13 +140,13 @@ bool CmdList::listFunctionOrClass(DebuggerClient *client) { ArrayIter iter(info); Array funcInfo = iter.second(); if (!subsymbol.empty()) { - String key = CmdInfo::FindSubSymbol(funcInfo["methods"], subsymbol); + String key = CmdInfo::FindSubSymbol(funcInfo[s_methods], subsymbol); if (key.isNull()) return false; - funcInfo = funcInfo["methods"][key].toArray(); + funcInfo = funcInfo[s_methods][key].toArray(); } - String file = funcInfo["file"].toString(); - int line1 = funcInfo["line1"].toInt32(); - int line2 = funcInfo["line2"].toInt32(); + String file = funcInfo[s_file].toString(); + int line1 = funcInfo[s_line1].toInt32(); + int line2 = funcInfo[s_line2].toInt32(); int line = line1 ? line1 : line2; if (file.empty() || !line) return false; client->setListLocation(file.data(), line - 1, false); diff --git a/hphp/runtime/eval/debugger/cmd/cmd_machine.cpp b/hphp/runtime/eval/debugger/cmd/cmd_machine.cpp index 2bd7914e0..752c79e05 100644 --- a/hphp/runtime/eval/debugger/cmd/cmd_machine.cpp +++ b/hphp/runtime/eval/debugger/cmd/cmd_machine.cpp @@ -287,11 +287,11 @@ bool CmdMachine::onClient(DebuggerClient *client) { bool CmdMachine::onServer(DebuggerProxy *proxy) { if (m_body == "rpc") { - String host = m_rpcConfig["host"].toString(); + String host = m_rpcConfig[s_host].toString(); if (host.empty()) { register_intercept("", false, uninit_null()); } else { - int port = m_rpcConfig["port"].toInt32(); + int port = m_rpcConfig[s_port].toInt32(); LibEventHttpClient::SetCache(host.data(), port, 1); register_intercept("", "fb_rpc_intercept_handler", m_rpcConfig); } diff --git a/hphp/runtime/eval/debugger/debugger_client.cpp b/hphp/runtime/eval/debugger/debugger_client.cpp index 7e2647588..82484741e 100644 --- a/hphp/runtime/eval/debugger/debugger_client.cpp +++ b/hphp/runtime/eval/debugger/debugger_client.cpp @@ -1156,17 +1156,19 @@ String DebuggerClient::getPrintString() { return s; } -static const StaticString s_output_type("output_type"); -static const StaticString s_file("file"); -static const StaticString s_line_no("line_no"); -static const StaticString s_watch_values("watch_values"); -static const StaticString s_stacktrace("stacktrace"); -static const StaticString s_frame("frame"); -static const StaticString s_values("values"); -static const StaticString s_text("text"); -static const StaticString s_invalid("invalid"); -static const StaticString s_cmd("cmd"); -static const StaticString s_code_loc("code_loc"); +static const StaticString + s_output_type("output_type"), + s_file("file"), + s_line("line"), + s_line_no("line_no"), + s_watch_values("watch_values"), + s_stacktrace("stacktrace"), + s_frame("frame"), + s_values("values"), + s_text("text"), + s_invalid("invalid"), + s_cmd("cmd"), + s_code_loc("code_loc"); Array DebuggerClient::getOutputArray() { TRACE(2, "DebuggerClient::getOutputArray\n"); @@ -2074,8 +2076,8 @@ void DebuggerClient::moveToFrame(int index, bool display /* = true */) { } CArrRef frame = m_stacktrace[m_frame]; if (!frame.isNull()) { - String file = frame["file"]; - int line = frame["line"].toInt32(); + String file = frame[s_file]; + int line = frame[s_line].toInt32(); if (!file.empty() && line) { if (m_frame == 0) { m_listFile.clear(); @@ -2091,11 +2093,11 @@ void DebuggerClient::moveToFrame(int index, bool display /* = true */) { } } -static const StaticString s_args("args"); -static const StaticString s_namespace("namespace"); -static const StaticString s_class("class"); -static const StaticString s_function("function"); -static const StaticString s_line("line"); +static const StaticString + s_args("args"), + s_namespace("namespace"), + s_class("class"), + s_function("function"); void DebuggerClient::printFrame(int index, CArrRef frame) { TRACE(2, "DebuggerClient::printFrame\n"); diff --git a/hphp/runtime/ext/ext_imagesprite.cpp b/hphp/runtime/ext/ext_imagesprite.cpp index fa6f21c1f..73d6c37fb 100644 --- a/hphp/runtime/ext/ext_imagesprite.cpp +++ b/hphp/runtime/ext/ext_imagesprite.cpp @@ -30,14 +30,16 @@ namespace HPHP { /////////////////////////////////////////////////////////////////////////////// -static const StaticString s_padding_top("padding_top"); -static const StaticString s_padding_right("padding_right"); -static const StaticString s_padding_bottom("padding_bottom"); -static const StaticString s_padding_left("padding_left"); -static const StaticString s_width("width"); -static const StaticString s_height("height"); -static const StaticString s_flush_left("flush_left"); -static const StaticString s_flush_right("flush_right"); +static const StaticString + s_padding_top("padding_top"), + s_padding_right("padding_right"), + s_padding_bottom("padding_bottom"), + s_padding_left("padding_left"), + s_width("width"), + s_height("height"), + s_flush_left("flush_left"), + s_flush_right("flush_right"), + s_id("id"); namespace ImageSprite { @@ -611,11 +613,11 @@ Object c_ImageSprite::t_loadimages(bool block /* = false */) { std::vector, \ ImageSprite::BlockAreaComparator> -static const StaticString s_x("x"); -static const StaticString s_y("y"); -static const StaticString s_id("id"); -static const StaticString s_images("images"); -static const StaticString s_sprite("sprite"); +static const StaticString + s_x("x"), + s_y("y"), + s_images("images"), + s_sprite("sprite"); void c_ImageSprite::map() { if (same(m_current, true)) { @@ -1107,7 +1109,7 @@ String c_ImageSprite::t_css(CStrRef css_namespace, output += String("/* File: ") + path + " */\n"; } - output += String(".") + css_namespace + "#i" + attr["id"] + "{"; + output += String(".") + css_namespace + "#i" + attr[s_id] + "{"; if (verbose) output += "\n "; output += "background-position:"; diff --git a/hphp/runtime/ext/soap/encoding.cpp b/hphp/runtime/ext/soap/encoding.cpp index d7bd31762..c4791883c 100644 --- a/hphp/runtime/ext/soap/encoding.cpp +++ b/hphp/runtime/ext/soap/encoding.cpp @@ -1354,10 +1354,12 @@ static Variant to_zval_object_ex(encodeTypePtr type, xmlNodePtr data, String clsname; if (pce) { ce = pce; - } else if (!SOAP_GLOBAL(classmap).empty() && !type->type_str.empty() && - SOAP_GLOBAL(classmap).exists(String(type->type_str))) { - clsname = SOAP_GLOBAL(classmap)[type->type_str.c_str()].toString(); - ce = clsname.data(); + } else if (!SOAP_GLOBAL(classmap).empty() && !type->type_str.empty()) { + String type_str(type->type_str); + if (SOAP_GLOBAL(classmap).exists(type_str)) { + clsname = SOAP_GLOBAL(classmap)[type_str].toString(); + ce = clsname.data(); + } } Variant ret; diff --git a/hphp/test/test_cpp_base.cpp b/hphp/test/test_cpp_base.cpp index d78471adc..fb7c8712e 100644 --- a/hphp/test/test_cpp_base.cpp +++ b/hphp/test/test_cpp_base.cpp @@ -257,22 +257,22 @@ bool TestCppBase::TestArray() { arr = Array::Create("name", 1); VERIFY(!arr.empty()); VERIFY(arr.size() == 1); VERIFY(arr.length() == 1); VERIFY(!arr.isNull()); - VERIFY((int)arr["name"] == 1); - VS(arr, Array(ArrayInit(1).set("name", 1).create())); + VERIFY((int)arr[s_name] == 1); + VS(arr, Array(ArrayInit(1).set(s_name, 1).create())); - arr = Array::Create("name", "test"); + arr = Array::Create(s_name, "test"); VERIFY(!arr.empty()); VERIFY(arr.size() == 1); VERIFY(arr.length() == 1); VERIFY(!arr.isNull()); - VERIFY(arr["name"] == "test"); - VS(arr, Array(ArrayInit(1).set("name", "test").create())); + VERIFY(arr[s_name] == "test"); + VS(arr, Array(ArrayInit(1).set(s_name, "test").create())); arrCopy = arr; - arr = Array::Create("name", arr); + arr = Array::Create(s_name, arr); VERIFY(!arr.empty()); VERIFY(arr.size() == 1); VERIFY(arr.length() == 1); VERIFY(!arr.isNull()); - VS(arr["name"], arrCopy); - VERIFY(arr["name"].toArray().size() == 1); - VS(arr, Array(ArrayInit(1).set("name", arrCopy).create())); + VS(arr[s_name], arrCopy); + VERIFY(arr[s_name].toArray().size() == 1); + VS(arr, Array(ArrayInit(1).set(s_name, arrCopy).create())); } // iteration diff --git a/hphp/test/test_ext_datetime.cpp b/hphp/test/test_ext_datetime.cpp index b5ea8a691..8d714a232 100644 --- a/hphp/test/test_ext_datetime.cpp +++ b/hphp/test/test_ext_datetime.cpp @@ -154,18 +154,25 @@ bool TestExtDatetime::test_date_format() { return Count(true); } +static const StaticString + s_warning_count("warning_count"), + s_error_count("error_count"), + s_warnings("warnings"), + s_errors("errors"), + s_sec("sec"); + bool TestExtDatetime::test_date_get_last_errors() { Object dt = f_date_create("asdfasdf"); Array errs = f_date_get_last_errors(); VS(errs.size(), 4); - VS(errs["warning_count"], 1); - Array err_warnings = errs["warnings"]; + VS(errs[s_warning_count], 1); + Array err_warnings = errs[s_warnings]; VS(err_warnings.size(), 1); VS(err_warnings[6], "Double timezone specification"); - VS(errs["error_count"], 1); - Array err_errors = errs["errors"]; + VS(errs[s_error_count], 1); + Array err_errors = errs[s_errors]; VS(err_errors.size(), 1); VS(err_errors[0], "The timezone could not be found in the database"); @@ -405,7 +412,7 @@ bool TestExtDatetime::test_getdate() { bool TestExtDatetime::test_gettimeofday() { Array ret = f_gettimeofday(); VS(ret.size(), 4); - VERIFY(more(ret["sec"], 1073504408)); + VERIFY(more(ret[s_sec], 1073504408)); VERIFY(more(f_gettimeofday(true), 1073504408.23910)); return Count(true); @@ -638,15 +645,21 @@ bool TestExtDatetime::test_timezone_identifiers_list() { return Count(true); } +static const StaticString + s_country_code("country_code"), + s_latitude("latitude"), + s_longitude("longitude"), + s_comments("comments"); + bool TestExtDatetime::test_timezone_location_get() { TIMELIB_TEST_UNIMPL(2011.1, Object tz = f_timezone_open("Europe/Prague"); Array loc = f_timezone_location_get(tz); VS(loc.size(), 4); - VS(loc["country_code"].toString(), "CZ"); - VS((int)(loc["latitude"].toDoubleVal() * 100), 5008); - VS((int)(loc["longitude"].toDoubleVal() * 100), 1443); - VS(loc["comments"].toString(), ""); + VS(loc[s_country_code].toString(), "CZ"); + VS((int)(loc[s_latitude].toDoubleVal() * 100), 5008); + VS((int)(loc[s_longitude].toDoubleVal() * 100), 1443); + VS(loc[s_comments].toString(), ""); return Count(true); ); } diff --git a/hphp/test/test_ext_file.cpp b/hphp/test/test_ext_file.cpp index d13f9532f..291923b86 100644 --- a/hphp/test/test_ext_file.cpp +++ b/hphp/test/test_ext_file.cpp @@ -920,11 +920,14 @@ bool TestExtFile::test_chroot() { } bool TestExtFile::test_dir() { + static const StaticString s_handle("handle"); + static const StaticString s_test_ext_file_txt("test_ext_file.txt"); + static const StaticString s_path("path"); Variant d = f_dir("test"); - VS(d.toArray()["path"], "test"); + VS(d.toArray()[s_path], "test"); Variant entry; bool seen = false; - while (!same(entry = f_readdir(d.toArray()["handle"]), false)) { + while (!same(entry = f_readdir(d.toArray()[s_handle]), false)) { if (same(entry, "test_ext_file.txt")) { seen = true; } diff --git a/hphp/test/test_ext_function.cpp b/hphp/test/test_ext_function.cpp index c1ce4faf7..3f35a6835 100644 --- a/hphp/test/test_ext_function.cpp +++ b/hphp/test/test_ext_function.cpp @@ -49,8 +49,9 @@ bool TestExtFunction::RunTests(const std::string &which) { /////////////////////////////////////////////////////////////////////////////// bool TestExtFunction::test_get_defined_functions() { + static const StaticString s_internal("internal"); Array funcs = f_get_defined_functions(); - VERIFY(!funcs["internal"][0].toString().empty()); + VERIFY(!funcs[s_internal][0].toString().empty()); return Count(true); } diff --git a/hphp/test/test_ext_imagesprite.cpp b/hphp/test/test_ext_imagesprite.cpp index fba69cfbc..7b952df64 100644 --- a/hphp/test/test_ext_imagesprite.cpp +++ b/hphp/test/test_ext_imagesprite.cpp @@ -177,8 +177,9 @@ bool TestExtImagesprite::test_clear() { return Count(true); } -static const StaticString s_width("width"); -static const StaticString s_height("height"); +static const StaticString + s_width("width"), + s_height("height"); bool TestExtImagesprite::test_loadDims() { sprite->t_addfile("test/images/php.gif"); @@ -254,25 +255,21 @@ bool TestExtImagesprite::test_loadImages() { return Count(true); } bool TestExtImagesprite::test_map() { - sprite->t_addfile("test/images/php.gif"); + static const StaticString + s_images("images"), + s_width("width"), + s_height("height"), + s_x("x"), + s_y("y"), + testpath("test/images/php.gif"); + + sprite->t_addfile(testpath); VS(sprite->m_current, false); Array map = sprite->t_mapping(); - VS( - map["images"].toArray()["test/images/php.gif"].toArray() - ["width"].toInt32(), - 120); - VS( - map["images"].toArray()["test/images/php.gif"].toArray() - ["height"].toInt32(), - 67); - VS( - map["images"].toArray()["test/images/php.gif"].toArray() - ["x"].toInt32(), - 0); - VS( - map["images"].toArray()["test/images/php.gif"].toArray() - ["y"].toInt32(), - 0); + VS(map[s_images].toArray()[testpath].toArray()[s_width].toInt32(), 120); + VS(map[s_images].toArray()[testpath].toArray()[s_height].toInt32(), 67); + VS(map[s_images].toArray()[testpath].toArray()[s_x].toInt32(), 0); + VS(map[s_images].toArray()[testpath].toArray()[s_y].toInt32(), 0); VS(map[s_width].toInt32(), 121); VS(map[s_height].toInt32(), 68); VS(sprite->m_current, true); @@ -281,26 +278,15 @@ bool TestExtImagesprite::test_map() { Array dims = Array::Create(); dims.set(s_width, 1); dims.set(s_height, 1); - sprite->t_addfile("test/images/php.gif", dims); + sprite->t_addfile(testpath, dims); VS(sprite->m_current, false); map = sprite->t_mapping(); - VS( - map["images"].toArray()["test/images/php.gif"].toArray() - ["width"].toInt32(), - 1); - VS( - map["images"].toArray()["test/images/php.gif"].toArray() - ["height"].toInt32(), - 1); - VS( - map["images"].toArray()["test/images/php.gif"].toArray() - ["x"].toInt32(), 0); - VS( - map["images"].toArray()["test/images/php.gif"].toArray() - ["y"].toInt32(), - 0); - VS(map["width"].toInt32(), 2); - VS(map["height"].toInt32(), 2); + VS(map[s_images].toArray()[testpath].toArray()[s_width].toInt32(), 1); + VS(map[s_images].toArray()[testpath].toArray()[s_height].toInt32(), 1); + VS(map[s_images].toArray()[testpath].toArray()[s_x].toInt32(), 0); + VS(map[s_images].toArray()[testpath].toArray()[s_y].toInt32(), 0); + VS(map[s_width].toInt32(), 2); + VS(map[s_height].toInt32(), 2); VS(sprite->m_current, true); return Count(true); diff --git a/hphp/test/test_ext_ipc.cpp b/hphp/test/test_ext_ipc.cpp index a4f3c7a71..3c01408eb 100644 --- a/hphp/test/test_ext_ipc.cpp +++ b/hphp/test/test_ext_ipc.cpp @@ -52,6 +52,7 @@ bool TestExtIpc::RunTests(const std::string &which) { /////////////////////////////////////////////////////////////////////////////// bool TestExtIpc::test_message_queue() { + static const StaticString s_msg_qnum("msg_qnum"); char filename[64]; strcpy(filename, "/tmp/XXXXXX"); close(mkstemp(filename)); @@ -82,7 +83,7 @@ bool TestExtIpc::test_message_queue() { VERIFY(same(msg, "ok")); Array ret = f_msg_stat_queue(queue); - VS(ret["msg_qnum"], 0); + VS(ret[s_msg_qnum], 0); f_msg_set_queue(queue, CREATE_MAP1("msg_perm.mode", 0666)); f_msg_remove_queue(queue); diff --git a/hphp/test/test_ext_openssl.cpp b/hphp/test/test_ext_openssl.cpp index c069f2395..426152944 100644 --- a/hphp/test/test_ext_openssl.cpp +++ b/hphp/test/test_ext_openssl.cpp @@ -324,19 +324,20 @@ bool TestExtOpenssl::test_openssl_pkey_free() { } bool TestExtOpenssl::test_openssl_pkey_get_details() { + static const StaticString s_bits("bits"); { Variant fkey = f_file_get_contents("test/test_public.pem"); Variant k = f_openssl_pkey_get_public(fkey); VERIFY(!same(k, false)); VERIFY(!k.isNull()); - VS(f_openssl_pkey_get_details(k)["bits"], 1024); + VS(f_openssl_pkey_get_details(k)[s_bits], 1024); } { Variant fkey = f_file_get_contents("test/test_private.pem"); Variant k = f_openssl_pkey_get_private(fkey); VERIFY(!same(k, false)); VERIFY(!k.isNull()); - VS(f_openssl_pkey_get_details(k)["bits"], 512); + VS(f_openssl_pkey_get_details(k)[s_bits], 512); } return Count(true); } diff --git a/hphp/test/test_ext_process.cpp b/hphp/test/test_ext_process.cpp index ba373e4cf..8457d60a5 100644 --- a/hphp/test/test_ext_process.cpp +++ b/hphp/test/test_ext_process.cpp @@ -362,6 +362,15 @@ bool TestExtProcess::test_proc_close() { } bool TestExtProcess::test_proc_get_status() { + static const StaticString + s_command("command"), + s_pid("pid"), + s_running("running"), + s_signaled("signaled"), + s_exitcode("exitcode"), + s_termsig("termsig"), + s_stopsig("stopsig"); + Array descriptorspec = CREATE_MAP3(0, CREATE_VECTOR2("pipe", "r"), 1, CREATE_VECTOR2("pipe", "w"), @@ -370,13 +379,13 @@ bool TestExtProcess::test_proc_get_status() { Variant process = f_proc_open(php_path, descriptorspec, ref(pipes)); VERIFY(!same(process, false)); Array ret = f_proc_get_status(process.toObject()); - VS(ret["command"], php_path); - VERIFY(ret["pid"].toInt32() > 0); - VERIFY(ret["running"]); - VERIFY(!ret["signaled"]); - VS(ret["exitcode"], -1); - VS(ret["termsig"], 0); - VS(ret["stopsig"], 0); + VS(ret[s_command], php_path); + VERIFY(ret[s_pid].toInt32() > 0); + VERIFY(ret[s_running]); + VERIFY(!ret[s_signaled]); + VS(ret[s_exitcode], -1); + VS(ret[s_termsig], 0); + VS(ret[s_stopsig], 0); { File *f = pipes[0].toObject().getTyped(); diff --git a/hphp/test/test_ext_sqlite3.cpp b/hphp/test/test_ext_sqlite3.cpp index 1b8c532d3..118aa0322 100644 --- a/hphp/test/test_ext_sqlite3.cpp +++ b/hphp/test/test_ext_sqlite3.cpp @@ -115,9 +115,12 @@ bool TestExtSqlite3::test_sqlite3() { db->t_close(); + static const StaticString s_versionString("versionString"); + static const StaticString s_versionNumber("versionNumber"); + // Since minor version can change frequently, just test the major version - VS(db->t_version()["versionString"][0], "3"); - VERIFY((int64_t)db->t_version()["versionNumber"] > + VS(db->t_version()[s_versionString][0], "3"); + VERIFY((int64_t)db->t_version()[s_versionNumber] > (int64_t)3000000); f_unlink(":memory:test"); return Count(true); diff --git a/hphp/test/test_ext_url.cpp b/hphp/test/test_ext_url.cpp index e8bd16499..5c28cbac4 100644 --- a/hphp/test/test_ext_url.cpp +++ b/hphp/test/test_ext_url.cpp @@ -59,23 +59,29 @@ bool TestExtUrl::test_base64_encode() { } bool TestExtUrl::test_get_headers() { + static const StaticString s_Connection("Connection"); String url = "http://www.example.com"; Array ret = f_get_headers(url); //VS(ret[0], "HTTP/1.1 200 OK"); VERIFY(ret.size() > 0); ret = f_get_headers(url, 1); - //VS(ret["Connection"], "close"); - VERIFY(!ret["Connection"].toString().empty()); + //VS(ret[s_Connection], "close"); + VERIFY(!ret[s_Connection].toString().empty()); return Count(true); } bool TestExtUrl::test_get_meta_tags() { + static const StaticString + s_author("author"), + s_keywords("keywords"), + s_description("description"), + s_geo_position("geo_position"); Array ret = f_get_meta_tags("test/test_get_meta_tags.html"); VS(ret.size(), 4); - VS(ret["author"], "name"); - VS(ret["keywords"], "php documentation"); - VS(ret["description"], "a php manual"); - VS(ret["geo_position"], "49.33;-86.59"); + VS(ret[s_author], "name"); + VS(ret[s_keywords], "php documentation"); + VS(ret[s_description], "a php manual"); + VS(ret[s_geo_position], "49.33;-86.59"); return Count(true); } diff --git a/hphp/test/test_logger.cpp b/hphp/test/test_logger.cpp index 66bcd2bd2..dd774e671 100644 --- a/hphp/test/test_logger.cpp +++ b/hphp/test/test_logger.cpp @@ -27,6 +27,9 @@ using namespace HPHP; /////////////////////////////////////////////////////////////////////////////// +static const StaticString + s_result("result"), + s_runId("runId"); bool TestLogger::initializeRun() { if (!doLog()) @@ -51,12 +54,11 @@ bool TestLogger::initializeRun() { Array response = postData(CREATE_MAP1("runData", dataArr)); - if (!response["result"]) { + if (!response[s_result]) { return false; } - run_id = response["result"]["runId"]; - + run_id = response[s_result][s_runId]; return true; } @@ -70,7 +72,7 @@ bool TestLogger::finishRun() { "runData", CREATE_MAP1("stillRunning", false)); Array response = postData(data); - if (response["result"]) + if (response[s_result]) return true; return false; } @@ -86,7 +88,7 @@ bool TestLogger::logTest(Array test) { "tests", CREATE_VECTOR1(test)); Array response = postData(data); - if (response["result"]) + if (response[s_result]) return true; return false; }