openMSX
ScopedAssign_test.cc
Go to the documentation of this file.
1#include "catch.hpp"
2#include "ScopedAssign.hh"
3
4TEST_CASE("ScopedAssign, local")
5{
6 int l = 1;
7 CHECK(l == 1);
8 {
9 ScopedAssign<int> sa1(l, 2);
10 CHECK(l == 2);
11 {
12 ScopedAssign<int> sa2(l, 3);
13 CHECK(l == 3);
14 }
15 CHECK(l == 2);
16 }
17 CHECK(l == 1);
18}
19
20int g;
21static void testAssign()
22{
23 CHECK(g == 2);
24 ScopedAssign<int> sa(g, 3);
25 CHECK(g == 3);
26}
27TEST_CASE("ScopedAssign, global")
28{
29 g = 1;
30 CHECK(g == 1);
31 {
32 ScopedAssign<int> sa(g, 2);
33 CHECK(g == 2);
34 testAssign();
35 CHECK(g == 2);
36 }
37 CHECK(g == 1);
38}
TEST_CASE("ScopedAssign, local")
int g
Assign new value to some variable and restore the original value when this object goes out of scope.
CHECK(m3==m3)