Skip to content

Commit

Permalink
#993. 32 and 64-bit integer tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey G. Grekhov committed Feb 19, 2021
1 parent 3bfbaa7 commit 01d84d3
Show file tree
Hide file tree
Showing 11 changed files with 326 additions and 1 deletion.
1 change: 0 additions & 1 deletion LibTest/ffi/Int16/Int16_A01_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ void main() {
Pointer<Int16> p1 = calloc<Int16>();
Pointer<Int32> p2 = new Pointer<Int32>.fromAddress(p1.address);
try {
Expect.equals(0, p1.value);
p2.value = 42;
Expect.equals(42, p1.value);
p2.value = -42;
Expand Down
38 changes: 38 additions & 0 deletions LibTest/ffi/Int32/Int32_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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 Represents a native signed 32 bit integer in C.
*
* @description Checks that this type represents a native signed 32 bit integer
* in C.
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "../ffi_utils.dart";
import "../../../Utils/expect.dart";

void main() {
Pointer<Int32> p1 = calloc<Int32>();
try {
Expect.equals(0, p1.value);
p1.value = 42;
Expect.equals(42, p1.value);
p1.value = -42;
Expect.equals(-42, p1.value);
p1.value = 32768;
Expect.equals(32768, p1.value);
p1.value = -32768;
Expect.equals(-32768, p1.value);
p1.value = 2147483647;
Expect.equals(2147483647, p1.value);
p1.value = 2147483648;
Expect.equals(-2147483648, p1.value);
p1.value = -2147483649;
Expect.equals(2147483647, p1.value);
} finally {
calloc.free(p1);
}
}
38 changes: 38 additions & 0 deletions LibTest/ffi/Int32/Int32_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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 Represents a native signed 32 bit integer in C.
*
* @description Checks that this type represents a native signed 32 bit integer
* in C.
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "../ffi_utils.dart";
import "../../../Utils/expect.dart";

void main() {
Pointer<Int32> p1 = calloc<Int32>();
Pointer<Int64> p2 = new Pointer<Int64>.fromAddress(p1.address);
try {
p2.value = 42;
Expect.equals(42, p1.value);
p2.value = -42;
Expect.equals(-42, p1.value);
p2.value = 32768;
Expect.equals(32768, p1.value);
p2.value = -32768;
Expect.equals(-32768, p1.value);
p2.value = 2147483647;
Expect.equals(2147483647, p1.value);
p2.value = 2147483648;
Expect.equals(-2147483648, p1.value);
p2.value = -2147483649;
Expect.equals(2147483647, p1.value);
} finally {
calloc.free(p1);
}
}
25 changes: 25 additions & 0 deletions LibTest/ffi/Int32/Int32_A02_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 Represents a native signed 32 bit integer in C.
*
* @description Checks that this type represents a native signed 16 bit integer
* in C.
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "../ffi_utils.dart";
import "../../../Utils/expect.dart";

void main() {
Pointer<Int32> p1 = calloc<Int32>(3);
try {
Expect.equals(4, p1.elementAt(1).address - p1.address);
Expect.equals(4, p1.elementAt(2).address - p1.elementAt(1).address);
} finally {
calloc.free(p1);
}
}
42 changes: 42 additions & 0 deletions LibTest/ffi/Int64/Int64_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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 Represents a native signed 64 bit integer in C.
*
* @description Checks that this type represents a native signed 64 bit integer
* in C.
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "../ffi_utils.dart";
import "../../../Utils/expect.dart";

void main() {
Pointer<Int64> p1 = calloc<Int64>();
try {
Expect.equals(0, p1.value);
p1.value = 42;
Expect.equals(42, p1.value);
p1.value = -42;
Expect.equals(-42, p1.value);
p1.value = 32768;
Expect.equals(32768, p1.value);
p1.value = -32768;
Expect.equals(-32768, p1.value);
p1.value = 2147483648;
Expect.equals(2147483648, p1.value);
p1.value = -2147483649;
Expect.equals(-2147483649, p1.value);
p1.value = 0x7FFFFFFFFFFFFFFF;
Expect.equals(9223372036854775807, p1.value);
p1.value = 0xFFFFFFFFFFFFFFFF;
Expect.equals(-1, p1.value);
p1.value = -9223372036854775808;
Expect.equals(-9223372036854775808, p1.value);
} finally {
calloc.free(p1);
}
}
25 changes: 25 additions & 0 deletions LibTest/ffi/Int64/Int64_A02_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 Represents a native signed 32 bit integer in C.
*
* @description Checks that this type represents a native signed 16 bit integer
* in C.
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "../ffi_utils.dart";
import "../../../Utils/expect.dart";

void main() {
Pointer<Int64> p1 = calloc<Int64>(3);
try {
Expect.equals(8, p1.elementAt(1).address - p1.address);
Expect.equals(8, p1.elementAt(2).address - p1.elementAt(1).address);
} finally {
calloc.free(p1);
}
}
36 changes: 36 additions & 0 deletions LibTest/ffi/Uint32/Uint32_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 Represents a native unsigned 32 bit integer in C.
*
* @description Checks that this type represents a native unsigned 32 bit
* integer in C.
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "../ffi_utils.dart";
import "../../../Utils/expect.dart";

void main() {
Pointer<Uint32> p1 = calloc<Uint32>();
try {
Expect.equals(0, p1.value);
p1.value = 256;
Expect.equals(256, p1.value);
p1.value = 32768;
Expect.equals(32768, p1.value);
p1.value = 65536;
Expect.equals(65536, p1.value);
p1.value = 4294967295;
Expect.equals(4294967295, p1.value);
p1.value = 4294967296;
Expect.equals(0, p1.value);
p1.value = -1;
Expect.equals(4294967295, p1.value);
} finally {
calloc.free(p1);
}
}
36 changes: 36 additions & 0 deletions LibTest/ffi/Uint32/Uint32_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 Represents a native unsigned 32 bit integer in C.
*
* @description Checks that this type represents a native unsigned 32 bit
* integer in C.
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "../ffi_utils.dart";
import "../../../Utils/expect.dart";

void main() {
Pointer<Uint32> p1 = calloc<Uint32>();
Pointer<Uint64> p2 = new Pointer<Uint64>.fromAddress(p1.address);
try {
p2.value = 256;
Expect.equals(256, p1.value);
p2.value = 32768;
Expect.equals(32768, p1.value);
p2.value = 65536;
Expect.equals(65536, p1.value);
p2.value = 4294967295;
Expect.equals(4294967295, p1.value);
p2.value = 4294967296;
Expect.equals(0, p1.value);
p2.value = -1;
Expect.equals(4294967295, p1.value);
} finally {
calloc.free(p1);
}
}
25 changes: 25 additions & 0 deletions LibTest/ffi/Uint32/Uint32_A02_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 Represents a native unsigned 32 bit integer in C.
*
* @description Checks that this type represents a native unsigned 32 bit
* integer in C.
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "../ffi_utils.dart";
import "../../../Utils/expect.dart";

void main() {
Pointer<Uint32> p1 = calloc<Uint32>(3);
try {
Expect.equals(4, p1.elementAt(1).address - p1.address);
Expect.equals(4, p1.elementAt(2).address - p1.elementAt(1).address);
} finally {
calloc.free(p1);
}
}
36 changes: 36 additions & 0 deletions LibTest/ffi/Uint64/Uint64_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 Represents a native unsigned 64 bit integer in C.
*
* @description Checks that this type represents a native unsigned 64 bit
* integer in C.
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "../ffi_utils.dart";
import "../../../Utils/expect.dart";

void main() {
Pointer<Uint64> p1 = calloc<Uint64>();
try {
Expect.equals(0, p1.value);
p1.value = 42;
Expect.equals(42, p1.value);
p1.value = 32768;
Expect.equals(32768, p1.value);
p1.value = 2147483648;
Expect.equals(2147483648, p1.value);
p1.value = 0x7FFFFFFFFFFFFFFF;
Expect.equals(0x7FFFFFFFFFFFFFFF, p1.value);
p1.value = 0xFFFFFFFFFFFFFFFF;
Expect.equals(-1, p1.value);
p1.value = -9223372036854775808;
Expect.equals(-9223372036854775808, p1.value);
} finally {
calloc.free(p1);
}
}
25 changes: 25 additions & 0 deletions LibTest/ffi/Uint64/Uint64_A02_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 Represents a native unsigned 64 bit integer in C.
*
* @description Checks that this type represents a native unsigned 64 bit
* integer in C.
* @author sgrekhov@unipro.ru
*/
import "dart:ffi";
import "../ffi_utils.dart";
import "../../../Utils/expect.dart";

void main() {
Pointer<Uint64> p1 = calloc<Uint64>(3);
try {
Expect.equals(8, p1.elementAt(1).address - p1.address);
Expect.equals(8, p1.elementAt(2).address - p1.elementAt(1).address);
} finally {
calloc.free(p1);
}
}

0 comments on commit 01d84d3

Please sign in to comment.