Flutter Engine
The 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
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
#define TEST(S, s, D, expected)
FlutterEngineResult FlutterEngineGetProcAddresses(FlutterEngineProcTable *table)
Gets the table of engine function pointers.
Definition embedder.cc:3329
GAsyncResult * result
Function-pointer-based versions of the APIs above.
Definition embedder.h:3317
FlutterEngineCreateAOTDataFnPtr CreateAOTData
Definition embedder.h:3321
size_t struct_size
The size of this struct. Must be sizeof(FlutterEngineProcs).
Definition embedder.h:3319
FlutterEngineGetCurrentTimeFnPtr GetCurrentTime
Definition embedder.h:3350
#define EXPECT_TRUE(handle)
Definition unit_test.h:685