Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
dart-lang
sdk
runtime
vm
native_entry_test.cc
Go to the documentation of this file.
1
// Copyright (c) 2011, 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 "
vm/native_entry_test.h
"
6
7
#include "
vm/code_patcher.h
"
8
#include "
vm/compiler/assembler/assembler.h
"
9
#include "
vm/dart_api_impl.h
"
10
#include "
vm/native_entry.h
"
11
#include "
vm/object.h
"
12
#include "
vm/stack_frame.h
"
13
#include "
vm/stub_code.h
"
14
#include "
vm/unit_test.h
"
15
16
namespace
dart
{
17
18
// A native call for test purposes.
19
// Arg0: a smi.
20
// Arg1: a smi.
21
// Result: a smi representing arg0 - arg1.
22
void
TestSmiSub
(
Dart_NativeArguments
args
) {
23
Dart_Handle
left
=
Dart_GetNativeArgument
(
args
, 0);
24
Dart_Handle
right
=
Dart_GetNativeArgument
(
args
, 1);
25
int64_t left_value = -1;
26
int64_t right_value = -1;
27
EXPECT_VALID
(
Dart_IntegerToInt64
(
left
, &left_value));
28
EXPECT_VALID
(
Dart_IntegerToInt64
(
right
, &right_value));
29
30
// Ignoring overflow in the calculation below.
31
int64_t
result
= left_value - right_value;
32
Dart_SetReturnValue
(
args
,
Dart_NewInteger
(
result
));
33
}
34
35
// A native call for test purposes.
36
// Arg0-4: 5 smis.
37
// Result: a smi representing the sum of all arguments.
38
void
TestSmiSum
(
Dart_NativeArguments
args
) {
39
int64_t
result
= 0;
40
int
arg_count =
Dart_GetNativeArgumentCount
(
args
);
41
for
(
int
i = 0; i < arg_count; i++) {
42
Dart_Handle
arg =
Dart_GetNativeArgument
(
args
, i);
43
int64_t arg_value = -1;
44
EXPECT_VALID
(
Dart_IntegerToInt64
(arg, &arg_value));
45
46
// Ignoring overflow in the addition below.
47
result
+= arg_value;
48
}
49
Dart_SetReturnValue
(
args
,
Dart_NewInteger
(
result
));
50
}
51
52
// Test for accepting null arguments in native function.
53
// Arg0-4: 5 smis or null.
54
// Result: a smi representing the sum of all non-null arguments.
55
void
TestNonNullSmiSum
(
Dart_NativeArguments
args
) {
56
int64_t
result
= 0;
57
int
arg_count =
Dart_GetNativeArgumentCount
(
args
);
58
// Test the lower level macro GET_NATIVE_ARGUMENT.
59
NativeArguments
* arguments =
reinterpret_cast<
NativeArguments
*
>
(
args
);
60
Zone
* zone =
Thread::Current
()->
zone
();
// Used by GET_NATIVE_ARGUMENT.
61
for
(
int
i = 0; i < arg_count; i++) {
62
Dart_Handle
arg =
Dart_GetNativeArgument
(
args
, i);
63
GET_NATIVE_ARGUMENT
(
Integer
, argument, arguments->
NativeArgAt
(i));
64
EXPECT
(argument.IsInteger());
// May be null.
65
EXPECT_EQ(
Api::UnwrapHandle
(arg), argument.ptr());
// May be null.
66
int64_t arg_value = -1;
67
if
(argument.IsNull()) {
68
EXPECT_ERROR
(
Dart_IntegerToInt64
(arg, &arg_value),
69
"Dart_IntegerToInt64 expects argument 'integer' "
70
"to be non-null."
);
71
}
else
{
72
EXPECT_VALID
(
Dart_IntegerToInt64
(arg, &arg_value));
73
EXPECT_EQ(arg_value, argument.AsInt64Value());
74
// Ignoring overflow in the addition below.
75
result
+= arg_value;
76
}
77
}
78
Dart_SetReturnValue
(
args
,
Dart_NewInteger
(
result
));
79
}
80
81
}
// namespace dart
left
static bool left(const SkPoint &p0, const SkPoint &p1)
Definition
SkPolyUtils.cpp:527
right
static bool right(const SkPoint &p0, const SkPoint &p1)
Definition
SkPolyUtils.cpp:532
EXPECT
#define EXPECT(type, expectedAlignment, expectedSize)
Definition
UniformOffsetCalculatorTest.cpp:33
assembler.h
dart::Api::UnwrapHandle
static ObjectPtr UnwrapHandle(Dart_Handle object)
Definition
dart_api_impl.cc:376
dart::Integer
Definition
object.h:9888
dart::NativeArguments
Definition
native_arguments.h:76
dart::NativeArguments::NativeArgAt
ObjectPtr NativeArgAt(int index) const
Definition
native_arguments.h:108
dart::ThreadState::zone
Zone * zone() const
Definition
thread_state.h:37
dart::Thread::Current
static Thread * Current()
Definition
thread.h:361
dart::Zone
Definition
unit_test_custom_zone.h:19
code_patcher.h
Dart_Handle
struct _Dart_Handle * Dart_Handle
Definition
dart_api.h:258
Dart_NativeArguments
struct _Dart_NativeArguments * Dart_NativeArguments
Definition
dart_api.h:3010
dart_api_impl.h
args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Definition
fl_event_channel.h:89
result
GAsyncResult * result
Definition
fl_text_input_plugin.cc:106
dart
Definition
dart_vm.cc:33
dart::Dart_NewInteger
DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value)
Definition
dart_api_impl.cc:2615
dart::Dart_SetReturnValue
DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, Dart_Handle retval)
Definition
dart_api_impl.cc:5221
dart::TestNonNullSmiSum
void TestNonNullSmiSum(Dart_NativeArguments args)
Definition
native_entry_test.cc:55
dart::Dart_GetNativeArgument
DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, int index)
Definition
dart_api_impl.cc:5101
dart::TestSmiSum
void TestSmiSum(Dart_NativeArguments args)
Definition
native_entry_test.cc:38
dart::TestSmiSub
void TestSmiSub(Dart_NativeArguments args)
Definition
native_entry_test.cc:22
dart::Dart_GetNativeArgumentCount
DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args)
Definition
dart_api_impl.cc:5113
dart::Dart_IntegerToInt64
DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, int64_t *value)
Definition
dart_api_impl.cc:2650
native_entry.h
GET_NATIVE_ARGUMENT
#define GET_NATIVE_ARGUMENT(type, name, value)
Definition
native_entry.h:84
native_entry_test.h
object.h
stack_frame.h
stub_code.h
unit_test.h
EXPECT_ERROR
#define EXPECT_ERROR(handle, substring)
Definition
unit_test.h:670
EXPECT_VALID
#define EXPECT_VALID(handle)
Definition
unit_test.h:650
Generated on Fri Apr 26 2024 06:15:10 for Flutter Engine by
1.9.8