Skip to content

Commit

Permalink
#993. Work with memory fixed in FFI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Aug 3, 2021
1 parent fea1468 commit af65a1a
Show file tree
Hide file tree
Showing 37 changed files with 371 additions and 219 deletions.
18 changes: 11 additions & 7 deletions LibTest/ffi/Pointer/DoublePointer.asTypedList_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ import '../../../Utils/expect.dart';

void main() {
Pointer<Double> p = calloc<Double>(3);
p[0] = 3.14;
p[1] = 42.42;
p[2] = 1.1;
Float64List l = p.asTypedList(3);
Expect.equals(3.14, l[0]);
Expect.equals(42.42, l[1]);
Expect.equals(1.1, l[2]);
try {
p[0] = 3.14;
p[1] = 42.42;
p[2] = 1.1;
Float64List l = p.asTypedList(3);
Expect.equals(3.14, l[0]);
Expect.equals(42.42, l[1]);
Expect.equals(1.1, l[2]);
} finally {
calloc.free(p);
}
}
10 changes: 7 additions & 3 deletions LibTest/ffi/Pointer/DoublePointer.value_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import '../../../Utils/expect.dart';

void main() {
Pointer<Double> p = calloc<Double>();
Expect.equals(0, p.value);
p.value = 3.14;
Expect.equals(3.14, p.value);
try {
Expect.equals(0, p.value);
p.value = 3.14;
Expect.equals(3.14, p.value);
} finally {
calloc.free(p);
}
}
14 changes: 9 additions & 5 deletions LibTest/ffi/Pointer/DoublePointer_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ import '../../../Utils/expect.dart';

void main() {
Pointer<Double> p1 = calloc<Double>(2);
Pointer<Double> p2 = new Pointer.fromAddress(p1.address + sizeOf<Double>());
p1.value = 1.1;
p2.value = 3.14;
Expect.equals(1.1, p1[0]);
Expect.equals(3.14, p1[1]);
try {
Pointer<Double> p2 = new Pointer.fromAddress(p1.address + sizeOf<Double>());
p1.value = 1.1;
p2.value = 3.14;
Expect.equals(1.1, p1[0]);
Expect.equals(3.14, p1[1]);
} finally {
calloc.free(p1);
}
}
16 changes: 10 additions & 6 deletions LibTest/ffi/Pointer/DoublePointer_A02_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ import '../../../Utils/expect.dart';

void main() {
Pointer<Double> p1 = calloc<Double>(2);
Pointer<Double> p2 = new Pointer.fromAddress(p1.address + sizeOf<Double>());
p1[0] = 1.1;
p1[1] = 3.14;
Expect.equals(1.1, p1[0]);
Expect.equals(3.14, p1[1]);
Expect.equals(3.14, p2.value);
try {
Pointer<Double> p2 = new Pointer.fromAddress(p1.address + sizeOf<Double>());
p1[0] = 1.1;
p1[1] = 3.14;
Expect.equals(1.1, p1[0]);
Expect.equals(3.14, p1[1]);
Expect.equals(3.14, p2.value);
} finally {
calloc.free(p1);
}
}
18 changes: 11 additions & 7 deletions LibTest/ffi/Pointer/Int16Pointer.asTypedList_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ import '../../../Utils/expect.dart';

void main() {
Pointer<Int16> p = calloc<Int16>(3);
p[0] = 3;
p[1] = 42;
p[2] = -1;
Int16List l = p.asTypedList(3);
Expect.equals(3, l[0]);
Expect.equals(42, l[1]);
Expect.equals(-1, l[2]);
try {
p[0] = 3;
p[1] = 42;
p[2] = -1;
Int16List l = p.asTypedList(3);
Expect.equals(3, l[0]);
Expect.equals(42, l[1]);
Expect.equals(-1, l[2]);
} finally {
calloc.free(p);
}
}
10 changes: 7 additions & 3 deletions LibTest/ffi/Pointer/Int16Pointer.value_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import '../../../Utils/expect.dart';

void main() {
Pointer<Int16> p = calloc<Int16>();
Expect.equals(0, p.value);
p.value = 42;
Expect.equals(42, p.value);
try {
Expect.equals(0, p.value);
p.value = 42;
Expect.equals(42, p.value);
} finally {
calloc.free(p);
}
}
14 changes: 9 additions & 5 deletions LibTest/ffi/Pointer/Int16Pointer.value_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ import '../../../Utils/expect.dart';

void main() {
Pointer<Int16> p = calloc<Int16>();
Expect.equals(0, p.value);
p.value = 500000;
Expect.equals(500000.toSigned(16), p.value);
p.value = -500000;
Expect.equals(-500000.toSigned(16), p.value);
try {
Expect.equals(0, p.value);
p.value = 500000;
Expect.equals(500000.toSigned(16), p.value);
p.value = -500000;
Expect.equals(-500000.toSigned(16), p.value);
} finally {
calloc.free(p);
}
}
14 changes: 9 additions & 5 deletions LibTest/ffi/Pointer/Int16Pointer_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ import '../../../Utils/expect.dart';

void main() {
Pointer<Int16> p1 = calloc<Int16>(2);
Pointer<Int16> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int16>());
p1.value = 1;
p2.value = 42;
Expect.equals(1, p1[0]);
Expect.equals(42, p1[1]);
try {
Pointer<Int16> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int16>());
p1.value = 1;
p2.value = 42;
Expect.equals(1, p1[0]);
Expect.equals(42, p1[1]);
} finally {
calloc.free(p1);
}
}
14 changes: 9 additions & 5 deletions LibTest/ffi/Pointer/Int16Pointer_A01_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ import '../../../Utils/expect.dart';

void main() {
Pointer<Int16> p1 = calloc<Int16>(2);
Pointer<Int16> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int16>());
p1.value = 500000;
p2.value = -500000;
Expect.equals(500000.toSigned(16), p1[0]);
Expect.equals(-500000.toSigned(16), p1[1]);
try {
Pointer<Int16> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int16>());
p1.value = 500000;
p2.value = -500000;
Expect.equals(500000.toSigned(16), p1[0]);
Expect.equals(-500000.toSigned(16), p1[1]);
} finally {
calloc.free(p1);
}
}
16 changes: 10 additions & 6 deletions LibTest/ffi/Pointer/Int16Pointer_A02_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ import '../../../Utils/expect.dart';

void main() {
Pointer<Int16> p1 = calloc<Int16>(2);
Pointer<Int16> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int16>());
p1[0] = 1;
p1[1] = 42;
Expect.equals(1, p1[0]);
Expect.equals(42, p1[1]);
Expect.equals(42, p2.value);
try {
Pointer<Int16> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int16>());
p1[0] = 1;
p1[1] = 42;
Expect.equals(1, p1[0]);
Expect.equals(42, p1[1]);
Expect.equals(42, p2.value);
} finally {
calloc.free(p1);
}
}
16 changes: 10 additions & 6 deletions LibTest/ffi/Pointer/Int16Pointer_A02_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ import '../../../Utils/expect.dart';

void main() {
Pointer<Int16> p1 = calloc<Int16>(2);
Pointer<Int16> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int16>());
p1[0] = 500000;
p1[1] = -500000;
Expect.equals(500000.toSigned(16), p1[0]);
Expect.equals(-500000.toSigned(16), p1[1]);
Expect.equals(-500000.toSigned(16), p2.value);
try {
Pointer<Int16> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int16>());
p1[0] = 500000;
p1[1] = -500000;
Expect.equals(500000.toSigned(16), p1[0]);
Expect.equals(-500000.toSigned(16), p1[1]);
Expect.equals(-500000.toSigned(16), p2.value);
} finally {
calloc.free(p1);
}
}
18 changes: 11 additions & 7 deletions LibTest/ffi/Pointer/Int32Pointer.asTypedList_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ import '../../../Utils/expect.dart';

void main() {
Pointer<Int32> p = calloc<Int32>(3);
p[0] = 3;
p[1] = 42;
p[2] = -1;
Int32List l = p.asTypedList(3);
Expect.equals(3, l[0]);
Expect.equals(42, l[1]);
Expect.equals(-1, l[2]);
try {
p[0] = 3;
p[1] = 42;
p[2] = -1;
Int32List l = p.asTypedList(3);
Expect.equals(3, l[0]);
Expect.equals(42, l[1]);
Expect.equals(-1, l[2]);
} finally {
calloc.free(p);
}
}
10 changes: 7 additions & 3 deletions LibTest/ffi/Pointer/Int32Pointer.value_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import '../../../Utils/expect.dart';

void main() {
Pointer<Int32> p = calloc<Int32>();
Expect.equals(0, p.value);
p.value = 42;
Expect.equals(42, p.value);
try {
Expect.equals(0, p.value);
p.value = 42;
Expect.equals(42, p.value);
} finally {
calloc.free(p);
}
}
14 changes: 9 additions & 5 deletions LibTest/ffi/Pointer/Int32Pointer.value_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ import '../../../Utils/expect.dart';

void main() {
Pointer<Int32> p = calloc<Int32>();
Expect.equals(0, p.value);
p.value = 5000000000;
Expect.equals(5000000000.toSigned(32), p.value);
p.value = -5000000000;
Expect.equals(-5000000000.toSigned(32), p.value);
try {
Expect.equals(0, p.value);
p.value = 5000000000;
Expect.equals(5000000000.toSigned(32), p.value);
p.value = -5000000000;
Expect.equals(-5000000000.toSigned(32), p.value);
} finally {
calloc.free(p);
}
}
14 changes: 9 additions & 5 deletions LibTest/ffi/Pointer/Int32Pointer_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ import '../../../Utils/expect.dart';

void main() {
Pointer<Int32> p1 = calloc<Int32>(2);
Pointer<Int32> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int32>());
p1.value = 1;
p2.value = 42;
Expect.equals(1, p1[0]);
Expect.equals(42, p1[1]);
try {
Pointer<Int32> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int32>());
p1.value = 1;
p2.value = 42;
Expect.equals(1, p1[0]);
Expect.equals(42, p1[1]);
} finally {
calloc.free(p1);
}
}
14 changes: 9 additions & 5 deletions LibTest/ffi/Pointer/Int32Pointer_A01_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ import '../../../Utils/expect.dart';

void main() {
Pointer<Int32> p1 = calloc<Int32>(2);
Pointer<Int32> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int32>());
p1.value = 5000000000;
p2.value = -5000000000;
Expect.equals(5000000000.toSigned(32), p1[0]);
Expect.equals(-5000000000.toSigned(32), p1[1]);
try {
Pointer<Int32> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int32>());
p1.value = 5000000000;
p2.value = -5000000000;
Expect.equals(5000000000.toSigned(32), p1[0]);
Expect.equals(-5000000000.toSigned(32), p1[1]);
} finally {
calloc.free(p1);
}
}
16 changes: 10 additions & 6 deletions LibTest/ffi/Pointer/Int32Pointer_A02_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ import '../../../Utils/expect.dart';

void main() {
Pointer<Int32> p1 = calloc<Int32>(2);
Pointer<Int32> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int32>());
p1[0] = 1;
p1[1] = 42;
Expect.equals(1, p1[0]);
Expect.equals(42, p1[1]);
Expect.equals(42, p2.value);
try {
Pointer<Int32> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int32>());
p1[0] = 1;
p1[1] = 42;
Expect.equals(1, p1[0]);
Expect.equals(42, p1[1]);
Expect.equals(42, p2.value);
} finally {
calloc.free(p1);
}
}
16 changes: 10 additions & 6 deletions LibTest/ffi/Pointer/Int32Pointer_A02_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ import '../../../Utils/expect.dart';

void main() {
Pointer<Int32> p1 = calloc<Int32>(2);
Pointer<Int32> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int32>());
p1[0] = 5000000000;
p1[1] = -5000000000;
Expect.equals(5000000000.toSigned(32), p1[0]);
Expect.equals(-5000000000.toSigned(32), p1[1]);
Expect.equals(-5000000000.toSigned(32), p2.value);
try {
Pointer<Int32> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int32>());
p1[0] = 5000000000;
p1[1] = -5000000000;
Expect.equals(5000000000.toSigned(32), p1[0]);
Expect.equals(-5000000000.toSigned(32), p1[1]);
Expect.equals(-5000000000.toSigned(32), p2.value);
} finally {
calloc.free(p1);
}
}
18 changes: 11 additions & 7 deletions LibTest/ffi/Pointer/Int64Pointer.asTypedList_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ import '../../../Utils/expect.dart';

void main() {
Pointer<Int64> p = calloc<Int64>(3);
p[0] = 3;
p[1] = 42;
p[2] = -1;
Int64List l = p.asTypedList(3);
Expect.equals(3, l[0]);
Expect.equals(42, l[1]);
Expect.equals(-1, l[2]);
try {
p[0] = 3;
p[1] = 42;
p[2] = -1;
Int64List l = p.asTypedList(3);
Expect.equals(3, l[0]);
Expect.equals(42, l[1]);
Expect.equals(-1, l[2]);
} finally {
calloc.free(p);
}
}
10 changes: 7 additions & 3 deletions LibTest/ffi/Pointer/Int64Pointer.value_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import '../../../Utils/expect.dart';

void main() {
Pointer<Int64> p = calloc<Int64>();
Expect.equals(0, p.value);
p.value = 42;
Expect.equals(42, p.value);
try {
Expect.equals(0, p.value);
p.value = 42;
Expect.equals(42, p.value);
} finally {
calloc.free(p);
}
}

0 comments on commit af65a1a

Please sign in to comment.