forked from dart-native/dart_native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit_test.dart
169 lines (139 loc) · 4.61 KB
/
unit_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import 'package:dart_native/dart_native.dart';
import 'package:dart_native_example/android/delegate_stub.dart';
import 'package:dart_native_example/android/runtimestub.dart';
import 'package:dart_native_example/android/entity.dart';
import 'package:dart_native_example/android/runtimestub_async.dart';
import 'package:dart_native_example/dn_unit_test.dart';
import 'package:ffi/ffi.dart';
/// Android unit test implementation.
class DNAndroidUnitTest with DNUnitTestBase {
final stub = RuntimeStub();
@override
Future<void> runAllUnitTests() async {
await testAndroid(stub);
}
}
testAndroid(RuntimeStub stub) async {
int ms = currentTimeMillis();
double resultDouble = stub.getDouble(3.40282e+038);
int use = currentTimeMillis() - ms;
print('getDouble result:$resultDouble , cost:$use');
ms = currentTimeMillis();
int resultChar = stub.getChar('a');
use = currentTimeMillis() - ms;
print('getChar result:$resultChar , cost:$use');
ms = currentTimeMillis();
int resultInt = stub.getInt(10);
use = currentTimeMillis() - ms;
print('getInt result:$resultInt , cost:$use');
ms = currentTimeMillis();
bool resultBool = stub.getBool(true);
use = currentTimeMillis() - ms;
print('getBool result:$resultBool , cost:$use');
ms = currentTimeMillis();
double resultFloat = stub.getFloat(10.5);
use = currentTimeMillis() - ms;
print('getFloat result:$resultFloat , cost:$use');
ms = currentTimeMillis();
int resultByte = stub.getByte(1);
use = currentTimeMillis() - ms;
print('getByte result:$resultByte , cost:$use');
ms = currentTimeMillis();
int resultShort = stub.getShort(1);
use = currentTimeMillis() - ms;
print('getShort result:$resultShort , cost:$use');
ms = currentTimeMillis();
int resultLong = stub.getLong(4294967296);
use = currentTimeMillis() - ms;
print('getLong result:$resultLong , cost:$use');
ms = currentTimeMillis();
String? resultString = stub.getString("test is success?");
use = currentTimeMillis() - ms;
print('getString result:$resultString, cost:$use');
ms = currentTimeMillis();
int resultAdd = stub.add(10, 20);
use = currentTimeMillis() - ms;
print('add result:$resultAdd, cost:$use');
ms = currentTimeMillis();
stub.log("testlog", "log test");
use = currentTimeMillis() - ms;
print('testlog, cost:$use');
bool resultCall =
stub.complexCall("test", 10, 'a', 10.0, 12.0, 1, 2, 10000, false);
print('call result:$resultCall');
Entity entity = stub.createEntity();
print('entity get time : ${entity.getCurrentTime()}');
print('stub get time : ${stub.getTime(entity)}');
print('new entity get time : ${stub.getTime(Entity())}');
List? list = stub.getList([1, 2, 3, 4]);
if (list != null) {
for (int item in list) {
print("item $item");
}
}
list = stub.getByteList(
[const byte(1), const byte(2), const byte(3), const byte(4)]);
if (list != null) {
for (int item in list) {
print("item $item");
}
}
list = stub.getFloatList(
[const float(1.0), const float(2.0), const float(3.0), const float(4.0)]);
if (list != null) {
for (double item in list) {
print("item $item");
}
}
list = stub.getCycleList([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]);
if (list != null) {
for (List items in list) {
for (int item in items) {
print("item $item");
}
}
}
List byteArray =
stub.getByteArray([const byte(1), const byte(2), const byte(3)]);
for (int byte in byteArray) {
print("item $byte");
}
Set? intSet = stub.getIntSet({1, 2, 3});
if (intSet != null) {
for (int setInt in intSet) {
print("intSet $setInt");
}
}
Set? fSet =
stub.getFloatSet({const float(1.0), const float(2.0), const float(4.0)});
if (fSet != null) {
for (double setF in fSet) {
print("fSet $setF");
}
}
Map? map = stub.getMap({"1": 10, "2": 20, "3": 30});
if (map != null) {
map.forEach((key, value) {
print("map from native $key : $value");
});
}
List? strList = stub.getStringList(["test啊 emoji🤣", "emoji🤣"]);
if (strList != null) {
for (var item in strList) {
print("item $item");
}
}
stub.setDelegateListener(DelegateStub());
print(
"getStringAsync ${await stub.getStringAsync('This is a long string: sdlfdksjflksndhiofuu2893873(*(%¥#@)*&……¥撒肥料开发时傅雷家书那份会计师东方丽景三等奖')}");
final buffer = stub.getByteBuffer();
print(
"get direct byte buffer result ${buffer?.bytes.cast<Utf8>().toDartString(length: buffer.lengthInBytes)}");
}
int currentTimeMillis() {
return DateTime.now().millisecondsSinceEpoch;
}