Skip to content

Commit

Permalink
Add a test to use ScopedUpdate via an accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Aug 13, 2023
1 parent 8106317 commit 07531f4
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion tests/accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,35 @@ TEST_CASE("view.withAccessor.Default.SharedPtr")
CHECK(addr == addr2);
}

namespace
{
struct AsScopedUpdate
{
template<typename Reference>
LLAMA_FN_HOST_ACC_INLINE auto operator()(Reference&& r) const
{
return llama::ScopedUpdate(r);
}
};
} // namespace

TEST_CASE("view.withAccessor.AsScopedUpdate")
{
auto change = [](int& v) { v = 42; };

auto view = llama::withAccessor<AsScopedUpdate>(llama::allocView(
llama::mapping::Byteswap<llama::ArrayExtents<int, 1>, Vec3I, llama::mapping::BindAoS<>::fn>{{}},
llama::bloballoc::SharedPtr{}));

{
auto x = view(0)(tag::X{});
change(x);
CHECK(x == 42);
CHECK(view(0)(tag::X{}) == 0);
}
CHECK(view(0)(tag::X{}) == 42);
}

TEMPLATE_TEST_CASE(
"view.withAccessor.shallowCopy.Default",
"",
Expand Down Expand Up @@ -171,4 +200,4 @@ TEST_CASE("view.allocView.Stacked")
llama::accessor::Stacked<llama::accessor::Default, llama::accessor::Restrict, llama::accessor::Default>{});
iotaFillView(view);
iotaCheckView(view);
}
}

0 comments on commit 07531f4

Please sign in to comment.