Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 6805600

Browse files
thewilsonatorTurkeyMan
authored andcommitted
Add tests
1 parent ca75535 commit 6805600

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

test/stdcpp/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include ../common.mak
22

3-
TESTS:=array new
3+
TESTS:=array allocator new
44

55
.PHONY: all clean
66

test/stdcpp/src/allocator.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <memory>
2+
3+
struct MyStruct
4+
{
5+
int *a;
6+
double *b;
7+
MyStruct *c;
8+
};
9+
10+
MyStruct cpp_alloc()
11+
{
12+
MyStruct r;
13+
r.a = std::allocator<int>().allocate(42);
14+
r.b = std::allocator<double>().allocate(42);
15+
r.c = std::allocator<MyStruct>().allocate(42);
16+
return r;
17+
}
18+
19+
void cpp_free(MyStruct& s)
20+
{
21+
std::allocator<int>().deallocate(s.a, 43);
22+
std::allocator<double>().deallocate(s.b, 43);
23+
std::allocator<MyStruct>().deallocate(s.c, 43);
24+
}

test/stdcpp/src/allocator_test.d

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import core.stdcpp.allocator;
2+
3+
extern(C++) struct MyStruct
4+
{
5+
int* a;
6+
double* b;
7+
MyStruct* c;
8+
}
9+
10+
extern(C++) MyStruct cpp_alloc();
11+
extern(C++) void cpp_free(ref MyStruct s);
12+
13+
unittest
14+
{
15+
// alloc in C++, delete in D
16+
MyStruct s = cpp_alloc();
17+
allocator!int().deallocate(s.a, 42);
18+
allocator!double().deallocate(s.b, 42);
19+
allocator!MyStruct().deallocate(s.c, 42);
20+
21+
// alloc in D, delete in C++
22+
s.a = allocator!int().allocate(43);
23+
s.b = allocator!double().allocate(43);
24+
s.c = allocator!MyStruct().allocate(43);
25+
cpp_free(s);
26+
}

test/stdcpp/win64.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ MODEL=64
55
DRUNTIMELIB=druntime64.lib
66
CC=cl
77

8-
TESTS= array new
8+
TESTS= array allocator new
99

1010
test: $(TESTS)
1111

0 commit comments

Comments
 (0)