5#include "flutter/testing/dart_isolate_runner.h"
6#include "flutter/testing/fixture_test.h"
15 DEFINE_WRAPPERTYPEINFO();
24 auto path = fml::MakeRefCounted<MyNativeClass>(
value);
25 path->AssociateWithDartWrapper(path_handle);
56 if (running_isolate_) {
66 running_isolate_ = std::move(isolate);
70 template <
typename C,
typename Signature, Signature function>
82 reinterpret_cast<void*
>(
86 AddNativeCallback(
"SignalDone",
89 weak_persistent_value.Clear();
94 ASSERT_TRUE(RunWithEntrypoint(testEntry));
97 running_isolate_->Shutdown();
100 template <
typename C,
typename Signature, Signature function>
102 const char* returnFfi,
103 const char* returnDart,
105 const char* argsDart) {
108 EXPECT_EQ(dispatcher.AllowedAsLeafCall(), leaf);
109 EXPECT_STREQ(dispatcher.GetReturnFfiRepresentation(), returnFfi);
110 EXPECT_STREQ(dispatcher.GetReturnDartRepresentation(), returnDart);
113 std::ostringstream stream_;
114 dispatcher.WriteFfiArguments(&stream_);
115 EXPECT_STREQ(stream_.str().c_str(), argsFfi);
119 std::ostringstream stream_;
120 dispatcher.WriteDartArguments(&stream_);
121 EXPECT_STREQ(stream_.str().c_str(), argsDart);
143 DoCallThroughTest<void, decltype(&Nop), &Nop>(
"Nop",
"callNop");
147 DoSerialiseTest<void, decltype(&Nop), &Nop>(
148 true,
"Void",
"void",
"",
"");
159 DoCallThroughTest<void, decltype(&EchoBool), &EchoBool>(
"EchoBool",
164 DoSerialiseTest<void, decltype(&EchoBool), &EchoBool>(
165 true,
"Bool",
"bool",
"Bool",
"bool");
176 DoCallThroughTest<void, decltype(&EchoIntPtr), &EchoIntPtr>(
"EchoIntPtr",
181 if (
sizeof(intptr_t) == 8) {
182 DoSerialiseTest<void, decltype(&EchoIntPtr), &EchoIntPtr>(
183 true,
"Int64",
"int",
"Int64",
"int");
185 EXPECT_EQ(
sizeof(intptr_t), 4ul);
186 DoSerialiseTest<void, decltype(&EchoIntPtr), &EchoIntPtr>(
187 true,
"Int32",
"int",
"Int32",
"int");
194 EXPECT_EQ(arg, 23.0);
199 DoCallThroughTest<void, decltype(&EchoDouble), &EchoDouble>(
"EchoDouble",
204 DoSerialiseTest<void, decltype(&EchoDouble), &EchoDouble>(
205 true,
"Double",
"double",
"Double",
"double");
211 const char* c_str =
nullptr;
213 EXPECT_STREQ(c_str,
"Hello EchoHandle");
218 DoCallThroughTest<void, decltype(&EchoHandle), &EchoHandle>(
"EchoHandle",
223 DoSerialiseTest<void, decltype(&EchoHandle), &EchoHandle>(
224 false,
"Handle",
"Object",
"Handle",
"Object");
230 EXPECT_STREQ(arg.c_str(),
"Hello EchoString");
235 DoCallThroughTest<void, decltype(&EchoString), &EchoString>(
"EchoString",
240 DoSerialiseTest<void, decltype(&EchoString), &EchoString>(
241 false,
"Handle",
"String",
"Handle",
"String");
247 EXPECT_EQ(arg, u
"Hello EchoU16String");
252 DoCallThroughTest<void, decltype(&EchoU16String), &EchoU16String>(
253 "EchoU16String",
"callEchoU16String");
257 DoSerialiseTest<void, decltype(&EchoU16String), &EchoU16String>(
258 false,
"Handle",
"String",
"Handle",
"String");
263std::vector<std::string>
EchoVector(
const std::vector<std::string>& arg) {
264 EXPECT_STREQ(arg[0].c_str(),
"Hello EchoVector");
269 DoCallThroughTest<void, decltype(&EchoVector), &EchoVector>(
"EchoVector",
274 DoSerialiseTest<void, decltype(&EchoVector), &EchoVector>(
275 false,
"Handle",
"List",
"Handle",
"List");
281 EXPECT_EQ(arg->
_value, 0x1234);
286 DoCallThroughTest<void, decltype(&EchoWrappable), &EchoWrappable>(
287 "EchoWrappable",
"callEchoWrappable");
291 if (
sizeof(intptr_t) == 8) {
292 DoSerialiseTest<void, decltype(&EchoWrappable), &EchoWrappable>(
293 true,
"Int64",
"int",
"Pointer",
"Pointer");
295 EXPECT_EQ(
sizeof(intptr_t), 4ul);
296 DoSerialiseTest<void, decltype(&EchoWrappable), &EchoWrappable>(
297 true,
"Int32",
"int",
"Pointer",
"Pointer");
304 EXPECT_NEAR(arg[1], 3.14, 0.01);
309 DoCallThroughTest<void, decltype(&EchoTypedList), &EchoTypedList>(
310 "EchoTypedList",
"callEchoTypedList");
314 DoSerialiseTest<void, decltype(&EchoTypedList), &EchoTypedList>(
315 false,
"Handle",
"Object",
"Handle",
"Object");
323 "MyNativeClass::MyTestFunction",
"callMyTestFunction");
329 false,
"Int32",
"int",
"Pointer, Int32, Handle",
330 "Pointer, int, Object");
344 false,
"Handle",
"Object",
"Pointer, Int64",
"Pointer, int");
static sk_sp< Effect > Create()
void DoCallThroughTest(const char *testName, const char *testEntry)
void DoSerialiseTest(bool leaf, const char *returnFfi, const char *returnDart, const char *argsFfi, const char *argsDart)
fml::RefPtr< fml::TaskRunner > thread_
bool RunWithEntrypoint(const std::string &entrypoint)
std::unique_ptr< AutoIsolateShutdown > running_isolate_
FML_DISALLOW_COPY_AND_ASSIGN(FfiNativeTest)
TaskRunners task_runners_
static void Create(Dart_Handle path_handle, intptr_t value)
Dart_Handle MyTestMethod(int64_t x)
static int32_t MyTestFunction(MyNativeClass *ptr, int32_t x, Dart_Handle handle)
struct _Dart_Handle * Dart_Handle
struct _Dart_NativeArguments * Dart_NativeArguments
DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle str, const char **cstr)
DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value)
TaskRunners task_runners_
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
fml::RefPtr< fml::TaskRunner > CreateNewThread(const std::string &name)
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
TEST_F(DisplayListTest, Defaults)
std::string GetDefaultKernelFilePath()
Returns the default path to kernel_blob.bin. This file is within the directory returned by GetFixture...
intptr_t EchoWrappable(MyNativeClass *arg)
std::string EchoString(std::string arg)
tonic::Float32List EchoTypedList(tonic::Float32List arg)
std::unique_ptr< AutoIsolateShutdown > RunDartCodeInIsolate(DartVMRef &vm_ref, const Settings &settings, const TaskRunners &task_runners, std::string entrypoint, const std::vector< std::string > &args, const std::string &kernel_file_path, fml::WeakPtr< IOManager > io_manager, std::shared_ptr< VolatilePathTracker > volatile_path_tracker, std::unique_ptr< PlatformConfiguration > platform_configuration)
intptr_t EchoIntPtr(intptr_t arg)
std::u16string EchoU16String(std::u16string arg)
std::vector< std::string > EchoVector(const std::vector< std::string > &arg)
double EchoDouble(double arg)
Dart_Handle EchoHandle(Dart_Handle str)
IMPLEMENT_WRAPPERTYPEINFO(flutter_gpu, FlutterGpuTestClass)
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
#define CREATE_NATIVE_ENTRY(native_entry)
#define EXPECT_TRUE(handle)