forked from microsoft/cppwinrt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvalid_events.cpp
More file actions
63 lines (47 loc) · 1.13 KB
/
invalid_events.cpp
File metadata and controls
63 lines (47 loc) · 1.13 KB
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
#include "pch.h"
using namespace winrt;
using namespace Windows::Foundation;
//
// Checks that invalid tokens may be removed harmlessly.
//
TEST_CASE("invalid_events")
{
event<TypedEventHandler<int, int>> event;
int counter{};
auto a = event.add([&](auto && ...)
{
counter += 1;
});
auto b = event.add([&](auto && ...)
{
counter += 10;
});
REQUIRE(counter == 0);
event(0, 0);
REQUIRE(counter == 11);
// Remove invalid token (with two valids)
event.remove(event_token {1});
counter = 0;
event(0, 0);
REQUIRE(counter == 11);
// Remove valid token
event.remove(b);
counter = 0;
event(0, 0);
REQUIRE(counter == 1);
// Remove invalid token (with one valid)
event.remove(event_token {1});
counter = 0;
event(0, 0);
REQUIRE(counter == 1);
// Remove remaining valid token
event.remove(a);
counter = 0;
event(0, 0);
REQUIRE(counter == 0);
// Remove invalid token (with no valids)
event.remove(event_token {1});
counter = 0;
event(0, 0);
REQUIRE(counter == 0);
}