std::string expected_str(IndexedMemoryRef imr) { std::ostringstream out; // See above about the rbp/r13 thing. if (imr.r.base == rbp || imr.r.base == r13 || imr.r.disp != 0) { expected_disp_str(imr.r.disp, out); } out << '(' << expected_str(imr.r.base) << ',' << expected_str(imr.r.index) << ',' << imr.r.scale << ')'; return out.str(); }
std::string expected_str(MemoryRef mr) { std::ostringstream out; if (mr.r.disp != 0) { expected_disp_str(mr.r.disp, out); } if (int(mr.r.index) != -1) { out << '(' << expected_str(mr.r.base) << ',' << expected_str(mr.r.index) << ',' << mr.r.scale << ')'; } else { out << '(' << expected_str(mr.r.base) << ')'; } return out.str(); }
void dotest(const char* opName, Asm& a, void (Asm::*memFn)(Arg1, Arg2), const std::vector<Arg1>& args1, const std::vector<Arg2>& args2) { std::vector<std::string> expecteds; for (auto& ar1 : args1) { for (auto& ar2 : args2) { expecteds.push_back( folly::format("{}, {}", expected_str(ar1), expected_str(ar2)).str() ); (a.*memFn)(ar1, ar2); } } auto const dump = dump_disasm(a); compare(opName, dump, expecteds); a.clear(); }
void dotest(const char* opName, Asm& a, void (Asm::*memFn)(Arg1, Arg2), const std::vector<Arg1>& args1, const std::vector<Arg2>& args2) { std::vector<std::string> expecteds; for (auto& ar1 : args1) { for (auto& ar2 : args2) { expecteds.push_back(str( boost::format("%s,%s") % expected_str(ar1) % expected_str(ar2) )); (a.*memFn)(ar1, ar2); } } std::ifstream dump; dump_disasm(a, dump); compare(opName, dump, expecteds); a.clear(); }
void dotest(const char* opName, Asm& a, void (Asm::*memFn)(Arg1, Arg2)) { std::vector<std::string> expecteds; auto& args1 = Gen<Arg1>::gen(); for (auto& ar1 : args1) { auto& args2 = Gen<Arg2>::gen(); for (auto& ar2 : args2) { expecteds.push_back(str( boost::format("%s,%s") % expected_str(ar1) % expected_str(ar2) )); (a.*memFn)(ar1, ar2); } } std::ifstream dump; dump_disasm(a, dump); compare(opName, dump, expecteds); a.code.frontier = a.code.base; }
void dotest(const char* opName, Asm& a, void (Asm::*memFn)(Arg)) { std::vector<std::string> expecteds; auto& args = Gen<Arg>::gen(); for (auto& ar : args) { expecteds.push_back(expected_str(ar)); (a.*memFn)(ar); } auto const dump = dump_disasm(a); compare(opName, dump, expecteds); a.clear(); }
void dotest(const char* opName, Asm& a, void (Asm::*memFn)(Arg)) { std::vector<std::string> expecteds; auto& args = Gen<Arg>::gen(); for (auto& ar : args) { expecteds.push_back(expected_str(ar)); (a.*memFn)(ar); } std::ifstream dump; dump_disasm(a, dump); compare(opName, dump, expecteds); a.code.frontier = a.code.base; }
std::string expected_str(MemoryRef mr) { std::ostringstream out; /* * Operations with "rbp-like" registers still are encoded with a * displacement byte, even if the displacement is zero. This wouldn't * matter, but objdump displays the zero displacements for these * registers (presumably because of this), so we have to add it to our * expected string in that case. */ if (mr.r.base == rbp || mr.r.base == r13 || mr.r.disp != 0) { expected_disp_str(mr.r.disp, out); } out << '(' << expected_str(mr.r.base) << ')'; return out.str(); }
void sd_object::test<10>() { std::string message("parcel '' is naughty."); std::stringstream str; str << "{'message':'" << LLSDNotationFormatter::escapeString(message) << "'}"; std::string expected_str("{'message':'parcel \\'\\' is naughty.'}"); std::string actual_str = str.str(); ensure_equals("stream contents", actual_str, expected_str); LLSD sd; S32 count = LLSDSerialize::fromNotation(sd, str, actual_str.size()); ensure_equals("parse count", count, 2); ensure("valid parse", sd.isDefined()); std::string actual = sd["message"].asString(); ensure_equals("message contents", actual, message); }
TEST(CPDF_LinkExtractTest, CheckMailLink) { CPDF_TestLinkExtract extractor; // Check cases that fail to extract valid mail link. const wchar_t* const invalid_strs[] = { L"", L"peter.pan", // '@' is required. L"abc@server", // Domain name needs at least one '.'. L"*****@*****.**", // '.' can not immediately precede '@'. L"abc@xyz&q.org", // Domain name should not contain '&'. L"*****@*****.**", // Domain name should not start with '.'. L"*****@*****.**" // Domain name should not have consecutive '.' }; for (size_t i = 0; i < FX_ArraySize(invalid_strs); ++i) { const wchar_t* const input = invalid_strs[i]; WideString text_str(input); EXPECT_FALSE(extractor.CheckMailLink(&text_str)) << input; } // Check cases that can extract valid mail link. // An array of {input_string, expected_extracted_email_address}. const wchar_t* const valid_strs[][2] = { {L"[email protected]", L"[email protected]"}, {L"*****@*****.**", L"*****@*****.**"}, {L"*****@*****.**", L"*****@*****.**"}, // '_' is ok before '@'. {L"*****@*****.**", L"*****@*****.**"}, // '-' is ok in user name. {L"*****@*****.**", L"*****@*****.**"}, // Stop at consecutive '.'. {L"*****@*****.**", L"*****@*****.**"}, // Remove heading '.'. {L"[email protected]?/", L"*****@*****.**"}, // Trim ending invalid chars. {L"fan{[email protected]", L"*****@*****.**"}, // Trim beginning invalid chars. {L"[email protected]..", L"*****@*****.**"}, // Trim the ending periods. {L"*****@*****.**", L"*****@*****.**"}, // Keep the original case. }; for (size_t i = 0; i < FX_ArraySize(valid_strs); ++i) { const wchar_t* const input = valid_strs[i][0]; WideString text_str(input); WideString expected_str(L"mailto:"); expected_str += valid_strs[i][1]; EXPECT_TRUE(extractor.CheckMailLink(&text_str)) << input; EXPECT_STREQ(expected_str.c_str(), text_str.c_str()); } }
void assert_u16_string(std::u16string actual_str, std::string expected) { std::u16string expected_str(expected.begin(), expected.end()); ASSERT_EQ(actual_str, expected_str); }