forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
closure_unittests.cc
71 lines (50 loc) · 1.57 KB
/
closure_unittests.cc
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
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "fml/closure.h"
#include "gtest/gtest.h"
TEST(ScopedCleanupClosureTest, DestructorDoesNothingWhenNoClosureSet) {
fml::ScopedCleanupClosure cleanup;
// Nothing should happen.
}
TEST(ScopedCleanupClosureTest, ReleaseDoesNothingWhenNoClosureSet) {
fml::ScopedCleanupClosure cleanup;
// Nothing should happen.
EXPECT_EQ(nullptr, cleanup.Release());
}
TEST(ScopedCleanupClosureTest, ClosureInvokedOnDestructorWhenSetInConstructor) {
auto invoked = false;
{
fml::ScopedCleanupClosure cleanup([&invoked]() { invoked = true; });
EXPECT_FALSE(invoked);
}
EXPECT_TRUE(invoked);
}
TEST(ScopedCleanupClosureTest, ClosureInvokedOnDestructorWhenSet) {
auto invoked = false;
{
fml::ScopedCleanupClosure cleanup;
cleanup.SetClosure([&invoked]() { invoked = true; });
EXPECT_FALSE(invoked);
}
EXPECT_TRUE(invoked);
}
TEST(ScopedCleanupClosureTest, ClosureNotInvokedWhenMoved) {
auto invoked = 0;
{
fml::ScopedCleanupClosure cleanup([&invoked]() { invoked++; });
fml::ScopedCleanupClosure cleanup2(std::move(cleanup));
EXPECT_EQ(0, invoked);
}
EXPECT_EQ(1, invoked);
}
TEST(ScopedCleanupClosureTest, ClosureNotInvokedWhenMovedViaAssignment) {
auto invoked = 0;
{
fml::ScopedCleanupClosure cleanup([&invoked]() { invoked++; });
fml::ScopedCleanupClosure cleanup2;
cleanup2 = std::move(cleanup);
EXPECT_EQ(0, invoked);
}
EXPECT_EQ(1, invoked);
}