Flutter Engine
The Flutter Engine
Functions
closure_unittests.cc File Reference
#include "fml/closure.h"
#include "gtest/gtest.h"

Go to the source code of this file.

Functions

 TEST (ScopedCleanupClosureTest, DestructorDoesNothingWhenNoClosureSet)
 
 TEST (ScopedCleanupClosureTest, ReleaseDoesNothingWhenNoClosureSet)
 
 TEST (ScopedCleanupClosureTest, ClosureInvokedOnDestructorWhenSetInConstructor)
 
 TEST (ScopedCleanupClosureTest, ClosureInvokedOnDestructorWhenSet)
 
 TEST (ScopedCleanupClosureTest, ClosureNotInvokedWhenMoved)
 
 TEST (ScopedCleanupClosureTest, ClosureNotInvokedWhenMovedViaAssignment)
 

Function Documentation

◆ TEST() [1/6]

TEST ( ScopedCleanupClosureTest  ,
ClosureInvokedOnDestructorWhenSet   
)

Definition at line 33 of file closure_unittests.cc.

33 {
34 auto invoked = false;
35
36 {
38 cleanup.SetClosure([&invoked]() { invoked = true; });
39
40 EXPECT_FALSE(invoked);
41 }
42
43 EXPECT_TRUE(invoked);
44}
Wraps a closure that is invoked in the destructor unless released by the caller.
Definition: closure.h:32
fml::closure SetClosure(const fml::closure &closure)
Definition: closure.h:50
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678

◆ TEST() [2/6]

TEST ( ScopedCleanupClosureTest  ,
ClosureInvokedOnDestructorWhenSetInConstructor   
)

Definition at line 21 of file closure_unittests.cc.

21 {
22 auto invoked = false;
23
24 {
25 fml::ScopedCleanupClosure cleanup([&invoked]() { invoked = true; });
26
27 EXPECT_FALSE(invoked);
28 }
29
30 EXPECT_TRUE(invoked);
31}

◆ TEST() [3/6]

TEST ( ScopedCleanupClosureTest  ,
ClosureNotInvokedWhenMoved   
)

Definition at line 46 of file closure_unittests.cc.

46 {
47 auto invoked = 0;
48
49 {
50 fml::ScopedCleanupClosure cleanup([&invoked]() { invoked++; });
51 fml::ScopedCleanupClosure cleanup2(std::move(cleanup));
52
53 EXPECT_EQ(0, invoked);
54 }
55
56 EXPECT_EQ(1, invoked);
57}

◆ TEST() [4/6]

TEST ( ScopedCleanupClosureTest  ,
ClosureNotInvokedWhenMovedViaAssignment   
)

Definition at line 59 of file closure_unittests.cc.

59 {
60 auto invoked = 0;
61
62 {
63 fml::ScopedCleanupClosure cleanup([&invoked]() { invoked++; });
65 cleanup2 = std::move(cleanup);
66
67 EXPECT_EQ(0, invoked);
68 }
69
70 EXPECT_EQ(1, invoked);
71}

◆ TEST() [5/6]

TEST ( ScopedCleanupClosureTest  ,
DestructorDoesNothingWhenNoClosureSet   
)

Definition at line 8 of file closure_unittests.cc.

8 {
10
11 // Nothing should happen.
12}

◆ TEST() [6/6]

TEST ( ScopedCleanupClosureTest  ,
ReleaseDoesNothingWhenNoClosureSet   
)

Definition at line 14 of file closure_unittests.cc.

14 {
16
17 // Nothing should happen.
18 EXPECT_EQ(nullptr, cleanup.Release());
19}
fml::closure Release()
Definition: closure.h:56