MCPcopy Create free account
hub / github.com/nodejs/nan / TlsTest

Class TlsTest

test/cpp/threadlocal.cpp:17–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15// Based on test-thread.c from libuv.
16
17class TlsTest : public AsyncWorker {
18 public:
19 explicit TlsTest(Tap *t) : AsyncWorker(NULL), t(t), i(0) {
20 t->plan(7);
21 t->ok(_(0 == nauv_key_create(&tls_key)));
22 t->ok(_(NULL == nauv_key_get(&tls_key)));
23 nauv_key_set(&tls_key, this);
24 t->ok(_(this == nauv_key_get(&tls_key)));
25 }
26 void Execute() {
27 ok(_(NULL == nauv_key_get(&tls_key)));
28 nauv_key_set(&tls_key, &i);
29 ok(_(&i == nauv_key_get(&tls_key)));
30 nauv_key_set(&tls_key, NULL);
31 ok(_(NULL == nauv_key_get(&tls_key)));
32 }
33 void WorkComplete() {
34 HandleScope scope;
35 for (unsigned j = 0; j < i; ++j)
36 t->ok(res[j].ok, res[j].msg);
37 nauv_key_delete(&tls_key);
38 t->ok(_(NULL == ErrorMessage()));
39 t->end();
40 delete t;
41 }
42
43 private:
44 nauv_key_t tls_key;
45
46 Tap *t;
47 struct { bool ok; const char* msg; } res[3];
48 unsigned i;
49 void ok(bool isOk, const char *msg) {
50 assert(i < sizeof(res)/sizeof(res[0]));
51 res[i].ok = isOk;
52 res[i].msg = msg;
53 ++i;
54 }
55};
56
57NAN_METHOD(thread_local_storage) {
58 Tap *t = new Tap(info[0]);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected