Flutter Engine
 
Loading...
Searching...
No Matches
embedder_unittests_proctable.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
6
7#include <set>
8
10
11#ifdef _WIN32
12// winbase.h defines GetCurrentTime as a macro.
13#undef GetCurrentTime
14#endif
15
16// This test suite uses raw pointer arithmetic to iterate through a proc table.
17// NOLINTBEGIN(clang-analyzer-security.ArrayBound)
18
19namespace flutter {
20namespace testing {
21
22// Verifies that the proc table is fully populated.
23TEST(EmbedderProcTable, AllPointersProvided) {
24 FlutterEngineProcTable procs = {};
25 procs.struct_size = sizeof(FlutterEngineProcTable);
26 ASSERT_EQ(FlutterEngineGetProcAddresses(&procs), kSuccess);
27
28 void (**proc)() = reinterpret_cast<void (**)()>(&procs.CreateAOTData);
29 const uintptr_t end_address =
30 reinterpret_cast<uintptr_t>(&procs) + procs.struct_size;
31 while (reinterpret_cast<uintptr_t>(proc) < end_address) {
32 EXPECT_NE(*proc, nullptr);
33 ++proc;
34 }
35}
36
37// Ensures that there are no duplicate pointers in the proc table, to catch
38// copy/paste mistakes when adding a new entry to FlutterEngineGetProcAddresses.
39TEST(EmbedderProcTable, NoDuplicatePointers) {
40 FlutterEngineProcTable procs = {};
41 procs.struct_size = sizeof(FlutterEngineProcTable);
42 ASSERT_EQ(FlutterEngineGetProcAddresses(&procs), kSuccess);
43
44 void (**proc)() = reinterpret_cast<void (**)()>(&procs.CreateAOTData);
45 const uintptr_t end_address =
46 reinterpret_cast<uintptr_t>(&procs) + procs.struct_size;
47 std::set<void (*)()> seen_procs;
48 while (reinterpret_cast<uintptr_t>(proc) < end_address) {
49 auto result = seen_procs.insert(*proc);
50 EXPECT_TRUE(result.second);
51 ++proc;
52 }
53}
54
55// Spot-checks that calling one of the function pointers works.
56TEST(EmbedderProcTable, CallProc) {
57 FlutterEngineProcTable procs = {};
58 procs.struct_size = sizeof(FlutterEngineProcTable);
59 ASSERT_EQ(FlutterEngineGetProcAddresses(&procs), kSuccess);
60
61 EXPECT_NE(procs.GetCurrentTime(), 0ULL);
62}
63
64} // namespace testing
65} // namespace flutter
66
67// NOLINTEND(clang-analyzer-security.ArrayBound)
FlutterEngineResult FlutterEngineGetProcAddresses(FlutterEngineProcTable *table)
Gets the table of engine function pointers.
Definition embedder.cc:3696
TEST(NativeAssetsManagerTest, NoAvailableAssets)
Function-pointer-based versions of the APIs above.
Definition embedder.h:3704
FlutterEngineCreateAOTDataFnPtr CreateAOTData
Definition embedder.h:3708
size_t struct_size
The size of this struct. Must be sizeof(FlutterEngineProcs).
Definition embedder.h:3706
FlutterEngineGetCurrentTimeFnPtr GetCurrentTime
Definition embedder.h:3737