Flutter Engine
The Flutter Engine
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
5#include "flutter/shell/platform/embedder/embedder.h"
6
7#include <set>
8
9#include "flutter/testing/testing.h"
10
11#ifdef _WIN32
12// winbase.h defines GetCurrentTime as a macro.
13#undef GetCurrentTime
14#endif
15
16namespace flutter {
17namespace testing {
18
19// Verifies that the proc table is fully populated.
20TEST(EmbedderProcTable, AllPointersProvided) {
21 FlutterEngineProcTable procs = {};
22 procs.struct_size = sizeof(FlutterEngineProcTable);
23 ASSERT_EQ(FlutterEngineGetProcAddresses(&procs), kSuccess);
24
25 void (**proc)() = reinterpret_cast<void (**)()>(&procs.CreateAOTData);
26 const uintptr_t end_address =
27 reinterpret_cast<uintptr_t>(&procs) + procs.struct_size;
28 while (reinterpret_cast<uintptr_t>(proc) < end_address) {
29 EXPECT_NE(*proc, nullptr);
30 ++proc;
31 }
32}
33
34// Ensures that there are no duplicate pointers in the proc table, to catch
35// copy/paste mistakes when adding a new entry to FlutterEngineGetProcAddresses.
36TEST(EmbedderProcTable, NoDuplicatePointers) {
37 FlutterEngineProcTable procs = {};
38 procs.struct_size = sizeof(FlutterEngineProcTable);
39 ASSERT_EQ(FlutterEngineGetProcAddresses(&procs), kSuccess);
40
41 void (**proc)() = reinterpret_cast<void (**)()>(&procs.CreateAOTData);
42 const uintptr_t end_address =
43 reinterpret_cast<uintptr_t>(&procs) + procs.struct_size;
44 std::set<void (*)()> seen_procs;
45 while (reinterpret_cast<uintptr_t>(proc) < end_address) {
46 auto result = seen_procs.insert(*proc);
47 EXPECT_TRUE(result.second);
48 ++proc;
49 }
50}
51
52// Spot-checks that calling one of the function pointers works.
53TEST(EmbedderProcTable, CallProc) {
54 FlutterEngineProcTable procs = {};
55 procs.struct_size = sizeof(FlutterEngineProcTable);
56 ASSERT_EQ(FlutterEngineGetProcAddresses(&procs), kSuccess);
57
58 EXPECT_NE(procs.GetCurrentTime(), 0ULL);
59}
60
61} // namespace testing
62} // namespace flutter
FlutterEngineResult FlutterEngineGetProcAddresses(FlutterEngineProcTable *table)
Gets the table of engine function pointers.
Definition: embedder.cc:3335
@ kSuccess
Definition: embedder.h:73
GAsyncResult * result
TEST(DisplayListComplexity, EmptyDisplayList)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
Definition: switches.h:76
Function-pointer-based versions of the APIs above.
Definition: embedder.h:3319
FlutterEngineCreateAOTDataFnPtr CreateAOTData
Definition: embedder.h:3323
size_t struct_size
The size of this struct. Must be sizeof(FlutterEngineProcs).
Definition: embedder.h:3321
FlutterEngineGetCurrentTimeFnPtr GetCurrentTime
Definition: embedder.h:3352
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678