Skip to content

Commit 96137d0

Browse files
author
Sergey G. Grekhov
committed
#993. sizeOf() tests added
1 parent 8187b21 commit 96137d0

File tree

6 files changed

+87
-3
lines changed

6 files changed

+87
-3
lines changed

LibTest/ffi/DartRepresentationOf/DartRepresentationOf_A01_t01.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void main() {
1717
DartRepresentationOf o1 = new DartRepresentationOf("");
1818
Expect.isTrue(o1 is DartRepresentationOf);
1919

20-
DartRepresentationOf o2 = new DartRepresentationOf("double");
20+
DartRepresentationOf o2 = new DartRepresentationOf("Double");
2121
Expect.isTrue(o2 is DartRepresentationOf);
2222
Expect.equals("DartRepresentationOf", o2.runtimeType.toString());
2323
}

LibTest/ffi/DynamicLibrary/DynamicLibrary.executable_A02_t01.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void main() {
2020
DynamicLibrary dl = new DynamicLibrary.executable();
2121
String executable = Platform.resolvedExecutable;
2222
asyncStart();
23-
Process.run("nm", ["-gD", executable], runInShell: true)
23+
Process.run("nm", ["-gDC", executable], runInShell: true)
2424
.then((ProcessResult res) {
2525
Expect.equals("", res.stderr);
2626
List<String> symbols = new List<String>.empty(growable: true);

LibTest/ffi/DynamicLibrary/lookup_A01_t02.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void main() {
2424
final path = libPathAbsolute(TEST_FUNCTIONS_LIB);
2525
DynamicLibrary dl = new DynamicLibrary.open(path);
2626
asyncStart();
27-
Process.run("nm", ["-gD", path], runInShell: true)
27+
Process.run("nm", ["-gDC", path], runInShell: true)
2828
.then((ProcessResult res) {
2929
Expect.equals("", res.stderr);
3030
List<String> symbols = new List<String>.empty(growable: true);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
3+
* for details. All rights reserved. Use of this source code is governed by a
4+
* BSD-style license that can be found in the LICENSE file.
5+
*/
6+
/**
7+
* @assertion int sizeOf <T extends NativeType>()
8+
* Number of bytes used by native type T.
9+
*
10+
* Includes padding and alignment of structs.
11+
*
12+
* @description Checks that this function returns Number of bytes used by native
13+
* type T
14+
15+
*/
16+
import "dart:ffi";
17+
import '../../../Utils/expect.dart';
18+
19+
void main() {
20+
Expect.equals(1, sizeOf<Int8>());
21+
Expect.equals(2, sizeOf<Int16>());
22+
Expect.equals(4, sizeOf<Int32>());
23+
Expect.equals(8, sizeOf<Int64>());
24+
Expect.equals(8, sizeOf<Double>());
25+
Expect.equals(4, sizeOf<Float>());
26+
Expect.equals(1, sizeOf<Uint8>());
27+
Expect.equals(2, sizeOf<Uint16>());
28+
Expect.equals(4, sizeOf<Uint32>());
29+
Expect.equals(8, sizeOf<Uint64>());
30+
31+
Expect.equals(8, sizeOf<IntPtr>());
32+
Expect.equals(8, sizeOf<Pointer>());
33+
Expect.equals(0, sizeOf<Struct>());
34+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
3+
* for details. All rights reserved. Use of this source code is governed by a
4+
* BSD-style license that can be found in the LICENSE file.
5+
*/
6+
/**
7+
* @assertion int sizeOf <T extends NativeType>()
8+
* Number of bytes used by native type T.
9+
*
10+
* Includes padding and alignment of structs.
11+
*
12+
* @description Checks that this function throws an exception if T is unsized
13+
14+
*/
15+
import "dart:ffi";
16+
import '../../../Utils/expect.dart';
17+
18+
void main() {
19+
Expect.throws(() {
20+
sizeOf<Void>();
21+
});
22+
Expect.throws(() {
23+
sizeOf<NativeType>();
24+
});
25+
Expect.throws(() {
26+
sizeOf<NativeFunction>();
27+
});
28+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
3+
* for details. All rights reserved. Use of this source code is governed by a
4+
* BSD-style license that can be found in the LICENSE file.
5+
*/
6+
/**
7+
* @assertion int sizeOf <T extends NativeType>()
8+
* Number of bytes used by native type T.
9+
*
10+
* Includes padding and alignment of structs.
11+
*
12+
* @description Checks that this function throws an exception if T is unsized
13+
14+
*/
15+
import "dart:ffi";
16+
import '../../../Utils/expect.dart';
17+
18+
void main() {
19+
// TODO Support of non-constant type arguments of 'sizeOf' will be removed.
20+
// TODO Rewrite this test to expect a failure
21+
sizeOf<Handle>();
22+
}

0 commit comments

Comments
 (0)