Flutter Engine
The Flutter Engine
entrypoints_verification_test.cc
Go to the documentation of this file.
1// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#include <stdio.h>
6#include <stdlib.h>
7#include <string.h>
8
9// TODO(dartbug.com/40579): This requires static linking to either link
10// dart.exe or dart_precompiled_runtime.exe on Windows.
11// The sample currently fails on Windows in AOT mode.
12#include "include/dart_api.h"
14
15#define CHECK(H) \
16 do { \
17 Dart_Handle __handle__ = H; \
18 if (Dart_IsError(__handle__)) { \
19 const char* message = Dart_GetError(__handle__); \
20 fprintf(stderr, "Check \"" #H "\" failed: %s", message); \
21 abort(); \
22 } \
23 } while (false)
24
25#define ASSERT(E) \
26 if (!(E)) { \
27 fprintf(stderr, "Assertion \"" #E "\" failed at %s:%d!\n", __FILE__, \
28 __LINE__); \
29 abort(); \
30 }
31
32static bool is_dart_precompiled_runtime = true;
33
34// Some invalid accesses are allowed in AOT since we don't retain @pragma
35// annotations. Therefore we skip the negative tests in AOT.
36#define FAIL(name, result) \
37 if (!is_dart_precompiled_runtime) { \
38 Fail(name, result); \
39 }
40
41void Fail(const char* name, Dart_Handle result) {
43 const char* error = Dart_GetError(result);
44 ASSERT(strstr(error, name));
45 ASSERT(strstr(error, "It is illegal to access"));
46}
47
48#define FAIL_INVOKE_FIELD(name, result) \
49 if (!is_dart_precompiled_runtime) { \
50 FailInvokeField(name, result); \
51 }
52
53static void FailInvokeField(const char* name, Dart_Handle result) {
55 const char* error = Dart_GetError(result);
56 ASSERT(strstr(error, name));
57 ASSERT(strstr(error, "Entry-points do not allow invoking fields"));
58}
59
62 const char* error = Dart_GetError(result);
63 ASSERT(strstr(error, name));
64 ASSERT(strstr(error, "No static getter"));
65}
66
69 FAIL("fld0",
71
73 "fld0",
74 Dart_Invoke(target, Dart_NewStringFromCString("fld0"), 0, nullptr));
75
79 "fld1",
80 Dart_Invoke(target, Dart_NewStringFromCString("fld1"), 0, nullptr));
81
83 FAIL("fld2",
86 "fld2",
87 Dart_Invoke(target, Dart_NewStringFromCString("fld2"), 0, nullptr));
88
92 "fld3",
93 Dart_Invoke(target, Dart_NewStringFromCString("fld3"), 0, nullptr));
94}
95
98
100
101 //////// Test allocation and constructor invocation.
102
104
106 CHECK(D_class);
107
108 CHECK(Dart_Allocate(D_class));
109
110 FAIL("D.", Dart_New(D_class, Dart_Null(), 0, nullptr));
111
112 CHECK(Dart_New(D_class, Dart_NewStringFromCString("defined"), 0, nullptr));
113 Dart_Handle D =
114 Dart_New(D_class, Dart_NewStringFromCString("fact"), 0, nullptr);
115 CHECK(D);
116
117 //////// Test actions against methods
118
120 "defined", Dart_GetField(D_class, Dart_NewStringFromCString("defined")));
122 "fact", Dart_GetField(D_class, Dart_NewStringFromCString("fact")));
123
124 FAIL("fn0", Dart_Invoke(D, Dart_NewStringFromCString("fn0"), 0, nullptr));
125
126 CHECK(Dart_Invoke(D, Dart_NewStringFromCString("fn1"), 0, nullptr));
127 FAIL("fn1", Dart_Invoke(D, Dart_NewStringFromCString("fn1_get"), 0, nullptr));
128 CHECK(Dart_Invoke(D, Dart_NewStringFromCString("fn1_call"), 0, nullptr));
129
131
134 FAIL("fn1", Dart_GetField(D, Dart_NewStringFromCString("fn1_call")));
135
136 FAIL("fn2",
137 Dart_Invoke(D_class, Dart_NewStringFromCString("fn2"), 0, nullptr));
138
139 CHECK(Dart_Invoke(D_class, Dart_NewStringFromCString("fn3"), 0, nullptr));
140 CHECK(
141 Dart_Invoke(D_class, Dart_NewStringFromCString("fn3_call"), 0, nullptr));
142 FAIL("fn3",
143 Dart_Invoke(D_class, Dart_NewStringFromCString("fn3_get"), 0, nullptr));
144
145 FAIL("fn2", Dart_GetField(D_class, Dart_NewStringFromCString("fn2")));
146
148 FAIL("fn3_call",
149 Dart_GetField(D_class, Dart_NewStringFromCString("fn3_call")));
150 CHECK(Dart_GetField(D_class, Dart_NewStringFromCString("fn3_get")));
151
152 FAIL("fn0", Dart_Invoke(lib, Dart_NewStringFromCString("fn0"), 0, nullptr));
153
154 CHECK(Dart_Invoke(lib, Dart_NewStringFromCString("fn1"), 0, nullptr));
155 FAIL("fn1",
156 Dart_Invoke(lib, Dart_NewStringFromCString("fn1_get"), 0, nullptr));
157 CHECK(Dart_Invoke(lib, Dart_NewStringFromCString("fn1_call"), 0, nullptr));
158
159 FAIL("fn0", Dart_GetField(lib, Dart_NewStringFromCString("fn0")));
160
163 FAIL("fn1", Dart_GetField(lib, Dart_NewStringFromCString("fn1_call")));
164
165 //////// Test actions against fields
166
167 TestFields(D);
168
170 TestFields(F_class);
171
172 TestFields(lib);
173}
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_Allocate(Dart_Handle type)
DART_EXPORT bool Dart_IsApiError(Dart_Handle handle)
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_Invoke(Dart_Handle target, Dart_Handle name, int number_of_arguments, Dart_Handle *arguments)
DART_EXPORT bool Dart_IsPrecompiledRuntime(void)
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_New(Dart_Handle type, Dart_Handle constructor_name, int number_of_arguments, Dart_Handle *arguments)
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_SetField(Dart_Handle container, Dart_Handle name, Dart_Handle value)
DART_EXPORT bool Dart_IsUnhandledExceptionError(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_Null(void)
DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, Dart_Handle class_name)
DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char *str)
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name)
DART_EXPORT const char * Dart_GetError(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_RootLibrary(void)
static void FailInvokeField(const char *name, Dart_Handle result)
static void FailClosurizeConstructor(const char *name, Dart_Handle result)
#define FAIL(name, result)
static void TestFields(Dart_Handle target)
void Fail(const char *name, Dart_Handle result)
#define CHECK(H)
DART_EXPORT void RunTests()
static bool is_dart_precompiled_runtime
#define ASSERT(E)
#define FAIL_INVOKE_FIELD(name, result)
#define DART_EXPORT
const uint8_t uint32_t uint32_t GError ** error
GAsyncResult * result
uint32_t * target
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32