add end to end test cases related to overloaded functions

This commit is contained in:
Lu Guanqun 2015-02-28 16:13:11 +08:00
parent a1eed07432
commit 114776dfba

View File

@ -3170,8 +3170,49 @@ BOOST_AUTO_TEST_CASE(pass_dynamic_arguments_to_the_base_base_with_gap)
BOOST_CHECK(callContractFunction("m_i()") == encodeArgs(4));
}
BOOST_AUTO_TEST_CASE(overloaded_function_call_resolve_to_first)
{
char const* sourceCode = R"(
contract test {
function f(uint k) returns(uint d) { return k; }
function f(uint a, uint b) returns(uint d) { return a + b; }
function g() returns(uint d) { return f(3); }
}
)";
compileAndRun(sourceCode);
BOOST_CHECK(callContractFunction("g()") == encodeArgs(3));
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(overloaded_function_call_resolve_to_second)
{
char const* sourceCode = R"(
contract test {
function f(uint a, uint b) returns(uint d) { return a + b; }
function f(uint k) returns(uint d) { return k; }
function g() returns(uint d) { return f(3, 7); }
}
)";
compileAndRun(sourceCode);
BOOST_CHECK(callContractFunction("g()") == encodeArgs(10));
}
BOOST_AUTO_TEST_CASE(overloaded_function_call_with_if_else)
{
char const* sourceCode = R"(
contract test {
function f(uint a, uint b) returns(uint d) { return a + b; }
function f(uint k) returns(uint d) { return k; }
function g(bool flag) returns(uint d) {
if (flag)
return f(3);
else
return f(3, 7);
}
}
)";
BOOST_CHECK(callContractFunction("g(bool)", true) == encodeArgs(3));
BOOST_CHECK(callContractFunction("g(bool)", false) == encodeArgs(10));
}
}
}