Add tests from vibe-d:core.
This commit is contained in:
parent
99bc332a81
commit
5a8d5a2fea
7 changed files with 354 additions and 0 deletions
51
tests/vibe.core.core.refcount.d
Normal file
51
tests/vibe.core.core.refcount.d
Normal file
|
@ -0,0 +1,51 @@
|
|||
/+ dub.sdl:
|
||||
name "tests"
|
||||
description "Invalid ref count after runTask"
|
||||
dependency "vibe-core" path="../"
|
||||
+/
|
||||
module test;
|
||||
import vibe.core.core;
|
||||
import std.stdio;
|
||||
|
||||
struct RC {
|
||||
int* rc;
|
||||
this(int* rc) { this.rc = rc; }
|
||||
this(this) {
|
||||
if (rc) {
|
||||
(*rc)++;
|
||||
writefln("addref %s", *rc);
|
||||
}
|
||||
}
|
||||
~this() {
|
||||
if (rc) {
|
||||
(*rc)--;
|
||||
writefln("release %s", *rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
int rc = 1;
|
||||
bool done = false;
|
||||
|
||||
{
|
||||
auto s = RC(&rc);
|
||||
assert(rc == 1);
|
||||
runTask((RC st) {
|
||||
assert(rc == 2);
|
||||
st = RC.init;
|
||||
assert(rc == 1);
|
||||
exitEventLoop();
|
||||
done = true;
|
||||
}, s);
|
||||
assert(rc == 2);
|
||||
}
|
||||
|
||||
assert(rc == 1);
|
||||
|
||||
runEventLoop();
|
||||
|
||||
assert(rc == 0);
|
||||
assert(done);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue