Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
6
7#include "vm/code_patcher.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
16namespace dart {
17
18// A native call for test purposes.
19// Arg0: a smi.
20// Arg1: a smi.
21// Result: a smi representing arg0 - arg1.
25 int64_t left_value = -1;
26 int64_t right_value = -1;
29
30 // Ignoring overflow in the calculation below.
31 int64_t result = left_value - right_value;
33}
34
35// A native call for test purposes.
36// Arg0-4: 5 smis.
37// Result: a smi representing the sum of all arguments.
39 int64_t result = 0;
40 int arg_count = Dart_GetNativeArgumentCount(args);
41 for (int i = 0; i < arg_count; 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 }
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.
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++) {
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 }
79}
80
81} // namespace dart
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
#define EXPECT(type, expectedAlignment, expectedSize)
static ObjectPtr UnwrapHandle(Dart_Handle object)
ObjectPtr NativeArgAt(int index) const
Zone * zone() const
static Thread * Current()
Definition thread.h:361
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
struct _Dart_NativeArguments * Dart_NativeArguments
Definition dart_api.h:3010
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
GAsyncResult * result
DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value)
DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, Dart_Handle retval)
void TestNonNullSmiSum(Dart_NativeArguments args)
DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, int index)
void TestSmiSum(Dart_NativeArguments args)
void TestSmiSub(Dart_NativeArguments args)
DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args)
DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, int64_t *value)
#define GET_NATIVE_ARGUMENT(type, name, value)
#define EXPECT_ERROR(handle, substring)
Definition unit_test.h:670
#define EXPECT_VALID(handle)
Definition unit_test.h:650