FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp.react/tests/src/MoveTest.h at master · SymmetryLabs/cpp.react · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
SymmetryLabs
/
cpp.react
Public
forked from
snakster/cpp.react
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp.react
/
tests
/
src
/
MoveTest.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
134 lines (105 loc) · 3.3 KB
Breadcrumbs
cpp.react
/
tests
/
src
/
MoveTest.h
Copy path
File metadata and controls
134 lines (105 loc) · 3.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//
Copyright Sebastian Jeckel 2014.
//
Distributed under the Boost Software License, Version 1.0.
//
(See accompanying file LICENSE_1_0.txt or copy at
//
http://www.boost.org/LICENSE_1_0.txt)
#
pragma
once
#
include
"
gtest/gtest.h
"
#
include
"
react/Domain.h
"
#
include
"
react/Signal.h
"
//
/////////////////////////////////////////////////////////////////////////////////////////////////
namespace
{
using
namespace
react
;
//
/////////////////////////////////////////////////////////////////////////////////////////////////
//
/ MoveTest fixture
//
/////////////////////////////////////////////////////////////////////////////////////////////////
template
<
typename
TParams>
class
MoveTest
:
public
testing
::Test
{
public:
template
<EPropagationMode mode>
class
MyEngine
:
public
TParams
::
template
EngineT<mode> {};
REACTIVE_DOMAIN
(MyDomain, TParams::mode, MyEngine)
struct
Stats
{
int
copyCount =
0
;
int
moveCount =
0
;
};
struct
CopyCounter
{
int
v =
0
;
Stats* stats =
nullptr
;
CopyCounter
() =
default
;
CopyCounter
(
int
x, Stats* s) :
v
( x ),
stats
( s )
{}
CopyCounter
(
const
CopyCounter& other) :
v
( other.v ),
stats
( other.stats )
{
stats->
copyCount
++;
}
CopyCounter
(CopyCounter&& other) :
v
( other.v ),
stats
( other.stats )
{
stats->
moveCount
++;
}
CopyCounter&
operator
=(
const
CopyCounter& other)
{
v = other.
v
;
stats = other.
stats
;
stats->
copyCount
++;
return
*
this
;
}
CopyCounter&
operator
=(CopyCounter&& other)
{
v = other.
v
;
stats = other.
stats
;
stats->
moveCount
++;
return
*
this
;
}
CopyCounter
operator
+(
const
CopyCounter& r)
const
{
return
CopyCounter{ v + r.
v
, stats };
}
bool
operator
==(
const
CopyCounter& other)
const
{
return
v == other.
v
;
}
};
};
TYPED_TEST_CASE_P
(MoveTest);
//
/////////////////////////////////////////////////////////////////////////////////////////////////
//
/ Copy1
//
/////////////////////////////////////////////////////////////////////////////////////////////////
TYPED_TEST_P
(MoveTest, Copy1)
{
using
D =
typename
Copy1::MyDomain;
using
CopyCounter =
typename
Copy1::CopyCounter;
using
Stats =
typename
Copy1::Stats;
Stats stats1;
auto
a = MakeVar<D>(CopyCounter{
1
,&stats1});
auto
b = MakeVar<D>(CopyCounter{
10
,&stats1});
auto
c = MakeVar<D>(CopyCounter{
100
,&stats1});
auto
d = MakeVar<D>(CopyCounter{
1000
,&stats1});
//
4x move to value_
//
4x copy to newValue_ (can't be unitialized for references)
ASSERT_EQ
(stats1.
copyCount
,
4
);
ASSERT_EQ
(stats1.
moveCount
,
4
);
auto
x = a + b + c + d;
ASSERT_EQ
(stats1.
copyCount
,
4
);
ASSERT_EQ
(stats1.
moveCount
,
7
);
ASSERT_EQ
(
x
().
v
,
1111
);
a <<= CopyCounter{
2
,&stats1};
ASSERT_EQ
(stats1.
copyCount
,
4
);
ASSERT_EQ
(stats1.
moveCount
,
10
);
ASSERT_EQ
(
x
().
v
,
1112
);
}
//
/////////////////////////////////////////////////////////////////////////////////////////////////
REGISTER_TYPED_TEST_CASE_P
(
MoveTest,
Copy1
);
}
//
~namespace
Back
|
FazBrowse Home
|
New Git URL