Skip to content

Commit

Permalink
#993. sizeOf() tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey G. Grekhov committed Feb 8, 2021
1 parent 8187b21 commit 96137d0
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void main() {
DartRepresentationOf o1 = new DartRepresentationOf("");
Expect.isTrue(o1 is DartRepresentationOf);

DartRepresentationOf o2 = new DartRepresentationOf("double");
DartRepresentationOf o2 = new DartRepresentationOf("Double");
Expect.isTrue(o2 is DartRepresentationOf);
Expect.equals("DartRepresentationOf", o2.runtimeType.toString());
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void main() {
DynamicLibrary dl = new DynamicLibrary.executable();
String executable = Platform.resolvedExecutable;
asyncStart();
Process.run("nm", ["-gD", executable], runInShell: true)
Process.run("nm", ["-gDC", executable], runInShell: true)
.then((ProcessResult res) {
Expect.equals("", res.stderr);
List<String> symbols = new List<String>.empty(growable: true);
Expand Down
2 changes: 1 addition & 1 deletion LibTest/ffi/DynamicLibrary/lookup_A01_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void main() {
final path = libPathAbsolute(TEST_FUNCTIONS_LIB);
DynamicLibrary dl = new DynamicLibrary.open(path);
asyncStart();
Process.run("nm", ["-gD", path], runInShell: true)
Process.run("nm", ["-gDC", path], runInShell: true)
.then((ProcessResult res) {
Expect.equals("", res.stderr);
List<String> symbols = new List<String>.empty(growable: true);
Expand Down
34 changes: 34 additions & 0 deletions LibTest/ffi/sizeOf/sizeOf_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
* for details. All rights reserved. Use of this source code is governed by a
* BSD-style license that can be found in the LICENSE file.
*/
/**
* @assertion int sizeOf <T extends NativeType>()
* Number of bytes used by native type T.
*
* Includes padding and alignment of structs.
*
* @description Checks that this function returns Number of bytes used by native
* type T
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import '../../../Utils/expect.dart';

void main() {
Expect.equals(1, sizeOf<Int8>());
Expect.equals(2, sizeOf<Int16>());
Expect.equals(4, sizeOf<Int32>());
Expect.equals(8, sizeOf<Int64>());
Expect.equals(8, sizeOf<Double>());
Expect.equals(4, sizeOf<Float>());
Expect.equals(1, sizeOf<Uint8>());
Expect.equals(2, sizeOf<Uint16>());
Expect.equals(4, sizeOf<Uint32>());
Expect.equals(8, sizeOf<Uint64>());

Expect.equals(8, sizeOf<IntPtr>());
Expect.equals(8, sizeOf<Pointer>());
Expect.equals(0, sizeOf<Struct>());
}
28 changes: 28 additions & 0 deletions LibTest/ffi/sizeOf/sizeOf_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
* for details. All rights reserved. Use of this source code is governed by a
* BSD-style license that can be found in the LICENSE file.
*/
/**
* @assertion int sizeOf <T extends NativeType>()
* Number of bytes used by native type T.
*
* Includes padding and alignment of structs.
*
* @description Checks that this function throws an exception if T is unsized
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import '../../../Utils/expect.dart';

void main() {
Expect.throws(() {
sizeOf<Void>();
});
Expect.throws(() {
sizeOf<NativeType>();
});
Expect.throws(() {
sizeOf<NativeFunction>();
});
}
22 changes: 22 additions & 0 deletions LibTest/ffi/sizeOf/sizeOf_A01_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
* for details. All rights reserved. Use of this source code is governed by a
* BSD-style license that can be found in the LICENSE file.
*/
/**
* @assertion int sizeOf <T extends NativeType>()
* Number of bytes used by native type T.
*
* Includes padding and alignment of structs.
*
* @description Checks that this function throws an exception if T is unsized
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import '../../../Utils/expect.dart';

void main() {
// TODO Support of non-constant type arguments of 'sizeOf' will be removed.
// TODO Rewrite this test to expect a failure
sizeOf<Handle>();
}

0 comments on commit 96137d0

Please sign in to comment.