Skip to content

Commit 75ff615

Browse files
author
Aidan Lee
committed
Add scratch tests
1 parent e6f4203 commit 75ff615

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

test/native/Native.hx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class Native
1818
new tests.TestNativeEnum(),
1919

2020
#if (haxe_ver>=5)
21+
new tests.TestScratch(),
22+
2123
new tests.marshalling.classes.TestLocalValueType(),
2224
new tests.marshalling.classes.TestClassValueType(),
2325
new tests.marshalling.classes.TestInterfaceValueType(),

test/native/tests/TestScratch.hx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package tests;
2+
3+
import cpp.Scratch;
4+
import utest.Test;
5+
import utest.Assert;
6+
7+
using haxe.Int64;
8+
9+
class TestScratch extends Test {
10+
function test_zeroed_small_alloc() {
11+
final size = 16;
12+
final alloc = Scratch.alloc(size);
13+
14+
Assert.equals(size, alloc.view.length.toInt());
15+
16+
for (i in 0...size.toInt()) {
17+
Assert.equals(0, alloc.view[i]);
18+
}
19+
}
20+
21+
function test_zeroed_large_alloc() {
22+
final size = 100_000;
23+
final alloc = Scratch.alloc(size);
24+
25+
Assert.equals(size, alloc.view.length.toInt());
26+
27+
for (i in 0...size.toInt()) {
28+
Assert.equals(0, alloc.view[i]);
29+
}
30+
}
31+
32+
function test_contents_wiped() {
33+
{
34+
final size = 16;
35+
final alloc = Scratch.alloc(size);
36+
37+
Assert.equals(size, alloc.view.length.toInt());
38+
39+
alloc.view.fill(7);
40+
}
41+
42+
{
43+
final size = 16;
44+
final alloc = Scratch.alloc(size);
45+
46+
Assert.equals(size, alloc.view.length.toInt());
47+
48+
for (i in 0...size.toInt()) {
49+
Assert.equals(0, alloc.view[i]);
50+
}
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)