cpp: Add unit test for evmc::result RAII

This commit is contained in:
Paweł Bylica 2019-05-14 16:06:56 +02:00
parent bc30e5a42f
commit 60c666a612
No known key found for this signature in database
GPG Key ID: 7A0C037434FE77EF
1 changed files with 37 additions and 0 deletions

View File

@ -120,3 +120,40 @@ TEST(cpp, host_call)
example_host_destroy_context(host_context);
}
TEST(cpp, result_raii)
{
static auto release_called = 0;
release_called = 0;
auto release_fn = [](const evmc_result*) noexcept { ++release_called; };
{
auto raw_result = evmc_result{};
raw_result.status_code = EVMC_INTERNAL_ERROR;
raw_result.release = release_fn;
auto raii_result = evmc::result{raw_result};
EXPECT_EQ(raii_result.status_code, EVMC_INTERNAL_ERROR);
EXPECT_EQ(raii_result.gas_left, 0);
raii_result.gas_left = -1;
auto raw_result2 = raii_result.raw();
EXPECT_EQ(raw_result2.status_code, EVMC_INTERNAL_ERROR);
EXPECT_EQ(raw_result.status_code, EVMC_INTERNAL_ERROR);
EXPECT_EQ(raw_result2.gas_left, -1);
EXPECT_EQ(raw_result.gas_left, 0);
EXPECT_EQ(raw_result2.release, release_fn);
EXPECT_EQ(raw_result.release, release_fn);
}
EXPECT_EQ(release_called, 0);
{
auto raw_result = evmc_result{};
raw_result.status_code = EVMC_INTERNAL_ERROR;
raw_result.release = release_fn;
auto raii_result = evmc::result{raw_result};
EXPECT_EQ(raii_result.status_code, EVMC_INTERNAL_ERROR);
}
EXPECT_EQ(release_called, 1);
}