| Flutter Impeller |

base_unittests.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "flutter/testing/testing.h"
6 #include "impeller/base/strings.h"
7 #include "impeller/base/thread.h"
8
9 namespace impeller {
10 namespace testing {
11
12 struct Foo {
13 Mutex mtx;
14 int a IPLR_GUARDED_BY(mtx);
15 };
16
17 struct RWFoo {
18 RWMutex mtx;
19 int a IPLR_GUARDED_BY(mtx);
20 };
21
22 TEST(ThreadTest, CanCreateMutex) {
23 Foo f = {};
24
25 // f.a = 100; <--- Static analysis error.
26 f.mtx.Lock();
27 f.a = 100;
28 f.mtx.Unlock();
29 }
30
31 TEST(ThreadTest, CanCreateMutexLock) {
32 Foo f = {};
33
34 // f.a = 100; <--- Static analysis error.
35 auto a = Lock(f.mtx);
36 f.a = 100;
37 }
38
39 TEST(ThreadTest, CanCreateRWMutex) {
40 RWFoo f = {};
41
42 // f.a = 100; <--- Static analysis error.
43 f.mtx.LockWriter();
44 f.a = 100;
45 f.mtx.UnlockWriter();
46 // int b = f.a; <--- Static analysis error.
47 f.mtx.LockReader();
48 int b = f.a; // NOLINT(clang-analyzer-deadcode.DeadStores)
49 FML_ALLOW_UNUSED_LOCAL(b);
50 f.mtx.UnlockReader();
51 }
52
53 TEST(ThreadTest, CanCreateRWMutexLock) {
54 RWFoo f = {};
55
56 // f.a = 100; <--- Static analysis error.
57 {
58 auto write_lock = WriterLock{f.mtx};
59 f.a = 100;
60 }
61
62 // int b = f.a; <--- Static analysis error.
63 {
64 auto read_lock = ReaderLock(f.mtx);
65 int b = f.a; // NOLINT(clang-analyzer-deadcode.DeadStores)
66 FML_ALLOW_UNUSED_LOCAL(b);
67 }
68
69 // f.mtx.UnlockReader(); <--- Static analysis error.
70 }
71
72 TEST(StringsTest, CanSPrintF) {
73 ASSERT_EQ(SPrintF("%sx%d", "Hello", 12), "Hellox12");
74 ASSERT_EQ(SPrintF(""), "");
75 ASSERT_EQ(SPrintF("Hello"), "Hello");
76 ASSERT_EQ(SPrintF("%sx%.2f", "Hello", 12.122222), "Hellox12.12");
77 }
78
79 } // namespace testing
80 } // namespace impeller
impeller::WriterLock
Definition: thread.h:83
impeller::testing::RWFoo
Definition: base_unittests.cc:17
impeller::Lock
Definition: thread.h:54
impeller::testing::TEST
TEST(AiksCanvasTest, EmptyCullRect)
Definition: canvas_unittests.cc:18
impeller::testing::RWFoo::mtx
RWMutex mtx
Definition: base_unittests.cc:18
impeller::testing::Foo::IPLR_GUARDED_BY
int a IPLR_GUARDED_BY(mtx)
impeller::ReaderLock
Definition: thread.h:68
impeller::SPrintF
std::string SPrintF(const char *format,...)
Definition: strings.cc:12
strings.h
impeller::testing::Foo
Definition: base_unittests.cc:12
thread.h
impeller
Definition: aiks_context.cc:10
impeller::testing::RWFoo::IPLR_GUARDED_BY
int a IPLR_GUARDED_BY(mtx)
impeller::testing::Foo::mtx
Mutex mtx
Definition: base_unittests.cc:13