2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/scoped.hpp>
|
|
|
|
#include <cruft/util/tap.hpp>
|
2019-04-12 16:40:17 +10:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
void test_restore (cruft::TAP::logger &tap)
|
|
|
|
{
|
|
|
|
int value = 42;
|
|
|
|
|
|
|
|
{
|
|
|
|
cruft::scoped::restore raii (value);
|
|
|
|
tap.expect_eq (value, 42, "restorer constructor doesn't modifier value");
|
|
|
|
value = 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
tap.expect_eq (value, 42, "restorer restores value at destruction");
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
cruft::scoped::restore raii (value);
|
|
|
|
value = 7;
|
2019-08-12 12:58:44 +10:00
|
|
|
raii.release ();
|
2019-04-12 16:40:17 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
tap.expect_eq (value, 7, "restorer reset doesn't modify value at destruction");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
int main ()
|
|
|
|
{
|
|
|
|
cruft::TAP::logger tap;
|
|
|
|
test_restore (tap);
|
|
|
|
return tap.status ();
|
|
|
|
}
|