Beispiel #1
0
Handle<Value> Signal_Disconnect(const Arguments& args)
{
    HandleScope handle_scope;

    Signal* self = GetPtr(args.This());
    assert(self);

    if ((args.Length() == 2) && args[0]->IsObject() && args[1]->IsFunction())
    {
        self->disconnect(Persistent<Object>::New(args[0]->ToObject()),
                         Persistent<Object>::New(args[1]->ToObject()));
    }
    else if ((args.Length() == 1) && args[0]->IsFunction())
    {
        self->disconnect(Persistent<Object>::New(args[0]->ToObject()));
    }
    else
    {
        return ThrowException(String::New("Invalid parameters, valid syntax:\ndisconnect(object, function)\ndisconnect(function)"));
    }

    return Handle<Value>();
}
Beispiel #2
0
		int main(int argc, char **argv) {
			Signal<int(int)> sig;

			Test("disconnect non existing");
			{
				bool res;
				res = sig.disconnect(0);
				ASSERT(!res);
			}

			Test("connect");
			size_t id = sig.connect(Util::dummy);

			Test("single connection: check result");
			const int input = 100;
			auto numVal = sig.emit(input);
			auto val = sig.results();
			ASSERT(numVal == val->size());
			ASSERT(val->size() == 1);
			ASSERT((*val)[0] == Util::dummy(input));

			Test("multiple connections: check results");
			size_t id2 = sig.connect(dummy2);
			size_t id3 = sig.connect(Util::dummy);
			size_t id4 = sig.connect(dummy2);
			numVal = sig.emit(input);
			val = sig.results();
			ASSERT(numVal == val->size());
			ASSERT(val->size() == 4);
			ASSERT((*val)[0] == Util::dummy(input));
			ASSERT((*val)[1] == dummy2(input));
			ASSERT((*val)[2] == Util::dummy(input));
			ASSERT((*val)[3] == dummy2(input));

			Test("multiple connections: ask results again");
			auto val2 = sig.results();
			ASSERT(numVal == val2->size());
			ASSERT(val2->size() == 4);
			ASSERT((*val2)[0] == Util::dummy(input));
			ASSERT((*val2)[1] == dummy2(input));
			ASSERT((*val2)[2] == Util::dummy(input));
			ASSERT((*val2)[3] == dummy2(input));

			Test("disconnections");
			{
				bool res;
				res = sig.disconnect(id2);
				ASSERT(res);

				res = sig.disconnect(id);
				ASSERT(res);

				//disconnect again
				res = sig.disconnect(id);
				ASSERT(!res);

				//wrong id
				res = sig.disconnect(id + 1);
				ASSERT(!res);
			}

			return 0;
		}