Add tests from vibe-d:core.

This commit is contained in:
Sönke Ludwig 2017-02-17 00:55:16 +01:00
parent 99bc332a81
commit 5a8d5a2fea
No known key found for this signature in database
GPG key ID: D95E8DB493EE314C
7 changed files with 354 additions and 0 deletions

View 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);
}